cloud-fan commented on a change in pull request #34823:
URL: https://github.com/apache/spark/pull/34823#discussion_r763290443
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -1178,16 +1178,24 @@ object InferFiltersFromGenerate extends
Rule[LogicalPlan] {
e.children.exists(_.isInstanceOf[UserDefinedExpression]) => 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))
+ val input = g.children.head
+ // Generating extra predicates here has overheads/risks:
+ // - We may evaluate expensive input expressions multiple times.
+ // - We may infer too many constraints later.
+ // - The input expression may fail to be evaluated under ANSI mode. If
we reorder the
+ // predicates and evaluate the input expression first, we may fail
the query unexpectedly.
+ // To be safe, here we only generate extra predicates if the input is an
attribute.
+ if (input.isInstanceOf[Attribute]) {
Review comment:
It's almost useless to generate predicate with `CreateArray/CreateMap`.
`Size(CreateArray(...))` is always true unless you create an empty array.
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -1178,16 +1178,24 @@ object InferFiltersFromGenerate extends
Rule[LogicalPlan] {
e.children.exists(_.isInstanceOf[UserDefinedExpression]) => 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))
+ val input = g.children.head
+ // Generating extra predicates here has overheads/risks:
+ // - We may evaluate expensive input expressions multiple times.
+ // - We may infer too many constraints later.
+ // - The input expression may fail to be evaluated under ANSI mode. If
we reorder the
+ // predicates and evaluate the input expression first, we may fail
the query unexpectedly.
+ // To be safe, here we only generate extra predicates if the input is an
attribute.
+ if (input.isInstanceOf[Attribute]) {
Review comment:
It's almost useless to generate predicate with `CreateArray/CreateMap`.
`Size(CreateArray(...)) > 0` is always true unless you create an empty array.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]