Search in sources :

Example 16 with HiveTableScan

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

the class HiveIncrementalRelMdRowCount method getRowCount.

@Override
public Double getRowCount(TableScan rel, RelMetadataQuery mq) {
    if (!(rel instanceof HiveTableScan)) {
        return super.getRowCount(rel, mq);
    }
    HiveTableScan tableScan = (HiveTableScan) rel;
    RelOptHiveTable relOptHiveTable = (RelOptHiveTable) tableScan.getTable();
    org.apache.hadoop.hive.ql.metadata.Table table = relOptHiveTable.getHiveTableMD();
    String fullyQualifiedName = TableName.getQualified(table.getCatName(), table.getDbName(), table.getTableName());
    SourceTable sourceTable = sourceTableMap.get(fullyQualifiedName);
    if (sourceTable == null) {
        return super.getRowCount(rel, mq);
    }
    return (double) sourceTable.getInsertedCount();
}
Also used : RelOptHiveTable(org.apache.hadoop.hive.ql.optimizer.calcite.RelOptHiveTable) SourceTable(org.apache.hadoop.hive.metastore.api.SourceTable) HiveTableScan(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan)

Example 17 with HiveTableScan

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

the class HivePartitionPruneRule method perform.

protected void perform(RelOptRuleCall call, Filter filter, HiveTableScan tScan) {
    // Original table
    RelOptHiveTable hiveTable = (RelOptHiveTable) tScan.getTable();
    // Copy original table scan and table
    HiveTableScan tScanCopy = tScan.copyIncludingTable(tScan.getRowType());
    RelOptHiveTable hiveTableCopy = (RelOptHiveTable) tScanCopy.getTable();
    // Execute partition pruning
    RexNode predicate = filter.getCondition();
    Pair<RexNode, RexNode> predicates = PartitionPrune.extractPartitionPredicates(filter.getCluster(), hiveTableCopy, predicate);
    RexNode partColExpr = predicates.left;
    hiveTableCopy.computePartitionList(conf, partColExpr, tScanCopy.getPartOrVirtualCols());
    if (StringUtils.equals(hiveTableCopy.getPartitionListKey(), hiveTable.getPartitionListKey())) {
        // Nothing changed, we do not need to produce a new expression
        return;
    }
    call.transformTo(filter.copy(filter.getTraitSet(), Collections.singletonList(tScanCopy)));
}
Also used : RelOptHiveTable(org.apache.hadoop.hive.ql.optimizer.calcite.RelOptHiveTable) HiveTableScan(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan) RexNode(org.apache.calcite.rex.RexNode)

Example 18 with HiveTableScan

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

the class HiveRelFieldTrimmer method fetchColStats.

private void fetchColStats(RelNode key, TableScan tableAccessRel, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields) {
    final List<Integer> iRefSet = Lists.newArrayList();
    if (key instanceof Project) {
        final Project project = (Project) key;
        for (RexNode rx : project.getProjects()) {
            iRefSet.addAll(HiveCalciteUtil.getInputRefs(rx));
        }
    } else {
        final int fieldCount = tableAccessRel.getRowType().getFieldCount();
        if (fieldsUsed.equals(ImmutableBitSet.range(fieldCount)) && extraFields.isEmpty()) {
            // get all cols
            iRefSet.addAll(ImmutableBitSet.range(fieldCount).asList());
        }
    }
    // Remove any virtual cols
    if (tableAccessRel instanceof HiveTableScan) {
        iRefSet.removeAll(((HiveTableScan) tableAccessRel).getVirtualCols());
    }
    if (!iRefSet.isEmpty()) {
        final RelOptTable table = tableAccessRel.getTable();
        if (table instanceof RelOptHiveTable) {
            ((RelOptHiveTable) table).getColStat(iRefSet, true);
            LOG.debug("Got col stats for {} in {}", iRefSet, tableAccessRel.getTable().getQualifiedName());
        }
    }
}
Also used : HiveProject(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject) Project(org.apache.calcite.rel.core.Project) RelOptHiveTable(org.apache.hadoop.hive.ql.optimizer.calcite.RelOptHiveTable) RelOptTable(org.apache.calcite.plan.RelOptTable) HiveTableScan(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

HiveTableScan (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan)18 RelOptHiveTable (org.apache.hadoop.hive.ql.optimizer.calcite.RelOptHiveTable)12 RelNode (org.apache.calcite.rel.RelNode)7 RexNode (org.apache.calcite.rex.RexNode)6 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)4 RexBuilder (org.apache.calcite.rex.RexBuilder)4 Table (org.apache.hadoop.hive.ql.metadata.Table)4 DruidQuery (org.apache.calcite.adapter.druid.DruidQuery)3 RelOptCluster (org.apache.calcite.plan.RelOptCluster)3 Project (org.apache.calcite.rel.core.Project)3 HiveRelNode (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveRelNode)3 BitSet (java.util.BitSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DruidSchema (org.apache.calcite.adapter.druid.DruidSchema)2 DruidTable (org.apache.calcite.adapter.druid.DruidTable)2 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)2