Class MysqlSqlDialect

java.lang.Object
org.apache.calcite.sql.SqlDialect
org.apache.calcite.sql.dialect.MysqlSqlDialect

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

    • MYSQL_TYPE_SYSTEM

      public static final RelDataTypeSystem MYSQL_TYPE_SYSTEM
      MySQL type system.
    • DEFAULT_CONTEXT

      public static final SqlDialect.Context DEFAULT_CONTEXT
    • DEFAULT

      public static final SqlDialect DEFAULT
    • ISNULL_FUNCTION

      public static final SqlFunction ISNULL_FUNCTION
      MySQL specific function.
  • Constructor Details

    • MysqlSqlDialect

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

    • 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`.
      Overrides:
      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:

      SELECT * FROM (SELECT * FROM Emp)

      In Oracle, both queries are legal.

      Overrides:
      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.

      Overrides:
      supportsAliasedValues in class SqlDialect
    • unparseOffsetFetch

      public void unparseOffsetFetch(SqlWriter writer, @Nullable SqlNode offset, @Nullable SqlNode fetch)
      Description copied from class: SqlDialect
      Converts an offset and fetch into SQL.

      At least one of offset and fetch must be provided.

      Common options:

      • OFFSET offset ROWS FETCH NEXT fetch ROWS ONLY (ANSI standard SQL, Oracle, PostgreSQL, and the default)
      • LIMIT fetch OFFSET offset (Apache Hive, MySQL, Redshift)
      Overrides:
      unparseOffsetFetch in class SqlDialect
      Parameters:
      writer - Writer
      offset - Number of rows to skip before emitting, or null
      fetch - Number of rows to fetch, or null
      See Also:
    • emulateNullDirection

      public @Nullable SqlNode emulateNullDirection(SqlNode node, boolean nullsFirst, boolean desc)
      Description copied from class: SqlDialect
      Returns the SqlNode for emulating the null direction for the given field or null if no emulation needs to be done.
      Overrides:
      emulateNullDirection in class SqlDialect
      Parameters:
      node - The SqlNode representing the expression
      nullsFirst - Whether nulls should come first
      desc - Whether the sort direction is RelFieldCollation.Direction.DESCENDING or RelFieldCollation.Direction.STRICTLY_DESCENDING
      Returns:
      A SqlNode for null direction emulation or null if not required
    • supportsAggregateFunction

      public boolean supportsAggregateFunction(SqlKind kind)
      Overrides:
      supportsAggregateFunction 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)) .
      Overrides:
      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.

      Overrides:
      supportsGroupByWithRollup in class SqlDialect
    • getCalendarPolicy

      public SqlDialect.CalendarPolicy getCalendarPolicy()
      Overrides:
      getCalendarPolicy in class SqlDialect
    • getCastSpec

      public @Nullable SqlNode getCastSpec(RelDataType type)
      Description copied from class: SqlDialect
      Returns SqlNode for type in "cast(column as type)", which might be different between databases by type name, precision etc.

      If this method returns null, the cast will be omitted. In the default implementation, this is the case for the NULL type, and therefore CAST(NULL AS <nulltype>) is rendered as NULL.

      Overrides:
      getCastSpec in class SqlDialect
    • rewriteSingleValueExpr

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

      public void unparseCall(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec)
      Overrides:
      unparseCall in class SqlDialect
    • unparseSqlIntervalQualifier

      public void unparseSqlIntervalQualifier(SqlWriter writer, SqlIntervalQualifier qualifier, RelDataTypeSystem typeSystem)
      Description copied from class: SqlDialect
      Converts an interval qualifier to a SQL string. The default implementation returns strings such as INTERVAL '1 2:3:4' DAY(4) TO SECOND(4).
      Overrides:
      unparseSqlIntervalQualifier in class SqlDialect
    • supportsJoinType

      public boolean supportsJoinType(JoinRelType joinType)
      Description copied from class: SqlDialect
      Returns whether this dialect support the specified type of join.
      Overrides:
      supportsJoinType in class SqlDialect