-
Notifications
You must be signed in to change notification settings - Fork 25.2k
SQL: Add PIVOT support #46489
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
SQL: Add PIVOT support #46489
Changes from 1 commit
84cee40
a0caa34
48c6a83
3f356ba
7af8f37
d28984a
d668751
854d09c
2606f36
7bbe026
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 |
---|---|---|
|
@@ -193,7 +193,13 @@ protected LogicalPlan rule(Pivot plan) { | |
// TODO: this should be removed when refactoring NamedExpression | ||
else if (namedExpression instanceof Literal) { | ||
rawValues.add(namedExpression); | ||
} else { | ||
} | ||
// TODO: NamedExpression refactoring should remove this | ||
else if (namedExpression.foldable()) { | ||
rawValues.add(Literal.of(namedExpression.name(), namedExpression)); | ||
} | ||
// TOOD: same as above | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo -> TODO |
||
else { | ||
UnresolvedAttribute attr = new UnresolvedAttribute(namedExpression.source(), namedExpression.name(), null, | ||
"Unexpected alias"); | ||
return new Pivot(plan.source(), plan.child(), plan.column(), singletonList(attr), plan.aggregates()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -873,6 +873,21 @@ public void testPivotValueNotFoldable() { | |
error("SELECT * FROM (SELECT int, keyword, bool FROM test) " + "PIVOT(AVG(int) FOR keyword IN ('bla', bool))")); | ||
} | ||
|
||
public void testPivotWithFunctionInput() { | ||
assertEquals("1:37: No functions allowed (yet); encountered [YEAR(date)]", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No functions allowed due to namedExpression issues. |
||
error("SELECT * FROM (SELECT int, keyword, YEAR(date) FROM test) " + "PIVOT(AVG(int) FOR keyword IN ('bla'))")); | ||
} | ||
|
||
public void testPivotWithFoldableFunctionInValues() { | ||
assertEquals("1:85: Non-literal [UCASE('bla')] found inside PIVOT values", | ||
error("SELECT * FROM (SELECT int, keyword, bool FROM test) " + "PIVOT(AVG(int) FOR keyword IN ( UCASE('bla') ))")); | ||
} | ||
|
||
public void testPivotWithNull() { | ||
assertEquals("1:85: Null not allowed as a PIVOT value", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @astefan Added test for forbidding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When
If for pivot this case should yield |
||
error("SELECT * FROM (SELECT int, keyword, bool FROM test) " + "PIVOT(AVG(int) FOR keyword IN ( null ))")); | ||
} | ||
|
||
public void testPivotValuesHaveDifferentTypeThanColumn() { | ||
assertEquals("1:81: Literal ['bla'] of type [keyword] does not match type [boolean] of PIVOT column [bool]", | ||
error("SELECT * FROM (SELECT int, keyword, bool FROM test) " + "PIVOT(AVG(int) FOR bool IN ('bla'))")); | ||
|
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.
AndLimit?