use of org.apache.calcite.adapter.jdbc.JdbcImplementor in project calcite by apache.
the class JdbcToSparkConverter method generateSql.
private String generateSql(SqlDialect dialect) {
final JdbcImplementor jdbcImplementor = new JdbcImplementor(dialect, (JavaTypeFactory) getCluster().getTypeFactory());
final JdbcImplementor.Result result = jdbcImplementor.visitChild(0, getInput());
return result.asStatement().toSqlString(dialect).getSql();
}
use of org.apache.calcite.adapter.jdbc.JdbcImplementor in project drill by apache.
the class ClickhouseJdbcDialect method generateSql.
@Override
public String generateSql(RelOptCluster cluster, RelNode input) {
final SqlDialect dialect = plugin.getDialect();
final JdbcImplementor jdbcImplementor = new ClickhouseJdbcImplementor(dialect, (JavaTypeFactory) cluster.getTypeFactory());
final JdbcImplementor.Result result = jdbcImplementor.visitChild(0, input.accept(SubsetRemover.INSTANCE));
return result.asStatement().toSqlString(dialect).getSql();
}
use of org.apache.calcite.adapter.jdbc.JdbcImplementor in project drill by apache.
the class DefaultJdbcDialect method generateSql.
@Override
public String generateSql(RelOptCluster cluster, RelNode input) {
final SqlDialect dialect = plugin.getDialect();
final JdbcImplementor jdbcImplementor = new JdbcImplementor(dialect, (JavaTypeFactory) cluster.getTypeFactory());
final JdbcImplementor.Result result = jdbcImplementor.visitChild(0, input.accept(SubsetRemover.INSTANCE));
return result.asStatement().toSqlString(dialect).getSql();
}
use of org.apache.calcite.adapter.jdbc.JdbcImplementor in project hive by apache.
the class CalcitePlanner method getOptimizedSql.
/**
* Get SQL rewrite for a Calcite logical plan
*
* @return Optimized SQL text (or null, if failed)
*/
public String getOptimizedSql(RelNode optimizedOptiqPlan) {
boolean nullsLast = HiveConf.getBoolVar(conf, ConfVars.HIVE_DEFAULT_NULLS_LAST);
NullCollation nullCollation = nullsLast ? NullCollation.LAST : NullCollation.LOW;
SqlDialect dialect = new HiveSqlDialect(SqlDialect.EMPTY_CONTEXT.withDatabaseProduct(SqlDialect.DatabaseProduct.HIVE).withDatabaseMajorVersion(// TODO: should not be hardcoded
4).withDatabaseMinorVersion(0).withIdentifierQuoteString("`").withDataTypeSystem(new HiveTypeSystemImpl()).withNullCollation(nullCollation)) {
@Override
protected boolean allowsAs() {
return true;
}
@Override
public boolean supportsCharSet() {
return false;
}
};
try {
final JdbcImplementor jdbcImplementor = new JdbcImplementor(dialect, (JavaTypeFactory) optimizedOptiqPlan.getCluster().getTypeFactory());
final JdbcImplementor.Result result = jdbcImplementor.visitRoot(optimizedOptiqPlan);
String sql = result.asStatement().toSqlString(dialect).getSql();
// VARCHAR(INTEGER.MAX) -> STRING
sql = PATTERN_VARCHAR.matcher(sql).replaceAll("STRING");
// TIMESTAMP(9) -> TIMESTAMP
sql = PATTERN_TIMESTAMP.matcher(sql).replaceAll("TIMESTAMP");
return sql;
} catch (Error | Exception e) {
// We play it safe here. If we get an error or exception,
// we will simply not print the optimized SQL.
LOG.warn("Rel2SQL Rewrite threw error", e);
}
return null;
}
Aggregations