use of org.apache.calcite.adapter.jdbc.JdbcRules.JdbcProject in project hive by apache.
the class JDBCProjectPushDownRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
LOG.debug("JDBCProjectPushDownRule has been called");
final HiveProject project = call.rel(0);
final HiveJdbcConverter converter = call.rel(1);
JdbcProject jdbcProject = new JdbcProject(project.getCluster(), project.getTraitSet().replace(converter.getJdbcConvention()), converter.getInput(), project.getProjects(), project.getRowType());
call.transformTo(converter.copy(converter.getTraitSet(), jdbcProject));
}
use of org.apache.calcite.adapter.jdbc.JdbcRules.JdbcProject in project hive by apache.
the class HiveJdbcConverter method generateSql.
public String generateSql() {
SqlDialect dialect = getJdbcDialect();
final HiveJdbcImplementor jdbcImplementor = new HiveJdbcImplementor(dialect, (JavaTypeFactory) getCluster().getTypeFactory());
Project topProject;
if (getInput() instanceof Project) {
topProject = (Project) getInput();
} else {
// If it is not a project operator, we add it on top of the input
// to force generating the column names instead of * while
// translating to SQL
RelNode nodeToTranslate = getInput();
RexBuilder builder = getCluster().getRexBuilder();
List<RexNode> projects = new ArrayList<>(nodeToTranslate.getRowType().getFieldList().size());
for (int i = 0; i < nodeToTranslate.getRowType().getFieldCount(); i++) {
projects.add(builder.makeInputRef(nodeToTranslate, i));
}
topProject = new JdbcProject(nodeToTranslate.getCluster(), nodeToTranslate.getTraitSet(), nodeToTranslate, projects, nodeToTranslate.getRowType());
}
final HiveJdbcImplementor.Result result = jdbcImplementor.visitRoot(topProject);
return result.asStatement().toSqlString(dialect).getSql();
}
Aggregations