Search in sources :

Example 11 with HiveProject

use of org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject 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 12 with HiveProject

use of org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject in project hive by apache.

the class HiveCalciteUtil method getTopLevelSelect.

/**
 * Get top level select starting from root. Assumption here is root can only
 * be Sort & Project. Also the top project should be at most 2 levels below
 * Sort; i.e Sort(Limit)-Sort(OB)-Select
 *
 * @param rootRel
 * @return
 */
public static Pair<RelNode, RelNode> getTopLevelSelect(final RelNode rootRel) {
    RelNode tmpRel = rootRel;
    RelNode parentOforiginalProjRel = rootRel;
    RelNode originalProjRel = null;
    while (tmpRel != null) {
        if (tmpRel instanceof HiveProject || tmpRel instanceof HiveTableFunctionScan) {
            originalProjRel = tmpRel;
            break;
        }
        parentOforiginalProjRel = tmpRel;
        tmpRel = tmpRel.getInput(0);
    }
    return (new Pair<RelNode, RelNode>(parentOforiginalProjRel, originalProjRel));
}
Also used : RelNode(org.apache.calcite.rel.RelNode) HiveProject(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject) HiveTableFunctionScan(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableFunctionScan)

Example 13 with HiveProject

use of org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject in project hive by apache.

the class HiveRelFieldTrimmer method trimFields.

/**
 * Variant of {@link #trimFields(RelNode, ImmutableBitSet, Set)} for
 * {@link org.apache.calcite.rel.logical.LogicalProject}.
 */
public TrimResult trimFields(Project project, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields) {
    // set columnAccessInfo for ViewColumnAuthorization
    final ColumnAccessInfo columnAccessInfo = COLUMN_ACCESS_INFO.get();
    final Map<HiveProject, Table> viewProjectToTableSchema = VIEW_PROJECT_TO_TABLE_SCHEMA.get();
    if (columnAccessInfo != null && viewProjectToTableSchema != null && viewProjectToTableSchema.containsKey(project)) {
        for (Ord<RexNode> ord : Ord.zip(project.getProjects())) {
            if (fieldsUsed.get(ord.i)) {
                Table tab = viewProjectToTableSchema.get(project);
                columnAccessInfo.add(tab.getCompleteName(), tab.getAllCols().get(ord.i).getName());
            }
        }
    }
    return super.trimFields(project, fieldsUsed, extraFields);
}
Also used : RelOptTable(org.apache.calcite.plan.RelOptTable) RelOptHiveTable(org.apache.hadoop.hive.ql.optimizer.calcite.RelOptHiveTable) Table(org.apache.hadoop.hive.ql.metadata.Table) HiveProject(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject) ColumnAccessInfo(org.apache.hadoop.hive.ql.parse.ColumnAccessInfo) RexNode(org.apache.calcite.rex.RexNode)

Example 14 with HiveProject

use of org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject in project hive by apache.

the class HiveRelFieldTrimmer method project.

private static RelNode project(DruidQuery dq, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields, RelBuilder relBuilder) {
    final int fieldCount = dq.getRowType().getFieldCount();
    if (fieldsUsed.equals(ImmutableBitSet.range(fieldCount)) && extraFields.isEmpty()) {
        return dq;
    }
    final List<RexNode> exprList = new ArrayList<>();
    final List<String> nameList = new ArrayList<>();
    final RexBuilder rexBuilder = dq.getCluster().getRexBuilder();
    final List<RelDataTypeField> fields = dq.getRowType().getFieldList();
    // Project the subset of fields.
    for (int i : fieldsUsed) {
        RelDataTypeField field = fields.get(i);
        exprList.add(rexBuilder.makeInputRef(dq, i));
        nameList.add(field.getName());
    }
    // extra fields, but we don't.)
    for (RelDataTypeField extraField : extraFields) {
        exprList.add(rexBuilder.ensureType(extraField.getType(), rexBuilder.constantNull(), true));
        nameList.add(extraField.getName());
    }
    HiveProject hp = (HiveProject) relBuilder.push(dq).project(exprList, nameList).build();
    hp.setSynthetic();
    return hp;
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) HiveProject(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject) ArrayList(java.util.ArrayList) RexBuilder(org.apache.calcite.rex.RexBuilder) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

HiveProject (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject)14 RelNode (org.apache.calcite.rel.RelNode)8 RexNode (org.apache.calcite.rex.RexNode)8 ArrayList (java.util.ArrayList)3 RelCollation (org.apache.calcite.rel.RelCollation)3 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)3 HiveSortLimit (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSortLimit)3 RelOptCluster (org.apache.calcite.plan.RelOptCluster)2 RelTraitSet (org.apache.calcite.plan.RelTraitSet)2 Project (org.apache.calcite.rel.core.Project)2 CalciteSemanticException (org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException)2 HiveJdbcConverter (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.jdbc.HiveJdbcConverter)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 HashSet (java.util.HashSet)1 JdbcProject (org.apache.calcite.adapter.jdbc.JdbcRules.JdbcProject)1 RelOptTable (org.apache.calcite.plan.RelOptTable)1 RelOptUtil (org.apache.calcite.plan.RelOptUtil)1 RelDistribution (org.apache.calcite.rel.RelDistribution)1 Sort (org.apache.calcite.rel.core.Sort)1 SortExchange (org.apache.calcite.rel.core.SortExchange)1