use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitDef in project calcite by apache.
the class VolcanoPlanner method changeTraitsUsingConverters.
private RelNode changeTraitsUsingConverters(RelNode rel, RelTraitSet toTraits, boolean allowAbstractConverters) {
final RelTraitSet fromTraits = rel.getTraitSet();
assert fromTraits.size() >= toTraits.size();
final boolean allowInfiniteCostConverters = SaffronProperties.INSTANCE.allowInfiniteCostConverters().get();
// Traits may build on top of another...for example a collation trait
// would typically come after a distribution trait since distribution
// destroys collation; so when doing the conversion below we use
// fromTraits as the trait of the just previously converted RelNode.
// Also, toTraits may have fewer traits than fromTraits, excess traits
// will be left as is. Finally, any null entries in toTraits are
// ignored.
RelNode converted = rel;
for (int i = 0; (converted != null) && (i < toTraits.size()); i++) {
RelTrait fromTrait = converted.getTraitSet().getTrait(i);
final RelTraitDef traitDef = fromTrait.getTraitDef();
RelTrait toTrait = toTraits.getTrait(i);
if (toTrait == null) {
continue;
}
assert traitDef == toTrait.getTraitDef();
// if (fromTrait.subsumes(toTrait)) {
if (fromTrait.equals(toTrait)) {
// No need to convert; it's already correct.
continue;
}
rel = traitDef.convert(this, converted, toTrait, allowInfiniteCostConverters);
if (rel != null) {
assert rel.getTraitSet().getTrait(traitDef).satisfies(toTrait);
rel = completeConversion(rel, allowInfiniteCostConverters, toTraits, Expressions.list(traitDef));
if (rel != null) {
register(rel, converted);
}
}
if ((rel == null) && allowAbstractConverters) {
RelTraitSet stepTraits = converted.getTraitSet().replace(toTrait);
rel = getSubset(converted, stepTraits);
}
converted = rel;
}
// make sure final converted traitset subsumes what was required
if (converted != null) {
assert converted.getTraitSet().satisfies(toTraits);
}
return converted;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitDef in project calcite by apache.
the class VolcanoPlanner method removeRule.
public boolean removeRule(RelOptRule rule) {
if (!ruleSet.remove(rule)) {
// Rule was not present.
return false;
}
// Remove description.
unmapRuleDescription(rule);
// Remove operands.
for (Iterator<RelOptRuleOperand> iter = classOperands.values().iterator(); iter.hasNext(); ) {
RelOptRuleOperand entry = iter.next();
if (entry.getRule().equals(rule)) {
iter.remove();
}
}
// graph.)
if (rule instanceof ConverterRule) {
ConverterRule converterRule = (ConverterRule) rule;
final RelTrait ruleTrait = converterRule.getInTrait();
final RelTraitDef ruleTraitDef = ruleTrait.getTraitDef();
if (traitDefs.contains(ruleTraitDef)) {
ruleTraitDef.deregisterConverterRule(this, converterRule);
}
}
return true;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitDef in project calcite by apache.
the class PlannerImpl method ready.
private void ready() {
switch(state) {
case STATE_0_CLOSED:
reset();
}
ensure(State.STATE_1_RESET);
Frameworks.withPlanner(new Frameworks.PlannerAction<Void>() {
public Void apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlus rootSchema) {
// use our own defaultSchema
Util.discard(rootSchema);
typeFactory = (JavaTypeFactory) cluster.getTypeFactory();
planner = cluster.getPlanner();
planner.setExecutor(executor);
return null;
}
}, config);
state = State.STATE_2_READY;
// then, register the trait def specified in traitDefs.
if (this.traitDefs != null) {
planner.clearRelTraitDefs();
for (RelTraitDef def : this.traitDefs) {
planner.addRelTraitDef(def);
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitDef in project calcite by apache.
the class FrameworksTest method testUpdate.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-2039">[CALCITE-2039]
* AssertionError when pushing project to ProjectableFilterableTable</a>
* using UPDATE via {@link Frameworks}.
*/
@Test
public void testUpdate() throws Exception {
Table table = new TableImpl();
final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
SchemaPlus schema = rootSchema.add("x", new AbstractSchema());
schema.add("MYTABLE", table);
List<RelTraitDef> traitDefs = new ArrayList<>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelDistributionTraitDef.INSTANCE);
SqlParser.Config parserConfig = SqlParser.configBuilder(SqlParser.Config.DEFAULT).setCaseSensitive(false).build();
final FrameworkConfig config = Frameworks.newConfigBuilder().parserConfig(parserConfig).defaultSchema(schema).traitDefs(traitDefs).ruleSets(RuleSets.ofList(AbstractConverter.ExpandConversionRule.INSTANCE)).programs(Programs.ofRules(Programs.RULE_SET)).build();
executeQuery(config, " UPDATE MYTABLE set id=7 where id=1", CalcitePrepareImpl.DEBUG);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitDef in project samza by apache.
the class SamzaSqlQueryParser method createPlanner.
private static Planner createPlanner() {
Connection connection;
SchemaPlus rootSchema;
try {
JavaTypeFactory typeFactory = new SamzaSqlJavaTypeFactoryImpl();
SamzaSqlDriver driver = new SamzaSqlDriver(typeFactory);
DriverManager.deregisterDriver(DriverManager.getDriver("jdbc:calcite:"));
DriverManager.registerDriver(driver);
connection = driver.connect("jdbc:calcite:", new Properties());
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
rootSchema = calciteConnection.getRootSchema();
} catch (SQLException e) {
throw new SamzaException(e);
}
final List<RelTraitDef> traitDefs = new ArrayList<>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder().parserConfig(SqlParser.configBuilder().setLex(Lex.JAVA).build()).defaultSchema(rootSchema).operatorTable(SqlStdOperatorTable.instance()).traitDefs(traitDefs).context(Contexts.EMPTY_CONTEXT).costFactory(null).build();
return Frameworks.getPlanner(frameworkConfig);
}
Aggregations