mihaibudiu commented on code in PR #3177:
URL: https://github.com/apache/calcite/pull/3177#discussion_r1817110272


##########
site/_docs/babel_reference.md:
##########
@@ -0,0 +1,139 @@
+---
+layout: docs
+title: SQL language (Babel)
+permalink: /docs/babel_reference.html
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+<style>
+.container {
+  width: 400px;
+  height: 26px;
+}
+.gray {
+  width: 60px;
+  height: 26px;
+  background: gray;
+  float: left;
+}
+.r15 {
+  width: 40px;
+  height: 6px;
+  background: yellow;
+  margin-top: 4px;
+  margin-left: 10px;
+}
+.r12 {
+  width: 10px;
+  height: 6px;
+  background: yellow;
+  margin-top: 4px;
+  margin-left: 10px;
+}
+.r13 {
+  width: 20px;
+  height: 6px;
+  background: yellow;
+  margin-top: 4px;
+  margin-left: 10px;
+}
+.r2 {
+  width: 2px;
+  height: 6px;
+  background: yellow;
+  margin-top: 4px;
+  margin-left: 20px;
+}
+.r24 {
+  width: 20px;
+  height: 6px;
+  background: yellow;
+  margin-top: 4px;
+  margin-left: 20px;
+}
+.r35 {
+  width: 20px;
+  height: 6px;
+  background: yellow;
+  margin-top: 4px;
+  margin-left: 30px;
+}
+</style>
+
+The page describes SQL expressions that are recognized by Calcite's babel SQL 
parser

Review Comment:
   I think that "statements" is more appropriate. Or perhaps both "expressions 
and statements".



##########
babel/src/test/java/org/apache/calcite/test/BabelParserTest.java:
##########
@@ -358,41 +358,82 @@ private void checkParseInfixCast(String sqlType) {
         .ok("SELECT (ARRAY['a', 'b'])");
   }
 
-  @Test void testPostgresqlShow() {
+  @Test void testPostgresSqlShow() {
     SqlParserFixture f = fixture().withDialect(PostgresqlSqlDialect.DEFAULT);
     f.sql("SHOW autovacuum")
         .ok("SHOW \"autovacuum\"");
+    f.sql("SHOW \"autovacuum\"")
+        .same();
+    f.sql("SHOW ALL")
+        .ok("SHOW \"all\"");
+    f.sql("SHOW TIME ZONE")
+        .ok("SHOW \"timezone\"");
+    f.sql("SHOW SESSION AUTHORIZATION")
+        .ok("SHOW \"session_authorization\"");
     f.sql("SHOW TRANSACTION ISOLATION LEVEL")
         .ok("SHOW \"transaction_isolation\"");
   }
 
-  @Test void testPostgresqlSetOption() {
+  @Test void testPostgresSqlSetOption() {
     SqlParserFixture f = fixture().withDialect(PostgresqlSqlDialect.DEFAULT);
     f.sql("SET SESSION autovacuum = true")
-        .ok("ALTER SESSION SET \"autovacuum\" = TRUE");
+        .ok("SET \"autovacuum\" = TRUE");
     f.sql("SET SESSION autovacuum = DEFAULT")
-        .ok("ALTER SESSION SET \"autovacuum\" = DEFAULT");
+        .ok("SET \"autovacuum\" = DEFAULT");
     f.sql("SET LOCAL autovacuum TO 'DEFAULT'")
-        .ok("ALTER LOCAL SET \"autovacuum\" = 'DEFAULT'");
+        .ok("SET LOCAL \"autovacuum\" = 'DEFAULT'");
 
     f.sql("SET SESSION TIME ZONE DEFAULT")
-        .ok("ALTER SESSION SET \"timezone\" = DEFAULT");
+        .ok("SET TIME ZONE DEFAULT");

Review Comment:
   is this right?
   does this mean the previous output was wrong?



##########
babel/src/main/java/org/apache/calcite/sql/babel/postgres/SqlSetOptions.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql.babel.postgres;
+
+import org.apache.calcite.sql.Symbolizable;
+
+/**
+ * Contains enums convertible to {@link org.apache.calcite.sql.SqlLiteral}, 
used for
+ * {@link org.apache.calcite.sql.SqlSetOption#name} and
+ * {@link org.apache.calcite.sql.SqlSetOption#value} fields.
+ */
+public class SqlSetOptions {
+  private SqlSetOptions() {
+  }
+
+  /**
+   * {@link org.apache.calcite.sql.SqlIdentifier} can not be used
+   * as a name parameter. For example, in PostgreSQL, these two SQL commands
+   * have different meanings:
+   * <ul>
+   *   <li><code>RESET ALL</code> resets all settable run-time parameters to 
default values.</li>
+   *   <li><code>RESET "ALL"</code> resets parameter "ALL".</li>
+   * </ul>
+   * Using only {@link org.apache.calcite.sql.SqlIdentifier} makes
+   * it impossible to distinguish which case is being referred to.
+   * This enum has been introduced to avoid this problem.
+   */
+  public enum Names implements Symbolizable {
+    ALL,
+    TRANSACTION,
+    TRANSACTION_SNAPSHOT,
+    SESSION_CHARACTERISTICS_AS_TRANSACTION,
+    TIME_ZONE,
+    ROLE;
+
+    @Override public String toString() {
+      return super.toString().replace("_", " ");
+    }
+  }
+
+  /**
+   * Makes possible to represent NONE, LOCAL as {@link 
org.apache.calcite.sql.SqlLiteral}.
+   * It is needed for the following SQL statements:
+   * <ul>
+   *   <li><code>SET TIME ZONE LOCAL</code></li>
+   *   <li><code>SET ROLE NONE</code></li>
+   * </ul>
+   *
+   * @see <a href="https://www.postgresql.org/docs/current/sql-set.html";>
+   * PostgreSQL SET documentation</a>
+   * @see <a href="https://www.postgresql.org/docs/current/sql-set-role.html";>
+   * PostgreSQL SET ROLE documentation</a>
+   */
+  public enum Values implements Symbolizable {
+    NONE,
+    LOCAL;
+
+    @Override public String toString() {
+      return super.toString().replace("_", " ");

Review Comment:
   is this necessary?



##########
core/src/main/java/org/apache/calcite/sql/SqlBasicFunction.java:
##########
@@ -42,7 +42,7 @@
  * behavior only by providing strategy objects, not by overriding methods in a
  * subclass.
  */
-public class SqlBasicFunction extends SqlFunction {
+public final class SqlBasicFunction extends SqlFunction {

Review Comment:
   this looks like a major change, which may break users of this class
   



##########
babel/src/test/java/org/apache/calcite/test/BabelParserTest.java:
##########
@@ -358,41 +358,82 @@ private void checkParseInfixCast(String sqlType) {
         .ok("SELECT (ARRAY['a', 'b'])");
   }
 
-  @Test void testPostgresqlShow() {
+  @Test void testPostgresSqlShow() {
     SqlParserFixture f = fixture().withDialect(PostgresqlSqlDialect.DEFAULT);
     f.sql("SHOW autovacuum")
         .ok("SHOW \"autovacuum\"");
+    f.sql("SHOW \"autovacuum\"")
+        .same();
+    f.sql("SHOW ALL")
+        .ok("SHOW \"all\"");
+    f.sql("SHOW TIME ZONE")
+        .ok("SHOW \"timezone\"");
+    f.sql("SHOW SESSION AUTHORIZATION")
+        .ok("SHOW \"session_authorization\"");
     f.sql("SHOW TRANSACTION ISOLATION LEVEL")
         .ok("SHOW \"transaction_isolation\"");
   }
 
-  @Test void testPostgresqlSetOption() {
+  @Test void testPostgresSqlSetOption() {
     SqlParserFixture f = fixture().withDialect(PostgresqlSqlDialect.DEFAULT);
     f.sql("SET SESSION autovacuum = true")
-        .ok("ALTER SESSION SET \"autovacuum\" = TRUE");
+        .ok("SET \"autovacuum\" = TRUE");
     f.sql("SET SESSION autovacuum = DEFAULT")
-        .ok("ALTER SESSION SET \"autovacuum\" = DEFAULT");
+        .ok("SET \"autovacuum\" = DEFAULT");
     f.sql("SET LOCAL autovacuum TO 'DEFAULT'")
-        .ok("ALTER LOCAL SET \"autovacuum\" = 'DEFAULT'");
+        .ok("SET LOCAL \"autovacuum\" = 'DEFAULT'");
 
     f.sql("SET SESSION TIME ZONE DEFAULT")
-        .ok("ALTER SESSION SET \"timezone\" = DEFAULT");
+        .ok("SET TIME ZONE DEFAULT");
     f.sql("SET SESSION TIME ZONE LOCAL")
-        .ok("ALTER SESSION SET \"timezone\" = 'LOCAL'");
-    f.sql("SET TIME ZONE 'PST8PDT'")
-        .ok("SET \"timezone\" = 'PST8PDT'");
-    f.sql("SET TIME ZONE INTERVAL '-08:00' HOUR TO MINUTE")
-        .ok("SET \"timezone\" = INTERVAL '-08:00' HOUR TO MINUTE");
+        .ok("SET TIME ZONE LOCAL");
+    f.sql("SET TIME ZONE 'PST8PDT'").same();
+    f.sql("SET TIME ZONE INTERVAL '-08:00' HOUR TO MINUTE").same();
+    f.sql("SET timezone = 'PST8PDT'")
+            .ok("SET \"timezone\" = 'PST8PDT'");
+
+    f.sql("SET SESSION AUTHORIZATION DEFAULT")
+        .ok("SET \"session_authorization\" = DEFAULT");
+    f.sql("SET SESSION AUTHORIZATION DEFAULT")
+        .ok("SET \"session_authorization\" = DEFAULT");
 
     f.sql("SET search_path = public,public,\"$user\"")
         .ok("SET \"search_path\" = \"public\", \"public\", \"$user\"");
     f.sql("SET SCHEMA public,public,\"$user\"")
         .ok("SET \"search_path\" = \"public\", \"public\", \"$user\"");
     f.sql("SET NAMES iso_8859_15_to_utf8")
         .ok("SET \"client_encoding\" = \"iso_8859_15_to_utf8\"");
+
+
+    f.sql("SET TRANSACTION READ ONLY").same();
+    f.sql("SET TRANSACTION READ WRITE").same();
+    f.sql("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE").same();
+    f.sql("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ ONLY, 
DEFERRABLE").same();
+    f.sql("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ WRITE, NOT 
DEFERRABLE").same();
+
+    f.sql("SET TRANSACTION SNAPSHOT '000003A1-1'").same();
+
+    f.sql("SET ROLE NONE").same();
+    f.sql("SET ROLE 'paul'").same();
+  }
+
+  @Test void testPostgresSqlReset() {
+    SqlParserFixture f = fixture().withDialect(PostgresqlSqlDialect.DEFAULT);
+
+    f.sql("RESET ALL").same();
+    f.sql("RESET ROLE")
+        .ok("RESET \"role\"");
+    f.sql("RESET SESSION AUTHORIZATION")
+        .ok("RESET \"session_authorization\"");

Review Comment:
   are these also right?



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to