Search in sources :

Example 31 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.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)

Example 32 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project drill by axbaretto.

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 33 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.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.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)

Example 34 with RelOptTable

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

the class HiveRelOptUtil method getColumnOriginSet.

public static Pair<RelOptTable, List<Integer>> getColumnOriginSet(RelNode rel, ImmutableBitSet colSet) {
    RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
    RexBuilder rexBuilder = rel.getCluster().getRexBuilder();
    Map<RelTableRef, List<Integer>> tabToOriginColumns = new HashMap<>();
    for (int col : colSet) {
        final RexInputRef tempColRef = rexBuilder.makeInputRef(rel, col);
        Set<RexNode> columnOrigins = mq.getExpressionLineage(rel, tempColRef);
        if (null == columnOrigins || columnOrigins.isEmpty()) {
            // if even on
            return null;
        }
        // we have either one or multiple origins of the column, we need to make sure that all of the column
        for (RexNode orgCol : columnOrigins) {
            RexTableInputRef inputRef = extractTableInputRef(orgCol);
            if (inputRef == null) {
                return null;
            }
            List<Integer> cols = tabToOriginColumns.get(inputRef.getTableRef());
            if (cols == null) {
                cols = new ArrayList<>();
            }
            cols.add(inputRef.getIndex());
            tabToOriginColumns.put(inputRef.getTableRef(), cols);
        }
    }
    // ideally we should return all, in case one doesn't work we can fall back to another
    for (Entry<RelTableRef, List<Integer>> mapEntries : tabToOriginColumns.entrySet()) {
        RelTableRef tblRef = mapEntries.getKey();
        List<Integer> mapColList = mapEntries.getValue();
        if (mapColList.size() == colSet.cardinality()) {
            RelOptTable tbl = tblRef.getTable();
            return Pair.of(tbl, mapColList);
        }
    }
    return null;
}
Also used : RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) HashMap(java.util.HashMap) RelTableRef(org.apache.calcite.rex.RexTableInputRef.RelTableRef) RexTableInputRef(org.apache.calcite.rex.RexTableInputRef) RelReferentialConstraint(org.apache.calcite.rel.RelReferentialConstraint) RexBuilder(org.apache.calcite.rex.RexBuilder) RexInputRef(org.apache.calcite.rex.RexInputRef) AbstractList(java.util.AbstractList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) RelOptTable(org.apache.calcite.plan.RelOptTable) RexNode(org.apache.calcite.rex.RexNode)

Example 35 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project hazelcast by hazelcast.

the class CalciteSqlOptimizer method extractPermissions.

private List<Permission> extractPermissions(PhysicalRel physicalRel) {
    List<Permission> permissions = new ArrayList<>();
    physicalRel.accept(new RelShuttleImpl() {

        @Override
        public RelNode visit(TableScan scan) {
            addPermissionForTable(scan.getTable(), ActionConstants.ACTION_READ);
            return super.visit(scan);
        }

        @Override
        public RelNode visit(RelNode other) {
            addPermissionForTable(other.getTable(), ActionConstants.ACTION_PUT);
            return super.visit(other);
        }

        private void addPermissionForTable(RelOptTable t, String action) {
            if (t == null) {
                return;
            }
            HazelcastTable table = t.unwrap(HazelcastTable.class);
            if (table != null && table.getTarget() instanceof AbstractMapTable) {
                String mapName = ((AbstractMapTable) table.getTarget()).getMapName();
                permissions.add(new MapPermission(mapName, action));
            }
        }
    });
    return permissions;
}
Also used : TableScan(org.apache.calcite.rel.core.TableScan) AbstractMapTable(com.hazelcast.sql.impl.schema.map.AbstractMapTable) RelNode(org.apache.calcite.rel.RelNode) MapPermission(com.hazelcast.security.permission.MapPermission) Permission(java.security.Permission) MapPermission(com.hazelcast.security.permission.MapPermission) ArrayList(java.util.ArrayList) RelShuttleImpl(org.apache.calcite.rel.RelShuttleImpl) RelOptTable(org.apache.calcite.plan.RelOptTable) SqlString(org.apache.calcite.sql.util.SqlString) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable)

Aggregations

RelOptTable (org.apache.calcite.plan.RelOptTable)63 RelDataType (org.apache.calcite.rel.type.RelDataType)20 RexNode (org.apache.calcite.rex.RexNode)18 RelNode (org.apache.calcite.rel.RelNode)17 Table (org.apache.calcite.schema.Table)15 ArrayList (java.util.ArrayList)14 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)12 RelTraitSet (org.apache.calcite.plan.RelTraitSet)10 SqlNode (org.apache.calcite.sql.SqlNode)10 RelOptCluster (org.apache.calcite.plan.RelOptCluster)9 ImmutableList (com.google.common.collect.ImmutableList)8 NlsString (org.apache.calcite.util.NlsString)8 List (java.util.List)6 LogicalJoin (org.apache.calcite.rel.logical.LogicalJoin)6 SchemaPlus (org.apache.calcite.schema.SchemaPlus)6 RelOptSchema (org.apache.calcite.plan.RelOptSchema)5 Project (org.apache.calcite.rel.core.Project)5 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)5 ProjectableFilterableTable (org.apache.calcite.schema.ProjectableFilterableTable)5 Test (org.junit.Test)5