Search in sources :

Example 1 with HiveJdbcImplementor

use of org.apache.hadoop.hive.ql.optimizer.calcite.rules.jdbc.HiveJdbcImplementor 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

ArrayList (java.util.ArrayList)1 JdbcProject (org.apache.calcite.adapter.jdbc.JdbcRules.JdbcProject)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 HiveRelNode (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveRelNode)1 HiveJdbcImplementor (org.apache.hadoop.hive.ql.optimizer.calcite.rules.jdbc.HiveJdbcImplementor)1