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, generateCountExpression, generateInlineForAnsi, generateInlineGeneric, generateOrderByNullsAnsi, generateOrderItem, getDatabaseProduct, getMaxColumnNameLength, getProduct, getQuoteIdentifierString, getStatisticsProviders, getType, isDatabase, needsExponent, quote, quoteDateLiteral, quoteDateLiteral, quoteIdentifier, quoteIdentifier, quoteIdentifier, quoteIdentifier, quoteNumericLiteral, quoteTimeLiteral, quoteTimestampLiteral, requiresGroupByAlias, requiresUnionOrderByExprToBeInSelectClause, requiresUnionOrderByOrdinal, supportsGroupByExpressions, supportsGroupingSets, supportsResultSetConcurrency, supportsUnlimitedValueList, toString, toUpper
public 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 JdbcDialectImpl
protected String deduceIdentifierQuoteString(DatabaseMetaData databaseMetaData)
deduceIdentifierQuoteString
in class JdbcDialectImpl
protected boolean deduceSupportsSelectNotInGroupBy(Connection connection) throws SQLException
JdbcDialectImpl
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.
deduceSupportsSelectNotInGroupBy
in class JdbcDialectImpl
connection
- The database connectionSQLException
- on errorpublic void appendHintsAfterFromClause(StringBuilder buf, Map<String,String> hints)
Dialect
appendHintsAfterFromClause
in interface Dialect
appendHintsAfterFromClause
in class JdbcDialectImpl
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 definitionpublic boolean requiresAliasForFromQuery()
Dialect
requiresAliasForFromQuery
in interface Dialect
requiresAliasForFromQuery
in class JdbcDialectImpl
Dialect.allowsFromQuery()
public boolean allowsFromQuery()
Dialect
SELECT * FROM (SELECT * FROM t) AS
x
allowsFromQuery
in interface Dialect
allowsFromQuery
in class JdbcDialectImpl
Dialect.requiresAliasForFromQuery()
public boolean allowsCompoundCountDistinct()
Dialect
COUNT(DISTINCT ...) aggregate function, for example
SELECT COUNT(DISTINCT x, y) FROM t
allowsCompoundCountDistinct
in interface Dialect
allowsCompoundCountDistinct
in class JdbcDialectImpl
Dialect.allowsCountDistinct()
,
Dialect.allowsMultipleCountDistinct()
public void quoteStringLiteral(StringBuilder buf, String s)
Dialect
For example, in the default dialect,
quoteStringLiteral(buf, "Can't")
appends
"'Can''t'
" to buf
.
quoteStringLiteral
in interface Dialect
quoteStringLiteral
in class JdbcDialectImpl
buf
- Buffer to append tos
- Literalpublic void quoteBooleanLiteral(StringBuilder buf, String value)
Dialect
In the default dialect, boolean literals are printed as is.
quoteBooleanLiteral
in interface Dialect
quoteBooleanLiteral
in class JdbcDialectImpl
buf
- Buffer to append tovalue
- Literalpublic String generateInline(List<String> columnNames, List<String> columnTypes, List<String[]> valueList)
Dialect
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')
generateInline
in interface Dialect
generateInline
in class JdbcDialectImpl
columnNames
- List of column namescolumnTypes
- List of column types ("String" or "Numeric")valueList
- List of rows valuesprotected String generateOrderByNulls(String expr, boolean ascending, boolean collateNullsLast)
JdbcDialectImpl
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 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 JdbcDialectImpl
expr
- Expression.ascending
- Whether ascending.collateNullsLast
- Whether nulls should appear first or last.public boolean requiresHavingAlias()
Dialect
For 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 Dialect
requiresHavingAlias
in class JdbcDialectImpl
public boolean supportsMultiValueInExpr()
Dialect
WHERE (col1, col2) IN ((val1a, val2a), (val1b, val2b))
supportsMultiValueInExpr
in interface Dialect
supportsMultiValueInExpr
in class JdbcDialectImpl
public boolean allowsRegularExpressionInWhereClause()
Dialect
allowsRegularExpressionInWhereClause
in interface Dialect
allowsRegularExpressionInWhereClause
in class JdbcDialectImpl
public String generateRegularExpression(String source, String javaRegex)
Dialect
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.
generateRegularExpression
in interface Dialect
generateRegularExpression
in class JdbcDialectImpl
source
- A String identifying the column to match against.javaRegex
- A Java regular expression to match against.public boolean requiresOrderByAlias()
requiresOrderByAlias
in interface Dialect
requiresOrderByAlias
in class JdbcDialectImpl
Copyright © 2018 Hitachi Vantara. All rights reserved.