-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-27255][SQL] Report error when illegal expressions are hosted by a plan operator. #24209
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
Changes from all commits
77b64db
2bc8e3a
2ed1360
5fac069
a86114d
3ae6cd0
f2e5174
f664d1c
bbab4c1
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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.catalyst.plans.logical | ||
|
|
||
| import org.apache.spark.sql.catalyst.expressions.{Expression, Generator, WindowExpression} | ||
| import org.apache.spark.sql.catalyst.expressions.aggregate.AggregateExpression | ||
|
|
||
| /** | ||
| * [[PlanHelper]] contains utility methods that can be used by Analyzer and Optimizer. | ||
| * It can also be container of methods that are common across multiple rules in Analyzer | ||
| * and Optimizer. | ||
| */ | ||
| object PlanHelper { | ||
| /** | ||
| * Check if there's any expression in this query plan operator that is | ||
| * - A WindowExpression but the plan is not Window | ||
| * - An AggregateExpresion but the plan is not Aggregate or Window | ||
| * - A Generator but the plan is not Generate | ||
| * Returns the list of invalid expressions that this operator hosts. This can happen when | ||
| * 1. The input query from users contain invalid expressions. | ||
| * Example : SELECT * FROM tab WHERE max(c1) > 0 | ||
| * 2. Query rewrites inadvertently produce plans that are invalid. | ||
| */ | ||
| def specialExpressionsInUnsupportedOperator(plan: LogicalPlan): Seq[Expression] = { | ||
| val exprs = plan.expressions | ||
| val invalidExpressions = exprs.flatMap { root => | ||
| root.collect { | ||
| case e: WindowExpression | ||
| if !plan.isInstanceOf[Window] => e | ||
| case e: AggregateExpression | ||
| if !(plan.isInstanceOf[Aggregate] || plan.isInstanceOf[Window]) => e | ||
| case e: Generator | ||
| if !plan.isInstanceOf[Generate] => e | ||
| } | ||
| } | ||
| invalidExpressions | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,9 +70,10 @@ Resolved attribute(s) t2b#x missing from min(t2a)#x,t2c#x in operator !Filter t2 | |
| SELECT t1a | ||
| FROM t1 | ||
| GROUP BY 1 | ||
| HAVING EXISTS (SELECT 1 | ||
| HAVING EXISTS (SELECT t2a | ||
|
||
| FROM t2 | ||
| WHERE t2a < min(t1a + t2a)) | ||
| GROUP BY 1 | ||
| HAVING t2a < min(t1a + t2a)) | ||
| -- !query 5 schema | ||
| struct<> | ||
| -- !query 5 output | ||
|
|
||
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.
BTW how about
SELECT max(c1) FROM tab WHERE max(c1) > 0? Does it work?Uh oh!
There was an error while loading. Please reload this page.
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.
@cloud-fan No, this case does not work. But this should work and i have a test case for this.