Java Code Examples for org.apache.calcite.sql.SqlExplainLevel

The following examples show how to use org.apache.calcite.sql.SqlExplainLevel. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: calcite   Source File: RelOptMaterialization.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Converts a relational expression to a form where
 * {@link org.apache.calcite.rel.logical.LogicalJoin}s are
 * as close to leaves as possible.
 */
public static RelNode toLeafJoinForm(RelNode rel) {
  final Program program = Programs.hep(
      ImmutableList.of(
          JoinProjectTransposeRule.RIGHT_PROJECT,
          JoinProjectTransposeRule.LEFT_PROJECT,
          FilterJoinRule.FilterIntoJoinRule.FILTER_ON_JOIN,
          ProjectRemoveRule.INSTANCE,
          ProjectMergeRule.INSTANCE),
      false,
      DefaultRelMetadataProvider.INSTANCE);
  if (CalciteSystemProperty.DEBUG.value()) {
    System.out.println(
        RelOptUtil.dumpPlan("before", rel, SqlExplainFormat.TEXT,
            SqlExplainLevel.DIGEST_ATTRIBUTES));
  }
  final RelNode rel2 = program.run(null, rel, null,
      ImmutableList.of(),
      ImmutableList.of());
  if (CalciteSystemProperty.DEBUG.value()) {
    System.out.println(
        RelOptUtil.dumpPlan("after", rel2, SqlExplainFormat.TEXT,
            SqlExplainLevel.DIGEST_ATTRIBUTES));
  }
  return rel2;
}
 
Example 2
Source Project: calcite   Source File: RelWriterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test void testTableModifyInsert() {
  final FrameworkConfig config = RelBuilderTest.config().build();
  final RelBuilder builder = RelBuilder.create(config);
  RelNode project = builder
      .scan("EMP")
      .project(builder.fields(), ImmutableList.of(), true)
      .build();
  LogicalTableModify modify = LogicalTableModify.create(
      project.getInput(0).getTable(),
      (Prepare.CatalogReader) project.getInput(0).getTable().getRelOptSchema(),
      project,
      TableModify.Operation.INSERT,
      null,
      null,
      false);
  String relJson = RelOptUtil.dumpPlan("", modify,
      SqlExplainFormat.JSON, SqlExplainLevel.EXPPLAN_ATTRIBUTES);
  String s = deserializeAndDumpToTextFormat(getSchema(modify), relJson);
  final String expected = ""
      + "LogicalTableModify(table=[[scott, EMP]], operation=[INSERT], flattened=[false])\n"
      + "  LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], "
      + "COMM=[$6], DEPTNO=[$7])\n"
      + "    LogicalTableScan(table=[[scott, EMP]])\n";
  assertThat(s, isLinux(expected));
}
 
Example 3
Source Project: Bats   Source File: RelDecorrelator.java    License: Apache License 2.0 6 votes vote down vote up
/** Decorrelates a query.
 *
 * <p>This is the main entry point to {@code RelDecorrelator}.
 *
 * @param rootRel           Root node of the query
 * @param relBuilder        Builder for relational expressions
 *
 * @return Equivalent query with all
 * {@link org.apache.calcite.rel.logical.LogicalCorrelate} instances removed
 */
public static RelNode decorrelateQuery(RelNode rootRel, RelBuilder relBuilder) {
    final CorelMap corelMap = new CorelMapBuilder().build(rootRel);
    if (!corelMap.hasCorrelation()) {
        return rootRel;
    }

    final RelOptCluster cluster = rootRel.getCluster();
    final RelDecorrelator decorrelator = new RelDecorrelator(corelMap, cluster.getPlanner().getContext(),
            relBuilder);

    RelNode newRootRel = decorrelator.removeCorrelationViaRule(rootRel);

    if (SQL2REL_LOGGER.isDebugEnabled()) {
        SQL2REL_LOGGER.debug(RelOptUtil.dumpPlan("Plan after removing Correlator", newRootRel,
                SqlExplainFormat.TEXT, SqlExplainLevel.EXPPLAN_ATTRIBUTES));
    }

    if (!decorrelator.cm.mapCorToCorRel.isEmpty()) {
        newRootRel = decorrelator.decorrelate(newRootRel);
    }

    return newRootRel;
}
 
Example 4
Source Project: calcite   Source File: RelWriterTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Unit test for {@link org.apache.calcite.rel.externalize.RelJsonReader}.
 */
@Test 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 TestUtil.rethrow(e);
        }
        return RelOptUtil.dumpPlan("", node, SqlExplainFormat.TEXT,
            SqlExplainLevel.EXPPLAN_ATTRIBUTES);
      });

  assertThat(s,
      isLinux("LogicalAggregate(group=[{0}], c=[COUNT(DISTINCT $1)], d=[COUNT()])\n"
          + "  LogicalFilter(condition=[=($1, 10)])\n"
          + "    LogicalTableScan(table=[[hr, emps]])\n"));
}
 
Example 5
Source Project: Bats   Source File: RelOptMaterialization.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Converts a relational expression to a form where
 * {@link org.apache.calcite.rel.logical.LogicalJoin}s are
 * as close to leaves as possible.
 */
public static RelNode toLeafJoinForm(RelNode rel) {
  final Program program = Programs.hep(
      ImmutableList.of(
          JoinProjectTransposeRule.RIGHT_PROJECT,
          JoinProjectTransposeRule.LEFT_PROJECT,
          FilterJoinRule.FilterIntoJoinRule.FILTER_ON_JOIN,
          ProjectRemoveRule.INSTANCE,
          ProjectMergeRule.INSTANCE),
      false,
      DefaultRelMetadataProvider.INSTANCE);
  if (CalciteSystemProperty.DEBUG.value()) {
    System.out.println(
        RelOptUtil.dumpPlan("before", rel, SqlExplainFormat.TEXT,
            SqlExplainLevel.DIGEST_ATTRIBUTES));
  }
  final RelNode rel2 = program.run(null, rel, null,
      ImmutableList.of(),
      ImmutableList.of());
  if (CalciteSystemProperty.DEBUG.value()) {
    System.out.println(
        RelOptUtil.dumpPlan("after", rel2, SqlExplainFormat.TEXT,
            SqlExplainLevel.DIGEST_ATTRIBUTES));
  }
  return rel2;
}
 
Example 6
Source Project: calcite   Source File: RelWriterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test void testArrayType() {
  final FrameworkConfig config = RelBuilderTest.config().build();
  final RelBuilder builder = RelBuilder.create(config);
  final RelNode rel = builder
      .scan("EMP")
      .project(
          builder.call(new MockSqlOperatorTable.SplitFunction(),
              builder.field("ENAME"), builder.literal(",")))
      .build();
  final String relJson = RelOptUtil.dumpPlan("", rel,
      SqlExplainFormat.JSON, SqlExplainLevel.EXPPLAN_ATTRIBUTES);
  final String s = deserializeAndDumpToTextFormat(getSchema(rel), relJson);
  final String expected = ""
      + "LogicalProject($f0=[SPLIT($1, ',')])\n"
      + "  LogicalTableScan(table=[[scott, EMP]])\n";
  assertThat(s, isLinux(expected));
}
 
Example 7
Source Project: calcite   Source File: RelWriterTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Deserialize a relnode from the json string by {@link RelJsonReader},
 * and dump it to text format.
 */
private String deserializeAndDumpToTextFormat(RelOptSchema schema, String relJson) {
  String s =
      Frameworks.withPlanner((cluster, relOptSchema, rootSchema) -> {
        final RelJsonReader reader = new RelJsonReader(
            cluster, schema, rootSchema);
        RelNode node;
        try {
          node = reader.read(relJson);
        } catch (IOException e) {
          throw TestUtil.rethrow(e);
        }
        return RelOptUtil.dumpPlan("", node, SqlExplainFormat.TEXT,
            SqlExplainLevel.EXPPLAN_ATTRIBUTES);
      });
  return s;
}
 
Example 8
Source Project: calcite   Source File: RelWriterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test void testUdf() {
  final FrameworkConfig config = RelBuilderTest.config().build();
  final RelBuilder builder = RelBuilder.create(config);
  final RelNode rel = builder
      .scan("EMP")
      .project(
          builder.call(new MockSqlOperatorTable.MyFunction(),
              builder.field("EMPNO")))
      .build();
  String relJson = RelOptUtil.dumpPlan("", rel,
      SqlExplainFormat.JSON, SqlExplainLevel.EXPPLAN_ATTRIBUTES);
  String s = deserializeAndDumpToTextFormat(getSchema(rel), relJson);
  final String expected = ""
      + "LogicalProject($f0=[MYFUN($0)])\n"
      + "  LogicalTableScan(table=[[scott, EMP]])\n";
  assertThat(s, isLinux(expected));
}
 
Example 9
Source Project: dremio-oss   Source File: PrelSequencer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Generate readable text and json plans and set them in <code>planHolder</code>
 * @param rel
 * @param explainlevel explain plan level.
 * @param observer
 */
public static String setPlansWithIds(final Prel rel, final SqlExplainLevel explainlevel, final AttemptObserver observer, final long millisTaken) {
  if (rel == null) {
    return null;
  }

  Map<Prel, OpId> relIdMap = getIdMap(rel);
  final StringWriter sw = new StringWriter();
  final RelWriter textPlanWriter = new NumberingRelWriter(relIdMap, new PrintWriter(sw), explainlevel);
  rel.explain(textPlanWriter);

  final String textPlan = sw.toString();
  observer.planText(sw.toString(), millisTaken);
  final RelJsonWriter jsonPlanWriter = new RelJsonWriter(getIdMap(rel), explainlevel);
  rel.explain(jsonPlanWriter);
  observer.planJsonPlan(jsonPlanWriter.asString());
  return textPlan;
}
 
Example 10
Source Project: dremio-oss   Source File: ScanRelBase.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public RelWriter explainTerms(RelWriter pw) {
  pw.item("table", tableMetadata.getName());
  if(projectedColumns != null){
    pw.item("columns", FluentIterable.from(projectedColumns).transform(new Function<SchemaPath, String>(){

      @Override
      public String apply(SchemaPath input) {
        return input.toString();
      }}).join(Joiner.on(", ")));
  }

  pw.item("splits", getTableMetadata().getSplitCount());

  if(observedRowcountAdjustment != 1.0d){
    pw.item("rowAdjust", observedRowcountAdjustment);
  }

  // we need to include the table metadata digest since not all properties (specifically which splits) are included in the explain output  (what base computeDigest uses).
  pw.itemIf("tableDigest", tableMetadata.computeDigest(), pw.getDetailLevel() == SqlExplainLevel.DIGEST_ATTRIBUTES);

  return pw;
}
 
Example 11
Source Project: calcite   Source File: VolcanoPlanner.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Dumps the internal state of this VolcanoPlanner to a writer.
 *
 * @param pw Print writer
 * @see #normalizePlan(String)
 */
public void dump(PrintWriter pw) {
  pw.println("Root: " + root);
  pw.println("Original rel:");

  if (originalRoot != null) {
    originalRoot.explain(
        new RelWriterImpl(pw, SqlExplainLevel.ALL_ATTRIBUTES, false));
  }

  try {
    if (CalciteSystemProperty.DUMP_SETS.value()) {
      pw.println();
      pw.println("Sets:");
      Dumpers.dumpSets(this, pw);
    }
    if (CalciteSystemProperty.DUMP_GRAPHVIZ.value()) {
      pw.println();
      pw.println("Graphviz:");
      Dumpers.dumpGraphviz(this, pw);
    }
  } catch (Exception | AssertionError e) {
    pw.println("Error when dumping plan state: \n"
        + e);
  }
}
 
Example 12
Source Project: calcite   Source File: RelWriterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test void testUDAF() {
  final FrameworkConfig config = RelBuilderTest.config().build();
  final RelBuilder builder = RelBuilder.create(config);
  final RelNode rel = builder
      .scan("EMP")
      .project(builder.field("ENAME"), builder.field("DEPTNO"))
      .aggregate(
          builder.groupKey("ENAME"),
          builder.aggregateCall(new MockSqlOperatorTable.MyAggFunc(),
              builder.field("DEPTNO")))
      .build();
  final String relJson = RelOptUtil.dumpPlan("", rel,
      SqlExplainFormat.JSON, SqlExplainLevel.EXPPLAN_ATTRIBUTES);
  final String result = deserializeAndDumpToTextFormat(getSchema(rel), relJson);
  final String expected = ""
      + "LogicalAggregate(group=[{0}], agg#0=[myAggFunc($1)])\n"
      + "  LogicalProject(ENAME=[$1], DEPTNO=[$7])\n"
      + "    LogicalTableScan(table=[[scott, EMP]])\n";
  assertThat(result, isLinux(expected));
}
 
Example 13
Source Project: calcite   Source File: TraitPropagationTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test void testOne() throws Exception {
  RelNode planned = run(new PropAction(), RULES);
  if (CalciteSystemProperty.DEBUG.value()) {
    System.out.println(
        RelOptUtil.dumpPlan("LOGICAL PLAN", planned, SqlExplainFormat.TEXT,
            SqlExplainLevel.ALL_ATTRIBUTES));
  }
  final RelMetadataQuery mq = planned.getCluster().getMetadataQuery();
  assertEquals(3, 0, mq.getCumulativeCost(planned).getRows(),
      "Sortedness was not propagated");
}
 
Example 14
Source Project: Bats   Source File: RelMetadataQuery.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the
 * {@link BuiltInMetadata.ExplainVisibility#isVisibleInExplain(SqlExplainLevel)}
 * statistic.
 *
 * @param rel          the relational expression
 * @param explainLevel level of detail
 * @return true for visible, false for invisible; if no metadata is available,
 * defaults to true
 */
public boolean isVisibleInExplain(RelNode rel,
    SqlExplainLevel explainLevel) {
  for (;;) {
    try {
      Boolean b = explainVisibilityHandler.isVisibleInExplain(rel, this,
          explainLevel);
      return b == null || b;
    } catch (JaninoRelMetadataProvider.NoHandler e) {
      explainVisibilityHandler =
          revise(e.relClass, BuiltInMetadata.ExplainVisibility.DEF);
    }
  }
}
 
Example 15
Source Project: Bats   Source File: Project.java    License: Apache License 2.0 5 votes vote down vote up
public RelWriter explainTerms(RelWriter pw) {
  super.explainTerms(pw);
  if (pw.nest()) {
    pw.item("fields", rowType.getFieldNames());
    pw.item("exprs", exps);
  } else {
    for (Ord<RelDataTypeField> field : Ord.zip(rowType.getFieldList())) {
      String fieldName = field.e.getName();
      if (fieldName == null) {
        fieldName = "field#" + field.i;
      }
      pw.item(fieldName, exps.get(field.i));
    }
  }

  // If we're generating a digest, include the rowtype. If two projects
  // differ in return type, we don't want to regard them as equivalent,
  // otherwise we will try to put rels of different types into the same
  // planner equivalence set.
  //CHECKSTYLE: IGNORE 2
  if ((pw.getDetailLevel() == SqlExplainLevel.DIGEST_ATTRIBUTES)
      && false) {
    pw.item("type", rowType);
  }

  return pw;
}
 
Example 16
Source Project: Bats   Source File: RelFieldTrimmer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 17
Source Project: calcite   Source File: RexProgram.java    License: Apache License 2.0 5 votes vote down vote up
public RelWriter collectExplainTerms(
    String prefix,
    RelWriter pw) {
  return collectExplainTerms(
      prefix,
      pw,
      SqlExplainLevel.EXPPLAN_ATTRIBUTES);
}
 
Example 18
Source Project: Bats   Source File: RelOptUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Converts a relational expression to a string.
 */
public static String toString(final RelNode rel, SqlExplainLevel detailLevel) {
    if (rel == null) {
        return null;
    }
    final StringWriter sw = new StringWriter();
    final RelWriter planWriter = new RelWriterImpl(new PrintWriter(sw), detailLevel, false);
    rel.explain(planWriter);
    return sw.toString();
}
 
Example 19
Source Project: Bats   Source File: PrelSequencer.java    License: Apache License 2.0 5 votes vote down vote up
public static String printWithIds(final Prel rel, SqlExplainLevel explainlevel) {
    if (rel == null) {
      return null;
    }
    final StringWriter sw = new StringWriter();
    final RelWriter planWriter = new NumberingRelWriter(getIdMap(rel), new PrintWriter(sw), explainlevel);
    rel.explain(planWriter);
    return sw.toString();

}
 
Example 20
Source Project: Bats   Source File: DefaultSqlHandler.java    License: Apache License 2.0 5 votes vote down vote up
protected void log(final String description, final RelNode node, final Logger logger, Stopwatch watch) {
  if (logger.isDebugEnabled()) {
    final String plan = RelOptUtil.toString(node, SqlExplainLevel.ALL_ATTRIBUTES);
    final String time = watch == null ? "" : String.format(" (%dms)", watch.elapsed(TimeUnit.MILLISECONDS));
    logger.debug(String.format("%s%s:\n%s", description, time, plan));
  }
}
 
Example 21
Source Project: Bats   Source File: DefaultSqlHandler.java    License: Apache License 2.0 5 votes vote down vote up
protected void logAndSetTextPlan(final String description, final Prel prel, final Logger logger) {
  final String plan = PrelSequencer.printWithIds(prel, SqlExplainLevel.ALL_ATTRIBUTES);
  if (textPlan != null) {
    textPlan.value = plan;
  }

  if (logger.isDebugEnabled()) {
    logger.debug(String.format("%s:\n%s", description, plan));
  }
}
 
Example 22
Source Project: Bats   Source File: ExplainHandler.java    License: Apache License 2.0 5 votes vote down vote up
public LogicalExplain(RelNode node, SqlExplainLevel level, QueryContext context) {
  this.text = RelOptUtil.toString(node, level);
  DrillImplementor implementor = new DrillImplementor(new DrillParseContext(context.getPlannerSettings()), ResultMode.LOGICAL);
  implementor.go( (DrillRel) node);
  LogicalPlan plan = implementor.getPlan();
  this.json = plan.unparse(context.getLpPersistence());
}
 
Example 23
Source Project: calcite   Source File: RelDecorrelator.java    License: Apache License 2.0 5 votes vote down vote up
/** Decorrelates a query.
 *
 * <p>This is the main entry point to {@code RelDecorrelator}.
 *
 * @param rootRel           Root node of the query
 * @param relBuilder        Builder for relational expressions
 *
 * @return Equivalent query with all
 * {@link org.apache.calcite.rel.core.Correlate} instances removed
 */
public static RelNode decorrelateQuery(RelNode rootRel,
    RelBuilder relBuilder) {
  final CorelMap corelMap = new CorelMapBuilder().build(rootRel);
  if (!corelMap.hasCorrelation()) {
    return rootRel;
  }

  final RelOptCluster cluster = rootRel.getCluster();
  final RelDecorrelator decorrelator =
      new RelDecorrelator(corelMap,
          cluster.getPlanner().getContext(), relBuilder);

  RelNode newRootRel = decorrelator.removeCorrelationViaRule(rootRel);

  if (SQL2REL_LOGGER.isDebugEnabled()) {
    SQL2REL_LOGGER.debug(
        RelOptUtil.dumpPlan("Plan after removing Correlator", newRootRel,
            SqlExplainFormat.TEXT, SqlExplainLevel.EXPPLAN_ATTRIBUTES));
  }

  if (!decorrelator.cm.mapCorToCorRel.isEmpty()) {
    newRootRel = decorrelator.decorrelate(newRootRel);
  }

  // Re-propagate the hints.
  newRootRel = RelOptUtil.propagateRelHints(newRootRel, true);

  return newRootRel;
}
 
Example 24
Source Project: Mycat2   Source File: HBTBaseTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void testRel(RelNode relNode, String expect) {
    Assert.assertEquals(
            expect.replace("\n", "").replace("\r", "").trim()
            ,
            RelOptUtil.toString(relNode, SqlExplainLevel.EXPPLAN_ATTRIBUTES)
                    .replace("\n", "").replace("\r", "").trim()
    );
}
 
Example 25
Source Project: Mycat2   Source File: HBTBaseTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void testRel(Schema schema, String relText, String normalSugarText) {
    RelNode relNode = toRelNode(schema);
    Schema schema1 = toDSL(relNode);
    Assert.assertEquals(normalSugarText, toNormalString(schema1));

    Assert.assertEquals(
            relText.replace("\n", "").replace("\r", "").trim()
            ,
            RelOptUtil.toString(relNode, SqlExplainLevel.EXPPLAN_ATTRIBUTES)
                    .replace("\n", "").replace("\r", "").trim()
    );
}
 
Example 26
Source Project: calcite   Source File: CalcitePrepareImpl.java    License: Apache License 2.0 5 votes vote down vote up
CalcitePreparedExplain(
    RelDataType resultType,
    RelDataType parameterRowType,
    RelRoot root,
    SqlExplainFormat format,
    SqlExplainLevel detailLevel) {
  super(resultType, parameterRowType, root, format, detailLevel);
}
 
Example 27
Source Project: calcite   Source File: RelWriterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test void testTableModifyDelete() {
  final FrameworkConfig config = RelBuilderTest.config().build();
  final RelBuilder builder = RelBuilder.create(config);
  RelNode filter = builder
      .scan("EMP")
      .filter(
          builder.call(
              SqlStdOperatorTable.EQUALS,
              builder.field("JOB"),
              builder.literal("c")))
      .build();
  LogicalTableModify modify = LogicalTableModify.create(
      filter.getInput(0).getTable(),
      (Prepare.CatalogReader) filter.getInput(0).getTable().getRelOptSchema(),
      filter,
      TableModify.Operation.DELETE,
      null,
      null,
      false);
  String relJson = RelOptUtil.dumpPlan("", modify,
      SqlExplainFormat.JSON, SqlExplainLevel.EXPPLAN_ATTRIBUTES);
  String s = deserializeAndDumpToTextFormat(getSchema(modify), relJson);
  final String expected = ""
      + "LogicalTableModify(table=[[scott, EMP]], operation=[DELETE], flattened=[false])\n"
      + "  LogicalFilter(condition=[=($2, 'c')])\n"
      + "    LogicalTableScan(table=[[scott, EMP]])\n";
  assertThat(s, isLinux(expected));
}
 
Example 28
Source Project: dremio-oss   Source File: ValuesRel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RelWriter explainTerms(RelWriter pw) {
  return super.explainTerms(pw)
      .itemIf("type", this.rowType, pw.getDetailLevel() == SqlExplainLevel.DIGEST_ATTRIBUTES)
      .itemIf("type", this.rowType.getFieldList(), pw.nest())
      .itemIf("tuplesCount", rowCount, pw.getDetailLevel() != SqlExplainLevel.ALL_ATTRIBUTES)
      .itemIf("tuples", options.asNode(), pw.getDetailLevel() == SqlExplainLevel.DIGEST_ATTRIBUTES);
}
 
Example 29
Source Project: calcite   Source File: RelWriterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test void testCalc() {
  final FrameworkConfig config = RelBuilderTest.config().build();
  final RelBuilder builder = RelBuilder.create(config);
  final RexBuilder rexBuilder = builder.getRexBuilder();
  final LogicalTableScan scan = (LogicalTableScan) builder.scan("EMP").build();
  final RexProgramBuilder programBuilder =
      new RexProgramBuilder(scan.getRowType(), rexBuilder);
  final RelDataTypeField field = scan.getRowType().getField("SAL", false, false);
  programBuilder.addIdentity();
  programBuilder.addCondition(
      rexBuilder.makeCall(SqlStdOperatorTable.GREATER_THAN,
          new RexInputRef(field.getIndex(), field.getType()),
          builder.literal(10)));
  final LogicalCalc calc = LogicalCalc.create(scan, programBuilder.getProgram());
  String relJson = RelOptUtil.dumpPlan("", calc,
      SqlExplainFormat.JSON, SqlExplainLevel.EXPPLAN_ATTRIBUTES);
  String s =
      Frameworks.withPlanner((cluster, relOptSchema, rootSchema) -> {
        final RelJsonReader reader = new RelJsonReader(
            cluster, getSchema(calc), rootSchema);
        RelNode node;
        try {
          node = reader.read(relJson);
        } catch (IOException e) {
          throw TestUtil.rethrow(e);
        }
        return RelOptUtil.dumpPlan("", node, SqlExplainFormat.TEXT,
            SqlExplainLevel.EXPPLAN_ATTRIBUTES);
      });
  final String expected =
      "LogicalCalc(expr#0..7=[{inputs}], expr#8=[10], expr#9=[>($t5, $t8)],"
          + " proj#0..7=[{exprs}], $condition=[$t9])\n"
          + "  LogicalTableScan(table=[[scott, EMP]])\n";
  assertThat(s, isLinux(expected));
}
 
Example 30
Source Project: dremio-oss   Source File: PrelTransformer.java    License: Apache License 2.0 5 votes vote down vote up
public static void log(final String description, final RelNode node, final Logger logger, Stopwatch watch) {
  if (logger.isDebugEnabled()) {
    final String plan = RelOptUtil.toString(node, SqlExplainLevel.ALL_ATTRIBUTES);
    final String time = watch == null ? "" : String.format(" (%dms)", watch.elapsed(TimeUnit.MILLISECONDS));
    logger.debug(String.format("%s%s:\n%s", description, time, plan));
  }
}