private PlannerResult planExplanation( final RelNode rel, final SqlExplain explain, final Set<String> datasourceNames ) { final String explanation = RelOptUtil.dumpPlan("", rel, explain.getFormat(), explain.getDetailLevel()); final Supplier<Sequence<Object[]>> resultsSupplier = Suppliers.ofInstance( Sequences.simple(ImmutableList.of(new Object[]{explanation}))); final RelDataTypeFactory typeFactory = rel.getCluster().getTypeFactory(); return new PlannerResult( resultsSupplier, typeFactory.createStructType( ImmutableList.of(Calcites.createSqlType(typeFactory, SqlTypeName.VARCHAR)), ImmutableList.of("PLAN") ), datasourceNames ); } }
@Override public Result implement(EnumerableRelImplementor enumImplementor, Prefer pref) { if (System.getProperty("calcite.debug") != null) { String dumpPlan = RelOptUtil.dumpPlan("", this, false, SqlExplainLevel.DIGEST_ATTRIBUTES); System.out.println("EXECUTION PLAN BEFORE REWRITE"); System.out.println(dumpPlan); String dumpPlan = RelOptUtil.dumpPlan("", this, false, SqlExplainLevel.DIGEST_ATTRIBUTES); System.out.println("EXECUTION PLAN AFTER OLAPCONTEXT IS SET"); System.out.println(dumpPlan); String dumpPlan = RelOptUtil.dumpPlan("", this, false, SqlExplainLevel.DIGEST_ATTRIBUTES); System.out.println("EXECUTION PLAN AFTER REWRITE"); System.out.println(dumpPlan);
private String dumpRelPlanForNode(RelNode relNode) { return RelOptUtil.dumpPlan("Rel expression: ", relNode, SqlExplainFormat.TEXT, SqlExplainLevel.EXPPLAN_ATTRIBUTES); }
public String toStringOrEmpty(final RelNode plan, boolean ensureDump) { if (!verbose && !ensureDump) { return ""; } if(plan == null) { return ""; } return RelOptUtil.dumpPlan("", plan, SqlExplainFormat.TEXT, SqlExplainLevel.ALL_ATTRIBUTES); }
private String dumpRelPlanForNode(RelNode relNode) { return RelOptUtil.dumpPlan("Rel expression: ", relNode, SqlExplainFormat.TEXT, SqlExplainLevel.EXPPLAN_ATTRIBUTES); }
public String explain(final RelNode node) { return RelOptUtil.dumpPlan("", node, false, SqlExplainLevel.DIGEST_ATTRIBUTES); } }
@Deprecated // to be removed before 2.0 public static String dumpPlan( String header, RelNode rel, boolean asXml, SqlExplainLevel detailLevel) { return dumpPlan(header, rel, asXml ? SqlExplainFormat.XML : SqlExplainFormat.TEXT, detailLevel); }
@Deprecated // to be removed before 2.0 public static String dumpPlan( String header, RelNode rel, boolean asXml, SqlExplainLevel detailLevel) { return dumpPlan(header, rel, asXml ? SqlExplainFormat.XML : SqlExplainFormat.TEXT, detailLevel); }
public String getCode() { if (root == null) { return RelOptUtil.dumpType(rowType); } else { return RelOptUtil.dumpPlan("", root.rel, format, detailLevel); } }
public String getCode() { if (root == null) { return RelOptUtil.dumpType(rowType); } else { return RelOptUtil.dumpPlan("", root.rel, format, detailLevel); } }
private RelNode parseInternal(String sql) throws SQLException { try { //final CalcitePrepare.Context prepareContext = context.getPrepareContext(); //Class elementType = Object[].class; //RelNode relNode = new QuarkPrepare().prepare(prepareContext, sql, elementType, -1); RelNode relNode = this.worker.parse(sql); LOG.info("\n" + RelOptUtil.dumpPlan( "", relNode, false, SqlExplainLevel.ALL_ATTRIBUTES)); return relNode; } catch (CalciteContextException e) { throw new SQLException(e.getMessage(), e); } }
@Override public void planRelTransform(final PlannerPhase phase, final RelNode before, final RelNode after, final long millisTaken) { if (!Strings.isNullOrEmpty(plan.get())) { return; } if (phase == PlannerPhase.LOGICAL) { plan.set(RelOptUtil.dumpPlan("", after, SqlExplainFormat.TEXT, SqlExplainLevel.ALL_ATTRIBUTES)); } } });
/** * the function {@link Predicate#matchesRawPrimaryKey(herddb.utils.Bytes, herddb.model.StatementEvaluationContext) * } * works on a projection of the table wich contains only the pk fields of * the table for instance if the predicate wants to access first element of * the pk, and this field is the 3rd in the column list then you will find * {@link AccessCurrentRowExpression} with index=2. To this expression you * have to apply the projection and map 2 (3rd element of the table) to 0 * (1st element of the pk) * * @param filterPk * @param table */ private CompiledSQLExpression remapPositionalAccessToToPrimaryKeyAccessor(CompiledSQLExpression filterPk, Table table, RelNode debug) { try { int[] projectionToKey = table.getPrimaryKeyProjection(); return filterPk.remapPositionalAccessToToPrimaryKeyAccessor(projectionToKey); } catch (IllegalStateException notImplemented) { LOG.log(Level.INFO, "Not implemented best access for PK on " + RelOptUtil.dumpPlan("", debug, SqlExplainFormat.TEXT, SqlExplainLevel.ALL_ATTRIBUTES), notImplemented); return null; } } private static final Logger LOG = Logger.getLogger(CalcitePlanner.class
private String toString(RelNode rel) { return Util.toLinux( RelOptUtil.dumpPlan("", rel, SqlExplainFormat.TEXT, SqlExplainLevel.DIGEST_ATTRIBUTES)); }
private String toString(RelNode rel) { return Util.toLinux( RelOptUtil.dumpPlan("", rel, SqlExplainFormat.TEXT, SqlExplainLevel.DIGEST_ATTRIBUTES)); }
/** * Trims unused fields from a relational expression. * * <p>We presume that all fields of the relational expression are wanted by * its consumer, so only trim fields that are not used within the tree. * * @param root Root node of relational expression * @return Trimmed relational expression */ public RelNode trim(RelNode root) { final int fieldCount = root.getRowType().getFieldCount(); final ImmutableBitSet fieldsUsed = ImmutableBitSet.range(fieldCount); final Set<RelDataTypeField> extraFields = Collections.emptySet(); final TrimResult trimResult = dispatchTrimFields(root, fieldsUsed, extraFields); if (!trimResult.right.isIdentity()) { throw new IllegalArgumentException(); } if (SqlToRelConverter.SQL2REL_LOGGER.isDebugEnabled()) { SqlToRelConverter.SQL2REL_LOGGER.debug( RelOptUtil.dumpPlan("Plan after trimming unused fields", trimResult.left, SqlExplainFormat.TEXT, SqlExplainLevel.EXPPLAN_ATTRIBUTES)); } return trimResult.left; }
private PlannerResult planExplanation( final RelNode rel, final SqlExplain explain ) { final String explanation = RelOptUtil.dumpPlan("", rel, explain.getFormat(), explain.getDetailLevel()); final Supplier<Sequence<Object[]>> resultsSupplier = Suppliers.ofInstance( Sequences.simple(ImmutableList.of(new Object[]{explanation}))); final RelDataTypeFactory typeFactory = rel.getCluster().getTypeFactory(); return new PlannerResult( resultsSupplier, typeFactory.createStructType( ImmutableList.of(Calcites.createSqlType(typeFactory, SqlTypeName.VARCHAR)), ImmutableList.of("PLAN") ) ); } }
@Test public void testOne() throws Exception { RelNode planned = run(new PropAction(), RULES); if (CalcitePrepareImpl.DEBUG) { System.out.println( RelOptUtil.dumpPlan("LOGICAL PLAN", planned, SqlExplainFormat.TEXT, SqlExplainLevel.ALL_ATTRIBUTES)); } final RelMetadataQuery mq = RelMetadataQuery.instance(); assertEquals("Sortedness was not propagated", 3, mq.getCumulativeCost(planned).getRows(), 0); }
@Test public void testOne() throws Exception { RelNode planned = run(new PropAction(), RULES); if (CalcitePrepareImpl.DEBUG) { System.out.println( RelOptUtil.dumpPlan("LOGICAL PLAN", planned, SqlExplainFormat.TEXT, SqlExplainLevel.ALL_ATTRIBUTES)); } final RelMetadataQuery mq = RelMetadataQuery.instance(); assertEquals("Sortedness was not propagated", 3, mq.getCumulativeCost(planned).getRows(), 0); }
/** * Unit test for {@link org.apache.calcite.rel.externalize.RelJsonReader}. */ @Test public void testReader() { String s = Frameworks.withPlanner((cluster, relOptSchema, rootSchema) -> { SchemaPlus schema = rootSchema.add("hr", new ReflectiveSchema(new JdbcTest.HrSchema())); final RelJsonReader reader = new RelJsonReader(cluster, relOptSchema, schema); RelNode node; try { node = reader.read(XX); } catch (IOException e) { throw new RuntimeException(e); } return RelOptUtil.dumpPlan("", node, SqlExplainFormat.TEXT, SqlExplainLevel.EXPPLAN_ATTRIBUTES); }); assertThat(s, isLinux("LogicalAggregate(group=[{0}], agg#0=[COUNT(DISTINCT $1)], agg#1=[COUNT()])\n" + " LogicalFilter(condition=[=($1, 10)])\n" + " LogicalTableScan(table=[[hr, emps]])\n")); } }