Java Code Examples for org.apache.calcite.sql.dialect.MysqlSqlDialect#DEFAULT

The following examples show how to use org.apache.calcite.sql.dialect.MysqlSqlDialect#DEFAULT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CalciteUtls.java    From Mycat2 with GNU General Public License v3.0 6 votes vote down vote up
public static String getFilterSQLText(List<SimpleColumnInfo> rawColumns, String schemaName, String tableName, List<RexNode> filters) {
    if (filters == null || filters.isEmpty()) {
        return "";
    }
    RexNode rexNode = RexUtil.composeConjunction(MycatCalciteSupport.INSTANCE.RexBuilder, filters);
    SqlImplementor.Context context = new SqlImplementor.Context(MysqlSqlDialect.DEFAULT, rawColumns.size()) {
        @Override
        public SqlNode field(int ordinal) {
            String fieldName = rawColumns.get(ordinal).getColumnName();
            return new SqlIdentifier(ImmutableList.of(schemaName, tableName, fieldName),
                    SqlImplementor.POS);
        }
    };
    try {
        return " where " + context.toSql(null, rexNode).toSqlString(MysqlSqlDialect.DEFAULT).getSql();
    } catch (Exception e) {
        LOGGER.warn("不能生成对应的sql", e);
    }
    return "";
}
 
Example 2
Source File: BabelParserTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Similar to {@link #testHoist()} but using custom parser. */
@Test void testHoistMySql() {
  // SQL contains back-ticks, which require MySQL's quoting,
  // and DATEADD, which requires Babel.
  final String sql = "select 1 as x,\n"
      + "  'ab' || 'c' as y\n"
      + "from `my emp` /* comment with 'quoted string'? */ as e\n"
      + "where deptno < 40\n"
      + "and DATEADD(day, 1, hiredate) > date '2010-05-06'";
  final SqlDialect dialect = MysqlSqlDialect.DEFAULT;
  final Hoist.Hoisted hoisted =
      Hoist.create(Hoist.config()
          .withParserConfig(
              dialect.configureParser(SqlParser.configBuilder())
                  .setParserFactory(SqlBabelParserImpl::new)
                  .build()))
          .hoist(sql);

  // Simple toString converts each variable to '?N'
  final String expected = "select ?0 as x,\n"
      + "  ?1 || ?2 as y\n"
      + "from `my emp` /* comment with 'quoted string'? */ as e\n"
      + "where deptno < ?3\n"
      + "and DATEADD(day, ?4, hiredate) > ?5";
  assertThat(hoisted.toString(), is(expected));

  // Custom string converts variables to '[N:TYPE:VALUE]'
  final String expected2 = "select [0:DECIMAL:1] as x,\n"
      + "  [1:CHAR:ab] || [2:CHAR:c] as y\n"
      + "from `my emp` /* comment with 'quoted string'? */ as e\n"
      + "where deptno < [3:DECIMAL:40]\n"
      + "and DATEADD(day, [4:DECIMAL:1], hiredate) > [5:DATE:2010-05-06]";
  assertThat(hoisted.substitute(SqlParserTest::varToStr), is(expected2));
}
 
Example 3
Source File: SqlDialectFactoryImpl.java    From Bats with Apache License 2.0 4 votes vote down vote up
/** Returns a basic dialect for a given product, or null if none is known. */
static SqlDialect simple(SqlDialect.DatabaseProduct databaseProduct) {
  switch (databaseProduct) {
  case ACCESS:
    return AccessSqlDialect.DEFAULT;
  case BIG_QUERY:
    return BigQuerySqlDialect.DEFAULT;
  case CALCITE:
    return CalciteSqlDialect.DEFAULT;
  case DB2:
    return Db2SqlDialect.DEFAULT;
  case DERBY:
    return DerbySqlDialect.DEFAULT;
  case FIREBIRD:
    return FirebirdSqlDialect.DEFAULT;
  case H2:
    return H2SqlDialect.DEFAULT;
  case HIVE:
    return HiveSqlDialect.DEFAULT;
  case HSQLDB:
    return HsqldbSqlDialect.DEFAULT;
  case INFOBRIGHT:
    return InfobrightSqlDialect.DEFAULT;
  case INFORMIX:
    return InformixSqlDialect.DEFAULT;
  case INGRES:
    return IngresSqlDialect.DEFAULT;
  case INTERBASE:
    return InterbaseSqlDialect.DEFAULT;
  case JETHRO:
    throw new RuntimeException("Jethro does not support simple creation");
  case LUCIDDB:
    return LucidDbSqlDialect.DEFAULT;
  case MSSQL:
    return MssqlSqlDialect.DEFAULT;
  case MYSQL:
    return MysqlSqlDialect.DEFAULT;
  case NEOVIEW:
    return NeoviewSqlDialect.DEFAULT;
  case NETEZZA:
    return NetezzaSqlDialect.DEFAULT;
  case ORACLE:
    return OracleSqlDialect.DEFAULT;
  case PARACCEL:
    return ParaccelSqlDialect.DEFAULT;
  case PHOENIX:
    return PhoenixSqlDialect.DEFAULT;
  case POSTGRESQL:
    return PostgresqlSqlDialect.DEFAULT;
  case REDSHIFT:
    return RedshiftSqlDialect.DEFAULT;
  case SYBASE:
    return SybaseSqlDialect.DEFAULT;
  case TERADATA:
    return TeradataSqlDialect.DEFAULT;
  case VERTICA:
    return VerticaSqlDialect.DEFAULT;
  case SPARK:
    return SparkSqlDialect.DEFAULT;
  case SQLSTREAM:
  case UNKNOWN:
  default:
    return null;
  }
}
 
Example 4
Source File: SqlDialectFactoryImpl.java    From calcite with Apache License 2.0 4 votes vote down vote up
/** Returns a basic dialect for a given product, or null if none is known. */
static SqlDialect simple(SqlDialect.DatabaseProduct databaseProduct) {
  switch (databaseProduct) {
  case ACCESS:
    return AccessSqlDialect.DEFAULT;
  case BIG_QUERY:
    return BigQuerySqlDialect.DEFAULT;
  case CALCITE:
    return CalciteSqlDialect.DEFAULT;
  case CLICKHOUSE:
    return ClickHouseSqlDialect.DEFAULT;
  case DB2:
    return Db2SqlDialect.DEFAULT;
  case DERBY:
    return DerbySqlDialect.DEFAULT;
  case FIREBIRD:
    return FirebirdSqlDialect.DEFAULT;
  case H2:
    return H2SqlDialect.DEFAULT;
  case HIVE:
    return HiveSqlDialect.DEFAULT;
  case HSQLDB:
    return HsqldbSqlDialect.DEFAULT;
  case INFOBRIGHT:
    return InfobrightSqlDialect.DEFAULT;
  case INFORMIX:
    return InformixSqlDialect.DEFAULT;
  case INGRES:
    return IngresSqlDialect.DEFAULT;
  case INTERBASE:
    return InterbaseSqlDialect.DEFAULT;
  case JETHRO:
    throw new RuntimeException("Jethro does not support simple creation");
  case LUCIDDB:
    return LucidDbSqlDialect.DEFAULT;
  case MSSQL:
    return MssqlSqlDialect.DEFAULT;
  case MYSQL:
    return MysqlSqlDialect.DEFAULT;
  case NEOVIEW:
    return NeoviewSqlDialect.DEFAULT;
  case NETEZZA:
    return NetezzaSqlDialect.DEFAULT;
  case ORACLE:
    return OracleSqlDialect.DEFAULT;
  case PARACCEL:
    return ParaccelSqlDialect.DEFAULT;
  case PHOENIX:
    return PhoenixSqlDialect.DEFAULT;
  case POSTGRESQL:
    return PostgresqlSqlDialect.DEFAULT;
  case PRESTO:
    return PrestoSqlDialect.DEFAULT;
  case REDSHIFT:
    return RedshiftSqlDialect.DEFAULT;
  case SYBASE:
    return SybaseSqlDialect.DEFAULT;
  case TERADATA:
    return TeradataSqlDialect.DEFAULT;
  case VERTICA:
    return VerticaSqlDialect.DEFAULT;
  case SPARK:
    return SparkSqlDialect.DEFAULT;
  case SQLSTREAM:
  case UNKNOWN:
  default:
    return null;
  }
}