Skip to content
Closed
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,15 @@ class Analyzer(
case other => Alias(other, other.toString)()
}

// TODO: We need to use bitmasks to determine which grouping expressions need to be
// set as nullable. For example, if we have GROUPING SETS ((a,b), a), we do not need
// to change the nullability of a.
val attributeMap = groupByAliases.map(a => (a -> a.toAttribute.withNullability(true))).toMap
val nonNullBitmask = x.bitmasks.reduce(_ & _)

val attributeMap = groupByAliases.zipWithIndex.map { case (a, idx) =>
if ((nonNullBitmask & 1 << idx) == 0) {
(a -> a.toAttribute.withNullability(true))
} else {
(a -> a.toAttribute)
}
}.toMap
Copy link
Contributor

Choose a reason for hiding this comment

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

c87531b#commitcomment-14712726 looks like a good idea.

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 think we did the same thing? I can't see the difference between this and @hvanhovell's suggestion?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is the same thing. I only suggested to aggregate the bitmap in advance: val nonNullBitmask = x.bitmasks.reduce(_ & _) and to use the nonNullBitmask to check for (non) nullability in the loop. It should be a tiny tiny tiny bit quicker (no re-iteration required , and less one closure).

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. That's cool. I updated this according to your suggestion.


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