Skip to content

Commit

Permalink
Add tableExpr pivot/unpivot output.
Browse files Browse the repository at this point in the history
  • Loading branch information
lingo-xp authored and wenshao committed Jan 23, 2025
1 parent 247304c commit 7d575c8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3217,24 +3217,30 @@ public boolean visit(SQLExprTableSource x) {
print(')');
}

SQLPivot pivot = x.getPivot();
printPivot(x.getPivot());

printUnpivot(x.getUnpivot());

if (isPrettyFormat() && x.hasAfterComment()) {
print(' ');
printlnComment(x.getAfterCommentsDirect());
}

return false;
}

protected void printPivot(SQLPivot pivot) {
if (pivot != null) {
println();
pivot.accept(this);
}
}

SQLUnpivot unpivot = x.getUnpivot();
protected void printUnpivot(SQLUnpivot unpivot) {
if (unpivot != null) {
println();
unpivot.accept(this);
}

if (isPrettyFormat() && x.hasAfterComment()) {
print(' ');
printlnComment(x.getAfterCommentsDirect());
}

return false;
}

public boolean visit(SQLSelectStatement stmt) {
Expand Down Expand Up @@ -4625,6 +4631,8 @@ public boolean visit(SQLJoinTableSource x) {

this.indentCount--;

printPivot(x.getPivot());
printUnpivot(x.getUnpivot());
return false;
}

Expand Down Expand Up @@ -4932,17 +4940,9 @@ public boolean visit(SQLSubqueryTableSource x) {
print(')');
}

SQLPivot pivot = x.getPivot();
if (pivot != null) {
println();
pivot.accept(this);
}
printPivot(x.getPivot());

SQLUnpivot unpivot = x.getUnpivot();
if (unpivot != null) {
println();
unpivot.accept(this);
}
printUnpivot(x.getUnpivot());

if (isPrettyFormat() && x.hasAfterComment()) {
print(' ');
Expand Down Expand Up @@ -4987,7 +4987,8 @@ public boolean visit(SQLUnnestTableSource x) {
print0(ucase ? " WITH OFFSET AS " : " with offset as ");
x.getOffset().accept(this);
}

printPivot(x.getPivot());
printUnpivot(x.getUnpivot());
return false;
}

Expand Down Expand Up @@ -5020,6 +5021,8 @@ public boolean visit(SQLGeneratedTableSource x) {
}
print(')');
}
printPivot(x.getPivot());
printUnpivot(x.getUnpivot());
return false;
}

Expand Down Expand Up @@ -7081,6 +7084,8 @@ public boolean visit(SQLUnionQueryTableSource x) {
}
print0(alias);
}
printPivot(x.getPivot());
printUnpivot(x.getUnpivot());

return false;
}
Expand Down
27 changes: 27 additions & 0 deletions core/src/test/resources/bvt/parser/bigquery/0.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
SELECT *
FROM (
SELECT a
FROM b
UNION ALL
SELECT a
FROM d
)
PIVOT (
SUM(a)
FOR a in (
'1'
)
)
ORDER BY a
--------------------
SELECT *
FROM (
SELECT a
FROM b
UNION ALL
SELECT a
FROM d
)
PIVOT (SUM(a) FOR a IN ('1'))
ORDER BY a
------------------------------------------------------------------------------------------------------------------------
select * from a unpivot(ct for type in ('1'))
--------------------
SELECT *
Expand Down

0 comments on commit 7d575c8

Please sign in to comment.