use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.
the class MergeJoinPlannerTest method testRightPassThroughOrderByRight3.
/**
* Test verifies the collation propagation from a parent node.
*
* <p>In case of right join, collation consisted of join keys only should be propagated as is.
*
* @throws Exception In case of any unexpected error.
*/
@Test
public void testRightPassThroughOrderByRight3() throws Exception {
IgniteSchema schema = createSchema(createTable("LEFT_T", IgniteDistributions.single(), "C1", Integer.class, "C2", Integer.class, "C3", Integer.class), createTable("RIGHT_T", IgniteDistributions.single(), "C1", Integer.class, "C2", Integer.class, "C3", Integer.class));
String sql = "" + "select * " + " from LEFT_T " + " right join RIGHT_T " + " on LEFT_T.c1 = RIGHT_T.c1 " + " and LEFT_T.c2 = RIGHT_T.c2 " + " order by RIGHT_T.c1 DESC, RIGHT_T.c2 ASC";
IgniteRel rel = physicalPlan(sql, schema, DISABLED_RULES);
assertNull(sortOnTopOfJoin(rel));
List<IgniteSort> sortNodes = sortOnTopOfScan(rel);
RelCollation expected = RelCollations.of(new RelFieldCollation(0, DESCENDING, RelFieldCollation.NullDirection.LAST), new RelFieldCollation(1, ASCENDING, RelFieldCollation.NullDirection.FIRST));
assertEquals(expected, sortNodes.get(0).collation());
assertEquals(expected, sortNodes.get(1).collation());
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.
the class PlannerHelper method optimize.
/**
* Optimize.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*
* @param sqlNode Sql node.
* @param planner Planner.
*/
public static IgniteRel optimize(SqlNode sqlNode, IgnitePlanner planner) {
try {
// Convert to Relational operators graph
RelRoot root = planner.rel(sqlNode);
RelNode rel = root.rel;
if (HintUtils.containsDisabledRules(root.hints)) {
planner.setDisabledRules(HintUtils.disabledRules(root.hints));
}
// Transformation chain
rel = planner.transform(PlannerPhase.HEP_DECORRELATE, rel.getTraitSet(), rel);
rel = planner.trimUnusedFields(root.withRel(rel)).rel;
rel = planner.transform(PlannerPhase.HEP_FILTER_PUSH_DOWN, rel.getTraitSet(), rel);
rel = planner.transform(PlannerPhase.HEP_PROJECT_PUSH_DOWN, rel.getTraitSet(), rel);
RelTraitSet desired = rel.getCluster().traitSet().replace(IgniteConvention.INSTANCE).replace(IgniteDistributions.single()).replace(root.collation == null ? RelCollations.EMPTY : root.collation).simplify();
IgniteRel igniteRel = planner.transform(PlannerPhase.OPTIMIZATION, desired, rel);
if (!root.isRefTrivial()) {
final List<RexNode> projects = new ArrayList<>();
final RexBuilder rexBuilder = igniteRel.getCluster().getRexBuilder();
for (int field : Pair.left(root.fields)) {
projects.add(rexBuilder.makeInputRef(igniteRel, field));
}
igniteRel = new IgniteProject(igniteRel.getCluster(), desired, igniteRel, projects, root.validatedRowType);
}
if (sqlNode.isA(Set.of(SqlKind.INSERT, SqlKind.UPDATE, SqlKind.MERGE))) {
igniteRel = new FixDependentModifyNodeShuttle().visit(igniteRel);
}
return igniteRel;
} catch (Throwable ex) {
LOG.error("Unexpected error at query optimizer.", ex);
if (LOG.isDebugEnabled()) {
LOG.error(planner.dump());
}
throw ex;
}
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.
the class PrepareServiceImpl method prepareQuery.
private QueryPlan prepareQuery(SqlNode sqlNode, PlanningContext ctx) {
IgnitePlanner planner = ctx.planner();
// Validate
ValidationResult validated = planner.validateAndGetTypeMetadata(sqlNode);
sqlNode = validated.sqlNode();
IgniteRel igniteRel = optimize(sqlNode, planner);
// Split query plan to query fragments.
List<Fragment> fragments = new Splitter().go(igniteRel);
QueryTemplate template = new QueryTemplate(fragments);
return new MultiStepQueryPlan(template, resultSetMetadata(ctx, validated.dataType(), validated.origins()));
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.
the class Cloner method go.
/**
* Clones and associates a plan with a new cluster.
*
* @param src Fragment to clone.
* @return New plan.
*/
public Fragment go(Fragment src) {
try {
remotes = new ArrayList<>();
IgniteRel newRoot = visit(src.root());
return new Fragment(src.fragmentId(), newRoot, List.copyOf(remotes), src.serialized(), src.mapping());
} finally {
remotes = null;
}
}
use of org.apache.ignite.internal.sql.engine.rel.IgniteRel in project ignite-3 by apache.
the class AbstractPlannerTest method physicalPlan.
protected IgniteRel physicalPlan(String sql, PlanningContext ctx) throws Exception {
try (IgnitePlanner planner = ctx.planner()) {
assertNotNull(planner);
String qry = ctx.query();
assertNotNull(qry);
// Parse
SqlNode sqlNode = planner.parse(qry);
// Validate
sqlNode = planner.validate(sqlNode);
try {
IgniteRel rel = PlannerHelper.optimize(sqlNode, planner);
return rel;
} catch (Throwable ex) {
System.err.println(planner.dump());
throw ex;
}
}
}
Aggregations