1212import org .apache .calcite .sql .SqlLiteral ;
1313import org .apache .calcite .sql .SqlNodeList ;
1414import org .apache .calcite .sql .SqlWriter ;
15+ import org .apache .calcite .sql .SqlOperator ;
1516import org .apache .calcite .sql .parser .SqlParserPos ;
1617import org .apache .calcite .sql .SqlAbstractDateTimeLiteral ;
1718import com .dremio .exec .store .jdbc .dialect .arp .ArpDialect ;
@@ -71,22 +72,23 @@ public void unparseDateTimeLiteral(SqlWriter writer,
7172 }
7273
7374 @ Override
74- public void unparseCall (final SqlWriter writer , final SqlCall call , final int leftPrec , final int rightPrec ) {
75- // Transform SqlSelect nodes that have a fetch node to be SqlSelect nodes with a TOP and no fetch.
76- if (call instanceof SqlSelect ) {
77- final SqlSelect select = (SqlSelect ) call ;
75+ public void unparseCall (SqlWriter writer , SqlCall call , int leftPrec , int rightPrec ) {
76+ final SqlOperator op = call .getOperator ();
7877
78+ if (call instanceof SqlSelect ) {
7979 // Transform SqlSelect nodes that have a fetch node without offset to be
8080 // SqlSelect nodes with a TOP and no fetch.
81- if (null != select .getFetch ()
82- && (null == select .getOffset () || 0 == ((SqlLiteral ) select .getOffset ()).getValueAs (Long .class ))) {
81+ final SqlSelect select = (SqlSelect ) call ;
82+
83+ if (select .getFetch () != null
84+ && (select .getOffset () == null || ((SqlLiteral ) select .getOffset ()).getValueAs (Long .class ) == 0 )) {
8385 final SqlNodeList keywords = new SqlNodeList (SqlParserPos .ZERO );
8486
8587 // Add the DISTINCT or ALL keywords if the original Select had either. (Only can have one of these).
8688 // These must go before TOP.
87- if (null != select .getModifierNode (SqlSelectKeyword .DISTINCT )) {
89+ if (select .getModifierNode (SqlSelectKeyword .DISTINCT ) != null ) {
8890 keywords .add (select .getModifierNode (SqlSelectKeyword .DISTINCT ));
89- } else if (null != select .getModifierNode (SqlSelectKeyword .ALL )) {
91+ } else if (select .getModifierNode (SqlSelectKeyword .ALL ) != null ) {
9092 keywords .add (select .getModifierNode (SqlSelectKeyword .ALL ));
9193 }
9294
@@ -103,6 +105,7 @@ public void unparseCall(final SqlWriter writer, final SqlCall call, final int le
103105 select .getGroup (),
104106 select .getHaving (),
105107 select .getWindowList (),
108+ select .getQualify (),
106109 select .getOrderList (),
107110 null ,
108111 null ,
0 commit comments