public class MySqlDialect extends JdbcDialectImpl
Dialect for the MySQL database.Dialect.DatabaseProduct, Dialect.Datatype| Modifier and Type | Field and Description |
|---|---|
static JdbcDialectFactory |
FACTORY |
databaseProduct, permitsSelectNotInGroupBy, productVersion| Constructor and Description |
|---|
MySqlDialect(Connection connection)
Creates a MySqlDialect.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
allowsCompoundCountDistinct()
Returns whether this Dialect allows multiple arguments to the
COUNT(DISTINCT ...) aggregate function, for example
|
boolean |
allowsFromQuery()
Returns whether this Dialect allows a subquery in the from clause,
for example
SELECT * FROM (SELECT * FROM t) AS
x |
boolean |
allowsRegularExpressionInWhereClause()
Informs Mondrian if the dialect supports regular expressions
when creating the 'where' or the 'having' clause.
|
void |
appendHintsAfterFromClause(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.
|
protected String |
deduceIdentifierQuoteString(DatabaseMetaData databaseMetaData) |
protected String |
deduceProductName(DatabaseMetaData databaseMetaData) |
protected boolean |
deduceSupportsSelectNotInGroupBy(Connection connection)
Detects whether the database is configured to permit queries
that include columns in the SELECT that are not also in the GROUP BY.
|
String |
generateInline(List<String> columnNames,
List<String> columnTypes,
List<String[]> valueList)
Generates a SQL statement to represent an inline dataset.
|
protected String |
generateOrderByNulls(String expr,
boolean ascending,
boolean collateNullsLast)
Generates SQL to force null values to collate last.
|
String |
generateRegularExpression(String source,
String javaRegex)
Must generate a String representing a regular expression match
operation between a string literal and a Java regular expression.
|
static boolean |
isInfobright(DatabaseMetaData databaseMetaData)
Detects whether this database is Infobright.
|
void |
quoteBooleanLiteral(StringBuilder buf,
String value)
Appends to a buffer a boolean literal.
|
void |
quoteStringLiteral(StringBuilder buf,
String s)
Appends to a buffer a single-quoted SQL string.
|
boolean |
requiresAliasForFromQuery()
Returns whether this Dialect requires subqueries in the FROM clause
to have an alias.
|
boolean |
requiresHavingAlias()
Returns true if this Dialect can include expressions in the HAVING
clause only by adding an expression to the SELECT clause and using
its alias.
|
boolean |
requiresOrderByAlias()
Required for MySQL 5.7+, where SQL_MODE include ONLY_FULL_GROUP_BY
by default.
|
boolean |
supportsMultiValueInExpr()
Returns true if this dialect supports multi-value IN expressions.
|
allowsAs, allowsCountDistinct, allowsCountDistinctWithOtherAggs, allowsDdl, allowsDialectSharing, allowsJoinOn, allowsMultipleCountDistinct, allowsMultipleDistinctSqlMeasures, allowsOrderByAlias, allowsSelectNotInGroupBy, caseWhenElse, computeStatisticsProviders, deduceMaxColumnNameLength, deduceProductVersion, deduceReadOnly, deduceSupportedResultSetStyles, extractEmbeddedFlags, generateCountExpression, generateInlineForAnsi, generateInlineGeneric, generateOrderByNullsAnsi, generateOrderItem, getDatabaseProduct, getMaxColumnNameLength, getProduct, getQuoteIdentifierString, getStatisticsProviders, getType, isDatabase, needsExponent, quote, quoteDateLiteral, quoteDateLiteral, quoteIdentifier, quoteIdentifier, quoteIdentifier, quoteIdentifier, quoteNumericLiteral, quoteTimeLiteral, quoteTimestampLiteral, quoteTimestampLiteral, requiresGroupByAlias, requiresUnionOrderByExprToBeInSelectClause, requiresUnionOrderByOrdinal, supportsGroupByExpressions, supportsGroupingSets, supportsResultSetConcurrency, supportsUnlimitedValueList, toString, toUpperpublic static final JdbcDialectFactory FACTORY
public MySqlDialect(Connection connection) throws SQLException
connection - ConnectionSQLException - on errorpublic static boolean isInfobright(DatabaseMetaData databaseMetaData)
Infobright uses the MySQL driver and appears to be a MySQL instance. The only difference is the presence of the BRIGHTHOUSE engine.
databaseMetaData - Database metadataprotected String deduceProductName(DatabaseMetaData databaseMetaData)
deduceProductName in class JdbcDialectImplprotected String deduceIdentifierQuoteString(DatabaseMetaData databaseMetaData)
deduceIdentifierQuoteString in class JdbcDialectImplprotected boolean deduceSupportsSelectNotInGroupBy(Connection connection) throws SQLException
JdbcDialectImplDetects 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.
deduceSupportsSelectNotInGroupBy in class JdbcDialectImplconnection - The database connectionSQLException - on errorpublic void appendHintsAfterFromClause(StringBuilder buf, Map<String,String> hints)
DialectappendHintsAfterFromClause in interface DialectappendHintsAfterFromClause in class JdbcDialectImplbuf - 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 definitionpublic boolean requiresAliasForFromQuery()
DialectrequiresAliasForFromQuery in interface DialectrequiresAliasForFromQuery in class JdbcDialectImplDialect.allowsFromQuery()public boolean allowsFromQuery()
DialectSELECT * FROM (SELECT * FROM t) AS
xallowsFromQuery in interface DialectallowsFromQuery in class JdbcDialectImplDialect.requiresAliasForFromQuery()public boolean allowsCompoundCountDistinct()
DialectCOUNT(DISTINCT ...) aggregate function, for example
SELECT COUNT(DISTINCT x, y) FROM t
allowsCompoundCountDistinct in interface DialectallowsCompoundCountDistinct in class JdbcDialectImplDialect.allowsCountDistinct(),
Dialect.allowsMultipleCountDistinct()public void quoteStringLiteral(StringBuilder buf, String s)
DialectFor example, in the default dialect,
quoteStringLiteral(buf, "Can't") appends
"'Can''t'" to buf.
quoteStringLiteral in interface DialectquoteStringLiteral in class JdbcDialectImplbuf - Buffer to append tos - Literalpublic void quoteBooleanLiteral(StringBuilder buf, String value)
DialectIn the default dialect, boolean literals are printed as is.
quoteBooleanLiteral in interface DialectquoteBooleanLiteral in class JdbcDialectImplbuf - Buffer to append tovalue - Literalpublic String generateInline(List<String> columnNames, List<String> columnTypes, List<String[]> valueList)
DialectFor 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')
generateInline in interface DialectgenerateInline in class JdbcDialectImplcolumnNames - List of column namescolumnTypes - List of column types ("String" or "Numeric")valueList - List of rows valuesprotected String generateOrderByNulls(String expr, boolean ascending, boolean collateNullsLast)
JdbcDialectImplThis 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 END
You 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
JdbcDialectImpl.generateOrderByNullsAnsi(java.lang.String, boolean, boolean).
This method is only called from
JdbcDialectImpl.generateOrderItem(String, boolean, boolean, boolean).
Some dialects override that method and therefore never call
this method.
generateOrderByNulls in class JdbcDialectImplexpr - Expression.ascending - Whether ascending.collateNullsLast - Whether nulls should appear first or last.public boolean requiresHavingAlias()
DialectFor example, in such a dialect,
SELECT CONCAT(x) as foo FROM t HAVING CONCAT(x) LIKE "%"
would be illegal, but
SELECT CONCAT(x) as foo FROM t HAVING foo LIKE "%"
would be legal.
MySQL is an example of such dialects.
requiresHavingAlias in interface DialectrequiresHavingAlias in class JdbcDialectImplpublic boolean supportsMultiValueInExpr()
DialectWHERE (col1, col2) IN ((val1a, val2a), (val1b, val2b))supportsMultiValueInExpr in interface DialectsupportsMultiValueInExpr in class JdbcDialectImplpublic boolean allowsRegularExpressionInWhereClause()
DialectallowsRegularExpressionInWhereClause in interface DialectallowsRegularExpressionInWhereClause in class JdbcDialectImplpublic String generateRegularExpression(String source, String javaRegex)
DialectPostgres / 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.
generateRegularExpression in interface DialectgenerateRegularExpression in class JdbcDialectImplsource - A String identifying the column to match against.javaRegex - A Java regular expression to match against.public boolean requiresOrderByAlias()
requiresOrderByAlias in interface DialectrequiresOrderByAlias in class JdbcDialectImplCopyright © 2021 Hitachi Vantara. All rights reserved.