use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule in project druid by druid-io.
the class Rules method baseRuleSet.
private static List<RelOptRule> baseRuleSet(final QueryMaker queryMaker, final DruidOperatorTable operatorTable) {
final PlannerConfig plannerConfig = queryMaker.getPlannerContext().getPlannerConfig();
final ImmutableList.Builder<RelOptRule> rules = ImmutableList.builder();
// Calcite rules.
rules.addAll(DEFAULT_RULES);
rules.addAll(MISCELLANEOUS_RULES);
rules.addAll(CONSTANT_REDUCTION_RULES);
rules.addAll(VOLCANO_ABSTRACT_RULES);
rules.addAll(RELOPTUTIL_ABSTRACT_RULES);
if (!plannerConfig.isUseApproximateCountDistinct()) {
// We'll need this to expand COUNT DISTINCTs.
// Avoid AggregateExpandDistinctAggregatesRule.INSTANCE; it uses grouping sets and we don't support those.
rules.add(AggregateExpandDistinctAggregatesRule.JOIN);
}
if (plannerConfig.isUseFallback()) {
rules.add(DruidRelToBindableRule.instance());
}
// Druid-specific rules.
rules.add(new DruidTableScanRule(queryMaker));
rules.add(new DruidFilterRule(operatorTable));
if (plannerConfig.getMaxSemiJoinRowsInMemory() > 0) {
rules.add(DruidSemiJoinRule.instance());
}
rules.addAll(SelectRules.rules(operatorTable));
rules.addAll(GroupByRules.rules(operatorTable));
return rules.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule in project samza by apache.
the class QueryPlanner method getPlanner.
private Planner getPlanner() {
Planner planner = null;
try {
Connection connection = DriverManager.getConnection("jdbc:calcite:");
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
registerSourceSchemas(rootSchema);
List<SamzaSqlScalarFunctionImpl> samzaSqlFunctions = udfMetadata.stream().map(SamzaSqlScalarFunctionImpl::new).collect(Collectors.toList());
final List<RelTraitDef> traitDefs = new ArrayList<>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
sqlOperatorTables.add(new SamzaSqlOperatorTable());
sqlOperatorTables.add(new SamzaSqlUdfOperatorTable(samzaSqlFunctions));
// TODO: Introduce a pluggable rule factory.
List<RelOptRule> rules = ImmutableList.of(FilterProjectTransposeRule.INSTANCE, ProjectMergeRule.INSTANCE, new SamzaSqlFilterRemoteJoinRule.SamzaSqlFilterIntoRemoteJoinRule(true, RelFactories.LOGICAL_BUILDER, systemStreamConfigBySource));
// Using lenient so that !=,%,- are allowed.
FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder().parserConfig(SqlParser.configBuilder().setLex(Lex.JAVA).setConformance(SqlConformanceEnum.LENIENT).setCaseSensitive(// Make Udfs case insensitive
false).build()).defaultSchema(rootSchema).operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables)).sqlToRelConverterConfig(SqlToRelConverter.Config.DEFAULT).traitDefs(traitDefs).programs(Programs.hep(rules, true, DefaultRelMetadataProvider.INSTANCE)).build();
planner = Frameworks.getPlanner(frameworkConfig);
return planner;
} catch (Exception e) {
String errorMsg = "Failed to create planner.";
LOG.error(errorMsg, e);
if (planner != null) {
planner.close();
}
throw new SamzaException(errorMsg, e);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule in project calcite by apache.
the class PlannerTest method testPlanTransformWithRuleNameConflicts.
/**
* Unit test that calls {@link Planner#transform} twice with
* rule name conflicts
*/
@Test
public void testPlanTransformWithRuleNameConflicts() throws Exception {
// Create two dummy rules with identical rules.
RelOptRule rule1 = new RelOptRule(operand(LogicalProject.class, operand(LogicalFilter.class, RelOptRule.any())), "MYRULE") {
@Override
public boolean matches(RelOptRuleCall call) {
return false;
}
public void onMatch(RelOptRuleCall call) {
}
};
RelOptRule rule2 = new RelOptRule(operand(LogicalFilter.class, operand(LogicalProject.class, RelOptRule.any())), "MYRULE") {
@Override
public boolean matches(RelOptRuleCall call) {
return false;
}
public void onMatch(RelOptRuleCall call) {
}
};
RuleSet ruleSet1 = RuleSets.ofList(rule1, EnumerableRules.ENUMERABLE_FILTER_RULE, EnumerableRules.ENUMERABLE_PROJECT_RULE);
RuleSet ruleSet2 = RuleSets.ofList(rule2);
Planner planner = getPlanner(null, Programs.of(ruleSet1), Programs.of(ruleSet2));
SqlNode parse = planner.parse("select * from \"emps\"");
SqlNode validate = planner.validate(parse);
RelNode convert = planner.rel(validate).rel;
RelTraitSet traitSet = planner.getEmptyTraitSet().replace(EnumerableConvention.INSTANCE);
RelNode transform = planner.transform(0, traitSet, convert);
RelNode transform2 = planner.transform(1, traitSet, transform);
assertThat(toString(transform2), equalTo("EnumerableProject(empid=[$0], deptno=[$1], name=[$2], salary=[$3], commission=[$4])\n" + " EnumerableTableScan(table=[[hr, emps]])\n"));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule in project calcite by apache.
the class PigRelBuilderStyleTest method getVolcanoPlanner.
private RelOptPlanner getVolcanoPlanner(RelNode root) {
final RelBuilderFactory builderFactory = RelBuilder.proto(PigRelFactories.ALL_PIG_REL_FACTORIES);
// VolcanoPlanner
final RelOptPlanner planner = root.getCluster().getPlanner();
for (RelOptRule r : PigRules.ALL_PIG_OPT_RULES) {
planner.addRule(r);
}
planner.removeRule(FilterAggregateTransposeRule.INSTANCE);
planner.removeRule(FilterJoinRule.FILTER_ON_JOIN);
planner.addRule(new FilterAggregateTransposeRule(PigFilter.class, builderFactory, PigAggregate.class));
planner.addRule(new FilterIntoJoinRule(true, builderFactory, TRUE_PREDICATE));
planner.setRoot(root);
return planner;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule in project calcite by apache.
the class VolcanoPlanner method onNewClass.
@Override
protected void onNewClass(RelNode node) {
super.onNewClass(node);
// Create mappings so that instances of this class will match existing
// operands.
final Class<? extends RelNode> clazz = node.getClass();
for (RelOptRule rule : ruleSet) {
for (RelOptRuleOperand operand : rule.getOperands()) {
if (operand.getMatchedClass().isAssignableFrom(clazz)) {
classOperands.put(clazz, operand);
}
}
}
}
Aggregations