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 2019/10/22 01:26:15 UTC

[GitHub] [calcite] danny0405 commented on a change in pull request #1524: [CALCITE-3416] SQL Dialects DEFAULTs should be more extensible

danny0405 commented on a change in pull request #1524: [CALCITE-3416] SQL Dialects DEFAULTs should be more extensible
URL: https://github.com/apache/calcite/pull/1524#discussion_r337304888
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/sql/dialect/SqlDialectContexts.java
 ##########
 @@ -0,0 +1,197 @@
+/*
+ * 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.dialect;
+
+import org.apache.calcite.avatica.util.Casing;
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
+import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+/**
+ * Pre-defined builders of {@link SqlDialect.Context} for all kinds of sql dialects.
+ *
+ * <p>To add a new {@link SqlDialect}, add a {@link SqlDialect.Context} instance first
+ * in this class and reference it in the {@link SqlDialect} sub-class.
+ * Take {@link MysqlSqlDialect} for a reference.
+ */
+public abstract class SqlDialectContexts {
+  //~ Static fields/initializers ---------------------------------------------
+
+  public static final SqlDialect.Context EMPTY = SqlDialect.EMPTY_CONTEXT;
+
+  public static final SqlDialect.Context MSSQL = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.MSSQL)
+      .withIdentifierQuoteString("[")
+      .withCaseSensitive(false)
+      .withNullCollation(NullCollation.LOW);
+
+  public static final SqlDialect.Context H2 = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.H2)
+      .withIdentifierQuoteString("\"");
+
+  public static final SqlDialect.Context ANSI = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.UNKNOWN)
+      .withIdentifierQuoteString("`");
+
+  public static final SqlDialect.Context DERBY = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.DERBY);
+
+  public static final SqlDialect.Context SYBASE = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.SYBASE);
+
+  public static final SqlDialect.Context TERADATA = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.TERADATA)
+      .withIdentifierQuoteString("\"");
+
+  /** OracleDB type system. */
+  private static final RelDataTypeSystem ORACLE_TYPE_SYSTEM =
+      new RelDataTypeSystemImpl() {
+        @Override public int getMaxPrecision(SqlTypeName typeName) {
+          switch (typeName) {
+          case VARCHAR:
+            // Maximum size of 4000 bytes for varchar2.
+            return 4000;
+          default:
+            return super.getMaxPrecision(typeName);
+          }
+        }
+      };
+
+  public static final SqlDialect.Context ORACLE = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.ORACLE)
+      .withIdentifierQuoteString("\"")
+      .withDataTypeSystem(ORACLE_TYPE_SYSTEM);
+
+  public static final SqlDialect.Context VERTICA = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.VERTICA)
+      .withIdentifierQuoteString("\"")
+      .withUnquotedCasing(Casing.UNCHANGED);
+
+  public static final SqlDialect.Context ACCESS = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.ACCESS)
+      .withIdentifierQuoteString("\"");
+
+  public static final SqlDialect.Context CALCITE = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.CALCITE)
+      .withIdentifierQuoteString("\"");
+
+  public static final SqlDialect.Context SPARK = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.SPARK)
+      .withNullCollation(NullCollation.LOW);
+
+  public static final SqlDialect.Context PHOENIX = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.PHOENIX)
+      .withIdentifierQuoteString("\"");
+
+  public static final SqlDialect.Context SNOWFLAKE = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.SNOWFLAKE)
+      .withIdentifierQuoteString("\"")
+      .withUnquotedCasing(Casing.TO_UPPER);
+
+  public static final SqlDialect.Context HSQLDB = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.HSQLDB);
+
+  public static final SqlDialect.Context INGRES = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.INGRES);
+
+  public static final SqlDialect.Context PARACCEL = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.PARACCEL)
+      .withIdentifierQuoteString("\"");
+
+  public static final SqlDialect.Context NETEZZA = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.NETEZZA)
+      .withIdentifierQuoteString("\"");
+
+  public static final SqlDialect.Context INTERBASE = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.INTERBASE);
+
+  public static final SqlDialect.Context INFOBRIGHT = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.INFOBRIGHT)
+      .withIdentifierQuoteString("`");
+
+  /** PostgreSQL type system. */
+  private static final RelDataTypeSystem POSTGRESQL_TYPE_SYSTEM =
+      new RelDataTypeSystemImpl() {
+        @Override public int getMaxPrecision(SqlTypeName typeName) {
+          switch (typeName) {
+          case VARCHAR:
+            // From htup_details.h in postgresql:
+            // MaxAttrSize is a somewhat arbitrary upper limit on the declared size of
+            // data fields of char(n) and similar types.  It need not have anything
+            // directly to do with the *actual* upper limit of varlena values, which
+            // is currently 1Gb (see TOAST structures in postgres.h).  I've set it
+            // at 10Mb which seems like a reasonable number --- tgl 8/6/00. */
+            return 10 * 1024 * 1024;
+          default:
+            return super.getMaxPrecision(typeName);
+          }
+        }
+      };
+
+  public static final SqlDialect.Context POSTGRESQL = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.POSTGRESQL)
+      .withIdentifierQuoteString("\"")
+      .withUnquotedCasing(Casing.TO_LOWER)
+      .withDataTypeSystem(POSTGRESQL_TYPE_SYSTEM);
+
+  public static final SqlDialect.Context REDSHIFT = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.REDSHIFT)
+      .withIdentifierQuoteString("\"")
+      .withQuotedCasing(Casing.TO_LOWER)
+      .withUnquotedCasing(Casing.TO_LOWER)
+      .withCaseSensitive(false);
+
+  public static final SqlDialect.Context FIREBIRD = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.FIREBIRD);
+
+  public static final SqlDialect.Context MYSQL = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.MYSQL)
+      .withIdentifierQuoteString("`")
+      .withUnquotedCasing(Casing.UNCHANGED)
+      .withNullCollation(NullCollation.LOW);
+
+  public static final SqlDialect.Context DB2 = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.DB2);
+
+  public static final SqlDialect.Context NEOVIEW = SqlDialect.EMPTY_CONTEXT
+      .withDatabaseProduct(SqlDialect.DatabaseProduct.NEOVIEW);
+
+  public static final SqlDialect.Context BIG_QUERY = SqlDialect.EMPTY_CONTEXT
 
 Review comment:
   Thanks, i just want to keep the name same as `SqlDialect.DatabaseProduct.BIG_QUERY`.

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


With regards,
Apache Git Services