From f5d3cd80ca00f1e1a3a8f3fe7941b8aa8820e2ca Mon Sep 17 00:00:00 2001 From: dssysolyatin Date: Thu, 6 Apr 2023 17:01:25 +0300 Subject: [PATCH] [CALCITE-5612] Babel parser should support PostgreSQL's SET TRANSACTION command --- babel/src/main/codegen/config.fmpp | 29 +- .../codegen/includes/parserPostgresImpls.ftl | 337 ++++++++++++++++++ .../includes/parserPostgresqlImpls.ftl | 264 -------------- .../{postgresql => postgres}/SqlBegin.java | 41 +-- .../{postgresql => postgres}/SqlCommit.java | 23 +- .../{postgresql => postgres}/SqlDiscard.java | 22 +- .../{postgresql => postgres}/SqlRollback.java | 23 +- .../sql/babel/postgres/SqlSetOptions.java | 72 ++++ .../{postgresql => postgres}/SqlShow.java | 23 +- .../TransactionChainingMode.java} | 4 +- .../sql/babel/postgres/TransactionMode.java | 37 ++ .../package-info.java | 2 +- .../apache/calcite/test/BabelParserTest.java | 71 +++- core/src/main/codegen/default_config.fmpp | 3 + core/src/main/codegen/templates/Parser.jj | 9 +- .../java/org/apache/calcite/sql/SqlAlter.java | 2 +- .../apache/calcite/sql/SqlBasicFunction.java | 2 +- .../org/apache/calcite/sql/SqlDialect.java | 32 ++ .../org/apache/calcite/sql/SqlOperator.java | 40 ++- .../org/apache/calcite/sql/SqlSetOption.java | 68 +++- .../sql/dialect/PostgresqlSqlDialect.java | 39 ++ .../calcite/sql/fun/SqlBasicOperator.java | 63 ++++ .../calcite/sql/fun/SqlCallFactories.java | 38 ++ .../calcite/sql/fun/SqlCallFactory.java | 48 +++ .../calcite/sql/fun/SqlStdOperatorTable.java | 2 +- .../calcite/sql/SqlSetOptionOperatorTest.java | 2 +- site/_docs/babel_reference.md | 139 ++++++++ .../calcite/sql/parser/SqlParserTest.java | 4 +- 28 files changed, 1010 insertions(+), 429 deletions(-) create mode 100644 babel/src/main/codegen/includes/parserPostgresImpls.ftl delete mode 100644 babel/src/main/codegen/includes/parserPostgresqlImpls.ftl rename babel/src/main/java/org/apache/calcite/sql/babel/{postgresql => postgres}/SqlBegin.java (62%) rename babel/src/main/java/org/apache/calcite/sql/babel/{postgresql => postgres}/SqlCommit.java (71%) rename babel/src/main/java/org/apache/calcite/sql/babel/{postgresql => postgres}/SqlDiscard.java (72%) rename babel/src/main/java/org/apache/calcite/sql/babel/{postgresql => postgres}/SqlRollback.java (71%) create mode 100644 babel/src/main/java/org/apache/calcite/sql/babel/postgres/SqlSetOptions.java rename babel/src/main/java/org/apache/calcite/sql/babel/{postgresql => postgres}/SqlShow.java (72%) rename babel/src/main/java/org/apache/calcite/sql/babel/{postgresql/AndChain.java => postgres/TransactionChainingMode.java} (92%) create mode 100644 babel/src/main/java/org/apache/calcite/sql/babel/postgres/TransactionMode.java rename babel/src/main/java/org/apache/calcite/sql/babel/{postgresql => postgres}/package-info.java (94%) create mode 100644 core/src/main/java/org/apache/calcite/sql/fun/SqlBasicOperator.java create mode 100644 core/src/main/java/org/apache/calcite/sql/fun/SqlCallFactories.java create mode 100644 core/src/main/java/org/apache/calcite/sql/fun/SqlCallFactory.java create mode 100644 site/_docs/babel_reference.md diff --git a/babel/src/main/codegen/config.fmpp b/babel/src/main/codegen/config.fmpp index bf5895c7c7d..981768ba9d3 100644 --- a/babel/src/main/codegen/config.fmpp +++ b/babel/src/main/codegen/config.fmpp @@ -30,12 +30,14 @@ data: { "org.apache.calcite.sql.SqlCreate", "org.apache.calcite.sql.babel.SqlBabelCreateTable", "org.apache.calcite.sql.babel.TableCollectionType", - "org.apache.calcite.sql.babel.postgresql.AndChain", - "org.apache.calcite.sql.babel.postgresql.SqlBegin", - "org.apache.calcite.sql.babel.postgresql.SqlCommit", - "org.apache.calcite.sql.babel.postgresql.SqlDiscard", - "org.apache.calcite.sql.babel.postgresql.SqlRollback", - "org.apache.calcite.sql.babel.postgresql.SqlShow", + "org.apache.calcite.sql.babel.postgres.TransactionMode", + "org.apache.calcite.sql.babel.postgres.TransactionChainingMode", + "org.apache.calcite.sql.babel.postgres.SqlBegin", + "org.apache.calcite.sql.babel.postgres.SqlCommit", + "org.apache.calcite.sql.babel.postgres.SqlDiscard", + "org.apache.calcite.sql.babel.postgres.SqlRollback", + "org.apache.calcite.sql.babel.postgres.SqlShow", + "org.apache.calcite.sql.babel.postgres.SqlSetOptions", "org.apache.calcite.sql.ddl.SqlDdlNodes", ] @@ -49,6 +51,7 @@ data: { "SEED" "SEMI" "SEQUENCES" + "SNAPSHOT" "TEMP" "VOLATILE" ] @@ -567,12 +570,11 @@ data: { ] statementParserMethods: [ - "PostgresqlSqlShow()", - "PostgresqlSqlSetOption()", - "PostgresqlSqlBegin()", - "PostgresqlSqlDiscard()", - "PostgresqlSqlCommit()", - "PostgresqlSqlRollback()" + "PostgresSqlBegin()" + "PostgresSqlCommit()" + "PostgresSqlDiscard()" + "PostgresSqlRollback()" + "PostgresSqlShow()" ] # Binary operators tokens. @@ -608,9 +610,10 @@ data: { # Example: "parserImpls.ftl". implementationFiles: [ "parserImpls.ftl" - "parserPostgresqlImpls.ftl" + "parserPostgresImpls.ftl" ] + setOptionParserMethod: "PostgresSqlSetOption" includePosixOperators: true includeParsingStringLiteralAsArrayLiteral: true } diff --git a/babel/src/main/codegen/includes/parserPostgresImpls.ftl b/babel/src/main/codegen/includes/parserPostgresImpls.ftl new file mode 100644 index 00000000000..f0fe683099e --- /dev/null +++ b/babel/src/main/codegen/includes/parserPostgresImpls.ftl @@ -0,0 +1,337 @@ +<#-- +// 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. +--> + +/** + *
+ *    SHOW ALL
+ *    SHOW TIME ZONE
+ *    SHOW TRANSACTION ISOLATION LEVEL
+ *    SHOW SESSION AUTHORIZATION
+ *    SHOW Identifier()
+ * 
+ * + * @see + * PostgreSQL SHOW documentation + * @see + * PostgreSQL grammar file (VariableShowStmt) + */ +SqlNode PostgresSqlShow() : +{ + final String name; + final Span s; +} +{ + { s = span(); } + ( { name = "all"; } + |