Class HiveDialect

  • All Implemented Interfaces:
    Dialect
    Direct Known Subclasses:
    ImpalaDialect

    public class HiveDialect
    extends JdbcDialectImpl
    Implementation of Dialect for the Hive database.
    Since:
    Jan 10, 2011
    Author:
    Hongwei Fu
    • Constructor Detail

      • HiveDialect

        public HiveDialect​(Connection connection)
                    throws SQLException
        Creates a HiveDialect.
        Parameters:
        connection - Connection
        Throws:
        SQLException - on error
    • Method Detail

      • requiresOrderByAlias

        public boolean requiresOrderByAlias()
        Description copied from interface: Dialect
        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.

        For example, in such a dialect,

        SELECT x FROM t ORDER BY x + y
        would be illegal, but
        SELECT x, x + y AS z FROM t ORDER BY z
        would be legal.

        MySQL, DB2 and Ingres are examples of such dialects.

        Specified by:
        requiresOrderByAlias in interface Dialect
        Overrides:
        requiresOrderByAlias in class JdbcDialectImpl
        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: Dialect
        Returns true if aliases defined in the SELECT clause can be used as expressions in the ORDER BY clause.

        For example, in such a dialect,

        SELECT x, x + y AS z FROM t ORDER BY z
        would be legal.

        MySQL, DB2 and Ingres are examples of dialects where this is true; Access is a dialect where this is false.

        Specified by:
        allowsOrderByAlias in interface Dialect
        Overrides:
        allowsOrderByAlias in class JdbcDialectImpl
        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: Dialect
        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.

        For example, in such a dialect,

        SELECT x, x FROM t GROUP BY x
        would be illegal, but
        SELECT x AS a, x AS b FROM t ORDER BY a, b
        would be legal.

        Infobright is the only such dialect.

        Specified by:
        requiresGroupByAlias in interface Dialect
        Overrides:
        requiresGroupByAlias in class JdbcDialectImpl
        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: Dialect
        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.

        For example, SELECT x, y + z FROM t
        UNION ALL
        SELECT x, y + z FROM t
        ORDER BY y + z
        is allowed but SELECT x, y, z FROM t
        UNION ALL
        SELECT x, y, z FROM t
        ORDER BY y + z
        SELECT x, y, z FROM t ORDER BY y + z is not.

        Access is an example of a dialect with this restriction.

        Specified by:
        requiresUnionOrderByExprToBeInSelectClause in interface Dialect
        Overrides:
        requiresUnionOrderByExprToBeInSelectClause in class JdbcDialectImpl
        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: Dialect
        Returns 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 t
        UNION ALL
        SELECT x, y + z FROM t
        ORDER BY 1, 2
        is allowed but SELECT x, y, z FROM t
        UNION ALL
        SELECT x, y, z FROM t
        ORDER BY x
        is not.

        Teradata is an example of a dialect with this restriction.

        Specified by:
        requiresUnionOrderByOrdinal in interface Dialect
        Overrides:
        requiresUnionOrderByOrdinal in class JdbcDialectImpl
        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: 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 interface Dialect
        Overrides:
        generateInline in class JdbcDialectImpl
        Parameters:
        columnNames - List of column names
        columnTypes - 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: 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 class JdbcDialectImpl
        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: Dialect
        Returns whether the SQL dialect allows "AS" in the FROM clause. If so, "SELECT * FROM t AS alias" is a valid query.
        Specified by:
        allowsAs in interface Dialect
        Overrides:
        allowsAs in class JdbcDialectImpl
        Returns:
        whether dialect allows AS in FROM clause
      • allowsJoinOn

        public boolean allowsJoinOn()
        Description copied from interface: Dialect
        Returns whether this dialect supports "ANSI-style JOIN syntax", FROM leftTable JOIN rightTable ON conditon.
        Specified by:
        allowsJoinOn in interface Dialect
        Overrides:
        allowsJoinOn in class JdbcDialectImpl
        Returns:
        Whether this dialect supports FROM-JOIN-ON syntax.
      • quoteTimestampLiteral

        public void quoteTimestampLiteral​(StringBuilder buf,
                                          String value)
        Description copied from interface: Dialect
        Appends to a buffer a timestamp literal.

        For example, in the default dialect, quoteStringLiteral(buf, "1969-03-17 12:34:56") appends TIMESTAMP '1969-03-17 12:34:56'.

        Specified by:
        quoteTimestampLiteral in interface Dialect
        Overrides:
        quoteTimestampLiteral in class JdbcDialectImpl
        Parameters:
        buf - Buffer to append to
        value - Literal