Class BigQuerySqlDialect
SqlDialect
implementation for Google BigQuery's "Standard SQL"
dialect.-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.calcite.sql.SqlDialect
SqlDialect.CalendarPolicy, SqlDialect.Context, SqlDialect.DatabaseProduct, SqlDialect.FakeUtil
-
Field Summary
Fields inherited from class org.apache.calcite.sql.SqlDialect
BUILT_IN_OPERATORS_LIST, EMPTY_CONTEXT, identifierEndQuoteString, identifierEscapedQuote, identifierQuoteString, literalEndQuoteString, literalEscapedQuote, literalQuoteString, LOGGER, nullCollation
-
Constructor Summary
ConstructorDescriptionBigQuerySqlDialect
(SqlDialect.Context context) Creates a BigQuerySqlDialect. -
Method Summary
Modifier and TypeMethodDescriptionconfigureParser
(SqlParser.Config configBuilder) Copies settings from this dialect into a parser configuration.@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.Returns a description of the format string used by functions in this dialect.protected boolean
Returns whether to quote an identifier.boolean
Returns whether this dialect supports the use of FILTER clauses for aggregate functions.boolean
Returns whether the dialect supports VALUES in a sub-query with and an "AS t(column, ...)" values to define column names.boolean
Returns whether this dialect supports APPROX_COUNT_DISTINCT functions.boolean
Returns whether the dialect supports implicit type coercion.boolean
Returns whether the dialect supports nested aggregations, for instanceSELECT SUM(SUM(1))
.void
unparseCall
(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) void
unparseOffsetFetch
(SqlWriter writer, @Nullable SqlNode offset, @Nullable SqlNode fetch) Converts an offset and fetch into SQL.void
unparseSqlIntervalLiteral
(SqlWriter writer, SqlIntervalLiteral literal, int leftPrec, int rightPrec) BigQuery interval syntax: INTERVAL int64 time_unit.void
unparseSqlIntervalQualifier
(SqlWriter writer, SqlIntervalQualifier qualifier, RelDataTypeSystem typeSystem) Converts an interval qualifier to a SQL string.Methods inherited from class org.apache.calcite.sql.SqlDialect
allowsAs, configureParser, containsNonAscii, create, defaultNullDirection, emulateJoinTypeForCrossJoin, emulateNullDirection, emulateNullDirectionWithIsNull, getCalendarPolicy, getConformance, getDatabaseProduct, getNullCollation, getProduct, getQuotedCasing, getQuoting, getSingleRowTableName, getTypeSystem, getUnquotedCasing, hasImplicitTableAlias, isCaseSensitive, quoteIdentifier, quoteIdentifier, quoteIdentifier, quoteStringLiteral, quoteStringLiteral, quoteStringLiteralUnicode, quoteTimestampLiteral, requiresAliasForFromItems, rewriteMaxMin, rewriteMaxMinExpr, rewriteSingleValueExpr, supportBooleanCaseWhen, supportsAggregateFunction, supportsCharSet, supportsDataType, supportsFunction, supportsGroupByLiteral, supportsGroupByWithCube, supportsGroupByWithRollup, supportsJoinType, supportsOffsetFetch, supportsTimestampPrecision, supportsWindowFunctions, unparseBoolLiteral, unparseDateTimeLiteral, unparseFetchUsingAnsi, unparseFetchUsingLimit, unparseLimit, unparseOffset, unparseSqlDatetimeArithmetic, unparseTableScanHints, unparseTopN, unquoteStringLiteral
-
Field Details
-
DEFAULT_CONTEXT
-
DEFAULT
-
-
Constructor Details
-
BigQuerySqlDialect
Creates a BigQuerySqlDialect.
-
-
Method Details
-
identifierNeedsQuote
Description copied from class:SqlDialect
Returns whether to quote an identifier. By default, all identifiers are quoted.- Overrides:
identifierNeedsQuote
in classSqlDialect
-
supportsImplicitTypeCoercion
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
RexCall
s, see SqlImplementor#stripCastFromString for details.- Overrides:
supportsImplicitTypeCoercion
in classSqlDialect
- 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 classSqlDialect
-
supportsNestedAggregations
public boolean supportsNestedAggregations()Description copied from class:SqlDialect
Returns whether the dialect supports nested aggregations, for instanceSELECT SUM(SUM(1))
.- Overrides:
supportsNestedAggregations
in classSqlDialect
-
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 classSqlDialect
-
configureParser
Description copied from class:SqlDialect
Copies settings from this dialect into a parser configuration.SqlDialect
,SqlParser.Config
andSqlConformance
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 classSqlDialect
- Parameters:
configBuilder
- Parser configuration builder- Returns:
- The configuration builder
-
unparseOffsetFetch
Description copied from class:SqlDialect
Converts an offset and fetch into SQL.At least one of
offset
andfetch
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 classSqlDialect
- Parameters:
writer
- Writeroffset
- Number of rows to skip before emitting, or nullfetch
- 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 classSqlDialect
-
unparseCall
- Overrides:
unparseCall
in classSqlDialect
-
unparseSqlIntervalLiteral
public void unparseSqlIntervalLiteral(SqlWriter writer, SqlIntervalLiteral literal, int leftPrec, int rightPrec) BigQuery interval syntax: INTERVAL int64 time_unit.- Overrides:
unparseSqlIntervalLiteral
in classSqlDialect
-
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 asINTERVAL '1 2:3:4' DAY(4) TO SECOND(4)
.- Overrides:
unparseSqlIntervalQualifier
in classSqlDialect
-
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 classSqlDialect
- See Also:
-
getCastSpec
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 asNULL
.BigQuery data type reference: BigQuery Standard SQL Data Types.
- Overrides:
getCastSpec
in classSqlDialect
-