-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-12335][SPARK-12336][SPARK-12341][SPARK-12342][SQL] Fixes several expression nullablility bugs #10296
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
[SPARK-12335][SPARK-12336][SPARK-12341][SPARK-12342][SQL] Fixes several expression nullablility bugs #10296
Changes from 7 commits
b2ea6aa
7b1600c
b84eb6a
02ad870
aa968e6
d84478e
05c36e5
d540b86
7e35e37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,10 +69,29 @@ case class BoundReference(ordinal: Int, dataType: DataType, nullable: Boolean) | |
| override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = { | ||
| val javaType = ctx.javaType(dataType) | ||
| val value = ctx.getValue(ctx.INPUT_ROW, dataType, ordinal.toString) | ||
| s""" | ||
| boolean ${ev.isNull} = ${ctx.INPUT_ROW}.isNullAt($ordinal); | ||
| $javaType ${ev.value} = ${ev.isNull} ? ${ctx.defaultValue(dataType)} : ($value); | ||
| """ | ||
|
|
||
| if (nullable) { | ||
| s""" | ||
| boolean ${ev.isNull} = ${ctx.INPUT_ROW}.isNullAt($ordinal); | ||
| $javaType ${ev.value} = ${ev.isNull} ? ${ctx.defaultValue(dataType)} : ($value); | ||
| """ | ||
| } else { | ||
| s""" | ||
| boolean ${ev.isNull} = ${ctx.INPUT_ROW}.isNullAt($ordinal); | ||
| $javaType ${ev.value}; | ||
|
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. Should we assign a default value for it? Or I'm afraid it can't compile...
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 should work under standard Java. Will double check how Janino behaves though. Update: it works as expected. |
||
| if (!${ev.isNull}) { | ||
| ${ev.value} = ($value); | ||
| } else { | ||
| throw new RuntimeException( | ||
| "Null value appeared in non-nullable field: " + | ||
| "ordinal=$ordinal, dataType=${dataType.simpleString}. " + | ||
| "If the schema is inferred from a Scala tuple/case class, or a Java bean, " + | ||
| "please try to use scala.Option[_] or other nullable types " + | ||
| "(e.g. java.lang.Integer instead of int/scala.Int)." | ||
| ); | ||
| } | ||
| """ | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,7 @@ abstract class CentralMomentAgg(child: Expression) extends ImperativeAggregate w | |
|
|
||
| override def children: Seq[Expression] = Seq(child) | ||
|
|
||
| override def nullable: Boolean = false | ||
| override def nullable: Boolean = true | ||
|
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 SPARK-12335. |
||
|
|
||
| override def dataType: DataType = DoubleType | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,6 @@ package org.apache.spark.sql.catalyst.expressions.aggregate | |
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.catalyst.analysis.TypeCheckResult | ||
| import org.apache.spark.sql.catalyst.expressions._ | ||
| import org.apache.spark.sql.catalyst.util.TypeUtils | ||
| import org.apache.spark.sql.types._ | ||
|
|
||
| /** | ||
|
|
@@ -42,7 +41,7 @@ case class Corr( | |
|
|
||
| override def children: Seq[Expression] = Seq(left, right) | ||
|
|
||
| override def nullable: Boolean = false | ||
| override def nullable: Boolean = true | ||
|
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 SPARK-12342. |
||
|
|
||
| override def dataType: DataType = DoubleType | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -499,10 +499,16 @@ class DataFrame private[sql]( | |
| // Analyze the self join. The assumption is that the analyzer will disambiguate left vs right | ||
| // by creating a new instance for one of the branch. | ||
| val joined = sqlContext.executePlan( | ||
| Join(logicalPlan, right.logicalPlan, joinType = Inner, None)).analyzed.asInstanceOf[Join] | ||
| Join(logicalPlan, right.logicalPlan, joinType = JoinType(joinType), None) | ||
| ).analyzed.asInstanceOf[Join] | ||
|
|
||
| // Project only one of the join columns. | ||
| val joinedCols = usingColumns.map(col => withPlan(joined.right).resolve(col)) | ||
| // | ||
| // SPARK-12336: For outer joins, attributes of at least one child plan output will be forced to | ||
| // be nullable. An `AttributeSet` is necessary so that we are not affected by different | ||
| // nullability values. | ||
| val joinedCols = AttributeSet(usingColumns.map(col => withPlan(joined.right).resolve(col))) | ||
|
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. should we rename this to
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. I think it's OK. The first line of the comment above already explained the purpose of this variable. |
||
|
|
||
| val condition = usingColumns.map { col => | ||
| catalyst.expressions.EqualTo( | ||
| withPlan(joined.left).resolve(col), | ||
|
|
@@ -514,12 +520,7 @@ class DataFrame private[sql]( | |
| withPlan { | ||
| Project( | ||
| joined.output.filterNot(joinedCols.contains(_)), | ||
| Join( | ||
| joined.left, | ||
| joined.right, | ||
| joinType = JoinType(joinType), | ||
| condition) | ||
| ) | ||
| joined.copy(condition = condition)) | ||
|
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. Changes in this file fixes SPARK-12336. |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ case class DescribeCommand( | |
| new MetadataBuilder().putString("comment", "name of the column").build())(), | ||
| AttributeReference("data_type", StringType, nullable = false, | ||
| new MetadataBuilder().putString("comment", "data type of the column").build())(), | ||
| AttributeReference("comment", StringType, nullable = false, | ||
| AttributeReference("comment", StringType, nullable = true, | ||
|
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 SPARK-12341. |
||
| new MetadataBuilder().putString("comment", "comment of the column").build())() | ||
| ) | ||
| } | ||
|
|
||
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.
I think ideally we would not do this check at all when
nullable = false.