Class HiveDialect
- java.lang.Object
-
- mondrian.spi.impl.JdbcDialectImpl
-
- mondrian.spi.impl.HiveDialect
-
- All Implemented Interfaces:
Dialect
- Direct Known Subclasses:
ImpalaDialect
public class HiveDialect extends JdbcDialectImpl
Implementation ofDialectfor the Hive database.- Since:
- Jan 10, 2011
- Author:
- Hongwei Fu
-
-
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 HiveDialect(Connection connection)Creates a HiveDialect.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallowsAs()Returns whether the SQL dialect allows "AS" in the FROM clause.booleanallowsCompoundCountDistinct()Returns whether this Dialect allows multiple arguments to theCOUNT(DISTINCT ...) aggregate function, for exampleSELECT COUNT(DISTINCT x, y) FROM tbooleanallowsJoinOn()Returns whether this dialect supports "ANSI-style JOIN syntax",FROM leftTable JOIN rightTable ON conditon.booleanallowsOrderByAlias()Returns true if aliases defined in the SELECT clause can be used as expressions in the ORDER BY clause.protected StringdeduceIdentifierQuoteString(DatabaseMetaData databaseMetaData)protected intdeduceMaxColumnNameLength(DatabaseMetaData databaseMetaData)protected booleandeduceReadOnly(DatabaseMetaData databaseMetaData)protected Set<List<Integer>>deduceSupportedResultSetStyles(DatabaseMetaData databaseMetaData)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.protected voidquoteDateLiteral(StringBuilder buf, String value, Date date)Helper method forJdbcDialectImpl.quoteDateLiteral(StringBuilder, String).voidquoteTimestampLiteral(StringBuilder buf, String value)Appends to a buffer a timestamp literal.booleanrequiresAliasForFromQuery()Returns whether this Dialect requires subqueries in the FROM clause to have an alias.booleanrequiresGroupByAlias()Returns 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.booleanrequiresOrderByAlias()Returns 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.booleanrequiresUnionOrderByExprToBeInSelectClause()Returns 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.booleanrequiresUnionOrderByOrdinal()Returns true if this dialect allows only integers in the ORDER BY clause of a UNION (or other set operation) query.-
Methods inherited from class mondrian.spi.impl.JdbcDialectImpl
allowsCountDistinct, allowsCountDistinctWithOtherAggs, allowsDdl, allowsDialectSharing, allowsFromQuery, allowsMultipleCountDistinct, allowsMultipleDistinctSqlMeasures, allowsRegularExpressionInWhereClause, allowsSelectNotInGroupBy, appendHintsAfterFromClause, caseWhenElse, computeStatisticsProviders, deduceProductName, deduceProductVersion, deduceSupportsSelectNotInGroupBy, extractEmbeddedFlags, generateCountExpression, generateInlineForAnsi, generateInlineGeneric, generateOrderByNullsAnsi, generateOrderItem, generateRegularExpression, getDatabaseProduct, getMaxColumnNameLength, getProduct, getQuoteIdentifierString, getStatisticsProviders, getType, isDatabase, needsExponent, quote, quoteBooleanLiteral, quoteDateLiteral, quoteIdentifier, quoteIdentifier, quoteIdentifier, quoteIdentifier, quoteNumericLiteral, quoteStringLiteral, quoteTimeLiteral, quoteTimestampLiteral, requiresHavingAlias, supportsGroupByExpressions, supportsGroupingSets, supportsMultiValueInExpr, supportsResultSetConcurrency, supportsUnlimitedValueList, toString, toUpper
-
-
-
-
Field Detail
-
FACTORY
public static final JdbcDialectFactory FACTORY
-
-
Constructor Detail
-
HiveDialect
public HiveDialect(Connection connection) throws SQLException
Creates a HiveDialect.- Parameters:
connection- Connection- Throws:
SQLException- on error
-
-
Method Detail
-
deduceIdentifierQuoteString
protected String deduceIdentifierQuoteString(DatabaseMetaData databaseMetaData)
- Overrides:
deduceIdentifierQuoteStringin classJdbcDialectImpl
-
deduceSupportedResultSetStyles
protected Set<List<Integer>> deduceSupportedResultSetStyles(DatabaseMetaData databaseMetaData)
- Overrides:
deduceSupportedResultSetStylesin classJdbcDialectImpl
-
deduceReadOnly
protected boolean deduceReadOnly(DatabaseMetaData databaseMetaData)
- Overrides:
deduceReadOnlyin classJdbcDialectImpl
-
deduceMaxColumnNameLength
protected int deduceMaxColumnNameLength(DatabaseMetaData databaseMetaData)
- Overrides:
deduceMaxColumnNameLengthin classJdbcDialectImpl
-
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()
-
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()
-
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- Overrides:
requiresOrderByAliasin classJdbcDialectImpl- 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
-
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- Overrides:
allowsOrderByAliasin classJdbcDialectImpl- Returns:
- Whether aliases defined in the SELECT clause can be used as expressions in the ORDER BY clause.
-
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- Overrides:
requiresGroupByAliasin classJdbcDialectImpl- 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
-
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- Overrides:
requiresUnionOrderByExprToBeInSelectClausein classJdbcDialectImpl- 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
-
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- Overrides:
requiresUnionOrderByOrdinalin classJdbcDialectImpl- Returns:
- whether this dialect allows only integers in the ORDER BY clause of a UNION (or other set operation) 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- Overrides:
generateInlinein classJdbcDialectImpl- Parameters:
columnNames- List of column namescolumnTypes- List of column types ("String" or "Numeric")valueList- List of rows values- Returns:
- SQL string
-
quoteDateLiteral
protected void quoteDateLiteral(StringBuilder buf, String value, Date date)
Description copied from class:JdbcDialectImplHelper method forJdbcDialectImpl.quoteDateLiteral(StringBuilder, String).- Overrides:
quoteDateLiteralin classJdbcDialectImpl- Parameters:
buf- Buffer to append tovalue- Value as stringdate- Value as date
-
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.
-
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.- Specified by:
allowsAsin interfaceDialect- Overrides:
allowsAsin classJdbcDialectImpl- Returns:
- whether dialect allows AS in FROM 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- Overrides:
allowsJoinOnin classJdbcDialectImpl- Returns:
- Whether this dialect supports FROM-JOIN-ON syntax.
-
quoteTimestampLiteral
public void quoteTimestampLiteral(StringBuilder buf, String value)
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- Overrides:
quoteTimestampLiteralin classJdbcDialectImpl- Parameters:
buf- Buffer to append tovalue- Literal
-
-