Class JdbcDialectImpl
- All Implemented Interfaces:
Dialect
- Direct Known Subclasses:
AccessDialect,Db2Dialect,DerbyDialect,FirebirdDialect,GoogleBigQueryDialect,HiveDialect,HsqldbDialect,InformixDialect,IngresDialect,InterbaseDialect,LucidDbDialect,MicrosoftSqlServerDialect,MonetDbDialect,MySqlDialect,NeoviewDialect,NuoDbDialect,OracleDialect,PdiDataServiceDialect,PostgreSqlDialect,SnowflakeDialect,SybaseDialect,TeradataDialect,VerticaDialect
Dialect based on a JDBC connection and metadata.
If you are writing a class for a specific database dialect, we recommend
that you use this as a base class, so your dialect class will be
forwards-compatible. If methods are added to Dialect in future
revisions, default implementations of those methods will be added to this
class.
Mondrian uses JdbcDialectImpl as a fallback if it cannot find a more specific dialect. JdbcDialectImpl reads properties from the JDBC driver's metadata, so can deduce some of the dialect's behavior.
- Since:
- Oct 10, 2008
- Author:
- jhyde
-
Nested Class Summary
Nested classes/interfaces inherited from interface mondrian.spi.Dialect
Dialect.DatabaseProduct, Dialect.Datatype -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Dialect.DatabaseProductMajor database product (or null if product is not a common one)protected booleanIndicates whether the database allows selection of columns not listed in the group by clause.protected final StringProduct version per JDBC driver. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanallowsAs()Returns whether the SQL dialect allows "AS" in the FROM clause.booleanReturns whether this Dialect allows multiple arguments to theCOUNT(DISTINCT ...) aggregate function, for exampleSELECT COUNT(DISTINCT x, y) FROM tbooleanReturns whether this Dialect supports distinct aggregations.booleanReturns whether this Dialect supports distinct aggregations with other aggregations in the same query.booleanReturns whether this dialect supports common SQL Data Definition Language (DDL) statements such asCREATE TABLEandDROP INDEX.booleanReturns whether this Dialect object can be used for all connections from the same data source.booleanReturns whether this Dialect allows a subquery in the from clause, for exampleSELECT * FROM (SELECT * FROM t) AS xbooleanReturns whether this dialect supports "ANSI-style JOIN syntax",FROM leftTable JOIN rightTable ON conditon.booleanReturns whether this Dialect supports more than one distinct aggregation in the same query.booleanReturns whether this Dialect has performant support of distinct SQL measures in the same query.booleanReturns true if aliases defined in the SELECT clause can be used as expressions in the ORDER BY clause.booleanInforms Mondrian if the dialect supports regular expressions when creating the 'where' or the 'having' clause.booleanReturns whether the database currently permits queries to include in the SELECT clause expressions that are not listed in the GROUP BY clause.voidappendHintsAfterFromClause(StringBuilder buf, Map<String, String> hints) Assembles and returns a string containing any hints that should be appended after the FROM clause in a SELECT statement, based on any hints provided.caseWhenElse(String cond, String thenExpr, String elseExpr) Generates a conditional statement in this dialect's syntax.protected List<StatisticsProvider>protected StringdeduceIdentifierQuoteString(DatabaseMetaData databaseMetaData) protected intdeduceMaxColumnNameLength(DatabaseMetaData databaseMetaData) protected StringdeduceProductName(DatabaseMetaData databaseMetaData) protected StringdeduceProductVersion(DatabaseMetaData databaseMetaData) protected booleandeduceReadOnly(DatabaseMetaData databaseMetaData) deduceSupportedResultSetStyles(DatabaseMetaData databaseMetaData) protected booleanDetects whether the database is configured to permit queries that include columns in the SELECT that are not also in the GROUP BY.extractEmbeddedFlags(String javaRegex, String[][] mapping, StringBuilder dialectFlags) Helper method to extract and map Java regular expression embedded flags expressions to dialect specific flags.Some databases, like Greenplum, don't include nulls as part of the results of a COUNT sql call.Generates a SQL statement to represent an inline dataset.generateInlineForAnsi(String alias, List<String> columnNames, List<String> columnTypes, List<String[]> valueList, boolean cast) Generates inline values list using ANSI 'VALUES' syntax.protected StringgenerateInlineGeneric(List<String> columnNames, List<String> columnTypes, List<String[]> valueList, String fromClause, boolean cast) Generic algorithm to generate inline values list, using an optional FROM clause, specified by the caller of this method, appropriate to the dialect of SQL.protected StringgenerateOrderByNulls(String expr, boolean ascending, boolean collateNullsLast) Generates SQL to force null values to collate last.protected final StringgenerateOrderByNullsAnsi(String expr, boolean ascending, boolean collateNullsLast) Implementation for thegenerateOrderByNulls(java.lang.String, boolean, boolean)method that uses the ANSI syntax "expr direction NULLS LAST" and "expr direction NULLS FIRST".generateOrderItem(String expr, boolean nullable, boolean ascending, boolean collateNullsLast) Generates an item for an ORDER BY clause, sorting in the required direction, and ensuring that NULL values collate either before or after all non-NULL values, depending on thecollateNullsLastparameter.generateRegularExpression(String source, String javaRegExp) Must generate a String representing a regular expression match operation between a string literal and a Java regular expression.Returns the database for this Dialect, orDialect.DatabaseProduct.UNKNOWNif the database is not a common database.intReturns the maximum length of the name of a database column or query alias allowed by this dialect.static Dialect.DatabaseProductgetProduct(String productName, String productVersion) Converts a product name and version (per the JDBC driver) into a product enumeration.Returns the character which is used to quote identifiers, or null if quoting is not supported.Returns a list of statistics providers for this dialect.getType(ResultSetMetaData metaData, int columnIndex) Chooses the most appropriate type for accessing the values of a column in a result set for a dialect.protected static booleanisDatabase(Dialect.DatabaseProduct databaseProduct, Connection connection) Helper method to determine if a connection would work with a given database product.booleanneedsExponent(Object value, String valueString) If Double values need to include additional exponent in its string represenation.voidquote(StringBuilder buf, Object value, Dialect.Datatype datatype) Appends to a buffer a value quoted for its type.voidquoteBooleanLiteral(StringBuilder buf, String value) Appends to a buffer a boolean literal.voidquoteDateLiteral(StringBuilder buf, String value) Appends to a buffer a date literal.protected voidquoteDateLiteral(StringBuilder buf, String value, Date date) Helper method forquoteDateLiteral(StringBuilder, String).quoteIdentifier(String val) Encloses an identifier in quotation marks appropriate for this Dialect.voidquoteIdentifier(StringBuilder buf, String... names) Appends to a buffer a list of identifiers, quoted appropriately for this Dialect.quoteIdentifier(String qual, String name) Encloses an identifier in quotation marks appropriate for the current SQL dialect.voidquoteIdentifier(String val, StringBuilder buf) Appends to a buffer an identifier, quoted appropriately for this Dialect.voidquoteNumericLiteral(StringBuilder buf, String value) Appends to a buffer a numeric literal.voidquoteStringLiteral(StringBuilder buf, String s) Appends to a buffer a single-quoted SQL string.voidquoteTimeLiteral(StringBuilder buf, String value) Appends to a buffer a time literal.voidquoteTimestampLiteral(StringBuilder buf, String value) Appends to a buffer a timestamp literal.protected voidquoteTimestampLiteral(StringBuilder buf, String value, Timestamp timestamp) booleanReturns whether this Dialect requires subqueries in the FROM clause to have an alias.booleanReturns true if this Dialect can include expressions in the GROUP BY clause only by adding an expression to the SELECT clause and using its alias.booleanReturns true if this Dialect can include expressions in the HAVING clause only by adding an expression to the SELECT clause and using its alias.booleanReturns true if this Dialect can include expressions in the ORDER BY clause only by adding an expression to the SELECT clause and using its alias.booleanReturns true if this dialect allows an expression in the ORDER BY clause of a UNION (or other set operation) query only if it occurs in the SELECT clause.booleanReturns true if this dialect allows only integers in the ORDER BY clause of a UNION (or other set operation) query.booleanReturns whether this Dialect supports expressions in the GROUP BY clause.booleanReturns whether this Dialect allows the GROUPING SETS construct in the GROUP BY clause.booleanReturns true if this dialect supports multi-value IN expressions.booleansupportsResultSetConcurrency(int type, int concurrency) Returns whether this Dialect supports the given concurrency type in combination with the given result set type.booleanReturns whether this Dialect places no limit on the number of rows which can appear as elements of an IN or VALUES expression.toString()Converts an expression to upper case.
-
Field Details
-
productVersion
Product version per JDBC driver. -
permitsSelectNotInGroupBy
protected boolean permitsSelectNotInGroupByIndicates whether the database allows selection of columns not listed in the group by clause. -
databaseProduct
Major database product (or null if product is not a common one)
-
-
Constructor Details
-
JdbcDialectImpl
Creates a JdbcDialectImpl.To prevent connection leaks, this constructor does not hold a reference to the connection after the call returns. It makes a copy of everything useful during the call. Derived classes must do the same.
- Parameters:
connection- Connection- Throws:
SQLException- on error
-
JdbcDialectImpl
public JdbcDialectImpl()
-
-
Method Details
-
getDatabaseProduct
Description copied from interface:DialectReturns the database for this Dialect, orDialect.DatabaseProduct.UNKNOWNif the database is not a common database.- Specified by:
getDatabaseProductin interfaceDialect- Returns:
- Database
-
appendHintsAfterFromClause
Description copied from interface:DialectAssembles and returns a string containing any hints that should be appended after the FROM clause in a SELECT statement, based on any hints provided. Any unrecognized or unsupported hints will be ignored.- Specified by:
appendHintsAfterFromClausein interfaceDialect- Parameters:
buf- The Stringbuffer to which the dialect-specific syntax for any relevant table hints may be appended. Must not be null.hints- A map of table hints provided in the schema definition
-
allowsDialectSharing
public boolean allowsDialectSharing()Description copied from interface:DialectReturns whether this Dialect object can be used for all connections from the same data source.The default implementation returns
true, and this allows dialects to be cached and reused in environments where connections are allocated from a pool based on the same data source.Data sources are deemed 'equal' by the same criteria used by Java collections, namely the
Object.equals(Object)andObject.hashCode()methods.- Specified by:
allowsDialectSharingin interfaceDialect- Returns:
- Whether this dialect can be used for other connections created from the same data source
- See Also:
-
deduceMaxColumnNameLength
-
deduceReadOnly
-
deduceProductName
-
deduceIdentifierQuoteString
-
deduceProductVersion
-
deduceSupportedResultSetStyles
-
deduceSupportsSelectNotInGroupBy
Detects whether the database is configured to permit queries that include columns in the SELECT that are not also in the GROUP BY. MySQL is an example of one that does, though this is configurable.
The expectation is that this will not change while Mondrian is running, though some databases (MySQL) allow changing it on the fly.
- Parameters:
conn- The database connection- Returns:
- Whether the feature is enabled.
- Throws:
SQLException- on error
-
toUpper
Description copied from interface:DialectConverts an expression to upper case.For example, for MySQL,
toUpper("foo.bar")returns"UPPER(foo.bar)". -
caseWhenElse
Description copied from interface:DialectGenerates a conditional statement in this dialect's syntax.For example,
caseWhenElse("b", "1", "0")returns"case when b then 1 else 0 end"on Oracle,"Iif(b, 1, 0)"on Access.- Specified by:
caseWhenElsein interfaceDialect- Parameters:
cond- Predicate expressionthenExpr- Expression if condition is trueelseExpr- Expression if condition is false- Returns:
- Conditional expression
-
quoteIdentifier
Description copied from interface:DialectEncloses an identifier in quotation marks appropriate for this Dialect.For example,
quoteIdentifier("emp")yields a string containing"emp"in Oracle, and a string containing[emp]in Access.- Specified by:
quoteIdentifierin interfaceDialect- Parameters:
val- Identifier- Returns:
- Quoted identifier
-
quoteIdentifier
Description copied from interface:DialectAppends to a buffer an identifier, quoted appropriately for this Dialect.- Specified by:
quoteIdentifierin interfaceDialect- Parameters:
val- identifier to quote (must not be null).buf- Buffer
-
quoteIdentifier
Description copied from interface:DialectEncloses an identifier in quotation marks appropriate for the current SQL dialect. For example, in Oracle, where the identifiers are quoted using double-quotes,quoteIdentifier("schema","table")yields a string containing"schema"."table".- Specified by:
quoteIdentifierin interfaceDialect- Parameters:
qual- Qualifier. If it is not null,"qual".is prepended.name- Name to be quoted.- Returns:
- Quoted identifier
-
quoteIdentifier
Description copied from interface:DialectAppends to a buffer a list of identifiers, quoted appropriately for this Dialect.Names in the list may be null, but there must be at least one non-null name in the list.
- Specified by:
quoteIdentifierin interfaceDialect- Parameters:
buf- Buffernames- List of names to be quoted
-
getQuoteIdentifierString
Description copied from interface:DialectReturns the character which is used to quote identifiers, or null if quoting is not supported.- Specified by:
getQuoteIdentifierStringin interfaceDialect- Returns:
- identifier quote
-
quoteStringLiteral
Description copied from interface:DialectAppends to a buffer a single-quoted SQL string.For example, in the default dialect,
quoteStringLiteral(buf, "Can't")appends "'Can''t'" tobuf.- Specified by:
quoteStringLiteralin interfaceDialect- Parameters:
buf- Buffer to append tos- Literal
-
quoteNumericLiteral
Description copied from interface:DialectAppends to a buffer a numeric literal.In the default dialect, numeric literals are printed as is.
- Specified by:
quoteNumericLiteralin interfaceDialect- Parameters:
buf- Buffer to append tovalue- Literal
-
quoteBooleanLiteral
Description copied from interface:DialectAppends to a buffer a boolean literal.In the default dialect, boolean literals are printed as is.
- Specified by:
quoteBooleanLiteralin interfaceDialect- Parameters:
buf- Buffer to append tovalue- Literal
-
quoteDateLiteral
Description copied from interface:DialectAppends to a buffer a date literal.For example, in the default dialect,
quoteStringLiteral(buf, "1969-03-17")appendsDATE '1969-03-17'.- Specified by:
quoteDateLiteralin interfaceDialect- Parameters:
buf- Buffer to append tovalue- Literal
-
quoteDateLiteral
Helper method forquoteDateLiteral(StringBuilder, String).- Parameters:
buf- Buffer to append tovalue- Value as stringdate- Value as date
-
quoteTimeLiteral
Description copied from interface:DialectAppends to a buffer a time literal.For example, in the default dialect,
quoteStringLiteral(buf, "12:34:56")appendsTIME '12:34:56'.- Specified by:
quoteTimeLiteralin interfaceDialect- Parameters:
buf- Buffer to append tovalue- Literal
-
quoteTimestampLiteral
Description copied from interface:DialectAppends to a buffer a timestamp literal.For example, in the default dialect,
quoteStringLiteral(buf, "1969-03-17 12:34:56")appendsTIMESTAMP '1969-03-17 12:34:56'.- Specified by:
quoteTimestampLiteralin interfaceDialect- Parameters:
buf- Buffer to append tovalue- Literal
-
quoteTimestampLiteral
-
requiresAliasForFromQuery
public boolean requiresAliasForFromQuery()Description copied from interface:DialectReturns whether this Dialect requires subqueries in the FROM clause to have an alias.- Specified by:
requiresAliasForFromQueryin interfaceDialect- Returns:
- whether dialewct requires subqueries to have an alias
- See Also:
-
allowsAs
public boolean allowsAs()Description copied from interface:DialectReturns whether the SQL dialect allows "AS" in the FROM clause. If so, "SELECT * FROM t AS alias" is a valid query. -
allowsFromQuery
public boolean allowsFromQuery()Description copied from interface:DialectReturns whether this Dialect allows a subquery in the from clause, for exampleSELECT * FROM (SELECT * FROM t) AS x- Specified by:
allowsFromQueryin interfaceDialect- Returns:
- whether Dialect allows subquery in FROM clause
- See Also:
-
allowsCompoundCountDistinct
public boolean allowsCompoundCountDistinct()Description copied from interface:DialectReturns whether this Dialect allows multiple arguments to theCOUNT(DISTINCT ...) aggregate function, for exampleSELECT COUNT(DISTINCT x, y) FROM t- Specified by:
allowsCompoundCountDistinctin interfaceDialect- Returns:
- whether Dialect allows multiple arguments to COUNT DISTINCT
- See Also:
-
allowsCountDistinct
public boolean allowsCountDistinct()Description copied from interface:DialectReturns whether this Dialect supports distinct aggregations.For example, Access does not allow
select count(distinct x) from t- Specified by:
allowsCountDistinctin interfaceDialect- Returns:
- whether Dialect allows COUNT DISTINCT
-
allowsMultipleCountDistinct
public boolean allowsMultipleCountDistinct()Description copied from interface:DialectReturns whether this Dialect supports more than one distinct aggregation in the same query.In Derby 10.1,
is OK, butselect couunt(distinct x) from t
gives "Multiple DISTINCT aggregates are not supported at this time."select couunt(distinct x), count(distinct y) from t- Specified by:
allowsMultipleCountDistinctin interfaceDialect- Returns:
- whether this Dialect supports more than one distinct aggregation in the same query
-
allowsMultipleDistinctSqlMeasures
public boolean allowsMultipleDistinctSqlMeasures()Description copied from interface:DialectReturns whether this Dialect has performant support of distinct SQL measures in the same query.- Specified by:
allowsMultipleDistinctSqlMeasuresin interfaceDialect- Returns:
- whether this dialect supports multiple count(distinct subquery) measures in one query.
-
allowsCountDistinctWithOtherAggs
public boolean allowsCountDistinctWithOtherAggs()Description copied from interface:DialectReturns whether this Dialect supports distinct aggregations with other aggregations in the same query. This may be enabled for performance reasons (Vertica)- Specified by:
allowsCountDistinctWithOtherAggsin interfaceDialect- Returns:
- whether this Dialect supports more than one distinct aggregation in the same query
-
generateInline
public String generateInline(List<String> columnNames, List<String> columnTypes, List<String[]> valueList) Description copied from interface:DialectGenerates a SQL statement to represent an inline dataset.For example, for Oracle, generates
SELECT 1 AS FOO, 'a' AS BAR FROM dual UNION ALL SELECT 2 AS FOO, 'b' AS BAR FROM dual
For ANSI SQL, generates:
VALUES (1, 'a'), (2, 'b')
- Specified by:
generateInlinein interfaceDialect- Parameters:
columnNames- List of column namescolumnTypes- List of column types ("String" or "Numeric")valueList- List of rows values- Returns:
- SQL string
-
generateInlineGeneric
protected String generateInlineGeneric(List<String> columnNames, List<String> columnTypes, List<String[]> valueList, String fromClause, boolean cast) Generic algorithm to generate inline values list, using an optional FROM clause, specified by the caller of this method, appropriate to the dialect of SQL.- Parameters:
columnNames- Column namescolumnTypes- Column typesvalueList- List rowsfromClause- FROM clause, or nullcast- Whether to cast the values in the first row- Returns:
- Expression that returns the given values
-
generateInlineForAnsi
public String generateInlineForAnsi(String alias, List<String> columnNames, List<String> columnTypes, List<String[]> valueList, boolean cast) Generates inline values list using ANSI 'VALUES' syntax. For example,SELECT * FROM (VALUES (1, 'a'), (2, 'b')) AS t(x, y)If NULL values are present, we use a CAST to ensure that they have the same type as other columns:
SELECT * FROM (VALUES (1, 'a'), (2, CASE(NULL AS VARCHAR(1)))) AS t(x, y)This syntax is known to work on Derby, but not Oracle 10 or Access.
- Parameters:
alias- Table aliascolumnNames- Column namescolumnTypes- Column typesvalueList- List rowscast- Whether to generate casts- Returns:
- Expression that returns the given values
-
needsExponent
Description copied from interface:DialectIf Double values need to include additional exponent in its string represenation. This is to make sure that Double literals will be interpreted as doubles by LucidDB.- Specified by:
needsExponentin interfaceDialect- Parameters:
value- Double value to generate string forvalueString- java string representation for this value.- Returns:
- whether an additional exponent "E0" needs to be appended
-
quote
Description copied from interface:DialectAppends to a buffer a value quoted for its type. -
allowsDdl
public boolean allowsDdl()Description copied from interface:DialectReturns whether this dialect supports common SQL Data Definition Language (DDL) statements such asCREATE TABLEandDROP INDEX.Access seems to allow DDL iff the .mdb file is writeable.
-
generateOrderItem
public String generateOrderItem(String expr, boolean nullable, boolean ascending, boolean collateNullsLast) Description copied from interface:DialectGenerates an item for an ORDER BY clause, sorting in the required direction, and ensuring that NULL values collate either before or after all non-NULL values, depending on thecollateNullsLastparameter.- Specified by:
generateOrderItemin interfaceDialect- Parameters:
expr- Expressionnullable- Whether expression may have NULL valuesascending- Whether to sort expression ascendingcollateNullsLast- Whether the null values should be sorted first or last.- Returns:
- Expression modified so that NULL values collate last
-
generateOrderByNulls
Generates SQL to force null values to collate last.This default implementation makes use of the ANSI SQL 1999 CASE-WHEN-THEN-ELSE in conjunction with IS NULL syntax. The resulting SQL will look something like this:
CASE WHEN "expr" IS NULL THEN 0 ELSE 1 ENDYou can override this method for a particular database to use something more efficient, like ISNULL().
ANSI SQL provides the syntax "ASC/DESC NULLS LAST" and "ASC/DESC NULLS FIRST". If your database supports the ANSI syntax, implement this method by calling
generateOrderByNullsAnsi(java.lang.String, boolean, boolean).This method is only called from
generateOrderItem(String, boolean, boolean, boolean). Some dialects override that method and therefore never call this method.- Parameters:
expr- Expression.ascending- Whether ascending.collateNullsLast- Whether nulls should appear first or last.- Returns:
- Expression to force null values to collate last or first.
-
generateOrderByNullsAnsi
protected final String generateOrderByNullsAnsi(String expr, boolean ascending, boolean collateNullsLast) Implementation for thegenerateOrderByNulls(java.lang.String, boolean, boolean)method that uses the ANSI syntax "expr direction NULLS LAST" and "expr direction NULLS FIRST".- Parameters:
expr- Expressionascending- Whether ascendingcollateNullsLast- Whether nulls should appear first or last.- Returns:
- Expression "expr direction NULLS LAST"
-
supportsGroupByExpressions
public boolean supportsGroupByExpressions()Description copied from interface:DialectReturns whether this Dialect supports expressions in the GROUP BY clause. Derby/Cloudscape and Infobright do not.- Specified by:
supportsGroupByExpressionsin interfaceDialect- Returns:
- Whether this Dialect allows expressions in the GROUP BY clause
-
allowsSelectNotInGroupBy
public boolean allowsSelectNotInGroupBy()Description copied from interface:DialectReturns whether the database currently permits queries to include in the SELECT clause expressions that are not listed in the GROUP BY clause. The SQL standard allows this if the database can deduce that the expression is functionally dependent on columns in the GROUP BY clause.For example,
SELECT empno, first_name || ' ' || last_name FROM emps GROUP BY empnois valid becauseempnois the primary key of theempstable, and therefore all columns are dependent on it. For a given value ofempno,first_name || ' ' || last_namehas a unique value.Most databases do not, MySQL is an example of one that does (if the functioality is enabled).
- Specified by:
allowsSelectNotInGroupByin interfaceDialect- Returns:
- Whether this Dialect allows SELECT clauses to contain columns that are not in the GROUP BY clause
-
allowsJoinOn
public boolean allowsJoinOn()Description copied from interface:DialectReturns whether this dialect supports "ANSI-style JOIN syntax",FROM leftTable JOIN rightTable ON conditon.- Specified by:
allowsJoinOnin interfaceDialect- Returns:
- Whether this dialect supports FROM-JOIN-ON syntax.
-
supportsGroupingSets
public boolean supportsGroupingSets()Description copied from interface:DialectReturns whether this Dialect allows the GROUPING SETS construct in the GROUP BY clause. Currently Greenplum, IBM DB2, Oracle, and Teradata.- Specified by:
supportsGroupingSetsin interfaceDialect- Returns:
- Whether this Dialect allows GROUPING SETS clause
-
supportsUnlimitedValueList
public boolean supportsUnlimitedValueList()Description copied from interface:DialectReturns whether this Dialect places no limit on the number of rows which can appear as elements of an IN or VALUES expression.- Specified by:
supportsUnlimitedValueListin interfaceDialect- Returns:
- whether value list length is unlimited
-
requiresGroupByAlias
public boolean requiresGroupByAlias()Description copied from interface:DialectReturns true if this Dialect can include expressions in the GROUP BY clause only by adding an expression to the SELECT clause and using its alias.For example, in such a dialect,
would be illegal, butSELECT x, x FROM t GROUP BY x
would be legal.SELECT x AS a, x AS b FROM t ORDER BY a, bInfobright is the only such dialect.
- Specified by:
requiresGroupByAliasin interfaceDialect- Returns:
- Whether this Dialect can include expressions in the GROUP BY clause only by adding an expression to the SELECT clause and using its alias
-
requiresOrderByAlias
public boolean requiresOrderByAlias()Description copied from interface:DialectReturns true if this Dialect can include expressions in the ORDER BY clause only by adding an expression to the SELECT clause and using its alias.For example, in such a dialect,
would be illegal, butSELECT x FROM t ORDER BY x + y
would be legal.SELECT x, x + y AS z FROM t ORDER BY zMySQL, DB2 and Ingres are examples of such dialects.
- Specified by:
requiresOrderByAliasin interfaceDialect- Returns:
- Whether this Dialect can include expressions in the ORDER BY clause only by adding an expression to the SELECT clause and using its alias
-
requiresHavingAlias
public boolean requiresHavingAlias()Description copied from interface:DialectReturns true if this Dialect can include expressions in the HAVING clause only by adding an expression to the SELECT clause and using its alias.For example, in such a dialect,
would be illegal, butSELECT CONCAT(x) as foo FROM t HAVING CONCAT(x) LIKE "%"
would be legal.SELECT CONCAT(x) as foo FROM t HAVING foo LIKE "%"MySQL is an example of such dialects.
- Specified by:
requiresHavingAliasin interfaceDialect- Returns:
- Whether this Dialect can include expressions in the HAVING clause only by adding an expression to the SELECT clause and using its alias
-
allowsOrderByAlias
public boolean allowsOrderByAlias()Description copied from interface:DialectReturns true if aliases defined in the SELECT clause can be used as expressions in the ORDER BY clause.For example, in such a dialect,
would be legal.SELECT x, x + y AS z FROM t ORDER BY zMySQL, DB2 and Ingres are examples of dialects where this is true; Access is a dialect where this is false.
- Specified by:
allowsOrderByAliasin interfaceDialect- Returns:
- Whether aliases defined in the SELECT clause can be used as expressions in the ORDER BY clause.
-
requiresUnionOrderByOrdinal
public boolean requiresUnionOrderByOrdinal()Description copied from interface:DialectReturns true if this dialect allows only integers in the ORDER BY clause of a UNION (or other set operation) query.For example,
SELECT x, y + z FROM tis allowed but
UNION ALL
SELECT x, y + z FROM t
ORDER BY 1, 2SELECT x, y, z FROM tis not.
UNION ALL
SELECT x, y, z FROM t
ORDER BY xTeradata is an example of a dialect with this restriction.
- Specified by:
requiresUnionOrderByOrdinalin interfaceDialect- Returns:
- whether this dialect allows only integers in the ORDER BY clause of a UNION (or other set operation) query
-
requiresUnionOrderByExprToBeInSelectClause
public boolean requiresUnionOrderByExprToBeInSelectClause()Description copied from interface:DialectReturns true if this dialect allows an expression in the ORDER BY clause of a UNION (or other set operation) query only if it occurs in the SELECT clause.For example,
SELECT x, y + z FROM tis allowed but
UNION ALL
SELECT x, y + z FROM t
ORDER BY y + zSELECT x, y, z FROM t
UNION ALL
SELECT x, y, z FROM t
ORDER BY y + zSELECT x, y, z FROM t ORDER BY y + zis not.Access is an example of a dialect with this restriction.
- Specified by:
requiresUnionOrderByExprToBeInSelectClausein interfaceDialect- Returns:
- whether this dialect allows an expression in the ORDER BY clause of a UNION (or other set operation) query only if it occurs in the SELECT clause
-
supportsMultiValueInExpr
public boolean supportsMultiValueInExpr()Description copied from interface:DialectReturns true if this dialect supports multi-value IN expressions. E.g.,WHERE (col1, col2) IN ((val1a, val2a), (val1b, val2b))- Specified by:
supportsMultiValueInExprin interfaceDialect- Returns:
- true if the dialect supports multi-value IN expressions
-
supportsResultSetConcurrency
public boolean supportsResultSetConcurrency(int type, int concurrency) Description copied from interface:DialectReturns whether this Dialect supports the given concurrency type in combination with the given result set type.The result is similar to
DatabaseMetaData.supportsResultSetConcurrency(int, int), except that the JdbcOdbc bridge in JDK 1.6 overstates its abilities. See bug 1690406.- Specified by:
supportsResultSetConcurrencyin interfaceDialect- Parameters:
type- defined inResultSetconcurrency- type defined inResultSet- Returns:
trueif so;falseotherwise
-
toString
-
getMaxColumnNameLength
public int getMaxColumnNameLength()Description copied from interface:DialectReturns the maximum length of the name of a database column or query alias allowed by this dialect.- Specified by:
getMaxColumnNameLengthin interfaceDialect- Returns:
- maximum number of characters in a column name
- See Also:
-
allowsRegularExpressionInWhereClause
public boolean allowsRegularExpressionInWhereClause()Description copied from interface:DialectInforms Mondrian if the dialect supports regular expressions when creating the 'where' or the 'having' clause.- Specified by:
allowsRegularExpressionInWhereClausein interfaceDialect- Returns:
- True if regular expressions are supported.
-
generateCountExpression
Description copied from interface:DialectSome databases, like Greenplum, don't include nulls as part of the results of a COUNT sql call. This allows dialects to wrap the count expression in something before it is used in the query.- Specified by:
generateCountExpressionin interfaceDialect- Parameters:
exp- The expression to wrap.- Returns:
- A valid expression to use for a count operation.
-
generateRegularExpression
Description copied from interface:DialectMust generate a String representing a regular expression match operation between a string literal and a Java regular expression. The string literal might be a column identifier or some other identifier, but the implementation must presume that it is already escaped and fit for use. The regular expression is not escaped and must be adapted to the proper dialect rules.Postgres / Greenplum example:
generateRegularExpression( "'foodmart'.'customer_name'", "(?i).*oo.*") -> 'foodmart'.'customer_name' ~ "(?i).*oo.*"Oracle example:
generateRegularExpression( "'foodmart'.'customer_name'", ".*oo.*") -> REGEXP_LIKE('foodmart'.'customer_name', ".*oo.*")Dialects are allowed to return null if the dialect cannot convert that particular regular expression into something that the database would support.
- Specified by:
generateRegularExpressionin interfaceDialect- Parameters:
source- A String identifying the column to match against.javaRegExp- A Java regular expression to match against.- Returns:
- A dialect specific matching operation, or null if the dialect cannot convert that particular regular expression into something that the database would support.
-
getStatisticsProviders
Description copied from interface:DialectReturns a list of statistics providers for this dialect.The default implementation looks for the value of the property
mondrian.statistics.providers.PRODUCTwhere product is the current dialect's product name (for example "MYSQL"). If that property has no value, looks at the propertymondrian.statistics.providers. The property value should be a comma-separated list of names of classes that implement theStatisticsProviderinterface. For each statistic required, Mondrian will call the method each statistics provider in turn, until one of them returns a non-negative value.- Specified by:
getStatisticsProvidersin interfaceDialect
-
getType
Description copied from interface:DialectChooses the most appropriate type for accessing the values of a column in a result set for a dialect.
Dialect-specific nuances involving type representation should be encapsulated in implementing methods. For example, if a dialect has implicit rules involving scale or precision, they should be handled within this method so the client can simply retrieve the "best fit" SqlStatement.Type for the column.
- Specified by:
getTypein interfaceDialect- Parameters:
metaData- Results set metadatacolumnIndex- Column ordinal (0-based)- Returns:
- the most appropriate SqlStatement.Type for the column
- Throws:
SQLException
-
computeStatisticsProviders
-
getProduct
Converts a product name and version (per the JDBC driver) into a product enumeration.- Parameters:
productName- Product nameproductVersion- Product version- Returns:
- database product
-
isDatabase
Helper method to determine if a connection would work with a given database product. This can be used to differenciate between databases which use the same driver as others.It will first try to use
DatabaseMetaData.getDatabaseProductName()and match the name ofDialect.DatabaseProductpassed as an argument.If that fails, it will try to execute
select version();and obtains some information directly from the server.- Parameters:
databaseProduct- Database product instanceconnection- SQL connection- Returns:
- true if a match was found. false otherwise.
-
extractEmbeddedFlags
public String extractEmbeddedFlags(String javaRegex, String[][] mapping, StringBuilder dialectFlags) Helper method to extract and map Java regular expression embedded flags expressions to dialect specific flags. All dialects will map the case insensitive expression (?i) to i. However, Vertica maps the dotall flag (?s) to n. For example, on Vertica, a regular expression like: "(?is).*Hello World.*" will return: ".*Hello World.*" with dialect flags: "in"- Parameters:
origExp- Java regular expressionmapping- 2D String array of supported Java flags that can be mapped to a dialect specific flag.dialectFlags- Returns the dialect specific flags in the input regular expression.- Returns:
- Regular expression with the Java flags removed.
-