diff --git a/cassandra/pom.xml b/cassandra/pom.xml
index 608a0083067..90f136bcac7 100644
--- a/cassandra/pom.xml
+++ b/cassandra/pom.xml
@@ -20,12 +20,12 @@ limitations under the License.
org.apache.calcitecalcite
- 1.116.0-kylin-4.x-r023
+ 1.116.0-kylin-4.x-r024calcite-cassandrajar
- 1.116.0-kylin-4.x-r023
+ 1.116.0-kylin-4.x-r024Calcite CassandraCassandra adapter for Calcite
diff --git a/core/pom.xml b/core/pom.xml
index f3824f66197..319f89a7174 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -20,12 +20,12 @@ limitations under the License.
org.apache.calcitecalcite
- 1.116.0-kylin-4.x-r023
+ 1.116.0-kylin-4.x-r024calcite-corejar
- 1.116.0-kylin-4.x-r023
+ 1.116.0-kylin-4.x-r024Calcite CoreCore Calcite APIs and engine.
diff --git a/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java b/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java
index 3b6be139053..17c052ded13 100644
--- a/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java
+++ b/core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java
@@ -27,7 +27,6 @@
import org.apache.calcite.plan.RelTrait;
import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.rel.core.CorrelationId;
-import org.apache.calcite.rel.externalize.RelWriterImpl;
import org.apache.calcite.rel.metadata.Metadata;
import org.apache.calcite.rel.metadata.MetadataFactory;
import org.apache.calcite.rel.metadata.RelMetadataQuery;
@@ -46,8 +45,6 @@
import org.slf4j.Logger;
-import java.io.PrintWriter;
-import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -192,16 +189,14 @@ public void register(RelOptPlanner planner) {
}
public final String getRelTypeName() {
- String className = getClass().getName();
- int i = className.lastIndexOf("$");
- if (i >= 0) {
- return className.substring(i + 1);
- }
- i = className.lastIndexOf(".");
- if (i >= 0) {
- return className.substring(i + 1);
+ String cn = getClass().getName();
+ int i = cn.length();
+ while (--i >= 0) {
+ if (cn.charAt(i) == '$' || cn.charAt(i) == '.') {
+ return cn.substring(i + 1);
+ }
}
- return className;
+ return cn;
}
public boolean isValid(Litmus litmus, Context context) {
@@ -394,33 +389,61 @@ public RelOptTable getTable() {
* @return Digest
*/
protected String computeDigest() {
- StringWriter sw = new StringWriter();
- RelWriter pw =
- new RelWriterImpl(
- new PrintWriter(sw),
- SqlExplainLevel.DIGEST_ATTRIBUTES, false) {
- protected void explain_(
- RelNode rel, List> values) {
- pw.write(getRelTypeName());
-
- for (RelTrait trait : traitSet) {
- pw.write(".");
- pw.write(trait.toString());
- }
-
- pw.write("(");
- int j = 0;
- for (Pair value : values) {
- if (j++ > 0) {
- pw.write(",");
- }
- pw.write(value.left + "=" + value.right);
- }
- pw.write(")");
- }
- };
- explain(pw);
- return sw.toString();
+ RelDigestWriter rdw = new RelDigestWriter();
+ explain(rdw);
+ return rdw.digest;
+ }
+
+ /**
+ * A writer object used exclusively for computing the digest of a RelNode.
+ *
+ *
The writer is meant to be used only for computing a single digest and then thrown away.
+ * After calling {@link #done(RelNode)} the writer should be used only to obtain the computed
+ * {@link #digest}. Any other action is prohibited.
+ *
+ */
+ private static final class RelDigestWriter implements RelWriter {
+
+ private final List> values = new ArrayList<>();
+
+ String digest = null;
+
+ @Override public void explain(final RelNode rel, final List> valueList) {
+ throw new IllegalStateException("Should not be called for computing digest");
+ }
+
+ @Override public SqlExplainLevel getDetailLevel() {
+ return SqlExplainLevel.DIGEST_ATTRIBUTES;
+ }
+
+ @Override public RelWriter item(String term, Object value) {
+ values.add(Pair.of(term, value));
+ return this;
+ }
+
+ @Override public RelWriter done(RelNode node) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(node.getRelTypeName());
+
+ for (RelTrait trait : node.getTraitSet()) {
+ sb.append('.');
+ sb.append(trait.toString());
+ }
+
+ sb.append('(');
+ int j = 0;
+ for (Pair value : values) {
+ if (j++ > 0) {
+ sb.append(',');
+ }
+ sb.append(value.left);
+ sb.append('=');
+ sb.append(value.right);
+ }
+ sb.append(')');
+ digest = sb.toString();
+ return this;
+ }
}
}
diff --git a/core/src/main/java/org/apache/calcite/rel/RelWriter.java b/core/src/main/java/org/apache/calcite/rel/RelWriter.java
index fa63bc2b79d..551685ccc1c 100644
--- a/core/src/main/java/org/apache/calcite/rel/RelWriter.java
+++ b/core/src/main/java/org/apache/calcite/rel/RelWriter.java
@@ -53,7 +53,9 @@ public interface RelWriter {
* @param term Term for input, e.g. "left" or "input #1".
* @param input Input relational expression
*/
- RelWriter input(String term, RelNode input);
+ default RelWriter input(String term, RelNode input) {
+ return item(term, input);
+ }
/**
* Adds an attribute to the explanation of the current node.
@@ -67,7 +69,9 @@ public interface RelWriter {
* Adds an input to the explanation of the current node, if a condition
* holds.
*/
- RelWriter itemIf(String term, Object value, boolean condition);
+ default RelWriter itemIf(String term, Object value, boolean condition) {
+ return condition ? item(term, value) : this;
+ }
/**
* Writes the completed explanation.
@@ -78,7 +82,9 @@ public interface RelWriter {
* Returns whether the writer prefers nested values. Traditional explain
* writers prefer flattened values.
*/
- boolean nest();
+ default boolean nest() {
+ return false;
+ }
}
// End RelWriter.java
diff --git a/core/src/main/java/org/apache/calcite/rel/externalize/RelJsonWriter.java b/core/src/main/java/org/apache/calcite/rel/externalize/RelJsonWriter.java
index 2db46a1a5a0..3bd3d049e2f 100644
--- a/core/src/main/java/org/apache/calcite/rel/externalize/RelJsonWriter.java
+++ b/core/src/main/java/org/apache/calcite/rel/externalize/RelJsonWriter.java
@@ -104,10 +104,6 @@ public SqlExplainLevel getDetailLevel() {
return SqlExplainLevel.ALL_ATTRIBUTES;
}
- public RelWriter input(String term, RelNode input) {
- return this;
- }
-
public RelWriter item(String term, Object value) {
values.add(Pair.of(term, value));
return this;
@@ -125,13 +121,6 @@ private List