Class MySqlDialect
- All Implemented Interfaces:
Dialect
- Direct Known Subclasses:
InfobrightDialect
,MariaDBDialect
Dialect
for the MySQL database.- Since:
- Nov 23, 2008
- Author:
- jhyde
-
Nested Class Summary
Nested classes/interfaces inherited from interface mondrian.spi.Dialect
Dialect.DatabaseProduct, Dialect.Datatype
-
Field Summary
Fields inherited from class mondrian.spi.impl.JdbcDialectImpl
databaseProduct, permitsSelectNotInGroupBy, productVersion
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns whether this Dialect allows multiple arguments to theCOUNT(DISTINCT ...) aggregate function, for example
SELECT COUNT(DISTINCT x, y) FROM t
boolean
Returns whether this Dialect allows a subquery in the from clause, for exampleSELECT * FROM (SELECT * FROM t) AS x
boolean
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.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.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
Returns whether this Dialect requires subqueries in the FROM clause to have an alias.boolean
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
Required for MySQL 5.7+, where SQL_MODE include ONLY_FULL_GROUP_BY by default.boolean
Returns true if this dialect supports multi-value IN expressions.Methods inherited from class mondrian.spi.impl.JdbcDialectImpl
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, toUpper
-
Field Details
-
FACTORY
-
-
Constructor Details
-
MySqlDialect
Creates a MySqlDialect.- Parameters:
connection
- Connection- Throws:
SQLException
- on error
-
-
Method Details
-
isInfobright
Detects whether this database is Infobright.Infobright uses the MySQL driver and appears to be a MySQL instance. The only difference is the presence of the BRIGHTHOUSE engine.
- Parameters:
databaseMetaData
- Database metadata- Returns:
- Whether this is Infobright
-
deduceProductName
- Overrides:
deduceProductName
in classJdbcDialectImpl
-
deduceIdentifierQuoteString
- Overrides:
deduceIdentifierQuoteString
in classJdbcDialectImpl
-
deduceSupportsSelectNotInGroupBy
Description copied from class: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.
- Overrides:
deduceSupportsSelectNotInGroupBy
in classJdbcDialectImpl
- Parameters:
connection
- The database connection- Returns:
- Whether the feature is enabled.
- Throws:
SQLException
- on error
-
appendHintsAfterFromClause
Description copied from interface:Dialect
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. Any unrecognized or unsupported hints will be ignored.- Specified by:
appendHintsAfterFromClause
in interfaceDialect
- Overrides:
appendHintsAfterFromClause
in classJdbcDialectImpl
- 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
-
requiresAliasForFromQuery
public boolean requiresAliasForFromQuery()Description copied from interface:Dialect
Returns whether this Dialect requires subqueries in the FROM clause to have an alias.- Specified by:
requiresAliasForFromQuery
in interfaceDialect
- Overrides:
requiresAliasForFromQuery
in classJdbcDialectImpl
- Returns:
- whether dialewct requires subqueries to have an alias
- See Also:
-
allowsFromQuery
public boolean allowsFromQuery()Description copied from interface:Dialect
Returns whether this Dialect allows a subquery in the from clause, for exampleSELECT * FROM (SELECT * FROM t) AS x
- Specified by:
allowsFromQuery
in interfaceDialect
- Overrides:
allowsFromQuery
in classJdbcDialectImpl
- Returns:
- whether Dialect allows subquery in FROM clause
- See Also:
-
allowsCompoundCountDistinct
public boolean allowsCompoundCountDistinct()Description copied from interface:Dialect
Returns whether this Dialect allows multiple arguments to theCOUNT(DISTINCT ...) aggregate function, for example
SELECT COUNT(DISTINCT x, y) FROM t
- Specified by:
allowsCompoundCountDistinct
in interfaceDialect
- Overrides:
allowsCompoundCountDistinct
in classJdbcDialectImpl
- Returns:
- whether Dialect allows multiple arguments to COUNT DISTINCT
- See Also:
-
quoteStringLiteral
Description copied from interface:Dialect
Appends to a buffer a single-quoted SQL string.For example, in the default dialect,
quoteStringLiteral(buf, "Can't")
appends "'Can''t'
" tobuf
.- Specified by:
quoteStringLiteral
in interfaceDialect
- Overrides:
quoteStringLiteral
in classJdbcDialectImpl
- Parameters:
buf
- Buffer to append tos
- Literal
-
quoteBooleanLiteral
Description copied from interface:Dialect
Appends to a buffer a boolean literal.In the default dialect, boolean literals are printed as is.
- Specified by:
quoteBooleanLiteral
in interfaceDialect
- Overrides:
quoteBooleanLiteral
in classJdbcDialectImpl
- Parameters:
buf
- Buffer to append tovalue
- Literal
-
generateInline
public String generateInline(List<String> columnNames, List<String> columnTypes, List<String[]> valueList) Description copied from interface:Dialect
Generates 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:
generateInline
in interfaceDialect
- Overrides:
generateInline
in classJdbcDialectImpl
- Parameters:
columnNames
- List of column namescolumnTypes
- List of column types ("String" or "Numeric")valueList
- List of rows values- Returns:
- SQL string
-
generateOrderByNulls
Description copied from class:JdbcDialectImpl
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 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.- Overrides:
generateOrderByNulls
in classJdbcDialectImpl
- 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.
-
requiresHavingAlias
public boolean requiresHavingAlias()Description copied from interface:Dialect
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.For example, in such a dialect,
SELECT CONCAT(x) as foo FROM t HAVING CONCAT(x) LIKE "%"
SELECT CONCAT(x) as foo FROM t HAVING foo LIKE "%"
MySQL is an example of such dialects.
- Specified by:
requiresHavingAlias
in interfaceDialect
- Overrides:
requiresHavingAlias
in classJdbcDialectImpl
- Returns:
- Whether this Dialect can include expressions in the HAVING clause only by adding an expression to the SELECT clause and using its alias
-
supportsMultiValueInExpr
public boolean supportsMultiValueInExpr()Description copied from interface:Dialect
Returns true if this dialect supports multi-value IN expressions. E.g.,WHERE (col1, col2) IN ((val1a, val2a), (val1b, val2b))
- Specified by:
supportsMultiValueInExpr
in interfaceDialect
- Overrides:
supportsMultiValueInExpr
in classJdbcDialectImpl
- Returns:
- true if the dialect supports multi-value IN expressions
-
allowsRegularExpressionInWhereClause
public boolean allowsRegularExpressionInWhereClause()Description copied from interface:Dialect
Informs Mondrian if the dialect supports regular expressions when creating the 'where' or the 'having' clause.- Specified by:
allowsRegularExpressionInWhereClause
in interfaceDialect
- Overrides:
allowsRegularExpressionInWhereClause
in classJdbcDialectImpl
- Returns:
- True if regular expressions are supported.
-
generateRegularExpression
Description copied from interface:Dialect
Must 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:
generateRegularExpression
in interfaceDialect
- Overrides:
generateRegularExpression
in classJdbcDialectImpl
- Parameters:
source
- A String identifying the column to match against.javaRegex
- 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.
-
requiresOrderByAlias
public boolean requiresOrderByAlias()Required for MySQL 5.7+, where SQL_MODE include ONLY_FULL_GROUP_BY by default. This prevent expressions like ISNULL(RTRIM(`promotion_name`)) ASC from being used in ORDER BY section. ISNULL(`c0`) ASC will be used, where `c0` is an alias of the RTRIM(`promotion_name`). And this is important for the cases where we're using SQL expressions in a Level definition. Jira ticket, that describes the issue: http://jira.pentaho.com/browse/MONDRIAN-2451- Specified by:
requiresOrderByAlias
in interfaceDialect
- Overrides:
requiresOrderByAlias
in classJdbcDialectImpl
- Returns:
- true when MySQL version is 5.7 or larger
-