Class MySqlDialect
- java.lang.Object
-
- mondrian.spi.impl.JdbcDialectImpl
-
- mondrian.spi.impl.MySqlDialect
-
- All Implemented Interfaces:
Dialect
- Direct Known Subclasses:
InfobrightDialect,MariaDBDialect
public class MySqlDialect extends JdbcDialectImpl
Implementation ofDialectfor 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 Modifier and Type Field Description static JdbcDialectFactoryFACTORY-
Fields inherited from class mondrian.spi.impl.JdbcDialectImpl
databaseProduct, permitsSelectNotInGroupBy, productVersion
-
-
Constructor Summary
Constructors Constructor Description MySqlDialect(Connection connection)Creates a MySqlDialect.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallowsCompoundCountDistinct()Returns whether this Dialect allows multiple arguments to theCOUNT(DISTINCT ...) aggregate function, for exampleSELECT COUNT(DISTINCT x, y) FROM tbooleanallowsFromQuery()Returns whether this Dialect allows a subquery in the from clause, for exampleSELECT * FROM (SELECT * FROM t) AS xbooleanallowsRegularExpressionInWhereClause()Informs Mondrian if the dialect supports regular expressions when creating the 'where' or the 'having' 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.protected StringdeduceIdentifierQuoteString(DatabaseMetaData databaseMetaData)protected StringdeduceProductName(DatabaseMetaData databaseMetaData)protected booleandeduceSupportsSelectNotInGroupBy(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.StringgenerateInline(List<String> columnNames, List<String> columnTypes, List<String[]> valueList)Generates a SQL statement to represent an inline dataset.protected StringgenerateOrderByNulls(String expr, boolean ascending, boolean collateNullsLast)Generates SQL to force null values to collate last.StringgenerateRegularExpression(String source, String javaRegex)Must generate a String representing a regular expression match operation between a string literal and a Java regular expression.static booleanisInfobright(DatabaseMetaData databaseMetaData)Detects whether this database is Infobright.voidquoteBooleanLiteral(StringBuilder buf, String value)Appends to a buffer a boolean literal.voidquoteStringLiteral(StringBuilder buf, String s)Appends to a buffer a single-quoted SQL string.booleanrequiresAliasForFromQuery()Returns whether this Dialect requires subqueries in the FROM clause to have an alias.booleanrequiresHavingAlias()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.booleanrequiresOrderByAlias()Required for MySQL 5.7+, where SQL_MODE include ONLY_FULL_GROUP_BY by default.booleansupportsMultiValueInExpr()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 Detail
-
FACTORY
public static final JdbcDialectFactory FACTORY
-
-
Constructor Detail
-
MySqlDialect
public MySqlDialect(Connection connection) throws SQLException
Creates a MySqlDialect.- Parameters:
connection- Connection- Throws:
SQLException- on error
-
-
Method Detail
-
isInfobright
public static boolean isInfobright(DatabaseMetaData databaseMetaData)
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
protected String deduceProductName(DatabaseMetaData databaseMetaData)
- Overrides:
deduceProductNamein classJdbcDialectImpl
-
deduceIdentifierQuoteString
protected String deduceIdentifierQuoteString(DatabaseMetaData databaseMetaData)
- Overrides:
deduceIdentifierQuoteStringin classJdbcDialectImpl
-
deduceSupportsSelectNotInGroupBy
protected boolean deduceSupportsSelectNotInGroupBy(Connection connection) throws SQLException
Description copied from class: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.
- Overrides:
deduceSupportsSelectNotInGroupByin classJdbcDialectImpl- Parameters:
connection- The database connection- Returns:
- Whether the feature is enabled.
- Throws:
SQLException- on error
-
appendHintsAfterFromClause
public void appendHintsAfterFromClause(StringBuilder buf, Map<String,String> hints)
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- Overrides:
appendHintsAfterFromClausein 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:DialectReturns whether this Dialect requires subqueries in the FROM clause to have an alias.- Specified by:
requiresAliasForFromQueryin interfaceDialect- Overrides:
requiresAliasForFromQueryin classJdbcDialectImpl- Returns:
- whether dialewct requires subqueries to have an alias
- See Also:
Dialect.allowsFromQuery()
-
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- Overrides:
allowsFromQueryin classJdbcDialectImpl- Returns:
- whether Dialect allows subquery in FROM clause
- See Also:
Dialect.requiresAliasForFromQuery()
-
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- Overrides:
allowsCompoundCountDistinctin classJdbcDialectImpl- Returns:
- whether Dialect allows multiple arguments to COUNT DISTINCT
- See Also:
Dialect.allowsCountDistinct(),Dialect.allowsMultipleCountDistinct()
-
quoteStringLiteral
public void quoteStringLiteral(StringBuilder buf, String s)
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- Overrides:
quoteStringLiteralin classJdbcDialectImpl- Parameters:
buf- Buffer to append tos- Literal
-
quoteBooleanLiteral
public void quoteBooleanLiteral(StringBuilder buf, String value)
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- Overrides:
quoteBooleanLiteralin 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: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- Overrides:
generateInlinein classJdbcDialectImpl- Parameters:
columnNames- List of column namescolumnTypes- List of column types ("String" or "Numeric")valueList- List of rows values- Returns:
- SQL string
-
generateOrderByNulls
protected String generateOrderByNulls(String expr, boolean ascending, boolean collateNullsLast)
Description copied from class:JdbcDialectImplGenerates 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
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:
generateOrderByNullsin 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: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- Overrides:
requiresHavingAliasin 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:DialectReturns true if this dialect supports multi-value IN expressions. E.g.,WHERE (col1, col2) IN ((val1a, val2a), (val1b, val2b))- Specified by:
supportsMultiValueInExprin interfaceDialect- Overrides:
supportsMultiValueInExprin classJdbcDialectImpl- Returns:
- true if the dialect supports multi-value IN expressions
-
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- Overrides:
allowsRegularExpressionInWhereClausein classJdbcDialectImpl- Returns:
- True if regular expressions are supported.
-
generateRegularExpression
public String generateRegularExpression(String source, String javaRegex)
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- Overrides:
generateRegularExpressionin 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:
requiresOrderByAliasin interfaceDialect- Overrides:
requiresOrderByAliasin classJdbcDialectImpl- Returns:
- true when MySQL version is 5.7 or larger
-
-