Class BigQuerySqlDialect

java.lang.Object
org.apache.calcite.sql.SqlDialect
org.apache.calcite.sql.dialect.BigQuerySqlDialect

public class BigQuerySqlDialect extends SqlDialect
A SqlDialect implementation for Google BigQuery's "Standard SQL" dialect.
  • Field Details

  • Constructor Details

    • BigQuerySqlDialect

      public BigQuerySqlDialect(SqlDialect.Context context)
      Creates a BigQuerySqlDialect.
  • Method Details

    • identifierNeedsQuote

      protected boolean identifierNeedsQuote(String val)
      Description copied from class: SqlDialect
      Returns whether to quote an identifier. By default, all identifiers are quoted.
      Overrides:
      identifierNeedsQuote in class SqlDialect
    • supportsImplicitTypeCoercion

      public boolean supportsImplicitTypeCoercion(RexCall call)
      Description copied from class: SqlDialect
      Returns whether the dialect supports implicit type coercion.

      Most of the sql dialects support implicit type coercion, so we make this method default return true. For instance, "cast('10' as integer) > 5" can be simplified to "'10' > 5" if the dialect supports implicit type coercion for VARCHAR and INTEGER comparison.

      For sql dialect that does not support implicit type coercion, such as the BigQuery, we can not convert '10' into INT64 implicitly.

      Now this method is used for some auxiliary decision when translating some RexCalls, see SqlImplementor#stripCastFromString for details.

      Overrides:
      supportsImplicitTypeCoercion in class SqlDialect
      Parameters:
      call - the call to make decision
    • supportsApproxCountDistinct

      public boolean supportsApproxCountDistinct()
      Description copied from class: SqlDialect
      Returns whether this dialect supports APPROX_COUNT_DISTINCT functions.
      Overrides:
      supportsApproxCountDistinct in class SqlDialect
    • supportsNestedAggregations

      public boolean supportsNestedAggregations()
      Description copied from class: SqlDialect
      Returns whether the dialect supports nested aggregations, for instance SELECT SUM(SUM(1)) .
      Overrides:
      supportsNestedAggregations in class SqlDialect
    • supportsAggregateFunctionFilter

      public boolean supportsAggregateFunctionFilter()
      Description copied from class: SqlDialect
      Returns whether this dialect supports the use of FILTER clauses for aggregate functions. e.g. COUNT(*) FILTER (WHERE a = 2).
      Overrides:
      supportsAggregateFunctionFilter in class SqlDialect
    • configureParser

      public SqlParser.Config configureParser(SqlParser.Config configBuilder)
      Description copied from class: SqlDialect
      Copies settings from this dialect into a parser configuration.

      SqlDialect, SqlParser.Config and SqlConformance cover different aspects of the same thing - the dialect of SQL spoken by a database - and this method helps to bridge between them. (The aspects are, respectively, generating SQL to send to a source database, parsing SQL sent to Calcite, and validating queries sent to Calcite. It makes sense to keep them as separate interfaces because they are used by different modules.)

      The settings copied may differ among dialects, and may change over time, but currently include the following:

      Overrides:
      configureParser in class SqlDialect
      Parameters:
      configBuilder - Parser configuration builder
      Returns:
      The configuration builder
    • unparseOffsetFetch

      public void unparseOffsetFetch(SqlWriter writer, @Nullable SqlNode offset, @Nullable SqlNode fetch)
      Description copied from class: SqlDialect
      Converts an offset and fetch into SQL.

      At least one of offset and fetch must be provided.

      Common options:

      • OFFSET offset ROWS FETCH NEXT fetch ROWS ONLY (ANSI standard SQL, Oracle, PostgreSQL, and the default)
      • LIMIT fetch OFFSET offset (Apache Hive, MySQL, Redshift)
      Overrides:
      unparseOffsetFetch in class SqlDialect
      Parameters:
      writer - Writer
      offset - Number of rows to skip before emitting, or null
      fetch - Number of rows to fetch, or null
      See Also:
    • supportsAliasedValues

      public boolean supportsAliasedValues()
      Description copied from class: SqlDialect
      Returns whether the dialect supports VALUES in a sub-query with and an "AS t(column, ...)" values to define column names.

      Currently, only Oracle does not. For this, we generate "SELECT v0 AS c0, v1 AS c1 ... UNION ALL ...". We may need to refactor this method when we support VALUES for other dialects.

      Overrides:
      supportsAliasedValues in class SqlDialect
    • unparseCall

      public void unparseCall(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec)
      Overrides:
      unparseCall in class SqlDialect
    • unparseSqlIntervalLiteral

      public void unparseSqlIntervalLiteral(SqlWriter writer, SqlIntervalLiteral literal, int leftPrec, int rightPrec)
      BigQuery interval syntax: INTERVAL int64 time_unit.
      Overrides:
      unparseSqlIntervalLiteral in class SqlDialect
    • unparseSqlIntervalQualifier

      public void unparseSqlIntervalQualifier(SqlWriter writer, SqlIntervalQualifier qualifier, RelDataTypeSystem typeSystem)
      Description copied from class: SqlDialect
      Converts an interval qualifier to a SQL string. The default implementation returns strings such as INTERVAL '1 2:3:4' DAY(4) TO SECOND(4).
      Overrides:
      unparseSqlIntervalQualifier in class SqlDialect
    • getFormatModel

      public FormatModel getFormatModel()
      Returns a description of the format string used by functions in this dialect.

      Dialects may need to override this element mapping if they differ from Oracle's format elements. By default, this returns FormatModels.DEFAULT.

      Overrides:
      getFormatModel in class SqlDialect
      See Also:
    • getCastSpec

      public @Nullable SqlNode getCastSpec(RelDataType type)
      Returns SqlNode for type in "cast(column as type)", which might be different between databases by type name, precision etc.

      If this method returns null, the cast will be omitted. In the default implementation, this is the case for the NULL type, and therefore CAST(NULL AS <nulltype>) is rendered as NULL.

      BigQuery data type reference: BigQuery Standard SQL Data Types.

      Overrides:
      getCastSpec in class SqlDialect