cloud-fan commented on a change in pull request #30504:
URL: https://github.com/apache/spark/pull/30504#discussion_r532447405
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -873,24 +873,30 @@ object InferFiltersFromGenerate extends Rule[LogicalPlan]
{
if !e.deterministic || e.children.forall(_.foldable) => generate
case generate @ Generate(g, _, false, _, _, _) if canInferFilters(g) =>
- // Exclude child's constraints to guarantee idempotency
- val inferredFilters = ExpressionSet(
- Seq(
- GreaterThan(Size(g.children.head), Literal(0)),
- IsNotNull(g.children.head)
- )
- ) -- generate.child.constraints
-
- if (inferredFilters.nonEmpty) {
- generate.copy(child = Filter(inferredFilters.reduce(And),
generate.child))
- } else {
- generate
+ g.children.head match {
+ case _: CreateNonEmptyNonNullCollection =>
+ // we don't need to add filters when creating an array because we
know its size
+ // is > 0 and its not null
+ generate
+ case _ =>
+ // Exclude child's constraints to guarantee idempotency
+ val inferredFilters = ExpressionSet(
+ Seq(
+ GreaterThan(Size(g.children.head), Literal(0)),
+ IsNotNull(g.children.head)
Review comment:
The semantic of an expression is decided by the expression itself, not
by where we create the expression.
Looking at it again, I think what's 100% safe is we can turn
`Size(CreateArray)` to `CreateArray.children.length`, e.g.
```
case Size(c: CreateArray) => Literal(c.children.length)
case Size(c: CreateMap) => Literal(c.children.length / 2)
```
We can put this in rule `ConstantFolding`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]