Search in sources :

Example 1 with RelOptTable

use of org.apache.calcite.plan.RelOptTable in project hive by apache.

the class HiveSubQRemoveRelBuilder method scan.

// Methods that create relational expressions
/** Creates a {@link org.apache.calcite.rel.core.TableScan} of the table
   * with a given name.
   *
   * <p>Throws if the table does not exist.
   *
   * <p>Returns this builder.
   *
   * @param tableNames Name of table (can optionally be qualified)
   */
public HiveSubQRemoveRelBuilder scan(Iterable<String> tableNames) {
    final List<String> names = ImmutableList.copyOf(tableNames);
    final RelOptTable relOptTable = relOptSchema.getTableForMember(names);
    if (relOptTable == null) {
        throw Static.RESOURCE.tableNotFound(Joiner.on(".").join(names)).ex();
    }
    final RelNode scan = scanFactory.createScan(cluster, relOptTable);
    push(scan);
    return this;
}
Also used : RelNode(org.apache.calcite.rel.RelNode) NlsString(org.apache.calcite.util.NlsString) RelOptTable(org.apache.calcite.plan.RelOptTable)

Example 2 with RelOptTable

use of org.apache.calcite.plan.RelOptTable in project drill by apache.

the class DirPrunedEnumerableTableScan method create.

/** Creates an DirPrunedEnumerableTableScan. */
public static EnumerableTableScan create(RelOptCluster cluster, RelOptTable relOptTable, String digestFromSelection) {
    final Table table = relOptTable.unwrap(Table.class);
    Class elementType = EnumerableTableScan.deduceElementType(table);
    final RelTraitSet traitSet = cluster.traitSetOf(EnumerableConvention.INSTANCE).replaceIfs(RelCollationTraitDef.INSTANCE, new Supplier<List<RelCollation>>() {

        public List<RelCollation> get() {
            if (table != null) {
                return table.getStatistic().getCollations();
            }
            return ImmutableList.of();
        }
    });
    return new DirPrunedEnumerableTableScan(cluster, traitSet, relOptTable, elementType, digestFromSelection);
}
Also used : Table(org.apache.calcite.schema.Table) RelOptTable(org.apache.calcite.plan.RelOptTable) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 3 with RelOptTable

use of org.apache.calcite.plan.RelOptTable in project storm by apache.

the class TridentModifyRule method convert.

@Override
public RelNode convert(RelNode rel) {
    final TableModify tableModify = (TableModify) rel;
    final RelNode input = tableModify.getInput();
    final RelOptCluster cluster = tableModify.getCluster();
    final RelTraitSet traitSet = tableModify.getTraitSet().replace(TridentLogicalConvention.INSTANCE);
    final RelOptTable relOptTable = tableModify.getTable();
    final Prepare.CatalogReader catalogReader = tableModify.getCatalogReader();
    final RelNode convertedInput = convert(input, input.getTraitSet().replace(TridentLogicalConvention.INSTANCE));
    final TableModify.Operation operation = tableModify.getOperation();
    final List<String> updateColumnList = tableModify.getUpdateColumnList();
    final List<RexNode> sourceExpressionList = tableModify.getSourceExpressionList();
    final boolean flattened = tableModify.isFlattened();
    final Table table = tableModify.getTable().unwrap(Table.class);
    switch(table.getJdbcTableType()) {
        case STREAM:
            if (operation != TableModify.Operation.INSERT) {
                throw new UnsupportedOperationException(String.format("Streams doesn't support %s modify operation", operation));
            }
            return new TridentStreamInsertRel(cluster, traitSet, relOptTable, catalogReader, convertedInput, operation, updateColumnList, sourceExpressionList, flattened);
        default:
            throw new IllegalArgumentException(String.format("Unsupported table type: %s", table.getJdbcTableType()));
    }
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) Table(org.apache.calcite.schema.Table) RelOptTable(org.apache.calcite.plan.RelOptTable) RelTraitSet(org.apache.calcite.plan.RelTraitSet) RelNode(org.apache.calcite.rel.RelNode) TridentStreamInsertRel(org.apache.storm.sql.planner.trident.rel.TridentStreamInsertRel) Prepare(org.apache.calcite.prepare.Prepare) RelOptTable(org.apache.calcite.plan.RelOptTable) LogicalTableModify(org.apache.calcite.rel.logical.LogicalTableModify) TableModify(org.apache.calcite.rel.core.TableModify) RexNode(org.apache.calcite.rex.RexNode)

Example 4 with RelOptTable

use of org.apache.calcite.plan.RelOptTable 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.getChildExps()) {
            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).getPartOrVirtualCols());
    }
    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 : Project(org.apache.calcite.rel.core.Project) HiveProject(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject) 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)

Example 5 with RelOptTable

use of org.apache.calcite.plan.RelOptTable in project druid by druid-io.

the class DruidTableScanRule method onMatch.

@Override
public void onMatch(final RelOptRuleCall call) {
    final LogicalTableScan scan = call.rel(0);
    final RelOptTable table = scan.getTable();
    final DruidTable druidTable = table.unwrap(DruidTable.class);
    if (druidTable != null) {
        call.transformTo(DruidQueryRel.fullScan(scan.getCluster(), table, druidTable, queryMaker));
    }
}
Also used : DruidTable(io.druid.sql.calcite.table.DruidTable) RelOptTable(org.apache.calcite.plan.RelOptTable) LogicalTableScan(org.apache.calcite.rel.logical.LogicalTableScan)

Aggregations

RelOptTable (org.apache.calcite.plan.RelOptTable)5 RelTraitSet (org.apache.calcite.plan.RelTraitSet)2 RelNode (org.apache.calcite.rel.RelNode)2 RexNode (org.apache.calcite.rex.RexNode)2 Table (org.apache.calcite.schema.Table)2 ImmutableList (com.google.common.collect.ImmutableList)1 DruidTable (io.druid.sql.calcite.table.DruidTable)1 List (java.util.List)1 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 Prepare (org.apache.calcite.prepare.Prepare)1 Project (org.apache.calcite.rel.core.Project)1 TableModify (org.apache.calcite.rel.core.TableModify)1 LogicalTableModify (org.apache.calcite.rel.logical.LogicalTableModify)1 LogicalTableScan (org.apache.calcite.rel.logical.LogicalTableScan)1 NlsString (org.apache.calcite.util.NlsString)1 RelOptHiveTable (org.apache.hadoop.hive.ql.optimizer.calcite.RelOptHiveTable)1 HiveProject (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject)1 HiveTableScan (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan)1 TridentStreamInsertRel (org.apache.storm.sql.planner.trident.rel.TridentStreamInsertRel)1