Skip to content

Commit 3c4938e

Browse files
viiryayhuai
authored andcommitted
[SPARK-11949][SQL] Check bitmasks to set nullable property
Following up apache#10038. We can use bitmasks to determine which grouping expressions need to be set as nullable. cc yhuai Author: Liang-Chi Hsieh <viirya@appier.com> Closes apache#10067 from viirya/fix-cube-following. (cherry picked from commit 0f37d1d) Signed-off-by: Yin Huai <yhuai@databricks.com>
1 parent 1f42295 commit 3c4938e

File tree

1 file changed

+9
-4
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis

1 file changed

+9
-4
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,15 @@ class Analyzer(
224224
case other => Alias(other, other.toString)()
225225
}
226226

227-
// TODO: We need to use bitmasks to determine which grouping expressions need to be
228-
// set as nullable. For example, if we have GROUPING SETS ((a,b), a), we do not need
229-
// to change the nullability of a.
230-
val attributeMap = groupByAliases.map(a => (a -> a.toAttribute.withNullability(true))).toMap
227+
val nonNullBitmask = x.bitmasks.reduce(_ & _)
228+
229+
val attributeMap = groupByAliases.zipWithIndex.map { case (a, idx) =>
230+
if ((nonNullBitmask & 1 << idx) == 0) {
231+
(a -> a.toAttribute.withNullability(true))
232+
} else {
233+
(a -> a.toAttribute)
234+
}
235+
}.toMap
231236

232237
val aggregations: Seq[NamedExpression] = x.aggregations.map {
233238
// If an expression is an aggregate (contains a AggregateExpression) then we dont change

0 commit comments

Comments
 (0)