use of org.apache.calcite.sql.dialect.MssqlSqlDialect in project drill by apache.
the class JdbcLimitRule method convert.
@Override
public RelNode convert(RelNode rel) {
DrillLimitRelBase limit = (DrillLimitRelBase) rel;
if (limit.getOffset() == null || !limit.getTraitSet().contains(RelCollations.EMPTY) || !(convention.getPlugin().getDialect() instanceof MssqlSqlDialect)) {
return super.convert(limit);
} else {
// MS SQL doesn't support either OFFSET or FETCH without ORDER BY.
// But for the case of FETCH without OFFSET, Calcite generates TOP N
// instead of FETCH, and it is supported by MS SQL.
// So do splitting the limit with both OFFSET and FETCH but without ORDER BY
int offset = Math.max(0, RexLiteral.intValue(limit.getOffset()));
int fetch = Math.max(0, RexLiteral.intValue(limit.getFetch()));
// child Limit uses conservative approach: use offset 0 and fetch = parent limit offset + parent limit fetch.
RexNode childFetch = limit.getCluster().getRexBuilder().makeExactLiteral(BigDecimal.valueOf(offset + fetch));
RelNode jdbcSort = new DrillJdbcSort(limit.getCluster(), limit.getTraitSet().plus(RelCollations.EMPTY).replace(this.out).simplify(), convert(limit.getInput(), limit.getInput().getTraitSet().replace(this.out).simplify()), RelCollations.EMPTY, null, childFetch);
return limit.copy(limit.getTraitSet(), Collections.singletonList(jdbcSort), true);
}
}
use of org.apache.calcite.sql.dialect.MssqlSqlDialect in project calcite by apache.
the class SqlDialectFactoryImpl method create.
public SqlDialect create(DatabaseMetaData databaseMetaData) {
String databaseProductName;
int databaseMajorVersion;
int databaseMinorVersion;
String databaseVersion;
try {
databaseProductName = databaseMetaData.getDatabaseProductName();
databaseMajorVersion = databaseMetaData.getDatabaseMajorVersion();
databaseMinorVersion = databaseMetaData.getDatabaseMinorVersion();
databaseVersion = databaseMetaData.getDatabaseProductVersion();
} catch (SQLException e) {
throw new RuntimeException("while detecting database product", e);
}
final String upperProductName = databaseProductName.toUpperCase(Locale.ROOT).trim();
final String quoteString = getIdentifierQuoteString(databaseMetaData);
final NullCollation nullCollation = getNullCollation(databaseMetaData);
final SqlDialect.Context c = SqlDialect.EMPTY_CONTEXT.withDatabaseProductName(databaseProductName).withDatabaseMajorVersion(databaseMajorVersion).withDatabaseMinorVersion(databaseMinorVersion).withDatabaseVersion(databaseVersion).withIdentifierQuoteString(quoteString).withNullCollation(nullCollation);
switch(upperProductName) {
case "ACCESS":
return new AccessSqlDialect(c);
case "APACHE DERBY":
return new DerbySqlDialect(c);
case "DBMS:CLOUDSCAPE":
return new DerbySqlDialect(c);
case "HIVE":
return new HiveSqlDialect(c);
case "INGRES":
return new IngresSqlDialect(c);
case "INTERBASE":
return new InterbaseSqlDialect(c);
case "JETHRODATA":
return new JethroDataSqlDialect(c.withJethroInfo(jethroCache.get(databaseMetaData)));
case "LUCIDDB":
return new LucidDbSqlDialect(c);
case "ORACLE":
return new OracleSqlDialect(c);
case "PHOENIX":
return new PhoenixSqlDialect(c);
case "MYSQL (INFOBRIGHT)":
return new InfobrightSqlDialect(c);
case "MYSQL":
return new MysqlSqlDialect(c);
case "REDSHIFT":
return new RedshiftSqlDialect(c);
}
// Now the fuzzy matches.
if (databaseProductName.startsWith("DB2")) {
return new Db2SqlDialect(c);
} else if (upperProductName.contains("FIREBIRD")) {
return new FirebirdSqlDialect(c);
} else if (databaseProductName.startsWith("Informix")) {
return new InformixSqlDialect(c);
} else if (upperProductName.contains("NETEZZA")) {
return new NetezzaSqlDialect(c);
} else if (upperProductName.contains("PARACCEL")) {
return new ParaccelSqlDialect(c);
} else if (databaseProductName.startsWith("HP Neoview")) {
return new NeoviewSqlDialect(c);
} else if (upperProductName.contains("POSTGRE")) {
return new PostgresqlSqlDialect(c);
} else if (upperProductName.contains("SQL SERVER")) {
return new MssqlSqlDialect(c);
} else if (upperProductName.contains("SYBASE")) {
return new SybaseSqlDialect(c);
} else if (upperProductName.contains("TERADATA")) {
return new TeradataSqlDialect(c);
} else if (upperProductName.contains("HSQL")) {
return new HsqldbSqlDialect(c);
} else if (upperProductName.contains("H2")) {
return new H2SqlDialect(c);
} else if (upperProductName.contains("VERTICA")) {
return new VerticaSqlDialect(c);
} else {
return new AnsiSqlDialect(c);
}
}
Aggregations