-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-4250] [SQL] Fix bug of constant null value mapping to ConstantObjectInspector #3114
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 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,6 +88,7 @@ private[hive] trait HiveInspectors { | |
| * @return convert the data into catalyst type | ||
| */ | ||
| def unwrap(data: Any, oi: ObjectInspector): Any = oi match { | ||
| case _ if data == null => null | ||
| case hvoi: HiveVarcharObjectInspector => | ||
| if (data == null) null else hvoi.getPrimitiveJavaObject(data).getValue | ||
| case hdoi: HiveDecimalObjectInspector => | ||
|
|
@@ -254,46 +255,59 @@ private[hive] trait HiveInspectors { | |
| } | ||
|
|
||
| def toInspector(expr: Expression): ObjectInspector = expr match { | ||
| case Literal(value: String, StringType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value) | ||
| case Literal(value: Int, IntegerType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value) | ||
| case Literal(value: Double, DoubleType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value) | ||
| case Literal(value: Boolean, BooleanType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value) | ||
| case Literal(value: Long, LongType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value) | ||
| case Literal(value: Float, FloatType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value) | ||
| case Literal(value: Short, ShortType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value) | ||
| case Literal(value: Byte, ByteType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value) | ||
| case Literal(value: Array[Byte], BinaryType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value) | ||
| case Literal(value: java.sql.Date, DateType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value) | ||
| case Literal(value: java.sql.Timestamp, TimestampType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value) | ||
| case Literal(value: BigDecimal, DecimalType()) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value) | ||
| case Literal(value: Decimal, DecimalType()) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value.toBigDecimal) | ||
| case Literal(value, StringType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value.asInstanceOf[String]) | ||
| case Literal(value, IntegerType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value.asInstanceOf[Int]) | ||
| case Literal(value, DoubleType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value.asInstanceOf[Double]) | ||
| case Literal(value, BooleanType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value.asInstanceOf[Boolean]) | ||
| case Literal(value, LongType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value.asInstanceOf[Long]) | ||
| case Literal(value, FloatType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value.asInstanceOf[Float]) | ||
| case Literal(value, ShortType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value.asInstanceOf[Short]) | ||
| case Literal(value, ByteType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value.asInstanceOf[Byte]) | ||
| case Literal(value, BinaryType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value.asInstanceOf[Array[Byte]]) | ||
| case Literal(value, DateType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value.asInstanceOf[java.sql.Date]) | ||
| case Literal(value, TimestampType) => | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector(value.asInstanceOf[java.sql.Timestamp]) | ||
| case Literal(value, DecimalType()) => | ||
| if (null == value) { | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector( | ||
| null.asInstanceOf[BigDecimal]) | ||
| } else { | ||
| HiveShim.getPrimitiveWritableConstantObjectInspector( | ||
|
Contributor
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. Nit: why remove this to only have to add a more verbose
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. We don't bind a type here, just to keep consistent with pattern match above, and it is also helpful in debugging, you know, sometimes we just confused what type for catalyst array ( |
||
| value.asInstanceOf[Decimal].toBigDecimal) | ||
| } | ||
| case Literal(_, NullType) => | ||
| HiveShim.getPrimitiveNullWritableConstantObjectInspector | ||
| case Literal(value: Seq[_], ArrayType(dt, _)) => | ||
| case Literal(value, ArrayType(dt, _)) => | ||
| val listObjectInspector = toInspector(dt) | ||
| val list = new java.util.ArrayList[Object]() | ||
| value.foreach(v => list.add(wrap(v, listObjectInspector))) | ||
| ObjectInspectorFactory.getStandardConstantListObjectInspector(listObjectInspector, list) | ||
| case Literal(map: Map[_, _], MapType(keyType, valueType, _)) => | ||
| val value = new java.util.HashMap[Object, Object]() | ||
| if (value == null) { | ||
| ObjectInspectorFactory.getStandardConstantListObjectInspector(listObjectInspector, null) | ||
| } else { | ||
| val list = new java.util.ArrayList[Object]() | ||
| value.asInstanceOf[Seq[_]].foreach(v => list.add(wrap(v, listObjectInspector))) | ||
| ObjectInspectorFactory.getStandardConstantListObjectInspector(listObjectInspector, list) | ||
| } | ||
| case Literal(value, MapType(keyType, valueType, _)) => | ||
| val keyOI = toInspector(keyType) | ||
| val valueOI = toInspector(valueType) | ||
| map.foreach (entry => value.put(wrap(entry._1, keyOI), wrap(entry._2, valueOI))) | ||
| ObjectInspectorFactory.getStandardConstantMapObjectInspector(keyOI, valueOI, value) | ||
| case Literal(_, dt) => sys.error(s"Hive doesn't support the constant type [$dt].") | ||
| if (value == null) { | ||
| ObjectInspectorFactory.getStandardConstantMapObjectInspector(keyOI, valueOI, null) | ||
| } else { | ||
| val map = new java.util.HashMap[Object, Object]() | ||
| value.asInstanceOf[Map[_, _]].foreach (entry => { | ||
| map.put(wrap(entry._1, keyOI), wrap(entry._2, valueOI)) | ||
| }) | ||
| ObjectInspectorFactory.getStandardConstantMapObjectInspector(keyOI, valueOI, map) | ||
| } | ||
| case _ => toInspector(expr.dataType) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 1 NULL 1 NULL 1.0 NULL true NULL 1 NULL 1.0 NULL 1 NULL 1 NULL 1 NULL 1970-01-01 NULL 1970-01-01 08:00:00.001 NULL 1 NULL |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| There is no documentation for function 'if' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| There is no documentation for function 'if' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 1 1 1 1 NULL 2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 128 1.1 ABC 12.3 |
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.
Why the cast here? This destroys null values:
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.
Oh, thanks, I thought it will be considered as Boxed primitives.