-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-23951][SQL] Use actual java class instead of string representation. #21026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
821e08a
0b194ca
45d3ed8
2488007
b2c1601
8ab0931
ce39905
e6abd22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,9 +19,10 @@ package org.apache.spark.sql.catalyst.expressions.codegen | |
|
|
||
| import scala.annotation.tailrec | ||
|
|
||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.catalyst.expressions._ | ||
| import org.apache.spark.sql.catalyst.expressions.aggregate.NoOp | ||
| import org.apache.spark.sql.catalyst.util.{ArrayBasedMapData, GenericArrayData} | ||
| import org.apache.spark.sql.catalyst.util.{ArrayBasedMapData, ArrayData, GenericArrayData, MapData} | ||
| import org.apache.spark.sql.types._ | ||
|
|
||
| /** | ||
|
|
@@ -53,9 +54,10 @@ object GenerateSafeProjection extends CodeGenerator[Seq[Expression], Projection] | |
| val rowClass = classOf[GenericInternalRow].getName | ||
|
|
||
| val fieldWriters = schema.map(_.dataType).zipWithIndex.map { case (dt, i) => | ||
| val converter = convertToSafe(ctx, | ||
| StatementValue(CodeGenerator.getValue(tmpInput, dt, i.toString), | ||
| CodeGenerator.javaType(dt)), dt) | ||
| val converter = convertToSafe( | ||
| ctx, | ||
| JavaCode.expression(CodeGenerator.getValue(tmpInput, dt, i.toString), dt), | ||
| dt) | ||
| s""" | ||
| if (!$tmpInput.isNullAt($i)) { | ||
| ${converter.code} | ||
|
|
@@ -76,7 +78,7 @@ object GenerateSafeProjection extends CodeGenerator[Seq[Expression], Projection] | |
| |final InternalRow $output = new $rowClass($values); | ||
| """.stripMargin | ||
|
|
||
| ExprCode(code, FalseLiteral, VariableValue(output, "InternalRow")) | ||
| ExprCode(code, FalseLiteral, VariableValue(output, classOf[InternalRow])) | ||
|
||
| } | ||
|
|
||
| private def createCodeForArray( | ||
|
|
@@ -91,9 +93,10 @@ object GenerateSafeProjection extends CodeGenerator[Seq[Expression], Projection] | |
| val index = ctx.freshName("index") | ||
| val arrayClass = classOf[GenericArrayData].getName | ||
|
|
||
| val elementConverter = convertToSafe(ctx, | ||
| StatementValue(CodeGenerator.getValue(tmpInput, elementType, index), | ||
| CodeGenerator.javaType(elementType)), elementType) | ||
| val elementConverter = convertToSafe( | ||
| ctx, | ||
| JavaCode.expression(CodeGenerator.getValue(tmpInput, elementType, index), elementType), | ||
| elementType) | ||
| val code = s""" | ||
| final ArrayData $tmpInput = $input; | ||
| final int $numElements = $tmpInput.numElements(); | ||
|
|
@@ -107,7 +110,7 @@ object GenerateSafeProjection extends CodeGenerator[Seq[Expression], Projection] | |
| final ArrayData $output = new $arrayClass($values); | ||
| """ | ||
|
|
||
| ExprCode(code, FalseLiteral, VariableValue(output, "ArrayData")) | ||
| ExprCode(code, FalseLiteral, VariableValue(output, classOf[ArrayData])) | ||
|
||
| } | ||
|
|
||
| private def createCodeForMap( | ||
|
|
@@ -128,7 +131,7 @@ object GenerateSafeProjection extends CodeGenerator[Seq[Expression], Projection] | |
| final MapData $output = new $mapClass(${keyConverter.value}, ${valueConverter.value}); | ||
| """ | ||
|
|
||
| ExprCode(code, FalseLiteral, VariableValue(output, "MapData")) | ||
| ExprCode(code, FalseLiteral, VariableValue(output, classOf[MapData])) | ||
|
||
| } | ||
|
|
||
| @tailrec | ||
|
|
@@ -140,7 +143,7 @@ object GenerateSafeProjection extends CodeGenerator[Seq[Expression], Projection] | |
| case ArrayType(elementType, _) => createCodeForArray(ctx, input, elementType) | ||
| case MapType(keyType, valueType, _) => createCodeForMap(ctx, input, keyType, valueType) | ||
| case udt: UserDefinedType[_] => convertToSafe(ctx, input, udt.sqlType) | ||
| case _ => ExprCode("", FalseLiteral, input) | ||
| case _ => ExprCode(FalseLiteral, input) | ||
| } | ||
|
|
||
| protected def create(expressions: Seq[Expression]): Projection = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,9 +52,9 @@ object GenerateUnsafeProjection extends CodeGenerator[Seq[Expression], UnsafePro | |
| // Puts `input` in a local variable to avoid to re-evaluate it if it's a statement. | ||
| val tmpInput = ctx.freshName("tmpInput") | ||
| val fieldEvals = fieldTypes.zipWithIndex.map { case (dt, i) => | ||
| ExprCode("", StatementValue(s"$tmpInput.isNullAt($i)", CodeGenerator.JAVA_BOOLEAN), | ||
| StatementValue(CodeGenerator.getValue(tmpInput, dt, i.toString), | ||
| CodeGenerator.javaType(dt))) | ||
| ExprCode( | ||
| JavaCode.isNullExpression(s"$tmpInput.isNullAt($i)"), | ||
| JavaCode.expression(CodeGenerator.getValue(tmpInput, dt, i.toString), dt)) | ||
| } | ||
|
|
||
| val rowWriterClass = classOf[UnsafeRowWriter].getName | ||
|
|
@@ -144,7 +144,7 @@ object GenerateUnsafeProjection extends CodeGenerator[Seq[Expression], UnsafePro | |
| case _ => s"$rowWriter.write($index, ${input.value});" | ||
| } | ||
|
|
||
| if (input.isNull == "false") { | ||
| if (input.isNull == FalseLiteral) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes an existing bug :) |
||
| s""" | ||
| ${input.code} | ||
| ${writeField.trim} | ||
|
|
@@ -337,8 +337,7 @@ object GenerateUnsafeProjection extends CodeGenerator[Seq[Expression], UnsafePro | |
| $writeExpressions | ||
| """ | ||
| // `rowWriter` is declared as a class field, so we can access it directly in methods. | ||
| ExprCode(code, FalseLiteral, StatementValue(s"$rowWriter.getRow()", "UnsafeRow", | ||
| canDirectAccess = true)) | ||
| ExprCode(code, FalseLiteral, SimpleExprValue(s"$rowWriter.getRow()", classOf[UnsafeRow])) | ||
|
||
| } | ||
|
|
||
| protected def canonicalize(in: Seq[Expression]): Seq[Expression] = | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops