This is an automated email from the ASF dual-hosted git repository.
rubenql pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/master by this push:
new 81db26d [CALCITE-4224] Add a method for RelNode to output its
relational expression string (Jiatao Tao)
81db26d is described below
commit 81db26dd077c44242417d2dbd1cd9f78890a4a73
Author: Jiatao Tao <[email protected]>
AuthorDate: Thu Sep 10 14:37:44 2020 +0800
[CALCITE-4224] Add a method for RelNode to output its relational expression
string (Jiatao Tao)
---
core/src/main/java/org/apache/calcite/rel/RelNode.java | 17 +++++++++++++++++
.../java/org/apache/calcite/plan/RelOptUtilTest.java | 6 +++---
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/core/src/main/java/org/apache/calcite/rel/RelNode.java
b/core/src/main/java/org/apache/calcite/rel/RelNode.java
index 54aae1f..bd865f6 100644
--- a/core/src/main/java/org/apache/calcite/rel/RelNode.java
+++ b/core/src/main/java/org/apache/calcite/rel/RelNode.java
@@ -22,6 +22,7 @@ import org.apache.calcite.plan.RelOptCost;
import org.apache.calcite.plan.RelOptNode;
import org.apache.calcite.plan.RelOptPlanner;
import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.plan.RelOptUtil;
import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.rel.core.CorrelationId;
import org.apache.calcite.rel.metadata.Metadata;
@@ -223,6 +224,22 @@ public interface RelNode extends RelOptNode, Cloneable {
void explain(RelWriter pw);
/**
+ * Returns a relational expression string of this {@code RelNode}.
+ * The string returned is the same as
+ * {@link RelOptUtil#toString(org.apache.calcite.rel.RelNode)}.
+ *
+ * This method is intended mainly for use while debugging in an IDE,
+ * as a convenient short-hand for RelOptUtil.toString.
+ * We recommend that classes implementing this interface
+ * do not override this method.
+ *
+ * @return Relational expression string of this {@code RelNode}
+ */
+ default String explain() {
+ return RelOptUtil.toString(this);
+ }
+
+ /**
* Receives notification that this expression is about to be registered. The
* implementation of this method must at least register all child
* expressions.
diff --git a/core/src/test/java/org/apache/calcite/plan/RelOptUtilTest.java
b/core/src/test/java/org/apache/calcite/plan/RelOptUtilTest.java
index 58d772d..2fa4015 100644
--- a/core/src/test/java/org/apache/calcite/plan/RelOptUtilTest.java
+++ b/core/src/test/java/org/apache/calcite/plan/RelOptUtilTest.java
@@ -574,7 +574,7 @@ class RelOptUtilTest {
RexInputRef.of(2, agg.getRowType()),
true))
.build();
- assertThat(RelOptUtil.toString(castNode),
is(RelOptUtil.toString(expectNode)));
+ assertThat(castNode.explain(), is(expectNode.explain()));
// Cast with row type(change field name):
// RecordType(SMALLINT NOT NULL EMPNO, VARCHAR(10) ENAME, BIGINT NOT NULL
JOB_CNT) NOT NULL
@@ -598,7 +598,7 @@ class RelOptUtilTest {
fieldEmpno.getName(),
fieldEname.getName(),
"JOB_CNT"));
- assertThat(RelOptUtil.toString(castNode1),
is(RelOptUtil.toString(expectNode1)));
+ assertThat(castNode1.explain(), is(expectNode1.explain()));
// Change the field JOB_CNT field name again.
// The projection expect to be merged.
final RelDataType castRowType2 = typeFactory
@@ -621,7 +621,7 @@ class RelOptUtilTest {
fieldEmpno.getName(),
fieldEname.getName(),
"JOB_CNT2"));
- assertThat(RelOptUtil.toString(castNode2),
is(RelOptUtil.toString(expectNode2)));
+ assertThat(castNode2.explain(), is(expectNode2.explain()));
}
/** Dummy sub-class of ConverterRule, to check whether generated descriptions