Class MysqlSqlDialect

  • public class MysqlSqlDialect
    extends SqlDialect
    A SqlDialect implementation for the MySQL database.
    • Field Detail


        public static final SqlFunction ISNULL_FUNCTION
        MySQL specific function.
      • majorVersion

        private final int majorVersion
    • Constructor Detail

      • MysqlSqlDialect

        public MysqlSqlDialect​(SqlDialect.Context context)
        Creates a MysqlSqlDialect.
    • Method Detail

      • supportsCharSet

        public boolean supportsCharSet()
        Description copied from class: SqlDialect
        Returns whether the dialect supports character set names as part of a data type, for instance VARCHAR(30) CHARACTER SET `ISO-8859-1`.
        supportsCharSet in class SqlDialect
      • requiresAliasForFromItems

        public boolean requiresAliasForFromItems()
        Description copied from class: SqlDialect
        Whether a sub-query in the FROM clause must have an alias.

        For example, in PostgreSQL, this query is legal:

        SELECT * FROM (SELECT * FROM Emp) As e

        but remove the alias e and it is not:


        In Oracle, both queries are legal.

        requiresAliasForFromItems in class SqlDialect
      • supportsAliasedValues

        public boolean supportsAliasedValues()
        Description copied from class: SqlDialect
        Returns whether the dialect supports VALUES in a sub-query with and an "AS t(column, ...)" values to define column names.

        Currently, only Oracle does not. For this, we generate "SELECT v0 AS c0, v1 AS c1 ... UNION ALL ...". We may need to refactor this method when we support VALUES for other dialects.

        supportsAliasedValues in class SqlDialect
      • supportsNestedAggregations

        public boolean supportsNestedAggregations()
        Description copied from class: SqlDialect
        Returns whether the dialect supports nested aggregations, for instance SELECT SUM(SUM(1)) .
        supportsNestedAggregations in class SqlDialect
      • supportsGroupByWithRollup

        public boolean supportsGroupByWithRollup()
        Description copied from class: SqlDialect
        Returns whether this dialect supports "WITH ROLLUP" in the "GROUP BY" clause.

        For instance, in MySQL version 5,

        SELECT deptno, job, COUNT(*) AS c FROM emp GROUP BY deptno, job WITH ROLLUP

        is equivalent to standard SQL

        SELECT deptno, job, COUNT(*) AS c FROM emp GROUP BY ROLLUP(deptno, job) ORDER BY deptno, job

        The "WITH ROLLUP" clause was introduced in MySQL and is not standard SQL.

        See also SqlDialect.supportsAggregateFunction(SqlKind) applied to SqlKind.ROLLUP, which returns true in MySQL 8 and higher.

        supportsGroupByWithRollup in class SqlDialect
      • rewriteSingleValueExpr

        public SqlNode rewriteSingleValueExpr​(SqlNode aggCall)
        Description copied from class: SqlDialect
        Rewrite SINGLE_VALUE into expression based on database variants E.g. HSQLDB, MYSQL, ORACLE, etc
        rewriteSingleValueExpr in class SqlDialect
      • unparseFloor

        private void unparseFloor​(SqlWriter writer,
                                  SqlCall call)
        Unparses datetime floor for MySQL. There is no TRUNC function, so simulate this using calls to DATE_FORMAT.
        writer - Writer
        call - Call
      • validate

        private org.apache.calcite.avatica.util.TimeUnit validate​(org.apache.calcite.avatica.util.TimeUnit timeUnit)