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
FieldsModifier and TypeFieldDescriptionstatic final SqlDialectstatic final SqlDialect.Contextstatic final RelDataTypeSystemFields inherited from class org.apache.calcite.sql.SqlDialect
BUILT_IN_OPERATORS_LIST, EMPTY_CONTEXT, identifierEndQuoteString, identifierEscapedQuote, identifierQuoteString, literalEndQuoteString, literalEscapedQuote, literalQuoteString, LOGGER, nullCollation -
Constructor Summary
ConstructorsConstructorDescriptionBigQuerySqlDialect(SqlDialect.Context context) Creates a BigQuerySqlDialect. -
Method Summary
Modifier and TypeMethodDescriptionconfigureParser(SqlParser.Config configBuilder) Copies settings from this dialect into a parser configuration.@Nullable SqlNodegetCastSpec(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.Returns the type system implementation for this dialect.protected booleanReturns whether to quote an identifier.booleanReturns whether this dialect supports the use of FILTER clauses for aggregate functions.booleanReturns whether the dialect supports VALUES in a sub-query with and an "AS t(column, ...)" values to define column names.booleanReturns whether this dialect supports APPROX_COUNT_DISTINCT functions.booleanReturns whether the dialect supports implicit type coercion.booleanReturns whether the dialect supports nested aggregations, for instanceSELECT SUM(SUM(1)).voidunparseCall(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) voidunparseOffsetFetch(SqlWriter writer, @Nullable SqlNode offset, @Nullable SqlNode fetch) Converts an offset and fetch into SQL.voidunparseSqlIntervalLiteral(SqlWriter writer, SqlIntervalLiteral literal, int leftPrec, int rightPrec) BigQuery interval syntax: INTERVAL int64 time_unit.voidunparseSqlIntervalQualifier(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, getUnquotedCasing, hasImplicitTableAlias, isCaseSensitive, prepareUnparse, 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, unparseNumericLiteral, unparseOffset, unparseSqlDatetimeArithmetic, unparseSqlSetOption, unparseTableScanHints, unparseTopN, unquoteStringLiteral
-
Field Details
-
DEFAULT_CONTEXT
-
DEFAULT
-
TYPE_SYSTEM
-
-
Constructor Details
-
BigQuerySqlDialect
Creates a BigQuerySqlDialect.
-
-
Method Details
-
identifierNeedsQuote
Description copied from class:SqlDialectReturns whether to quote an identifier. By default, all identifiers are quoted.- Overrides:
identifierNeedsQuotein classSqlDialect
-
supportsImplicitTypeCoercion
Description copied from class:SqlDialectReturns 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:
supportsImplicitTypeCoercionin classSqlDialect- Parameters:
call- the call to make decision
-
getTypeSystem
Description copied from class:SqlDialectReturns the type system implementation for this dialect.- Overrides:
getTypeSystemin classSqlDialect
-
supportsApproxCountDistinct
public boolean supportsApproxCountDistinct()Description copied from class:SqlDialectReturns whether this dialect supports APPROX_COUNT_DISTINCT functions.- Overrides:
supportsApproxCountDistinctin classSqlDialect
-
supportsNestedAggregations
public boolean supportsNestedAggregations()Description copied from class:SqlDialectReturns whether the dialect supports nested aggregations, for instanceSELECT SUM(SUM(1)).- Overrides:
supportsNestedAggregationsin classSqlDialect
-
supportsAggregateFunctionFilter
public boolean supportsAggregateFunctionFilter()Description copied from class:SqlDialectReturns whether this dialect supports the use of FILTER clauses for aggregate functions. e.g.COUNT(*) FILTER (WHERE a = 2).- Overrides:
supportsAggregateFunctionFilterin classSqlDialect
-
configureParser
Description copied from class:SqlDialectCopies settings from this dialect into a parser configuration.SqlDialect,SqlParser.ConfigandSqlConformancecover 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:
configureParserin classSqlDialect- Parameters:
configBuilder- Parser configuration builder- Returns:
- The configuration builder
-
unparseOffsetFetch
Description copied from class:SqlDialectConverts an offset and fetch into SQL.At least one of
offsetandfetchmust 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:
unparseOffsetFetchin 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:SqlDialectReturns 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:
supportsAliasedValuesin classSqlDialect
-
unparseCall
- Overrides:
unparseCallin classSqlDialect
-
unparseSqlIntervalLiteral
public void unparseSqlIntervalLiteral(SqlWriter writer, SqlIntervalLiteral literal, int leftPrec, int rightPrec) BigQuery interval syntax: INTERVAL int64 time_unit.- Overrides:
unparseSqlIntervalLiteralin classSqlDialect
-
unparseSqlIntervalQualifier
public void unparseSqlIntervalQualifier(SqlWriter writer, SqlIntervalQualifier qualifier, RelDataTypeSystem typeSystem) Description copied from class:SqlDialectConverts an interval qualifier to a SQL string. The default implementation returns strings such asINTERVAL '1 2:3:4' DAY(4) TO SECOND(4).- Overrides:
unparseSqlIntervalQualifierin 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:
getFormatModelin 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:
getCastSpecin classSqlDialect
-