Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/7658#discussion_r35781012
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateUnsafeProjection.scala
---
@@ -32,25 +31,43 @@ import org.apache.spark.sql.types.{NullType,
BinaryType, StringType}
*/
object GenerateUnsafeProjection extends CodeGenerator[Seq[Expression],
UnsafeProjection] {
- protected def canonicalize(in: Seq[Expression]): Seq[Expression] =
- in.map(ExpressionCanonicalizer.execute)
+ private val StringWriter =
classOf[UnsafeRowWriters.UTF8StringWriter].getName
+ private val BinaryWriter = classOf[UnsafeRowWriters.BinaryWriter].getName
- protected def bind(in: Seq[Expression], inputSchema: Seq[Attribute]):
Seq[Expression] =
- in.map(BindReferences.bindReference(_, inputSchema))
+ /** Returns true iff we support this data type. */
+ def canSupport(dataType: DataType): Boolean = dataType match {
+ case t: AtomicType if !t.isInstanceOf[DecimalType] => true
+ case NullType => true
+ case _ => false
+ }
+
+ /**
+ * Generates the code to create an [[UnsafeRow]] object based on the
input expressions.
+ * @param ctx context for code generation
+ * @param ev specifies the name of the variable for the output
[[UnsafeRow]] object
+ * @param expressions input expressions
+ * @return generated code to put the expression output into an
[[UnsafeRow]]
+ */
+ def createCode(ctx: CodeGenContext, ev: GeneratedExpressionCode,
expressions: Seq[Expression])
+ : String = {
+
+ val ret = ev.primitive
+ ctx.addMutableState("UnsafeRow", ret, s"$ret = new UnsafeRow();")
+ val bufferTerm = ctx.freshName("buffer")
+ ctx.addMutableState("byte[]", bufferTerm, s"$bufferTerm = new
byte[64];")
--- End diff --
so we can reuse a byte array for all rows
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]