You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2021/03/11 01:49:45 UTC

[GitHub] [calcite] chunweilei commented on a change in pull request #2366: [CALCITE-4526] Fixup the unparse's output of SqlSnapshot,when tableRel is a SqlAsOperator (jibiyr)

chunweilei commented on a change in pull request #2366:
URL: https://github.com/apache/calcite/pull/2366#discussion_r592008165



##########
File path: core/src/main/java/org/apache/calcite/sql/SqlSnapshot.java
##########
@@ -127,10 +129,25 @@ private SqlSnapshotOperator() {
         int leftPrec,
         int rightPrec) {
       final SqlSnapshot snapshot = (SqlSnapshot) call;
-
-      snapshot.tableRef.unparse(writer, 0, 0);
-      writer.keyword("FOR SYSTEM_TIME AS OF");
-      snapshot.period.unparse(writer, 0, 0);
+      SqlNode tableRef = snapshot.tableRef;
+
+      if (tableRef instanceof SqlBasicCall
+          && ((SqlBasicCall) tableRef).getOperator() instanceof SqlAsOperator) {
+        SqlBasicCall basicCall = (SqlBasicCall) tableRef;
+        basicCall.operand(0).unparse(writer, 0, 0);
+        writer.setNeedWhitespace(true);
+        writeForSystemTimeAsOf(writer, snapshot);
+        writer.keyword("AS");
+        basicCall.operand(1).unparse(writer, 0, 0);
+      } else {
+        tableRef.unparse(writer, 0, 0);
+        writeForSystemTimeAsOf(writer, snapshot);
+      }
     }
   }
+
+  private static void writeForSystemTimeAsOf(SqlWriter writer, SqlSnapshot snapshot) {
+    writer.keyword("FOR SYSTEM_TIME AS OF");
+    snapshot.period.unparse(writer, 0, 0);

Review comment:
       Maybae it is better to put `writeForSystemTimeAsOf` in SqlSnapshotOperator.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org