use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project hazelcast by hazelcast.
the class UpdateByKeyMapLogicalRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
TableModifyLogicalRel update = call.rel(0);
FullScanLogicalRel scan = call.rel(1);
RelOptTable table = scan.getTable();
RexNode keyCondition = OptUtils.extractKeyConstantExpression(table, update.getCluster().getRexBuilder());
if (keyCondition != null) {
UpdateByKeyMapLogicalRel rel = new UpdateByKeyMapLogicalRel(update.getCluster(), OptUtils.toLogicalConvention(update.getTraitSet()), table, keyCondition, update.getUpdateColumnList(), update.getSourceExpressionList());
call.transformTo(rel);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project hazelcast by hazelcast.
the class DeleteByKeyMapLogicalRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
TableModify delete = call.rel(0);
TableScan scan = call.rel(1);
RelOptTable table = scan.getTable();
RexNode keyCondition = OptUtils.extractKeyConstantExpression(table, delete.getCluster().getRexBuilder());
if (keyCondition != null) {
DeleteByKeyMapLogicalRel rel = new DeleteByKeyMapLogicalRel(delete.getCluster(), OptUtils.toLogicalConvention(delete.getTraitSet()), table, keyCondition);
call.transformTo(rel);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project hazelcast by hazelcast.
the class IndexResolver method createIndexScan.
private static IndexScanMapPhysicalRel createIndexScan(FullScanLogicalRel scan, MapTableIndex index, List<RexNode> conjunctions, List<IndexComponentFilter> filterDescriptors, List<Boolean> ascs) {
// Collect filters and relevant expressions
List<IndexFilter> filters = new ArrayList<>(filterDescriptors.size());
Set<RexNode> exps = new HashSet<>();
for (IndexComponentFilter filterDescriptor : filterDescriptors) {
filters.add(filterDescriptor.getFilter());
exps.addAll(filterDescriptor.getExpressions());
}
// Construct Calcite expressions.
RexBuilder rexBuilder = scan.getCluster().getRexBuilder();
RexNode exp = RexUtil.composeConjunction(rexBuilder, exps);
List<RexNode> remainderConjunctiveExps = excludeNodes(conjunctions, exps);
RexNode remainderExp = remainderConjunctiveExps.isEmpty() ? null : RexUtil.composeConjunction(rexBuilder, remainderConjunctiveExps);
// Prepare traits
RelTraitSet traitSet = scan.getTraitSet();
// Make a collation trait
RelCollation relCollation = buildCollationTrait(scan, index, ascs);
traitSet = OptUtils.traitPlus(traitSet, relCollation);
// Prepare table
HazelcastRelOptTable originalRelTable = (HazelcastRelOptTable) scan.getTable();
HazelcastTable originalHazelcastTable = OptUtils.extractHazelcastTable(scan);
RelOptTable newRelTable = createRelTable(originalRelTable, originalHazelcastTable.withFilter(null), scan.getCluster().getTypeFactory());
// Try composing the final filter out of the isolated component filters if possible
IndexFilter filter = composeFilter(filters, index.getType(), index.getComponentsCount());
if (filter == null) {
return null;
}
// Construct the scan
return new IndexScanMapPhysicalRel(scan.getCluster(), OptUtils.toPhysicalConvention(traitSet), newRelTable, index, filter, exp, remainderExp);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project beam by apache.
the class TableScanConverter method convert.
@Override
public RelNode convert(ResolvedTableScan zetaNode, List<RelNode> inputs) {
List<String> tablePath = getTablePath(zetaNode.getTable());
SchemaPlus defaultSchemaPlus = getConfig().getDefaultSchema();
if (defaultSchemaPlus == null) {
throw new AssertionError("Default schema is null.");
}
// TODO: reject incorrect top-level schema
Table calciteTable = TableResolution.resolveCalciteTable(defaultSchemaPlus, tablePath);
// we already resolved the table before passing the query to Analyzer, so it should be there
checkNotNull(calciteTable, "Unable to resolve the table path %s in schema %s", tablePath, defaultSchemaPlus.getName());
String defaultSchemaName = defaultSchemaPlus.getName();
final CalciteCatalogReader catalogReader = new CalciteCatalogReader(CalciteSchema.from(defaultSchemaPlus), ImmutableList.of(defaultSchemaName), getCluster().getTypeFactory(), new CalciteConnectionConfigImpl(new Properties()));
RelOptTableImpl relOptTable = RelOptTableImpl.create(catalogReader, calciteTable.getRowType(getCluster().getTypeFactory()), calciteTable, ImmutableList.<String>builder().add(defaultSchemaName).addAll(tablePath).build());
if (calciteTable instanceof TranslatableTable) {
return ((TranslatableTable) calciteTable).toRel(createToRelContext(), relOptTable);
} else {
throw new UnsupportedOperationException("Does not support non TranslatableTable type table!");
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project calcite by apache.
the class EnumerableTableScan method create.
/**
* Creates an EnumerableTableScan.
*/
public static EnumerableTableScan create(RelOptCluster cluster, RelOptTable relOptTable) {
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 EnumerableTableScan(cluster, traitSet, relOptTable, elementType);
}
Aggregations