Skip to content

Commit

Permalink
[CALCITE-5299] JDBC adapter sometimes adds unnecessary parentheses ar…
Browse files Browse the repository at this point in the history
…ound SELECT in WITH body

Remove SET_QUERY from SqlKind#EXPRESSION.

This closes apache#2938
  • Loading branch information
l4wei authored and libenchao committed Oct 25, 2022
1 parent 5d771d8 commit defea67
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 76 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/apache/calcite/sql/SqlKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ public enum SqlKind {
NULLS_FIRST, NULLS_LAST, COLLECTION_TABLE, TABLESAMPLE,
VALUES, WITH, WITH_ITEM, ITEM, SKIP_TO_FIRST, SKIP_TO_LAST,
JSON_VALUE_EXPRESSION, UNNEST),
AGGREGATE, DML, DDL));
SET_QUERY, AGGREGATE, DML, DDL));

/**
* Category of all SQL statement types.
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/org/apache/calcite/sql/SqlWith.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ private SqlWithOperator() {
}
writer.endList(frame1);
final SqlWriter.Frame frame2 =
writer.startList(SqlWriter.FrameTypeEnum.SIMPLE);
with.body.unparse(writer, 100, 100);
writer.startList(SqlWriter.FrameTypeEnum.WITH_BODY);
with.body.unparse(writer,
SqlWithOperator.INSTANCE.getLeftPrec(), SqlWithOperator.INSTANCE.getRightPrec());
writer.endList(frame2);
writer.endList(frame);
}
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/org/apache/calcite/sql/SqlWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ enum FrameTypeEnum implements FrameType {
*/
WITH,

/**
* The body query of WITH.
*/
WITH_BODY,

/**
* OFFSET clause.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public void setWindowDeclListNewline(boolean windowDeclListNewline) {
return (frame == null)
|| (frame.frameType == FrameTypeEnum.SELECT)
|| (frame.frameType == FrameTypeEnum.ORDER_BY)
|| (frame.frameType == FrameTypeEnum.WITH)
|| (frame.frameType == FrameTypeEnum.WITH_BODY)
|| (frame.frameType == FrameTypeEnum.SETOP);
}

Expand Down
Loading

0 comments on commit defea67

Please sign in to comment.