Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce calcite 2902 #300

Open
wants to merge 4 commits into
base: kycalcite-spark3-1.16.0.x-4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cassandra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
Copy link

@yahoNanJing yahoNanJing Oct 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a property to indicate the version and manage the related dependency to the dependencyManagement?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, but now the main pom.xml will update the version with every change. So the related dependencies are clear to be managed.

</parent>

<artifactId>calcite-cassandra</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Cassandra</name>
<description>Cassandra adapter for Calcite</description>

Expand Down
4 changes: 2 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-core</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Core</name>
<description>Core Calcite APIs and engine.</description>

Expand Down
101 changes: 62 additions & 39 deletions core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<Pair<String, Object>> values) {
pw.write(getRelTypeName());

for (RelTrait trait : traitSet) {
pw.write(".");
pw.write(trait.toString());
}

pw.write("(");
int j = 0;
for (Pair<String, Object> 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.
*
* <p>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.</p>
*
*/
private static final class RelDigestWriter implements RelWriter {

private final List<Pair<String, Object>> values = new ArrayList<>();

String digest = null;

@Override public void explain(final RelNode rel, final List<Pair<String, Object>> 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<String, Object> value : values) {
if (j++ > 0) {
sb.append(',');
}
sb.append(value.left);
sb.append('=');
sb.append(value.right);
}
sb.append(')');
digest = sb.toString();
return this;
}
}
}

Expand Down
12 changes: 9 additions & 3 deletions core/src/main/java/org/apache/calcite/rel/RelWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -125,13 +121,6 @@ private List<Object> getList(List<Pair<String, Object>> values, String tag) {
return list;
}

public RelWriter itemIf(String term, Object value, boolean condition) {
if (condition) {
item(term, value);
}
return this;
}

public RelWriter done(RelNode node) {
final List<Pair<String, Object>> valuesCopy =
ImmutableList.copyOf(values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,12 @@ public SqlExplainLevel getDetailLevel() {
return detailLevel;
}

public RelWriter input(String term, RelNode input) {
values.add(Pair.of(term, (Object) input));
return this;
}

public RelWriter item(String term, Object value) {
values.add(Pair.of(term, value));
return this;
}

public RelWriter itemIf(String term, Object value, boolean condition) {
if (condition) {
item(term, value);
}
return this;
}

public RelWriter done(RelNode node) {
assert checkInputsPresentInExplain(node);
final List<Pair<String, Object>> valuesCopy =
Expand All @@ -170,10 +159,6 @@ private boolean checkInputsPresentInExplain(RelNode node) {
return true;
}

public boolean nest() {
return false;
}

/**
* Converts the collected terms and values to a string. Does not write to
* the parent writer.
Expand Down
4 changes: 2 additions & 2 deletions druid/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-druid</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Druid</name>
<description>Druid adapter for Calcite</description>

Expand Down
4 changes: 2 additions & 2 deletions elasticsearch2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-elasticsearch2</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Elasticsearch</name>
<description>Elasticsearch adapter for Calcite</description>

Expand Down
4 changes: 2 additions & 2 deletions elasticsearch5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-elasticsearch5</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Elasticsearch5</name>
<description>Elasticsearch5 adapter for Calcite</description>

Expand Down
4 changes: 2 additions & 2 deletions example/csv/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-example</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-example-csv</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Example CSV</name>
<description>An example Calcite provider that reads CSV files</description>

Expand Down
4 changes: 2 additions & 2 deletions example/function/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-example</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-example-function</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Example Function</name>
<description>Examples of user-defined Calcite functions</description>

Expand Down
4 changes: 2 additions & 2 deletions example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<!-- The basics. -->
<artifactId>calcite-example</artifactId>
<packaging>pom</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Examples</name>
<description>Calcite examples</description>

Expand Down
4 changes: 2 additions & 2 deletions file/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<!-- The basics. -->
<artifactId>calcite-file</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite File</name>
<description>Calcite provider that reads files and URIs</description>

Expand Down
4 changes: 2 additions & 2 deletions geode/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-geode</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Geode</name>
<description>Geode adapter for Calcite</description>

Expand Down
4 changes: 2 additions & 2 deletions linq4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ limitations under the License.
<parent>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite</artifactId>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
</parent>

<artifactId>calcite-linq4j</artifactId>
<packaging>jar</packaging>
<version>1.116.0-kylin-4.x-r023</version>
<version>1.116.0-kylin-4.x-r024</version>
<name>Calcite Linq4j</name>
<description>Calcite APIs for LINQ (Language-Integrated Query) in Java</description>

Expand Down
Loading