forked from apache/hudi
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HUDI-5347] Cleaned up transient state from
ExpressionPayload
makin…
…g it non-serializable (apache#7424) - Internal state (cached records, writer schemas) are removed to make sure that `ExpressionPayload` object is serializable at all times. - `ExpressionPayload` caches are scoped down to `ThreadLocal` since some of the re-used components (AvroSerializer, AvroDeserializer, SafeProjection) have internal mutable state and therefore are not thread-safe
- Loading branch information
1 parent
6cd17aa
commit 3067881
Showing
2 changed files
with
172 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...hudi-spark2/src/main/scala/org/apache/spark/sql/catalyst/expressions/SafeProjection.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.catalyst.expressions | ||
|
||
import org.apache.spark.sql.catalyst.expressions.codegen.GenerateSafeProjection | ||
import org.apache.spark.sql.types.{DataType, StructType} | ||
|
||
/** | ||
* A projection that could turn UnsafeRow into GenericInternalRow | ||
* | ||
* NOTE: PLEASE REFRAIN MAKING ANY CHANGES TO THIS CODE UNLESS ABSOLUTELY NECESSARY | ||
* This code is borrowed from Spark 3.1.x | ||
* This code is borrowed, to fill in the gaps of Spark 2.x | ||
*/ | ||
object SafeProjection extends CodeGeneratorWithInterpretedFallback[Seq[Expression], Projection] { | ||
|
||
override protected def createCodeGeneratedObject(in: Seq[Expression]): Projection = { | ||
GenerateSafeProjection.generate(in) | ||
} | ||
|
||
override protected def createInterpretedObject(in: Seq[Expression]): Projection = { | ||
throw new UnsupportedOperationException("Interpreted safe projection is not supported for Spark 2.x!") | ||
} | ||
|
||
/** | ||
* Returns a SafeProjection for given StructType. | ||
*/ | ||
def create(schema: StructType): Projection = create(schema.fields.map(_.dataType)) | ||
|
||
/** | ||
* Returns a SafeProjection for given Array of DataTypes. | ||
*/ | ||
def create(fields: Array[DataType]): Projection = { | ||
createObject(fields.zipWithIndex.map(x => new BoundReference(x._2, x._1, true))) | ||
} | ||
|
||
/** | ||
* Returns a SafeProjection for given sequence of Expressions (bounded). | ||
*/ | ||
def create(exprs: Seq[Expression]): Projection = { | ||
createObject(exprs) | ||
} | ||
|
||
/** | ||
* Returns a SafeProjection for given sequence of Expressions, which will be bound to | ||
* `inputSchema`. | ||
*/ | ||
def create(exprs: Seq[Expression], inputSchema: Seq[Attribute]): Projection = { | ||
create(bindReferences(exprs, inputSchema)) | ||
} | ||
|
||
/** | ||
* A helper function to bind given expressions to an input schema. | ||
*/ | ||
private def bindReferences[A <: Expression]( | ||
expressions: Seq[A], | ||
input: AttributeSeq): Seq[A] = { | ||
expressions.map(BindReferences.bindReference(_, input)) | ||
} | ||
} |