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));
}
}
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);
}
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());
}
}
}
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;
}
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;
}
Aggregations