/** * Converts a relational expression to a string, showing just basic * attributes. */ public static String toString(final RelNode rel) { return toString(rel, SqlExplainLevel.EXPPLAN_ATTRIBUTES); }
private void checkConvertedType(SqlNode query, RelNode result) { if (!query.isA(SqlKind.DML)) { // Verify that conversion from SQL to relational algebra did // not perturb any type information. (We can't do this if the // SQL statement is something like an INSERT which has no // validator type information associated with its result, // hence the namespace check above.) RelDataType convertedRowType = result.getRowType(); if (!checkConvertedRowType(query, convertedRowType)) { RelDataType validatedRowType = validator.getValidatedNodeType(query); validatedRowType = uniquifyFields(validatedRowType); throw Util.newInternal( "Conversion to relational algebra failed to preserve " + "datatypes:\n" + "validated type:\n" + validatedRowType.getFullTypeString() + "\nconverted type:\n" + convertedRowType.getFullTypeString() + "\nrel:\n" + RelOptUtil.toString(result)); } } }
public RelNode go(RelNode replacement) { assert equalType("find", find, "replacement", replacement); replacementMap.put(find, replacement); final UnifyResult unifyResult = matchRecurse(find); if (unifyResult != null) { final RelNode node = replace(query, unifyResult.query, unifyResult.result); System.out.println( "Convert: query=" + RelOptUtil.toString(query) + "\nnode=" + RelOptUtil.toString(node)); return node; } return null; }
public void setRoot(RelNode rel) { this.root = registerImpl(rel, null); if (this.originalRoot == null) { this.originalRoot = rel; } this.originalRootString = RelOptUtil.toString(root, SqlExplainLevel.ALL_ATTRIBUTES); // Making a node the root changes its importance. this.ruleQueue.recompute(this.root); }
public void setRoot(RelNode rel) { this.root = registerImpl(rel, null); if (this.originalRoot == null) { this.originalRoot = rel; } this.originalRootString = RelOptUtil.toString(root); // Making a node the root changes its importance. this.ruleQueue.recompute(this.root); }
public Void apply(RelNode relNode) { String s = RelOptUtil.toString(relNode); assertThat(s, not(containsString("CorrelatorRel"))); return null; } });
public Void apply(RelNode relNode) { String s = RelOptUtil.toString(relNode); assertThat(s, containsString(expected)); return null; } });
/** * Takes care of tracing and listener notification when a rule's * transformation is applied. * * @param ruleCall description of rule call * @param newRel result of transformation * @param before true before registration of new rel; false after */ protected void notifyTransformation( RelOptRuleCall ruleCall, RelNode newRel, boolean before) { if (before && tracer.isLoggable(Level.FINE)) { tracer.fine( "Rule " + ruleCall.getRule() + " arguments " + RelOptUtil.toString(ruleCall.rels) + " produced " + newRel); } if (listener != null) { RelOptListener.RuleProductionEvent event = new RelOptListener.RuleProductionEvent( this, newRel, ruleCall, before); listener.ruleProductionSucceeded(event); } }
/** Converts a relational expression to use a * {@link net.hydromatic.optiq.impl.StarTable} defined in {@code schema}. * Uses the first star table that fits. */ private void useStar(OptiqSchema schema, Materialization materialization) { List<OptiqSchema.TableEntry> starTables = getStarTables(schema); if (starTables.isEmpty()) { // Don't waste effort converting to leaf-join form. return; } final RelNode rel2 = RelOptMaterialization.toLeafJoinForm(materialization.queryRel); for (OptiqSchema.TableEntry starTable : starTables) { final Table table = starTable.getTable(); assert table instanceof StarTable; RelOptTableImpl starRelOptTable = RelOptTableImpl.create(catalogReader, table.getRowType(typeFactory), starTable); final RelNode rel3 = RelOptMaterialization.tryUseStar(rel2, starRelOptTable); if (rel3 != null) { // Success -- we found a star table that matches. materialization.materialize(rel3, starRelOptTable); System.out.println("Materialization " + materialization.materializedTable + " matched star table " + starTable + "; query after re-write: " + RelOptUtil.toString(materialization.queryRel)); return; } } }
LOGGER.fine( "Plan after physical tweaks: " + RelOptUtil.toString(rootRel4, SqlExplainLevel.ALL_ATTRIBUTES));
tracer.fine( "Apply rule [" + ruleCall.getRule() + "] to [" + RelOptUtil.toString(ruleCall.rels) + "]");
tracer.finest( "Rule " + getRule() + " arguments " + RelOptUtil.toString(rels) + " created " + relDesc);
private void checkConvertedType(SqlNode query, RelNode result) { if (!query.isA(SqlKind.DML)) { // Verify that conversion from SQL to relational algebra did // not perturb any type information. (We can't do this if the // SQL statement is something like an INSERT which has no // validator type information associated with its result, // hence the namespace check above.) RelDataType convertedRowType = result.getRowType(); if (!checkConvertedRowType(query, convertedRowType)) { RelDataType validatedRowType = validator.getValidatedNodeType(query); validatedRowType = uniquifyFields(validatedRowType); throw Util.newInternal( "Conversion to relational algebra failed to preserve " + "datatypes:\n" + "validated type:\n" + validatedRowType.getFullTypeString() + "\nconverted type:\n" + convertedRowType.getFullTypeString() + "\nrel:\n" + RelOptUtil.toString(result)); } } }
private void checkConvertedType(SqlNode query, RelNode result) { if (!query.isA(SqlKind.DML)) { // Verify that conversion from SQL to relational algebra did // not perturb any type information. (We can't do this if the // SQL statement is something like an INSERT which has no // validator type information associated with its result, // hence the namespace check above.) RelDataType convertedRowType = result.getRowType(); if (!checkConvertedRowType(query, convertedRowType)) { RelDataType validatedRowType = validator.getValidatedNodeType(query); validatedRowType = uniquifyFields(validatedRowType); throw Util.newInternal( "Conversion to relational algebra failed to preserve " + "datatypes:" + Util.lineSeparator + "validated type:" + Util.lineSeparator + validatedRowType.getFullTypeString() + Util.lineSeparator + "converted type:" + Util.lineSeparator + convertedRowType.getFullTypeString() + Util.lineSeparator + "rel:" + Util.lineSeparator + RelOptUtil.toString(result)); } } }
public void assertConvertsTo( String sql, String plan, boolean trim) { String sql2 = getDiffRepos().expand("sql", sql); RelNode rel = convertSqlToRel(sql2); assertTrue(rel != null); assertValid(rel); if (trim) { final RelFieldTrimmer trimmer = createFieldTrimmer(); rel = trimmer.trim(rel); assertTrue(rel != null); assertValid(rel); } // NOTE jvs 28-Mar-2006: insert leading newline so // that plans come out nicely stacked instead of first // line immediately after CDATA start String actual = NL + RelOptUtil.toString(rel); diffRepos.assertEquals("plan", plan, actual); }
public void assertConvertsTo( String sql, String plan, boolean trim) { String sql2 = getDiffRepos().expand("sql", sql); RelNode rel = convertSqlToRel(sql2); assertTrue(rel != null); assertValid(rel); if (trim) { final RelFieldTrimmer trimmer = createFieldTrimmer(); rel = trimmer.trim(rel); assertTrue(rel != null); assertValid(rel); } // NOTE jvs 28-Mar-2006: insert leading newline so // that plans come out nicely stacked instead of first // line immediately after CDATA start String actual = NL + RelOptUtil.toString(rel); diffRepos.assertEquals("plan", plan, actual); }
RelNode relAfter = planner.findBestExp(); String planBefore = NL + RelOptUtil.toString(relAfter); diffRepos.assertEquals("planBefore", "${planBefore}", planBefore); relAfter = planner2.findBestExp(); String planAfter = NL + RelOptUtil.toString(relAfter); diffRepos.assertEquals("planAfter", "${planAfter}", planAfter);
public String checkTpchQuery(String tpchTestQuery) throws Exception { final SchemaPlus schema = Frameworks.createRootSchema(true).add("tpch", new ReflectiveSchema(new TpchSchema())); final FrameworkConfig config = Frameworks.newConfigBuilder() .lex(Lex.MYSQL) .defaultSchema(schema) .programs(Programs.ofRules(Programs.RULE_SET)) .build(); Planner p = Frameworks.getPlanner(config); SqlNode n = p.parse(tpchTestQuery); n = p.validate(n); RelNode r = p.convert(n); String plan = RelOptUtil.toString(r); p.close(); return plan; }