Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address comment.
  • Loading branch information
viirya committed Apr 10, 2018
commit 912c2c2f954bc53be1d4b80f47ee1d2774f382f6
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ object InternalRow {
case t: StructType => (input) => input.getStruct(ordinal, t.size)
case _: ArrayType => (input) => input.getArray(ordinal)
case _: MapType => (input) => input.getMap(ordinal)
case u: UserDefinedType[_] => getAccessor(u.sqlType, ordinal)
case _ => (input) => input.get(ordinal, dataType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle UDT?

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ case class BoundReference(ordinal: Int, dataType: DataType, nullable: Boolean)

override def toString: String = s"input[$ordinal, ${dataType.simpleString}, $nullable]"

private lazy val accessor: InternalRow => Any = InternalRow.getAccessor(dataType, ordinal)
private val accessor: InternalRow => Any = InternalRow.getAccessor(dataType, ordinal)

// Use special getter for primitive types (for UnsafeRow)
override def eval(input: InternalRow): Any = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ case class LambdaVariable(
dataType: DataType,
nullable: Boolean = true) extends LeafExpression with NonSQLExpression {

private lazy val accessor: InternalRow => Any = InternalRow.getAccessor(dataType, 0)
private val accessor: InternalRow => Any = InternalRow.getAccessor(dataType, 0)

// Interpreted execution of `LambdaVariable` always get the 0-index element from input row.
override def eval(input: InternalRow): Any = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,19 @@ trait ExpressionEvalHelper extends GeneratorDrivenPropertyChecks {
checkEvaluationWithOptimization(expr, catalystValue, inputRow)
}


private def getActualDataType(dt: DataType): DataType = dt match {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a similar method to the UserDefinedType companion. Which one shall we add?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can use the method you added.

case u: UserDefinedType[_] => getActualDataType(u.sqlType)
case _ => dt
}

/**
* Check the equality between result of expression and expected value, it will handle
* Array[Byte], Spread[Double], MapData and Row.
*/
protected def checkResult(result: Any, expected: Any, dataType: DataType): Boolean = {
protected def checkResult(result: Any, expected: Any, exprDataType: DataType): Boolean = {
val dataType = getActualDataType(exprDataType)

(result, expected) match {
case (result: Array[Byte], expected: Array[Byte]) =>
java.util.Arrays.equals(result, expected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.apache.spark.serializer.{JavaSerializer, KryoSerializer}
import org.apache.spark.sql.{RandomDataGenerator, Row}
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.analysis.ResolveTimeZone
import org.apache.spark.sql.catalyst.encoders.{ExpressionEncoder, RowEncoder}
import org.apache.spark.sql.catalyst.encoders.{ExamplePointUDT, ExpressionEncoder, RowEncoder}
import org.apache.spark.sql.catalyst.expressions.codegen.GenerateUnsafeProjection
import org.apache.spark.sql.catalyst.expressions.objects._
import org.apache.spark.sql.catalyst.util.{ArrayBasedMapData, ArrayData, GenericArrayData}
Expand Down Expand Up @@ -282,7 +282,7 @@ class ObjectExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
test("LambdaVariable should support interpreted execution") {
val elementTypes = Seq(BooleanType, ByteType, ShortType, IntegerType, LongType, FloatType,
DoubleType, DecimalType.USER_DEFAULT, StringType, BinaryType, DateType, TimestampType,
CalendarIntervalType)
CalendarIntervalType, new ExamplePointUDT())
val arrayTypes = elementTypes.flatMap { elementType =>
Seq(ArrayType(elementType, containsNull = false), ArrayType(elementType, containsNull = true))
}
Expand Down