public class BigQuerySqlDialect extends SqlDialect
SqlDialect implementation for Google BigQuery's "Standard SQL"
dialect.SqlDialect.CalendarPolicy, SqlDialect.Context, SqlDialect.DatabaseProduct, SqlDialect.FakeUtil| Modifier and Type | Field and Description |
|---|---|
static SqlDialect |
DEFAULT |
static SqlDialect.Context |
DEFAULT_CONTEXT |
BUILT_IN_OPERATORS_LIST, EMPTY_CONTEXT, identifierEndQuoteString, identifierEscapedQuote, identifierQuoteString, literalEndQuoteString, literalEscapedQuote, literalQuoteString, LOGGER, nullCollation| Constructor and Description |
|---|
BigQuerySqlDialect(SqlDialect.Context context)
Creates a BigQuerySqlDialect.
|
| Modifier and Type | Method and Description |
|---|---|
SqlParser.Config |
configureParser(SqlParser.Config configBuilder)
Copies settings from this dialect into a parser configuration.
|
@Nullable SqlNode |
emulateNullDirection(SqlNode node,
boolean nullsFirst,
boolean desc)
Returns the SqlNode for emulating the null direction for the given field
or
null if no emulation needs to be done. |
@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.
|
protected boolean |
identifierNeedsQuote(String val)
Returns whether to quote an identifier.
|
boolean |
supportsAggregateFunctionFilter()
Returns whether this dialect supports the use of FILTER clauses for
aggregate functions.
|
boolean |
supportsAliasedValues()
Returns whether the dialect supports VALUES in a sub-query with
and an "AS t(column, ...)" values to define column names.
|
boolean |
supportsApproxCountDistinct()
Returns whether this dialect supports APPROX_COUNT_DISTINCT functions.
|
boolean |
supportsImplicitTypeCoercion(RexCall call)
Returns whether the dialect supports implicit type coercion.
|
boolean |
supportsNestedAggregations()
Returns whether the dialect supports nested aggregations, for instance
SELECT 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.
|
allowsAs, configureParser, containsNonAscii, create, defaultNullDirection, emulateJoinTypeForCrossJoin, emulateNullDirectionWithIsNull, getCalendarPolicy, getConformance, getDatabaseProduct, getNullCollation, getProduct, getQuotedCasing, getQuoting, getSingleRowTableName, getTypeSystem, getUnquotedCasing, hasImplicitTableAlias, isCaseSensitive, quoteIdentifier, quoteIdentifier, quoteIdentifier, quoteStringLiteral, quoteStringLiteral, quoteStringLiteralUnicode, quoteTimestampLiteral, requiresAliasForFromItems, rewriteSingleValueExpr, supportsAggregateFunction, supportsCharSet, supportsDataType, supportsFunction, supportsGroupByLiteral, supportsGroupByWithCube, supportsGroupByWithRollup, supportsJoinType, supportsOffsetFetch, supportsWindowFunctions, unparseDateTimeLiteral, unparseFetchUsingAnsi, unparseFetchUsingLimit, unparseLimit, unparseOffset, unparseSqlDatetimeArithmetic, unparseTableScanHints, unparseTopN, unquoteStringLiteralpublic static final SqlDialect.Context DEFAULT_CONTEXT
public static final SqlDialect DEFAULT
public BigQuerySqlDialect(SqlDialect.Context context)
protected boolean identifierNeedsQuote(String val)
SqlDialectidentifierNeedsQuote in class SqlDialectpublic @Nullable SqlNode emulateNullDirection(SqlNode node, boolean nullsFirst, boolean desc)
SqlDialectnull if no emulation needs to be done.emulateNullDirection in class SqlDialectnode - The SqlNode representing the expressionnullsFirst - Whether nulls should come firstdesc - Whether the sort direction is
RelFieldCollation.Direction#DESCENDING or
RelFieldCollation.Direction#STRICTLY_DESCENDINGnull if not requiredpublic boolean supportsImplicitTypeCoercion(RexCall call)
SqlDialectMost 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.
supportsImplicitTypeCoercion in class SqlDialectcall - the call to make decisionpublic boolean supportsApproxCountDistinct()
SqlDialectsupportsApproxCountDistinct in class SqlDialectpublic boolean supportsNestedAggregations()
SqlDialectSELECT SUM(SUM(1)) .supportsNestedAggregations in class SqlDialectpublic boolean supportsAggregateFunctionFilter()
SqlDialectCOUNT(*) FILTER (WHERE a = 2).supportsAggregateFunctionFilter in class SqlDialectpublic SqlParser.Config configureParser(SqlParser.Config configBuilder)
SqlDialectSqlDialect, 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:
configureParser in class SqlDialectconfigBuilder - Parser configuration builderpublic void unparseOffsetFetch(SqlWriter writer, @Nullable SqlNode offset, @Nullable SqlNode fetch)
SqlDialectAt 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)
unparseOffsetFetch in class SqlDialectwriter - Writeroffset - Number of rows to skip before emitting, or nullfetch - Number of rows to fetch, or nullSqlDialect.unparseFetchUsingAnsi(SqlWriter, SqlNode, SqlNode),
SqlDialect.unparseFetchUsingLimit(SqlWriter, SqlNode, SqlNode)public boolean supportsAliasedValues()
SqlDialectCurrently, 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.
supportsAliasedValues in class SqlDialectpublic void unparseCall(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec)
unparseCall in class SqlDialectpublic void unparseSqlIntervalLiteral(SqlWriter writer, SqlIntervalLiteral literal, int leftPrec, int rightPrec)
unparseSqlIntervalLiteral in class SqlDialectpublic void unparseSqlIntervalQualifier(SqlWriter writer, SqlIntervalQualifier qualifier, RelDataTypeSystem typeSystem)
SqlDialectINTERVAL '1 2:3:4' DAY(4) TO SECOND(4).unparseSqlIntervalQualifier in class SqlDialectpublic @Nullable SqlNode getCastSpec(RelDataType type)
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.
getCastSpec in class SqlDialectCopyright © 2012-2022 Apache Software Foundation. All Rights Reserved.