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.calcite calcite - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-cassandra jar - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite Cassandra Cassandra 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.calcite calcite - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-core jar - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite Core Core 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 getList(List> 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> valuesCopy = ImmutableList.copyOf(values); diff --git a/core/src/main/java/org/apache/calcite/rel/externalize/RelWriterImpl.java b/core/src/main/java/org/apache/calcite/rel/externalize/RelWriterImpl.java index af2985e3d67..15430512ef4 100644 --- a/core/src/main/java/org/apache/calcite/rel/externalize/RelWriterImpl.java +++ b/core/src/main/java/org/apache/calcite/rel/externalize/RelWriterImpl.java @@ -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> valuesCopy = @@ -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. diff --git a/druid/pom.xml b/druid/pom.xml index 9ceab219fb0..1698af7bced 100644 --- a/druid/pom.xml +++ b/druid/pom.xml @@ -20,12 +20,12 @@ limitations under the License. org.apache.calcite calcite - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-druid jar - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite Druid Druid adapter for Calcite diff --git a/elasticsearch2/pom.xml b/elasticsearch2/pom.xml index b7cba4dede0..8b76386132a 100644 --- a/elasticsearch2/pom.xml +++ b/elasticsearch2/pom.xml @@ -21,12 +21,12 @@ limitations under the License. org.apache.calcite calcite - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-elasticsearch2 jar - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite Elasticsearch Elasticsearch adapter for Calcite diff --git a/elasticsearch5/pom.xml b/elasticsearch5/pom.xml index ee472e4e450..82108ddfcff 100644 --- a/elasticsearch5/pom.xml +++ b/elasticsearch5/pom.xml @@ -21,12 +21,12 @@ limitations under the License. org.apache.calcite calcite - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-elasticsearch5 jar - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite Elasticsearch5 Elasticsearch5 adapter for Calcite diff --git a/example/csv/pom.xml b/example/csv/pom.xml index 0ad931b2186..cdddea62ce9 100644 --- a/example/csv/pom.xml +++ b/example/csv/pom.xml @@ -20,12 +20,12 @@ limitations under the License. org.apache.calcite calcite-example - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-example-csv jar - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite Example CSV An example Calcite provider that reads CSV files diff --git a/example/function/pom.xml b/example/function/pom.xml index 0b9f338baff..2a8fba1bf24 100644 --- a/example/function/pom.xml +++ b/example/function/pom.xml @@ -20,12 +20,12 @@ limitations under the License. org.apache.calcite calcite-example - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-example-function jar - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite Example Function Examples of user-defined Calcite functions diff --git a/example/pom.xml b/example/pom.xml index 3b17afc5237..5507e2e5042 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -20,13 +20,13 @@ limitations under the License. org.apache.calcite calcite - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-example pom - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite Examples Calcite examples diff --git a/file/pom.xml b/file/pom.xml index 50302bcd37d..a039fa90b86 100644 --- a/file/pom.xml +++ b/file/pom.xml @@ -19,13 +19,13 @@ limitations under the License. org.apache.calcite calcite - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-file jar - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite File Calcite provider that reads files and URIs diff --git a/geode/pom.xml b/geode/pom.xml index 184e4108ec2..e6d6a790785 100644 --- a/geode/pom.xml +++ b/geode/pom.xml @@ -20,12 +20,12 @@ limitations under the License. org.apache.calcite calcite - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-geode jar - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite Geode Geode adapter for Calcite diff --git a/linq4j/pom.xml b/linq4j/pom.xml index b74ffeb9c1d..9335552c6fd 100644 --- a/linq4j/pom.xml +++ b/linq4j/pom.xml @@ -20,12 +20,12 @@ limitations under the License. org.apache.calcite calcite - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-linq4j jar - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite Linq4j Calcite APIs for LINQ (Language-Integrated Query) in Java diff --git a/mongodb/pom.xml b/mongodb/pom.xml index 37f2bf469cf..717c4e6f467 100644 --- a/mongodb/pom.xml +++ b/mongodb/pom.xml @@ -20,12 +20,12 @@ limitations under the License. org.apache.calcite calcite - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-mongodb jar -1.116.0-kylin-4.x-r023 +1.116.0-kylin-4.x-r024 Calcite MongoDB MongoDB adapter for Calcite diff --git a/pig/pom.xml b/pig/pom.xml index d8833570179..b177e6f6939 100644 --- a/pig/pom.xml +++ b/pig/pom.xml @@ -20,11 +20,11 @@ limitations under the License. org.apache.calcite calcite - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-pig jar - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite Pig Pig adapter for Calcite diff --git a/piglet/pom.xml b/piglet/pom.xml index 8bd538af4d6..5e948a17185 100644 --- a/piglet/pom.xml +++ b/piglet/pom.xml @@ -20,12 +20,12 @@ limitations under the License. org.apache.calcite calcite - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-piglet jar - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite Piglet Pig-like language built on top of Calcite algebra diff --git a/plus/pom.xml b/plus/pom.xml index 735431ec343..17f7ecb0e7b 100644 --- a/plus/pom.xml +++ b/plus/pom.xml @@ -20,12 +20,12 @@ limitations under the License. org.apache.calcite calcite - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-plus jar - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite Plus Miscellaneous extras for Calcite diff --git a/pom.xml b/pom.xml index 702ae1b3dd9..a820dddeaba 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ limitations under the License. org.apache.calcite calcite pom - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite @@ -132,6 +132,7 @@ limitations under the License. 2.7.1 2.9.1 0.9.0 + 1.12 @@ -500,6 +501,11 @@ limitations under the License. ${jcip-annotations.version} test + + org.openjdk.jmh + jmh-core + ${jmh.version} + @@ -1134,16 +1140,18 @@ limitations under the License. - - user-snapshots - User Project SNAPSHOTS - https://repository.kyligence.io/repository/maven-snapshots/ - - user-releases - User Project Release - https://repository.kyligence.io/repository/maven-releases/ + ${repository.id} + ${repository.url} + ${repository.name} + default + + ${repository.id.snapshots} + ${repository.url.snapshots} + ${repository.name.snapshots} + default + diff --git a/server/pom.xml b/server/pom.xml index c6ea95a6a92..bd27653c56e 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -20,12 +20,12 @@ limitations under the License. org.apache.calcite calcite - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-server jar - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite Server Calcite Server diff --git a/spark/pom.xml b/spark/pom.xml index ddb0419e1d8..7964c0468fd 100644 --- a/spark/pom.xml +++ b/spark/pom.xml @@ -20,12 +20,12 @@ limitations under the License. org.apache.calcite calcite - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-spark jar - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite Spark diff --git a/splunk/pom.xml b/splunk/pom.xml index 858fd5f8268..5cf99d64dca 100644 --- a/splunk/pom.xml +++ b/splunk/pom.xml @@ -20,12 +20,12 @@ limitations under the License. org.apache.calcite calcite - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 calcite-splunk jar - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 Calcite Splunk Splunk adapter for Calcite; also a JDBC driver for Splunk diff --git a/ubenchmark/pom.xml b/ubenchmark/pom.xml index 4f3ea5497be..9f17e945c25 100644 --- a/ubenchmark/pom.xml +++ b/ubenchmark/pom.xml @@ -20,7 +20,7 @@ limitations under the License. org.apache.calcite calcite - 1.116.0-kylin-4.x-r023 + 1.116.0-kylin-4.x-r024 diff --git a/ubenchmark/src/main/java/org/apache/calcite/benchmarks/AbstractRelNodeGetRelTypeNameBenchmark.java b/ubenchmark/src/main/java/org/apache/calcite/benchmarks/AbstractRelNodeGetRelTypeNameBenchmark.java new file mode 100644 index 00000000000..b805ef19b10 --- /dev/null +++ b/ubenchmark/src/main/java/org/apache/calcite/benchmarks/AbstractRelNodeGetRelTypeNameBenchmark.java @@ -0,0 +1,260 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.calcite.benchmarks; + +import org.apache.calcite.rel.AbstractRelNode; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Level; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Threads; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +import java.util.Random; +import java.util.concurrent.TimeUnit; + +/** + * A benchmark of alternative implementations for {@link AbstractRelNode#getRelTypeName()} + * method. + */ +@Fork(value = 1, jvmArgsPrepend = "-Xmx1024m") +@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS) +@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS) +@Threads(1) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@BenchmarkMode(Mode.AverageTime) +public class AbstractRelNodeGetRelTypeNameBenchmark { + + /** + * A state holding the full class names of all built-in implementors of the + * {@link org.apache.calcite.rel.RelNode} interface. + */ + @State(Scope.Thread) + public static class ClassNameState { + + private final String[] fullNames = new String[]{ + "org.apache.calcite.interpreter.InterpretableRel", + "org.apache.calcite.interpreter.BindableRel", + "org.apache.calcite.adapter.enumerable.EnumerableInterpretable", + "org.apache.calcite.adapter.enumerable.EnumerableRel", + "org.apache.calcite.adapter.enumerable.EnumerableLimit", + "org.apache.calcite.adapter.enumerable.EnumerableUnion", + "org.apache.calcite.adapter.enumerable.EnumerableCollect", + "org.apache.calcite.adapter.enumerable.EnumerableTableFunctionScan", + "org.apache.calcite.adapter.enumerable.EnumerableValues", + "org.apache.calcite.adapter.enumerable.EnumerableSemiJoin", + "org.apache.calcite.adapter.enumerable.EnumerableMinus", + "org.apache.calcite.adapter.enumerable.EnumerableIntersect", + "org.apache.calcite.adapter.enumerable.EnumerableUncollect", + "org.apache.calcite.adapter.enumerable.EnumerableMergeJoin", + "org.apache.calcite.adapter.enumerable.EnumerableProject", + "org.apache.calcite.adapter.enumerable.EnumerableFilter", + "org.apache.calcite.adapter.jdbc.JdbcToEnumerableConverter", + "org.apache.calcite.adapter.enumerable.EnumerableThetaJoin", + "org.apache.calcite.adapter.enumerable.EnumerableTableScan", + "org.apache.calcite.adapter.enumerable.EnumerableJoin", + "org.apache.calcite.adapter.enumerable.EnumerableTableModify", + "org.apache.calcite.adapter.enumerable.EnumerableAggregate", + "org.apache.calcite.adapter.enumerable.EnumerableCorrelate", + "org.apache.calcite.adapter.enumerable.EnumerableSort", + "org.apache.calcite.adapter.enumerable.EnumerableWindow", + "org.apache.calcite.plan.volcano.VolcanoPlannerTraitTest$FooRel", + "org.apache.calcite.adapter.enumerable.EnumerableCalc", + "org.apache.calcite.adapter.enumerable.EnumerableInterpreter", + "org.apache.calcite.adapter.geode.rel.GeodeToEnumerableConverter", + "org.apache.calcite.adapter.pig.PigToEnumerableConverter", + "org.apache.calcite.adapter.mongodb.MongoToEnumerableConverter", + "org.apache.calcite.adapter.csv.CsvTableScan", + "org.apache.calcite.adapter.spark.SparkToEnumerableConverter", + "org.apache.calcite.adapter.elasticsearch.ElasticsearchToEnumerableConverter", + "org.apache.calcite.adapter.file.FileTableScan", + "org.apache.calcite.adapter.cassandra.CassandraToEnumerableConverter", + "org.apache.calcite.adapter.splunk.SplunkTableScan", + "org.apache.calcite.adapter.jdbc.JdbcRel", + "org.apache.calcite.adapter.jdbc.JdbcTableScan", + "org.apache.calcite.adapter.jdbc.JdbcRules$JdbcJoin", + "org.apache.calcite.adapter.jdbc.JdbcRules$JdbcCalc", + "org.apache.calcite.adapter.jdbc.JdbcRules$JdbcProject", + "org.apache.calcite.adapter.jdbc.JdbcRules$JdbcFilter", + "org.apache.calcite.adapter.jdbc.JdbcRules$JdbcAggregate", + "org.apache.calcite.adapter.jdbc.JdbcRules$JdbcSort", + "org.apache.calcite.adapter.jdbc.JdbcRules$JdbcUnion", + "org.apache.calcite.adapter.jdbc.JdbcRules$JdbcIntersect", + "org.apache.calcite.adapter.jdbc.JdbcRules$JdbcMinus", + "org.apache.calcite.adapter.jdbc.JdbcRules$JdbcTableModify", + "org.apache.calcite.adapter.jdbc.JdbcRules$JdbcValues", + "org.apache.calcite.tools.PlannerTest$MockJdbcTableScan", + "org.apache.calcite.rel.AbstractRelNode", + "org.apache.calcite.rel.rules.MultiJoin", + "org.apache.calcite.rel.core.TableFunctionScan", + "org.apache.calcite.rel.BiRel", + "org.apache.calcite.rel.SingleRel", + "org.apache.calcite.rel.core.Values", + "org.apache.calcite.rel.core.TableScan", + "org.apache.calcite.plan.hep.HepRelVertex", + "org.apache.calcite.plan.RelOptPlanReaderTest$MyRel", + "org.apache.calcite.plan.volcano.TraitPropagationTest$PhysTable", + "org.apache.calcite.plan.volcano.PlannerTests$TestLeafRel", + "org.apache.calcite.plan.volcano.RelSubset", + "org.apache.calcite.rel.core.SetOp", + "org.apache.calcite.plan.volcano.VolcanoPlannerTraitTest$TestLeafRel", + "org.apache.calcite.adapter.druid.DruidQuery", + "org.apache.calcite.sql2rel.RelStructuredTypeFlattener$SelfFlatteningRel", + "org.apache.calcite.rel.convert.Converter", + "org.apache.calcite.rel.convert.ConverterImpl", + "org.apache.calcite.plan.volcano.TraitPropagationTest$Phys", + "org.apache.calcite.plan.volcano.TraitPropagationTest$PhysTable", + "org.apache.calcite.plan.volcano.TraitPropagationTest$PhysSort", + "org.apache.calcite.plan.volcano.TraitPropagationTest$PhysAgg", + "org.apache.calcite.plan.volcano.TraitPropagationTest$PhysProj", + "org.apache.calcite.interpreter.BindableRel", + "org.apache.calcite.adapter.enumerable.EnumerableBindable", + "org.apache.calcite.interpreter.Bindables$BindableTableScan", + "org.apache.calcite.interpreter.Bindables$BindableFilter", + "org.apache.calcite.interpreter.Bindables$BindableProject", + "org.apache.calcite.interpreter.Bindables$BindableSort", + "org.apache.calcite.interpreter.Bindables$BindableJoin", + "org.apache.calcite.interpreter.Bindables$BindableUnion", + "org.apache.calcite.interpreter.Bindables$BindableValues", + "org.apache.calcite.interpreter.Bindables$BindableAggregate", + "org.apache.calcite.interpreter.Bindables$BindableWindow", + "org.apache.calcite.adapter.druid.DruidQuery", + "org.apache.calcite.adapter.cassandra.CassandraRel", + "org.apache.calcite.adapter.cassandra.CassandraFilter", + "org.apache.calcite.adapter.cassandra.CassandraProject", + "org.apache.calcite.adapter.cassandra.CassandraLimit", + "org.apache.calcite.adapter.cassandra.CassandraSort", + "org.apache.calcite.adapter.cassandra.CassandraTableScan", + "org.apache.calcite.adapter.mongodb.MongoRel", + "org.apache.calcite.adapter.mongodb.MongoTableScan", + "org.apache.calcite.adapter.mongodb.MongoProject", + "org.apache.calcite.adapter.mongodb.MongoFilter", + "org.apache.calcite.adapter.mongodb.MongoAggregate", + "org.apache.calcite.adapter.mongodb.MongoSort", + "org.apache.calcite.adapter.spark.SparkRel", + "org.apache.calcite.adapter.spark.JdbcToSparkConverter", + "org.apache.calcite.adapter.spark.SparkRules$SparkValues", + "org.apache.calcite.adapter.spark.EnumerableToSparkConverter", + "org.apache.calcite.adapter.spark.SparkRules$SparkCalc", + "org.apache.calcite.adapter.elasticsearch.ElasticsearchRel", + "org.apache.calcite.adapter.elasticsearch.ElasticsearchFilter", + "org.apache.calcite.adapter.elasticsearch.ElasticsearchProject", + "org.apache.calcite.adapter.elasticsearch.ElasticsearchAggregate", + "org.apache.calcite.adapter.elasticsearch.ElasticsearchTableScan", + "org.apache.calcite.adapter.elasticsearch.ElasticsearchSort", + "org.apache.calcite.adapter.geode.rel.GeodeRel", + "org.apache.calcite.adapter.geode.rel.GeodeSort", + "org.apache.calcite.adapter.geode.rel.GeodeTableScan", + "org.apache.calcite.adapter.geode.rel.GeodeProject", + "org.apache.calcite.adapter.geode.rel.GeodeFilter", + "org.apache.calcite.adapter.geode.rel.GeodeAggregate", + "org.apache.calcite.adapter.pig.PigRel", + "org.apache.calcite.adapter.pig.PigTableScan", + "org.apache.calcite.adapter.pig.PigAggregate", + "org.apache.calcite.adapter.pig.PigJoin", + "org.apache.calcite.adapter.pig.PigFilter", + "org.apache.calcite.adapter.pig.PigProject" + }; + + @Param({"11", "31", "63"}) + private long seed; + + private Random r = null; + + /** + * Setups the random number generator at the beginning of each iteration. + * + * To have relatively comparable results the generator should always use the same seed for the + * whole duration of the benchmark. + */ + @Setup(Level.Iteration) + public void setupRandom() { + r = new Random(seed); + } + + /** + * Returns a pseudo random class name which corresponds to an implementor of the RelNode + * interface. + */ + public String nextName() { + return fullNames[r.nextInt(fullNames.length)]; + } + } + + @Benchmark + public String useStringLastIndexOfTwoTimesV1(ClassNameState state) { + String cn = state.nextName(); + int i = cn.lastIndexOf("$"); + if (i >= 0) { + return cn.substring(i + 1); + } + i = cn.lastIndexOf("."); + if (i >= 0) { + return cn.substring(i + 1); + } + return cn; + } + + @Benchmark + public String useStringLastIndexOfTwoTimeV2(ClassNameState state) { + String cn = state.nextName(); + int i = cn.lastIndexOf('$'); + if (i >= 0) { + return cn.substring(i + 1); + } + i = cn.lastIndexOf('.'); + if (i >= 0) { + return cn.substring(i + 1); + } + return cn; + } + + @Benchmark + public String useCustomLastIndexOf(ClassNameState state) { + String cn = state.nextName(); + int i = cn.length(); + while (--i >= 0) { + if (cn.charAt(i) == '$' || cn.charAt(i) == '.') { + return cn.substring(i + 1); + } + } + return cn; + } + + public static void main(String[] args) throws RunnerException { + Options opt = new OptionsBuilder() + .include(AbstractRelNodeGetRelTypeNameBenchmark.class.getName()) + .detectJvmArgs() + .build(); + + new Runner(opt).run(); + } +} + +// End AbstractRelNodeGetRelTypeNameBenchmark.java