Search in sources :

Example 1 with JdbcProject

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));
}
Also used : HiveProject(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject) JdbcProject(org.apache.calcite.adapter.jdbc.JdbcRules.JdbcProject) HiveJdbcConverter(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.jdbc.HiveJdbcConverter)

Example 2 with 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();
}
Also used : Project(org.apache.calcite.rel.core.Project) JdbcProject(org.apache.calcite.adapter.jdbc.JdbcRules.JdbcProject) HiveJdbcImplementor(org.apache.hadoop.hive.ql.optimizer.calcite.rules.jdbc.HiveJdbcImplementor) HiveRelNode(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveRelNode) RelNode(org.apache.calcite.rel.RelNode) JdbcProject(org.apache.calcite.adapter.jdbc.JdbcRules.JdbcProject) ArrayList(java.util.ArrayList) SqlDialect(org.apache.calcite.sql.SqlDialect) RexBuilder(org.apache.calcite.rex.RexBuilder) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

JdbcProject (org.apache.calcite.adapter.jdbc.JdbcRules.JdbcProject)2 ArrayList (java.util.ArrayList)1 RelNode (org.apache.calcite.rel.RelNode)1 Project (org.apache.calcite.rel.core.Project)1 RexBuilder (org.apache.calcite.rex.RexBuilder)1 RexNode (org.apache.calcite.rex.RexNode)1 SqlDialect (org.apache.calcite.sql.SqlDialect)1 HiveProject (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject)1 HiveRelNode (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveRelNode)1 HiveJdbcConverter (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.jdbc.HiveJdbcConverter)1 HiveJdbcImplementor (org.apache.hadoop.hive.ql.optimizer.calcite.rules.jdbc.HiveJdbcImplementor)1