Skip to content
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

[SPARK-35069][SQL] TRANSFORM forbidden DISTICNT and ALL, also make the error clear #32149

Closed
Closed
Show file tree
Hide file tree
Changes from 2 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 @@ -524,9 +524,9 @@ querySpecification
;

transformClause
: (SELECT kind=TRANSFORM '(' namedExpressionSeq ')'
| kind=MAP namedExpressionSeq
| kind=REDUCE namedExpressionSeq)
: (SELECT kind=TRANSFORM '(' setQuantifier? namedExpressionSeq ')'
| kind=MAP setQuantifier? namedExpressionSeq
| kind=REDUCE setQuantifier? namedExpressionSeq)
inRowFormat=rowFormat?
(RECORDWRITER recordWriter=STRING)?
USING script=STRING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,9 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
havingClause: HavingClauseContext,
windowClause: WindowClauseContext,
relation: LogicalPlan): LogicalPlan = withOrigin(ctx) {
if (transformClause.setQuantifier != null) {
throw QueryParsingErrors.transformNotSupportQuantifierError(transformClause.setQuantifier)
}
// Create the attributes.
val (attributes, schemaLess) = if (transformClause.colTypeList != null) {
// Typed return columns.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ object QueryParsingErrors {
new ParseException("DISTRIBUTE BY is not supported", ctx)
}

def transformNotSupportQuantifierError(ctx: ParserRuleContext): Throwable = {
new ParseException("TRANSFORM not support quantifier DISTINCT/ALL " +
AngersZhuuuu marked this conversation as resolved.
Show resolved Hide resolved
"for input expression seq", ctx)
AngersZhuuuu marked this conversation as resolved.
Show resolved Hide resolved
}

def transformWithSerdeUnsupportedError(ctx: ParserRuleContext): Throwable = {
new ParseException("TRANSFORM with serde is only supported in hive mode", ctx)
}
Expand Down
14 changes: 12 additions & 2 deletions sql/core/src/test/resources/sql-tests/inputs/transform.sql
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ SET spark.sql.legacy.parser.havingWithoutGroupByAsWhere=false;
SET spark.sql.parser.quotedRegexColumnNames=true;

SELECT TRANSFORM(`(a|b)?+.+`)
USING 'cat' AS (c)
USING 'cat' AS (c)
FROM script_trans;

SET spark.sql.parser.quotedRegexColumnNames=false;
Expand All @@ -320,4 +320,14 @@ SET spark.sql.parser.quotedRegexColumnNames=false;
WITH temp AS (
SELECT TRANSFORM(a) USING 'cat' AS (b string) FROM t
)
SELECT t1.b FROM temp t1 JOIN temp t2 ON t1.b = t2.b
SELECT t1.b FROM temp t1 JOIN temp t2 ON t1.b = t2.b;

SELECT TRANSFORM(DISTINCT b, a, c)
USING 'cat' AS (a, b, c)
FROM script_trans
WHERE a <= 4;

SELECT TRANSFORM(ALL b, a, c)
USING 'cat' AS (a, b, c)
FROM script_trans
WHERE a <= 4;
45 changes: 43 additions & 2 deletions sql/core/src/test/resources/sql-tests/results/transform.sql.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 42
-- Number of queries: 44


-- !query
Expand Down Expand Up @@ -610,7 +610,7 @@ spark.sql.parser.quotedRegexColumnNames true

-- !query
SELECT TRANSFORM(`(a|b)?+.+`)
USING 'cat' AS (c)
USING 'cat' AS (c)
FROM script_trans
-- !query schema
struct<c:string>
Expand All @@ -627,6 +627,7 @@ struct<key:string,value:string>
-- !query output
spark.sql.parser.quotedRegexColumnNames false


-- !query
WITH temp AS (
SELECT TRANSFORM(a) USING 'cat' AS (b string) FROM t
Expand All @@ -638,3 +639,43 @@ struct<b:string>
1
2
3


-- !query
SELECT TRANSFORM(DISTINCT b, a, c)
USING 'cat' AS (a, b, c)
FROM script_trans
WHERE a <= 4
-- !query schema
struct<>
-- !query output
org.apache.spark.sql.catalyst.parser.ParseException

TRANSFORM not support quantifier DISTINCT/ALL for input expression seq(line 1, pos 17)

== SQL ==
SELECT TRANSFORM(DISTINCT b, a, c)
-----------------^^^
USING 'cat' AS (a, b, c)
FROM script_trans
WHERE a <= 4


-- !query
SELECT TRANSFORM(ALL b, a, c)
USING 'cat' AS (a, b, c)
FROM script_trans
WHERE a <= 4
-- !query schema
struct<>
-- !query output
org.apache.spark.sql.catalyst.parser.ParseException

TRANSFORM not support quantifier DISTINCT/ALL for input expression seq(line 1, pos 17)

== SQL ==
SELECT TRANSFORM(ALL b, a, c)
-----------------^^^
USING 'cat' AS (a, b, c)
FROM script_trans
WHERE a <= 4