(calcite) branch main updated: [CALCITE-6338] RelMdCollation#project can return an incomplete list of collations in the presence of aliasing

2024-03-25 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new d5b6b5c01f [CALCITE-6338] RelMdCollation#project can return an 
incomplete list of collations in the presence of aliasing
d5b6b5c01f is described below

commit d5b6b5c01ff17cac100a591a4cc4c9e83d4e1ace
Author: Ruben Quesada Lopez 
AuthorDate: Thu Mar 21 16:43:37 2024 +

[CALCITE-6338] RelMdCollation#project can return an incomplete list of 
collations in the presence of aliasing
---
 .../calcite/rel/metadata/RelMdCollation.java   | 20 ---
 .../org/apache/calcite/test/RelMetadataTest.java   | 40 ++
 core/src/test/resources/sql/sub-query.iq   |  5 ++-
 3 files changed, 57 insertions(+), 8 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdCollation.java 
b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdCollation.java
index 7c107d39d6..9c728384f4 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdCollation.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdCollation.java
@@ -316,22 +316,32 @@ public class RelMdCollation
 targetsWithMonotonicity.put(project.i, 
call.getOperator().getMonotonicity(binding));
   }
 }
-final List fieldCollations = new ArrayList<>();
+List> fieldCollationsList = new ArrayList<>();
   loop:
 for (RelCollation ic : inputCollations) {
   if (ic.getFieldCollations().isEmpty()) {
 continue;
   }
-  fieldCollations.clear();
+  fieldCollationsList.clear();
+  fieldCollationsList.add(new ArrayList<>());
   for (RelFieldCollation ifc : ic.getFieldCollations()) {
 final Collection integers = targets.get(ifc.getFieldIndex());
 if (integers.isEmpty()) {
   continue loop; // cannot do this collation
 }
-fieldCollations.add(ifc.withFieldIndex(integers.iterator().next()));
+fieldCollationsList = fieldCollationsList.stream()
+.flatMap(fieldCollations -> integers.stream()
+.map(integer -> {
+  List newFieldCollations = new 
ArrayList<>(fieldCollations);
+  newFieldCollations.add(ifc.withFieldIndex(integer));
+  return newFieldCollations;
+})).collect(Collectors.toList());
+  }
+  assert !fieldCollationsList.isEmpty();
+  for (List fieldCollations : fieldCollationsList) {
+assert !fieldCollations.isEmpty();
+collations.add(RelCollations.of(fieldCollations));
   }
-  assert !fieldCollations.isEmpty();
-  collations.add(RelCollations.of(fieldCollations));
 }
 
 final List fieldCollationsForRexCalls =
diff --git a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java 
b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
index db1f65c242..d9733486bd 100644
--- a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
@@ -1948,6 +1948,46 @@ public class RelMetadataTest {
 assertEquals("[[0]]", collations.toString());
   }
 
+  /**
+   * Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-6338;>[CALCITE-6338]
+   * RelMdCollation#project can return an incomplete list of collations
+   * in the presence of aliasing.
+   */
+  @Test void testCollationProjectAliasing() {
+final RelBuilder builder = RelBuilderTest.createBuilder();
+final RelNode relNode1 = builder
+.scan("EMP")
+.sort(2, 3)
+.project(builder.field(0), builder.field(2), builder.field(2), 
builder.field(3))
+.build();
+checkCollationProjectAliasing(relNode1, "[[1, 3], [2, 3]]");
+final RelNode relNode2 = builder
+.scan("EMP")
+.sort(0, 1)
+.project(builder.field(0), builder.field(0), builder.field(1), 
builder.field(1))
+.build();
+checkCollationProjectAliasing(relNode2, "[[0, 2], [0, 3], [1, 2], [1, 
3]]");
+final RelNode relNode3 = builder
+.scan("EMP")
+.sort(0, 1, 2)
+.project(
+builder.field(0), builder.field(0),
+builder.field(1), builder.field(1), builder.field(1),
+builder.field(2))
+.build();
+checkCollationProjectAliasing(relNode3,
+"[[0, 2, 5], [0, 3, 5], [0, 4, 5], [1, 2, 5], [1, 3, 5], [1, 4, 5]]");
+  }
+
+  private void checkCollationProjectAliasing(RelNode relNode, String 
expectedCollation) {
+final RelMetadataQuery mq = relNode.getCluster().getMetadataQuery();
+assertThat(relNode, instanceOf(Project.class));
+final ImmutableList collations = mq.collations(relNode);
+assertThat(collations, notNullValue

(calcite) branch main updated: [CALCITE-6249] RelNode::estimatedRowCount should not be used in computeSelfCost

2024-02-19 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new a19a954738 [CALCITE-6249] RelNode::estimatedRowCount should not be 
used in computeSelfCost
a19a954738 is described below

commit a19a954738e3405f621843a9df71e51002e1609b
Author: Ulrich Kramer 
AuthorDate: Wed Feb 7 08:07:36 2024 +0100

[CALCITE-6249] RelNode::estimatedRowCount should not be used in 
computeSelfCost
---
 .../calcite/adapter/enumerable/EnumerableBatchNestedLoopJoin.java | 4 ++--
 .../org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java | 4 ++--
 .../org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java| 4 ++--
 .../apache/calcite/adapter/enumerable/EnumerableNestedLoopJoin.java   | 4 ++--
 core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java | 4 ++--
 core/src/main/java/org/apache/calcite/rel/core/Correlate.java | 4 ++--
 core/src/main/java/org/apache/calcite/rel/core/TableScan.java | 2 +-
 .../java/org/apache/calcite/rel/rules/AggregateStarTableRule.java | 2 +-
 8 files changed, 14 insertions(+), 14 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableBatchNestedLoopJoin.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableBatchNestedLoopJoin.java
index 94ef9c3213..11a3620c8c 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableBatchNestedLoopJoin.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableBatchNestedLoopJoin.java
@@ -124,8 +124,8 @@ public class EnumerableBatchNestedLoopJoin extends Join 
implements EnumerableRel
   final RelMetadataQuery mq) {
 double rowCount = mq.getRowCount(this);
 
-final double rightRowCount = right.estimateRowCount(mq);
-final double leftRowCount = left.estimateRowCount(mq);
+final double rightRowCount = mq.getRowCount(right);
+final double leftRowCount = mq.getRowCount(left);
 if (Double.isInfinite(leftRowCount) || Double.isInfinite(rightRowCount)) {
   return planner.getCostFactory().makeInfiniteCost();
 }
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java
index cfe44da75d..8bd9ffbf08 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java
@@ -149,8 +149,8 @@ public class EnumerableHashJoin extends Join implements 
EnumerableRel {
 
 // Cheaper if the smaller number of rows is coming from the LHS.
 // Model this by adding L log L to the cost.
-final double rightRowCount = right.estimateRowCount(mq);
-final double leftRowCount = left.estimateRowCount(mq);
+final double rightRowCount = mq.getRowCount(right);
+final double leftRowCount = mq.getRowCount(left);
 if (Double.isInfinite(leftRowCount)) {
   rowCount = leftRowCount;
 } else {
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
index 3f42e065c8..97eae019d3 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
@@ -424,8 +424,8 @@ public class EnumerableMergeJoin extends Join implements 
EnumerableRel {
 // We assume that the inputs are sorted. The price of sorting them has
 // already been paid. The cost of the join is therefore proportional to the
 // input and output size.
-final double rightRowCount = right.estimateRowCount(mq);
-final double leftRowCount = left.estimateRowCount(mq);
+final double rightRowCount = mq.getRowCount(right);
+final double leftRowCount = mq.getRowCount(left);
 final double rowCount = mq.getRowCount(this);
 final double d = leftRowCount + rightRowCount + rowCount;
 return planner.getCostFactory().makeCost(d, 0, 0);
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableNestedLoopJoin.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableNestedLoopJoin.java
index 6b1bf40cf7..de539ad574 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableNestedLoopJoin.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableNestedLoopJoin.java
@@ -108,8 +108,8 @@ public class EnumerableNestedLoopJoin extends Join 
implements EnumerableRel {
   }
 }
 
-final double rightRowCount = right.estimateRowCount(mq);
-final double leftRowCount = left.estimateRowCount(mq);
+final double rightRowCount = mq.getRowCount(right

(calcite) branch main updated: [CALCITE-6251] InnerEnumerator in EnumerableDefaults::correlateBatchJoin is not closed

2024-02-12 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new abf462a7dd [CALCITE-6251] InnerEnumerator in 
EnumerableDefaults::correlateBatchJoin is not closed
abf462a7dd is described below

commit abf462a7ddab11a44610827b0cd69510c099d9b6
Author: Ulrich Kramer 
AuthorDate: Wed Feb 7 14:10:26 2024 +0100

[CALCITE-6251] InnerEnumerator in EnumerableDefaults::correlateBatchJoin is 
not closed
---
 .../java/org/apache/calcite/linq4j/EnumerableDefaults.java| 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git 
a/linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java 
b/linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java
index 3d2c141574..34819551d8 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java
@@ -1717,6 +1717,8 @@ public abstract class EnumerableDefaults {
 if (innerEnumerable == null) {
   innerEnumerable = Linq4j.emptyEnumerable();
 }
+closeInner();
+Enumerable innerEnumerable = 
requireNonNull(this.innerEnumerable);
 innerEnumerator = innerEnumerable.enumerator();
 innerEnumHasNext = innerEnumerator.moveNext();
 
@@ -1799,11 +1801,16 @@ public abstract class EnumerableDefaults {
 i = -1;
   }
 
-  @Override public void close() {
-outerEnumerator.close();
+  private void closeInner() {
 if (innerEnumerator != null) {
   innerEnumerator.close();
+  innerEnumerator = null;
 }
+  }
+
+  @Override public void close() {
+outerEnumerator.close();
+closeInner();
 outerValue = null;
 innerValue = null;
   }



(calcite) branch main updated: [CALCITE-5647] RelMdPopulationSize should use mq.getRowCount(rel) instead of rel.estimateRowCount(mq)

2024-02-07 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new f7069cc524 [CALCITE-5647] RelMdPopulationSize should use 
mq.getRowCount(rel) instead of rel.estimateRowCount(mq)
f7069cc524 is described below

commit f7069cc5245c22f816c565669f52b4f30b046f4d
Author: Adam Kennedy 
AuthorDate: Fri Apr 14 15:40:06 2023 -0700

[CALCITE-5647] RelMdPopulationSize should use mq.getRowCount(rel) instead 
of rel.estimateRowCount(mq)

Use RelMetadataQuery#getRowCount() instead of estimateRowCount()
when calculating RelMdPopulatioSize#getRowCount()
---
 .../calcite/rel/metadata/RelMdPopulationSize.java  |  2 +-
 .../org/apache/calcite/test/RelMetadataTest.java   | 39 ++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPopulationSize.java 
b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPopulationSize.java
index 963c3bac5f..bbd4c0fa82 100644
--- 
a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPopulationSize.java
+++ 
b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPopulationSize.java
@@ -113,7 +113,7 @@ public class RelMdPopulationSize
   public Double getPopulationSize(Values rel, RelMetadataQuery mq,
   ImmutableBitSet groupKey) {
 // assume half the rows are duplicates
-return rel.estimateRowCount(mq) / 2;
+return mq.getRowCount(rel) / 2;
   }
 
   public @Nullable Double getPopulationSize(Project rel, RelMetadataQuery mq,
diff --git a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java 
b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
index 24155414e6..db1f65c242 100644
--- a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 package org.apache.calcite.test;
+
 import org.apache.calcite.adapter.enumerable.EnumerableConvention;
 import org.apache.calcite.adapter.enumerable.EnumerableLimit;
 import org.apache.calcite.adapter.enumerable.EnumerableMergeJoin;
@@ -76,6 +77,7 @@ import 
org.apache.calcite.rel.metadata.ReflectiveRelMetadataProvider;
 import org.apache.calcite.rel.metadata.RelColumnOrigin;
 import org.apache.calcite.rel.metadata.RelMdCollation;
 import org.apache.calcite.rel.metadata.RelMdColumnUniqueness;
+import org.apache.calcite.rel.metadata.RelMdPopulationSize;
 import org.apache.calcite.rel.metadata.RelMdUtil;
 import org.apache.calcite.rel.metadata.RelMetadataProvider;
 import org.apache.calcite.rel.metadata.RelMetadataQuery;
@@ -3639,6 +3641,43 @@ public class RelMetadataTest {
 is(mq.getPopulationSize(rel, bitSetOf(0;
   }
 
+  /**
+   * Test that RelMdPopulationSize is calculated based on the 
RelMetadataQuery#getRowCount().
+   *
+   * @see https://issues.apache.org/jira/browse/CALCITE-5647;>[CALCITE-5647]
+   */
+  @Test public void testPopulationSizeFromValues() {
+final String sql = "values(1,2,3),(1,2,3),(1,2,3),(1,2,3)";
+final RelNode rel = sql(sql).toRel();
+assertThat(rel, instanceOf(Values.class));
+
+RelMetadataProvider provider = RelMdPopulationSize.SOURCE;
+
+List> handlers =
+provider.handlers(BuiltInMetadata.PopulationSize.Handler.class);
+
+// The population size is calculated to be half the row count. (The 
assumption is that half
+// the rows are duplicated.) With the default handler it should evaluate 
to 2 since there
+// are 4 rows.
+RelMdPopulationSize populationSize = (RelMdPopulationSize) handlers.get(0);
+Double popSize =
+populationSize.getPopulationSize((Values) rel, 
rel.getCluster().getMetadataQuery(),
+bitSetOf(0, 1, 2));
+assertEquals(2.0, popSize);
+
+// If we use a custom RelMetadataQuery and override the row count, the 
population size
+// should be half the reported row count. In this case we will have the 
RelMetadataQuery say
+// the row count is 12 for testing purposes, so we should expect a 
population size of 6.
+RelMetadataQuery customQuery = new RelMetadataQuery() {
+  @Override public Double getRowCount(RelNode rel) {
+return 12.0;
+  }
+};
+
+popSize = populationSize.getPopulationSize((Values) rel, customQuery, 
bitSetOf(0, 1, 2));
+assertEquals(6.0, popSize);
+  }
+
   private static final SqlOperator NONDETERMINISTIC_OP =
   SqlBasicFunction.create("NDC", ReturnTypes.BOOLEAN, 
OperandTypes.VARIADIC)
   .withDeterministic(false);



(calcite) branch main updated: [CALCITE-6234] Add tests on SqlOperatorTest for to_char function

2024-02-02 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 2aabf210dc [CALCITE-6234] Add tests on SqlOperatorTest for to_char 
function
2aabf210dc is described below

commit 2aabf210dc1918c6ca20e63b39661ff445535eb8
Author: caicancai <2356672...@qq.com>
AuthorDate: Tue Jan 30 23:25:44 2024 +0800

[CALCITE-6234] Add tests on SqlOperatorTest for to_char function
---
 .../org/apache/calcite/test/SqlOperatorTest.java   | 27 ++
 1 file changed, 27 insertions(+)

diff --git a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java 
b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
index a8b8d876e5..d4ee5b75f6 100644
--- a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
+++ b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
@@ -4423,6 +4423,33 @@ public class SqlOperatorTest {
 f.checkString("to_char(timestamp '2022-06-03 12:15:48.678', '-MM-DD 
HH24:MI:SS.MS TZ')",
 "2022-06-03 12:15:48.678",
 "VARCHAR(2000) NOT NULL");
+f.checkString("to_char(timestamp '2022-06-03 12:15:48.678', 'Day')",
+"Friday",
+"VARCHAR(2000) NOT NULL");
+f.checkString("to_char(timestamp '2022-06-03 12:15:48.678', 'CC')",
+"21",
+"VARCHAR(2000) NOT NULL");
+f.checkString("to_char(timestamp '2022-06-03 13:15:48.678', 'HH12')",
+"01",
+"VARCHAR(2000) NOT NULL");
+f.checkString("to_char(timestamp '2022-06-03 13:15:48.678', 'HH24')",
+"13",
+"VARCHAR(2000) NOT NULL");
+f.checkString("to_char(timestamp '2022-06-03 13:15:48.678', 'MI')",
+"15",
+"VARCHAR(2000) NOT NULL");
+f.checkString("to_char(timestamp '2022-06-03 13:15:48.678', 'MS')",
+"678",
+"VARCHAR(2000) NOT NULL");
+f.checkString("to_char(timestamp '2022-06-03 13:15:48.678', 'Q')",
+"2",
+"VARCHAR(2000) NOT NULL");
+f.checkString("to_char(timestamp '2022-06-03 13:15:48.678', 'IW')",
+"23",
+"VARCHAR(2000) NOT NULL");
+f.checkNull("to_char(timestamp '2022-06-03 12:15:48.678', NULL)");
+f.checkNull("to_char(cast(NULL as timestamp), NULL)");
+f.checkNull("to_char(cast(NULL as timestamp), 'Day')");
   }
 
   @Test void testFromBase64() {



[calcite] branch main updated: [CALCITE-5949] RexExecutable should return unchanged original expressions when it fails

2023-10-27 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 417a1b53ec [CALCITE-5949] RexExecutable should return unchanged 
original expressions when it fails
417a1b53ec is described below

commit 417a1b53ec9fd6bd449601036535bdb323229059
Author: rubenada 
AuthorDate: Thu Oct 26 13:41:13 2023 +0100

[CALCITE-5949] RexExecutable should return unchanged original expressions 
when it fails

Co-authored-by: arkanovicz 
---
 .../java/org/apache/calcite/rex/RexExecutable.java |  6 +-
 .../org/apache/calcite/rex/RexExecutorTest.java| 24 ++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/rex/RexExecutable.java 
b/core/src/main/java/org/apache/calcite/rex/RexExecutable.java
index cc8d787686..8828654c24 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexExecutable.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexExecutable.java
@@ -32,6 +32,7 @@ import java.io.Serializable;
 import java.io.StringReader;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -87,11 +88,14 @@ public class RexExecutable {
 values = new Object[constExps.size()];
   } else {
 assert values.length == constExps.size();
+final List successfullyReduced = new 
ArrayList<>(constExps.size());
 final List<@Nullable Object> valueList = Arrays.asList(values);
 for (Pair value : Pair.zip(constExps, 
valueList)) {
-  reducedValues.add(
+  successfullyReduced.add(
   rexBuilder.makeLiteral(value.right, value.left.getType(), true));
 }
+assert successfullyReduced.size() == constExps.size();
+reducedValues.addAll(successfullyReduced);
   }
 } catch (RuntimeException e) {
   // One or more of the expressions failed.
diff --git a/core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java 
b/core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java
index b1cb804175..74c51229f2 100644
--- a/core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java
+++ b/core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java
@@ -378,4 +378,28 @@ class RexExecutorTest {
   interface Action {
 void check(RexBuilder rexBuilder, RexExecutorImpl executor);
   }
+
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-5949;>[CALCITE-5949]
+   * RexExecutable should return unchanged original expressions when it 
fails.
+   */
+  @Test void testInvalidExpressionInList() {
+check((rexBuilder, executor) -> {
+  final List reducedValues = new ArrayList<>();
+  final RelDataTypeFactory typeFactory = rexBuilder.getTypeFactory();
+  final RelDataType integer =
+  typeFactory.createSqlType(SqlTypeName.INTEGER);
+  final RexCall first =
+  (RexCall) rexBuilder.makeCall(SqlStdOperatorTable.LN,
+  rexBuilder.makeLiteral(3, integer, true));
+  final RexCall second =
+  (RexCall) rexBuilder.makeCall(SqlStdOperatorTable.LN,
+  rexBuilder.makeLiteral(-2, integer, true));
+  executor.reduce(rexBuilder, ImmutableList.of(first, second),
+  reducedValues);
+  assertThat(reducedValues, hasSize(2));
+  assertThat(reducedValues.get(0), instanceOf(RexCall.class));
+  assertThat(reducedValues.get(1), instanceOf(RexCall.class));
+});
+  }
 }



[calcite] branch main updated: [CALCITE-5921] SqlOperatorFixture.checkFails and checkAggFails don't check runtime failure (follow-up)

2023-10-25 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 345961a9d2 [CALCITE-5921] SqlOperatorFixture.checkFails and 
checkAggFails don't check runtime failure (follow-up)
345961a9d2 is described below

commit 345961a9d21f1f669a452571fe70520185cbb424
Author: rubenada 
AuthorDate: Wed Oct 25 13:19:03 2023 +0100

[CALCITE-5921] SqlOperatorFixture.checkFails and checkAggFails don't check 
runtime failure (follow-up)
---
 .../calcite/test/SqlOperatorUnparseTest.java   |  5 +++
 .../org/apache/calcite/test/SqlOperatorTest.java   | 43 +-
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git 
a/core/src/test/java/org/apache/calcite/test/SqlOperatorUnparseTest.java 
b/core/src/test/java/org/apache/calcite/test/SqlOperatorUnparseTest.java
index 13512d1aa4..49872ef988 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlOperatorUnparseTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlOperatorUnparseTest.java
@@ -99,6 +99,11 @@ public class SqlOperatorUnparseTest extends 
CalciteSqlOperatorTest {
 }
   }
 
+  @Override @Disabled("Runtime error message differs after parsing and 
unparsing")
+  void testBitAndFuncRuntimeFails() {
+super.testContainsSubstrFunc();
+  }
+
   // Every test that is Disabled below corresponds to a bug.
   // These tests should just be deleted when the corresponding bugs are fixed.
 
diff --git a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java 
b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
index a9a24cfe92..891df133c3 100644
--- a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
+++ b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
@@ -919,8 +919,8 @@ public class SqlOperatorTest {
   void testCastWithRoundingToScalar(CastType castType, SqlOperatorFixture f) {
 f.setFor(SqlStdOperatorTable.CAST, VmName.EXPAND);
 
-f.checkFails("cast(1.25 as int)", "INTEGER", true);
-f.checkFails("cast(1.25E0 as int)", "INTEGER", true);
+f.checkScalar("cast(1.25 as int)", 1, "INTEGER NOT NULL");
+f.checkScalar("cast(1.25E0 as int)", 1, "INTEGER NOT NULL");
 if (!f.brokenTestsEnabled()) {
   return;
 }
@@ -960,8 +960,8 @@ public class SqlOperatorTest {
   void testCastDecimalToDoubleToInteger(CastType castType, SqlOperatorFixture 
f) {
 f.setFor(SqlStdOperatorTable.CAST, VmName.EXPAND);
 
-f.checkFails("cast( cast(1.25 as double) as integer)", 
OUT_OF_RANGE_MESSAGE, true);
-f.checkFails("cast( cast(-1.25 as double) as integer)", 
OUT_OF_RANGE_MESSAGE, true);
+f.checkScalar("cast( cast(1.25 as double) as integer)", 1, "INTEGER NOT 
NULL");
+f.checkScalar("cast( cast(-1.25 as double) as integer)", -1, "INTEGER NOT 
NULL");
 if (!f.brokenTestsEnabled()) {
   return;
 }
@@ -1222,7 +1222,11 @@ public class SqlOperatorTest {
   "12:42:25.34", "TIME(2) NOT NULL");
 }
 
-f.checkFails("cast('nottime' as TIME)", BAD_DATETIME_MESSAGE, true);
+if (castType == CastType.CAST) {
+  f.checkFails("cast('nottime' as TIME)", BAD_DATETIME_MESSAGE, true);
+} else {
+  f.checkNull("cast('nottime' as TIME)");
+}
 f.checkScalar("cast('1241241' as TIME)", "72:40:12", "TIME(0) NOT NULL");
 f.checkScalar("cast('12:54:78' as TIME)", "12:55:18", "TIME(0) NOT NULL");
 f.checkScalar("cast('12:34:5' as TIME)", "12:34:05", "TIME(0) NOT NULL");
@@ -1287,7 +1291,11 @@ public class SqlOperatorTest {
   f.checkScalar("cast('1945-1-24 12:23:34.454' as TIMESTAMP)",
   "1945-01-24 12:23:34", "TIMESTAMP(0) NOT NULL");
 }
-f.checkFails("cast('nottime' as TIMESTAMP)", BAD_DATETIME_MESSAGE, true);
+if (castType == CastType.CAST) {
+  f.checkFails("cast('nottime' as TIMESTAMP)", BAD_DATETIME_MESSAGE, true);
+} else {
+  f.checkNull("cast('nottime' as TIMESTAMP)");
+}
 
 // date <-> string
 f.checkCastToString("DATE '1945-02-24'", null, "1945-02-24", castType);
@@ -1297,7 +1305,11 @@ public class SqlOperatorTest {
 f.checkScalar("cast(' 1945-2-4 ' as DATE)", "1945-02-04", "DATE NOT NULL");
 f.checkScalar("cast('  1945-02-24  ' as DATE)",
 "1945-02-24", "DATE NOT NULL");
-f.checkFails("cast('notdate' as DATE)", BAD_DATETIME_MESSAGE, true);
+if (castType == CastType.CAST) {
+  f.checkFails("cast

[calcite] branch main updated: [CALCITE-5921] SqlOperatorFixture.checkFails and checkAggFails don't check runtime failure

2023-10-25 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 0bec957071 [CALCITE-5921] SqlOperatorFixture.checkFails and 
checkAggFails don't check runtime failure
0bec957071 is described below

commit 0bec957071468a2e54a22519290ac101a752fcad
Author: Mihai Budiu 
AuthorDate: Sat Oct 14 21:17:32 2023 -0700

[CALCITE-5921] SqlOperatorFixture.checkFails and checkAggFails don't check 
runtime failure

Signed-off-by: Mihai Budiu 
---
 .../apache/calcite/runtime/CalciteResource.java|  2 +-
 .../org/apache/calcite/runtime/SqlFunctions.java   | 25 +---
 .../calcite/runtime/CalciteResource.properties |  2 +-
 .../calcite/sql/test/SqlOperatorFixture.java   |  2 +-
 .../java/org/apache/calcite/sql/test/SqlTests.java | 12 +---
 .../calcite/test/SqlOperatorFixtureImpl.java   |  2 ++
 .../org/apache/calcite/test/SqlOperatorTest.java   | 34 +++---
 .../org/apache/calcite/test/SqlRuntimeTester.java  |  4 +--
 8 files changed, 46 insertions(+), 37 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java 
b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
index dabc84ba1f..ee03bfe959 100644
--- a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
+++ b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
@@ -298,7 +298,7 @@ public interface CalciteResource {
   @BaseMessage("Date literal ''{0}'' out of range")
   ExInst dateLiteralOutOfRange(String a0);
 
-  @BaseMessage("Input arguments of {0} out of range: {1,number,#}; should be 
in the range of {2}")
+  @BaseMessage("Input arguments of {0} out of range: {1,number,#.#}; should be 
in the range of {2}")
   ExInst inputArgumentsOfFunctionOutOfRange(String a0, 
Number a1, String a2);
 
   @BaseMessage("String literal continued on same line")
diff --git a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java 
b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
index 8a0e04c6d1..4ac14126fa 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
@@ -860,17 +860,22 @@ public class SqlFunctions {
 assert map != null;
 Set keys = map.keySet();
 Collection values = map.values();
-switch (JsonScope.valueOf(jsonScope)) {
-case JSON_KEYS:
-  return keys.contains(substr);
-case JSON_KEYS_AND_VALUES:
-  return keys.contains(substr) || values.contains(substr);
-case JSON_VALUES:
-  return values.contains(substr);
-default:
-  throw new IllegalArgumentException("json_scope argument must be one of: 
\"JSON_KEYS\", "
-  + "\"JSON_VALUES\", \"JSON_KEYS_AND_VALUES\".");
+try {
+  switch (JsonScope.valueOf(jsonScope)) {
+  case JSON_KEYS:
+return keys.contains(substr);
+  case JSON_KEYS_AND_VALUES:
+return keys.contains(substr) || values.contains(substr);
+  case JSON_VALUES:
+return values.contains(substr);
+  default:
+break;
+  }
+} catch (IllegalArgumentException ignored) {
+  // Happens when jsonScope is not one of the legal enum values
 }
+throw new IllegalArgumentException("json_scope argument must be one of: 
\"JSON_KEYS\", "
+  + "\"JSON_VALUES\", \"JSON_KEYS_AND_VALUES\".");
   }
 
   /** SQL CONTAINS_SUBSTR(expr, substr) operator. */
diff --git 
a/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties 
b/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
index c1f28de6e8..5475f2dafd 100644
--- 
a/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
+++ 
b/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
@@ -102,7 +102,7 @@ OperandNotComparable=Operands {0} not comparable to each 
other
 TypeNotComparableEachOther=Types {0} not comparable to each other
 NumberLiteralOutOfRange=Numeric literal ''{0}'' out of range
 DateLiteralOutOfRange=Date literal ''{0}'' out of range
-InputArgumentsOfFunctionOutOfRange=Input arguments of {0} out of range: 
{1,number,#}; should be in the range of {2}
+InputArgumentsOfFunctionOutOfRange=Input arguments of {0} out of range: 
{1,number,#.#}; should be in the range of {2}
 StringFragsOnSameLine=String literal continued on same line
 AliasMustBeSimpleIdentifier=Table or column alias must be a simple identifier
 CharLiteralAliasNotValid=Expecting alias, found character literal
diff --git 
a/testkit/src/main/java/org/apache/calcite/sql/test/SqlOperatorFixture.java 
b/testkit/src/main/java/org/apache/calcite/sql/test/SqlOperatorFixture.jav

[calcite] branch main updated: [CALCITE-6014] Create a SqlOperatorFixture that parses, unparses, and then parses again before executing

2023-10-16 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 5151168e9a [CALCITE-6014] Create a SqlOperatorFixture that parses, 
unparses, and then parses again before executing
5151168e9a is described below

commit 5151168e9a9035595939c2ae0f21a06984229209
Author: Mihai Budiu 
AuthorDate: Fri Oct 13 11:42:07 2023 -0700

[CALCITE-6014] Create a SqlOperatorFixture that parses, unparses, and then 
parses again before executing

Signed-off-by: Mihai Budiu 
---
 .../calcite/test/SqlOperatorUnparseTest.java   | 116 +
 .../calcite/test/SqlOperatorFixtureImpl.java   |   2 +-
 2 files changed, 117 insertions(+), 1 deletion(-)

diff --git 
a/core/src/test/java/org/apache/calcite/test/SqlOperatorUnparseTest.java 
b/core/src/test/java/org/apache/calcite/test/SqlOperatorUnparseTest.java
new file mode 100644
index 00..13512d1aa4
--- /dev/null
+++ b/core/src/test/java/org/apache/calcite/test/SqlOperatorUnparseTest.java
@@ -0,0 +1,116 @@
+/*
+ * 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.test;
+
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.test.SqlOperatorFixture;
+import org.apache.calcite.sql.test.SqlTestFactory;
+
+import org.junit.jupiter.api.Disabled;
+
+import java.util.function.Consumer;
+import java.util.function.UnaryOperator;
+
+/**
+ * Version of a SqlOperatorTest which first parses and unparses
+ * the test program before executing it. Although similar to
+ * {@link org.apache.calcite.sql.parser.SqlUnParserTest},
+ * this test also validates the code after unparsing.
+ */
+@SuppressWarnings("JavadocReference")
+public class SqlOperatorUnparseTest extends CalciteSqlOperatorTest {
+  /** Fixture that runs an operator test after parsing and unparsing a query. 
*/
+  static class SqlOperatorFixtureUnparseImpl extends SqlOperatorFixtureImpl {
+SqlOperatorFixtureUnparseImpl(SqlTestFactory factory) {
+  super(factory, new UnparseTester(factory), false);
+}
+
+/**
+ * Retrieve the tester as an UnparseTester.  A downcast is needed because
+ * our tester implements a richer API than a regular SqlTester -- for 
example,
+ * it has a method withFactory.
+ */
+UnparseTester getUnparseTester() {
+  return (UnparseTester) this.getTester();
+}
+
+public static final SqlOperatorFixtureImpl DEFAULT =
+new SqlOperatorFixtureUnparseImpl(SqlTestFactory.INSTANCE);
+
+@Override public SqlOperatorFixture 
withFactory(UnaryOperator transform) {
+  return super
+  .withFactory(transform)
+  // Pass the transform to the tester
+  .withTester(t -> this.getUnparseTester().withFactory(transform));
+}
+  }
+
+  @Override protected SqlOperatorFixture fixture() {
+return SqlOperatorFixtureUnparseImpl.DEFAULT;
+  }
+
+  /** A tester which parses, unparses, and then tests a query. */
+  static class UnparseTester extends TesterImpl {
+public final SqlTestFactory factory;
+
+UnparseTester(SqlTestFactory factory) {
+  this.factory = factory;
+}
+
+TesterImpl withFactory(UnaryOperator transform) {
+  return new UnparseTester(transform.apply(this.factory));
+}
+
+String rewrite(String sql) throws SqlParseException {
+  final SqlParser parser = factory.createParser(sql);
+  final SqlNode sqlNode = parser.parseStmt();
+  return sqlNode.toSqlString(c -> c).getSql();
+}
+
+@Override public void forEachQuery(
+SqlTestFactory factory, String expression, Consumer consumer) {
+  consumer.accept(buildQuery2(factory, expression));
+}
+
+@Override public void check(SqlTestFactory factory, String sql, 
TypeChecker typeChecker,
+ParameterChecker parameterChecker, ResultChecker resultChecker) {
+  try {
+String optQuery = this.rewrite(sql);
+super.check(factory, optQuery, typeCheck

[calcite] branch main updated: [CALCITE-6033] Correct broken links on adapter page

2023-10-09 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 0291e1eeb4 [CALCITE-6033] Correct broken links on adapter page
0291e1eeb4 is described below

commit 0291e1eeb4c5e01dccbac14e1a6eeeb79d87282b
Author: duanzhengqiang 
AuthorDate: Thu Oct 5 20:07:06 2023 +0800

[CALCITE-6033] Correct broken links on adapter page
---
 site/_config.yml  | 4 ++--
 site/_docs/adapter.md | 8 
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/site/_config.yml b/site/_config.yml
index 4759a1864e..3f16f24d24 100644
--- a/site/_config.yml
+++ b/site/_config.yml
@@ -36,8 +36,8 @@ apiRoot: /javadocAggregate
 # apiRoot: http://calcite.apache.org/javadocAggregate
 
 # The URL where Avatica's Javadocs are located
-avaticaApiRoot: /avatica/apidocs
-# avaticaApiRoot: http://calcite.apache.org/avatica/apidocs
+avaticaApiRoot: /avatica/javadocAggregate
+# avaticaApiRoot: http://calcite.apache.org/avatica/javadocAggregate
 
 # The URL where the JDK's Javadocs are located
 jdkApiRoot: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/
diff --git a/site/_docs/adapter.md b/site/_docs/adapter.md
index 570060c15f..1ceff6518a 100644
--- a/site/_docs/adapter.md
+++ b/site/_docs/adapter.md
@@ -48,7 +48,7 @@ presenting the data as tables within a schema.
 
 ### Other language interfaces
 
-* Piglet (calcite-piglet) runs 
queries in a subset of https://pig.apache.org/docs/r0.7.0/piglatin_ref1.html;>Pig Latin
+* Piglet (calcite-piglet) runs 
queries in a subset of https://pig.apache.org/docs/latest/basic.html;>Pig Latin
 
 ## Engines
 
@@ -343,7 +343,7 @@ Grouped window functions are functions that operate the 
`GROUP BY` clause
 to gather together records into sets. The built-in grouped window functions
 are `HOP`, `TUMBLE` and `SESSION`.
 You can define additional functions by implementing
-[interface SqlGroupedWindowFunction]({{ site.apiRoot 
}}/org/apache/calcite/sql/fun/SqlGroupedWindowFunction.html).
+[interface SqlGroupedWindowFunction]({{ site.apiRoot 
}}/org/apache/calcite/sql/SqlGroupedWindowFunction.html).
 
 ### Table functions and table macros
 
@@ -497,7 +497,7 @@ Each of these has a "pure" logical sub-class,
 [LogicalProject]({{ site.apiRoot 
}}/org/apache/calcite/rel/logical/LogicalProject.html)
 and so forth. Any given adapter will have counterparts for the operations that
 its engine can implement efficiently; for example, the Cassandra adapter has
-[CassandraProject]({{ site.apiRoot 
}}/org/apache/calcite/rel/cassandra/CassandraProject.html)
+[CassandraProject]({{ site.apiRoot 
}}/org/apache/calcite/adapter/cassandra/CassandraProject.html)
 but there is no `CassandraJoin`.
 
 You can define your own sub-class of `RelNode` to add a new operator, or
@@ -590,7 +590,7 @@ Each kind of metadata has an interface with (usually) one 
method.
 For example, selectivity is defined by
 [class RelMdSelectivity]({{ site.apiRoot 
}}/org/apache/calcite/rel/metadata/RelMdSelectivity.html)
 and the method
-[getSelectivity(RelNode rel, RexNode predicate)]({{ site.apiRoot 
}}/org/apache/calcite/rel/metadata/RelMetadataQuery.html#getSelectivity-org.apache.calcite.rel.RelNode-org.apache.calcite.rex.RexNode-).
+[getSelectivity(RelNode rel, RexNode predicate)]({{ site.apiRoot 
}}/org/apache/calcite/rel/metadata/RelMetadataQuery.html#getSelectivity(org.apache.calcite.rel.RelNode,org.apache.calcite.rex.RexNode)).
 
 There are many built-in kinds of metadata, including
 [collation]({{ site.apiRoot 
}}/org/apache/calcite/rel/metadata/RelMdCollation.html),



[calcite] branch main updated: [CALCITE-5989] Type inference for RPAD and LPAD functions (BIGQUERY) is incorrect

2023-09-29 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 3bb7117446 [CALCITE-5989] Type inference for RPAD and LPAD functions 
(BIGQUERY) is incorrect
3bb7117446 is described below

commit 3bb71174460d10542c3c9892c6a1a8effb573f9e
Author: Mihai Budiu 
AuthorDate: Fri Sep 29 12:02:01 2023 -0700

[CALCITE-5989] Type inference for RPAD and LPAD functions (BIGQUERY) is 
incorrect

Signed-off-by: Mihai Budiu 
---
 .../calcite/sql/fun/SqlLibraryOperators.java   | 10 --
 .../org/apache/calcite/test/RelOptRulesTest.java   | 40 ++
 .../org/apache/calcite/test/RelOptRulesTest.xml| 34 ++
 .../org/apache/calcite/test/SqlOperatorTest.java   | 32 -
 4 files changed, 98 insertions(+), 18 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java 
b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
index 2835184788..d58ae302d2 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
@@ -275,12 +275,18 @@ public abstract class SqlLibraryOperators {
   public static final SqlFunction LENGTH =
   SqlStdOperatorTable.CHAR_LENGTH.withName("LENGTH");
 
+  // Helper function for deriving types for the *PAD functions
+  private static RelDataType deriveTypePad(SqlOperatorBinding binding, 
RelDataType type) {
+SqlTypeName result = SqlTypeUtil.isBinary(type) ? SqlTypeName.VARBINARY : 
SqlTypeName.VARCHAR;
+return binding.getTypeFactory().createSqlType(result);
+  }
+
   /** The "LPAD(original_value, return_length[, pattern])" function. */
   @LibraryOperator(libraries = {BIG_QUERY, ORACLE})
   public static final SqlFunction LPAD =
   SqlBasicFunction.create(
   "LPAD",
-  ReturnTypes.ARG0_NULLABLE_VARYING,
+  ReturnTypes.ARG0.andThen(SqlLibraryOperators::deriveTypePad),
   OperandTypes.STRING_NUMERIC_OPTIONAL_STRING,
   SqlFunctionCategory.STRING);
 
@@ -289,7 +295,7 @@ public abstract class SqlLibraryOperators {
   public static final SqlFunction RPAD =
   SqlBasicFunction.create(
   "RPAD",
-  ReturnTypes.ARG0_NULLABLE_VARYING,
+  ReturnTypes.ARG0.andThen(SqlLibraryOperators::deriveTypePad),
   OperandTypes.STRING_NUMERIC_OPTIONAL_STRING,
   SqlFunctionCategory.STRING);
 
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java 
b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index 71b80771ce..b16a480203 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -262,6 +262,46 @@ class RelOptRulesTest extends RelOptTestBase {
 .check();
   }
 
+  /**
+   * Test case for https://issues.apache.org/jira/browse/CALCITE-5989;>[CALCITE-5989]
+   * Type inference for RPAD and LPAD functions (BIGQUERY) is incorrect. */
+  @Test void testRpad() {
+HepProgramBuilder builder = new HepProgramBuilder();
+builder.addRuleClass(ReduceExpressionsRule.class);
+HepPlanner hepPlanner = new HepPlanner(builder.build());
+hepPlanner.addRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS);
+
+final String sql = "select RPAD('abc', 8, 'A')";
+fixture()
+.withFactory(
+t -> t.withOperatorTable(opTab ->
+SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
+SqlLibrary.BIG_QUERY))) // needed for RPAD function
+.sql(sql)
+.withPlanner(hepPlanner)
+.check();
+  }
+
+  /**
+   * Test case for https://issues.apache.org/jira/browse/CALCITE-5989;>[CALCITE-5989]
+   * Type inference for RPAD and LPAD functions (BIGQUERY) is incorrect. */
+  @Test void testLpad() {
+HepProgramBuilder builder = new HepProgramBuilder();
+builder.addRuleClass(ReduceExpressionsRule.class);
+HepPlanner hepPlanner = new HepPlanner(builder.build());
+hepPlanner.addRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS);
+
+final String sql = "select LPAD('abc', 8, 'A')";
+fixture()
+.withFactory(
+t -> t.withOperatorTable(opTab ->
+SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
+SqlLibrary.BIG_QUERY))) // needed for LPAD function
+.sql(sql)
+.withPlanner(hepPlanner)
+.check();
+  }
+
   /**
* Test case for https://issues.apache.org/jira/browse/CALCITE-5971;>[CALCITE-5971]
* Add the RelRule to rewrite the bernoulli sample as Filter. */
diff --git 
a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml 
b/core/src/test/resource

[calcite] branch main updated: [CALCITE-6017] Update the GitHub link of released versions

2023-09-27 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 56f7b82483 [CALCITE-6017] Update the GitHub link of released versions
56f7b82483 is described below

commit 56f7b8248352568539cbfe0222606903d69e521c
Author: Ran Tao 
AuthorDate: Tue Sep 26 14:21:10 2023 +0800

[CALCITE-6017] Update the GitHub link of released versions
---
 site/_docs/history.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/site/_docs/history.md b/site/_docs/history.md
index 00cdd3a576..481bf5a512 100644
--- a/site/_docs/history.md
+++ b/site/_docs/history.md
@@ -24,7 +24,7 @@ limitations under the License.
 -->
 
 For a full list of releases, see
-https://github.com/apache/calcite/releases;>github.
+https://github.com/apache/calcite/tags;>github.
 Downloads are available on the
 [downloads page]({{ site.baseurl }}/downloads/).
 



[calcite] branch main updated: [CALCITE-5994] Add optimization rule to remove Sort when its input's row number is less or equal to one

2023-09-21 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 1775baf218 [CALCITE-5994] Add optimization rule to remove Sort when 
its input's row number is less or equal to one
1775baf218 is described below

commit 1775baf2184bc2d10b4991a2dea7e60c474bb5fc
Author: shenlang 
AuthorDate: Mon Sep 11 20:34:51 2023 +0800

[CALCITE-5994] Add optimization rule to remove Sort when its input's row 
number is less or equal to one
---
 .../org/apache/calcite/rel/rules/CoreRules.java|  5 ++
 .../calcite/rel/rules/SortRemoveRedundantRule.java | 77 ++
 .../org/apache/calcite/test/RelOptRulesTest.java   | 27 
 .../org/apache/calcite/test/RelOptRulesTest.xml| 43 
 4 files changed, 152 insertions(+)

diff --git a/core/src/main/java/org/apache/calcite/rel/rules/CoreRules.java 
b/core/src/main/java/org/apache/calcite/rel/rules/CoreRules.java
index 61ce78587b..50411d2462 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/CoreRules.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/CoreRules.java
@@ -721,6 +721,11 @@ public class CoreRules {
   public static final SortRemoveConstantKeysRule SORT_REMOVE_CONSTANT_KEYS =
   SortRemoveConstantKeysRule.Config.DEFAULT.toRule();
 
+  /** Rule that removes redundant {@link Sort} if its input max row number
+   * is less than or equal to one. */
+  public static final SortRemoveRedundantRule SORT_REMOVE_REDUNDANT =
+  SortRemoveRedundantRule.Config.DEFAULT.toRule();
+
   /** Rule that pushes a {@link Sort} past a {@link Join}. */
   public static final SortJoinTransposeRule SORT_JOIN_TRANSPOSE =
   SortJoinTransposeRule.Config.DEFAULT.toRule();
diff --git 
a/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRedundantRule.java 
b/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRedundantRule.java
new file mode 100644
index 00..68a449b43d
--- /dev/null
+++ 
b/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRedundantRule.java
@@ -0,0 +1,77 @@
+/*
+ * 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.rel.rules;
+
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.core.Sort;
+
+import org.immutables.value.Value;
+
+/**
+ * Planner rule that removes
+ * the redundant {@link org.apache.calcite.rel.core.Sort} if its input
+ * max row number is less than or equal to one.
+ *
+ *  For example:
+ * {@code
+ *  select max(totalprice) from orders order by 1}
+ *  
+ *
+ *  could be converted to
+ * {@code
+ *  select max(totalprice) from orders}
+ *  
+ *
+ * @see CoreRules#SORT_REMOVE_REDUNDANT
+ */
+@Value.Enclosing
+public class SortRemoveRedundantRule
+extends RelRule
+implements TransformationRule {
+  protected SortRemoveRedundantRule(final SortRemoveRedundantRule.Config 
config) {
+super(config);
+  }
+
+  @Override public void onMatch(final RelOptRuleCall call) {
+final Sort sort = call.rel(0);
+if (sort.offset != null || sort.fetch != null) {
+  // Don't remove sort if it has explicit OFFSET and LIMIT
+  return;
+}
+
+// Get the max row count for sort's input RelNode.
+final Double maxRowCount = 
call.getMetadataQuery().getMaxRowCount(sort.getInput());
+// If the max row count is not null and less than or equal to 1,
+// then we could remove the sort.
+if (maxRowCount != null && maxRowCount <= 1D) {
+  call.transformTo(sort.getInput());
+}
+  }
+
+  /** Rule configuration. */
+  @Value.Immutable
+  public interface Config extends RelRule.Config {
+Config DEFAULT = ImmutableSortRemoveRedundantRule.Config.of()
+.withOperandSupplier(b ->
+b.operand(Sort.class).anyInputs());
+
+@Override default SortRemoveRedundantRule toRule() {
+  return new SortRemoveRedundantRule(this);
+}
+  }
+}
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java 
b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
i

[calcite] branch main updated: [CALCITE-5980] QuidemTests are not effectively executed on Windows

2023-09-09 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 7176860882 [CALCITE-5980] QuidemTests are not effectively executed on 
Windows
7176860882 is described below

commit 717686088265aeb1a1b3ba561748c6cb64e1b1b0
Author: rubenada 
AuthorDate: Wed Sep 6 11:41:57 2023 +0100

[CALCITE-5980] QuidemTests are not effectively executed on Windows
---
 testkit/src/main/java/org/apache/calcite/test/QuidemTest.java | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/testkit/src/main/java/org/apache/calcite/test/QuidemTest.java 
b/testkit/src/main/java/org/apache/calcite/test/QuidemTest.java
index 60bcd15c9d..aec668e469 100644
--- a/testkit/src/main/java/org/apache/calcite/test/QuidemTest.java
+++ b/testkit/src/main/java/org/apache/calcite/test/QuidemTest.java
@@ -178,6 +178,10 @@ public abstract class QuidemTest {
   .build();
   new Quidem(config).execute();
 }
+// Sanity check: we do not allow an empty input file, it may indicate that 
it was overwritten
+if (inFile.length() == 0) {
+  fail("Input file was empty: " + inFile + "\n");
+}
 final String diff = DiffTestCase.diff(inFile, outFile);
 if (!diff.isEmpty()) {
   fail("Files differ: " + outFile + " " + inFile + "\n"
@@ -193,7 +197,7 @@ public abstract class QuidemTest {
*/
   private static File replaceDir(File file, String target, String replacement) 
{
 return new File(
-file.getAbsolutePath().replace(n2u('/' + target + '/'),
+n2u(file.getAbsolutePath()).replace(n2u('/' + target + '/'),
 n2u('/' + replacement + '/')));
   }
 



[calcite] branch main updated: [CALCITE-5732] EnumerableHashJoin and EnumerableMergeJoin on composite key return rows matching condition 'null = null'

2023-09-08 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 3aee0b86aa [CALCITE-5732] EnumerableHashJoin and EnumerableMergeJoin 
on composite key return rows matching condition 'null = null'
3aee0b86aa is described below

commit 3aee0b86aa23476cbdecc75ad5d43b936a6fff7b
Author: rubenada 
AuthorDate: Wed Jul 12 14:45:05 2023 +0100

[CALCITE-5732] EnumerableHashJoin and EnumerableMergeJoin on composite key 
return rows matching condition 'null = null'
---
 .../adapter/enumerable/EnumerableHashJoin.java |   8 +-
 .../adapter/enumerable/EnumerableMergeJoin.java|   7 +-
 .../calcite/adapter/enumerable/PhysType.java   |  26 +++-
 .../calcite/adapter/enumerable/PhysTypeImpl.java   | 168 +
 .../java/org/apache/calcite/runtime/Utilities.java |  11 ++
 .../org/apache/calcite/util/BuiltInMethod.java |   2 +-
 .../apache/calcite/runtime/EnumerablesTest.java|  28 ++--
 .../test/enumerable/EnumerableHashJoinTest.java| 136 ++---
 .../test/enumerable/EnumerableJoinTest.java| 101 ++---
 .../apache/calcite/linq4j/EnumerableDefaults.java  | 105 -
 10 files changed, 430 insertions(+), 162 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java
index 259fb68503..cfe44da75d 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableHashJoin.java
@@ -218,8 +218,8 @@ public class EnumerableHashJoin extends Join implements 
EnumerableRel {
 Expressions.list(
 leftExpression,
 rightExpression,
-leftResult.physType.generateAccessor(joinInfo.leftKeys),
-rightResult.physType.generateAccessor(joinInfo.rightKeys),
+
leftResult.physType.generateAccessorWithoutNulls(joinInfo.leftKeys),
+
rightResult.physType.generateAccessorWithoutNulls(joinInfo.rightKeys),
 Util.first(keyPhysType.comparer(),
 Expressions.constant(null)),
 predicate)))
@@ -264,8 +264,8 @@ public class EnumerableHashJoin extends Join implements 
EnumerableRel {
 BuiltInMethod.HASH_JOIN.method,
 Expressions.list(
 rightExpression,
-leftResult.physType.generateAccessor(joinInfo.leftKeys),
-rightResult.physType.generateAccessor(joinInfo.rightKeys),
+
leftResult.physType.generateAccessorWithoutNulls(joinInfo.leftKeys),
+
rightResult.physType.generateAccessorWithoutNulls(joinInfo.rightKeys),
 EnumUtils.joinSelector(joinType,
 physType,
 ImmutableList.of(
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
index d3f45d8d31..3f42e065c8 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
@@ -492,7 +492,7 @@ public class EnumerableMergeJoin extends Join implements 
EnumerableRel {
   RelFieldCollation.NullDirection.LAST));
 }
 final RelCollation collation = RelCollations.of(fieldCollations);
-final Expression comparator = 
leftKeyPhysType.generateComparator(collation);
+final Expression comparator = 
leftKeyPhysType.generateMergeJoinComparator(collation);
 
 return implementor.result(
 physType,
@@ -512,6 +512,9 @@ public class EnumerableMergeJoin extends Join implements 
EnumerableRel {
 ImmutableList.of(
 leftResult.physType, rightResult.physType)),
 Expressions.constant(EnumUtils.toLinq4jJoinType(joinType)),
-comparator))).toBlock());
+comparator,
+Util.first(
+leftKeyPhysType.comparer(),
+Expressions.constant(null).toBlock());
   }
 }
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysType.java 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysType.java
index 4447e91dfe..8d4eeb176c 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysType.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysType.java
@@ -112,11 +112,28 @@ public interface PhysType {
*public Object[] apply(Employee v1) {
*return

[calcite] branch main updated: [CALCITE-5967] UnsupportedOperationException while implementing a call that requires a special collator

2023-09-06 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 164ff0a27e [CALCITE-5967] UnsupportedOperationException while 
implementing a call that requires a special collator
164ff0a27e is described below

commit 164ff0a27e243850d294908dc5cff90760d0a35a
Author: rubenada 
AuthorDate: Tue Aug 29 17:49:20 2023 +0100

[CALCITE-5967] UnsupportedOperationException while implementing a call that 
requires a special collator
---
 .../calcite/adapter/enumerable/RexImpTable.java|  6 --
 .../enumerable/EnumerableStringComparisonTest.java | 23 ++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
index 93203afe3c..91a7aed9b0 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
@@ -44,6 +44,7 @@ import org.apache.calcite.rex.RexInputRef;
 import org.apache.calcite.rex.RexLiteral;
 import org.apache.calcite.rex.RexNode;
 import org.apache.calcite.rex.RexPatternFieldRef;
+import org.apache.calcite.runtime.FlatLists;
 import org.apache.calcite.runtime.SqlFunctions;
 import org.apache.calcite.schema.FunctionContext;
 import org.apache.calcite.schema.ImplementableAggFunction;
@@ -2865,7 +2866,7 @@ public class RexImpTable {
 @Override Expression implementSafe(
 final RexToLixTranslator translator,
 final RexCall call,
-final List argValueList) {
+List argValueList) {
   // neither nullable:
   //   return x OP y
   // x nullable
@@ -2892,7 +2893,8 @@ public class RexImpTable {
   final Expression fieldComparator =
   generateCollatorExpression(relDataType0.getCollation());
   if (fieldComparator != null) {
-argValueList.add(fieldComparator);
+// We need to add the comparator, the argValueList might be 
non-mutable, so create a new one
+argValueList = FlatLists.append(argValueList, fieldComparator);
   }
 
   final Primitive primitive = Primitive.ofBoxOr(type0);
diff --git 
a/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableStringComparisonTest.java
 
b/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableStringComparisonTest.java
index fd12311b49..d7f40b4dc5 100644
--- 
a/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableStringComparisonTest.java
+++ 
b/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableStringComparisonTest.java
@@ -137,6 +137,29 @@ class EnumerableStringComparisonTest {
 "name=presales");
   }
 
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-5967;>[CALCITE-5967]
+   * UnsupportedOperationException while implementing a call that requires a 
special collator.
+   */
+  @Test void testFilterStringSpecialCollation() {
+tester()
+.withRel(builder -> builder
+.values(
+createRecordVarcharSpecialCollation(builder),
+"Legal", "presales", "hr", "Administration", "MARKETING")
+// Filter on a field with special collation:
+// a special comparator needs to be used inside the eq operation
+.filter(
+builder.equals(
+builder.field(1, 0, "name"),
+builder.literal("MARKETING")))
+.build())
+.explainHookMatches(""
++ "EnumerableCalc(expr#0=[{inputs}], expr#1=['MARKETING'], 
expr#2=[=($t0, $t1)], name=[$t0], $condition=[$t2])\n"
++ "  EnumerableValues(tuples=[[{ 'Legal' }, { 'presales' }, { 'hr' 
}, { 'Administration' }, { 'MARKETING' }]])\n")
+.returnsUnordered("name=MARKETING");
+  }
+
   @Test void testMergeJoinOnStringSpecialCollation() {
 tester()
 .withHook(Hook.PLANNER, (Consumer) planner -> {



[calcite] branch main updated: [CALCITE-5952] SemiJoinJoinTransposeRule should check if JoinType supports pushing predicates into its inputs

2023-09-06 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new d667123585 [CALCITE-5952] SemiJoinJoinTransposeRule should check if 
JoinType supports pushing predicates into its inputs
d667123585 is described below

commit d667123585bf518edd6a9bf93e23c1785fe03376
Author: Leonid Chistov 
AuthorDate: Mon Sep 4 18:33:56 2023 +0300

[CALCITE-5952] SemiJoinJoinTransposeRule should check if JoinType supports 
pushing predicates into its inputs
---
 .../rel/rules/SemiJoinJoinTransposeRule.java   | 12 +++
 .../calcite/runtime/RelOptRulesRuntimeTest.java| 97 ++
 .../org/apache/calcite/test/RelOptRulesTest.java   | 92 
 .../org/apache/calcite/test/RelOptRulesTest.xml| 62 ++
 4 files changed, 263 insertions(+)

diff --git 
a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinJoinTransposeRule.java
 
b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinJoinTransposeRule.java
index d314b2819a..f523209893 100644
--- 
a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinJoinTransposeRule.java
+++ 
b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinJoinTransposeRule.java
@@ -114,6 +114,18 @@ public class SemiJoinJoinTransposeRule
   return;
 }
 
+// join type needs to allow pushing predicate (represented as semi-join in 
our case)
+// to the corresponding input
+if (nKeysFromX > 0) {
+  if (!join.getJoinType().canPushLeftFromAbove()) {
+return;
+  }
+} else {
+  if (!join.getJoinType().canPushRightFromAbove()) {
+return;
+  }
+}
+
 // need to convert the semi-join condition and possibly the keys
 final RexNode newSemiJoinFilter;
 int[] adjustments = new int[nTotalFields];
diff --git 
a/core/src/test/java/org/apache/calcite/runtime/RelOptRulesRuntimeTest.java 
b/core/src/test/java/org/apache/calcite/runtime/RelOptRulesRuntimeTest.java
new file mode 100644
index 00..7faa2385eb
--- /dev/null
+++ b/core/src/test/java/org/apache/calcite/runtime/RelOptRulesRuntimeTest.java
@@ -0,0 +1,97 @@
+/*
+ * 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.runtime;
+
+import org.apache.calcite.adapter.java.ReflectiveSchema;
+import org.apache.calcite.config.CalciteConnectionProperty;
+import org.apache.calcite.config.Lex;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.rules.CoreRules;
+import org.apache.calcite.test.CalciteAssert;
+import org.apache.calcite.test.schemata.hr.HrSchema;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.function.Consumer;
+
+/**
+ * Unit tests for rules in {@code org.apache.calcite.rel} and subpackages.
+ */
+public class RelOptRulesRuntimeTest {
+
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-5952;>[CALCITE-5952]
+   * SemiJoinJoinTransposeRule should check if JoinType supports pushing 
predicates
+   * into its inputs. */
+  @Test void semiJoinLeftJoinTransposeTest() {
+tester(true, new HrSchema())
+.withRel(
+builder -> builder.scan("s", "depts")
+.scan("s", "emps")
+.join(JoinRelType.LEFT,
+builder.equals(
+builder.field(2, 0, "deptno"),
+builder.field(2, 1, "deptno"))
+)
+.scan("s", "dependents")
+.semiJoin(
+builder.equals(
+builder.field(2, 0, "empid"),
+builder.field(2, 1, "empid")))
+.build()
+)
+.withHook(Hook.PLANNER, (Consumer) planner ->
+planner.addRule(CoreRules.SEMI_JOIN_JOIN_TRANSPOSE)
+)
+.returnsUnordered();
+  }
+
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-5952;>[CALCITE-5952]
+   * SemiJoinJoinTra

[calcite] branch main updated: [CALCITE-5965] Avoid unnecessary String concatenations in the RexFieldAccess constructor to improve the performance

2023-08-31 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 267d633165 [CALCITE-5965] Avoid unnecessary String concatenations in 
the RexFieldAccess constructor to improve the performance
267d633165 is described below

commit 267d63316511289ebe91079714e43b4e2d2ba085
Author: Thomas Rebele 
AuthorDate: Tue Aug 29 15:21:37 2023 +0200

[CALCITE-5965] Avoid unnecessary String concatenations in the 
RexFieldAccess constructor to improve the performance
---
 core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java 
b/core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java
index 886f98f0e5..0f09672f38 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java
@@ -75,7 +75,7 @@ public class RexFieldAccess extends RexNode {
 Preconditions.checkArgument(
 fieldIdx >= 0 && fieldIdx < exprType.getFieldList().size()
 && exprType.getFieldList().get(fieldIdx).equals(field),
-"Field " + field + " does not exist for expression " + expr);
+"Field %s does not exist for expression %s", field, expr);
   }
 
   public RelDataTypeField getField() {



[calcite] branch main updated: [CALCITE-5843] Constant expression with nested casts causes a compiler crash

2023-08-11 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new bde9110ca6 [CALCITE-5843] Constant expression with nested casts causes 
a compiler crash
bde9110ca6 is described below

commit bde9110ca6d0905eb6973cbacb5c1bb10e04cdce
Author: Mihai Budiu 
AuthorDate: Fri Aug 11 10:19:53 2023 -0700

[CALCITE-5843] Constant expression with nested casts causes a compiler crash

Signed-off-by: Mihai Budiu 
---
 .../apache/calcite/linq4j/tree/Expressions.java| 10 +++-
 .../org/apache/calcite/linq4j/tree/Primitive.java  | 29 ++
 .../org/apache/calcite/test/SqlOperatorTest.java   | 11 
 3 files changed, 49 insertions(+), 1 deletion(-)

diff --git 
a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Expressions.java 
b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Expressions.java
index 5f0b87f9e0..2e49cbcb05 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Expressions.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Expressions.java
@@ -570,7 +570,15 @@ public abstract class Expressions {
   value = new BigInteger(stringValue);
 }
 if (primitive != null) {
-  value = primitive.parse(stringValue);
+  if (value instanceof Number) {
+Number valueNumber = (Number) value;
+value = primitive.numberValue(valueNumber);
+if (value == null) {
+  value = primitive.parse(stringValue);
+}
+  } else {
+value = primitive.parse(stringValue);
+  }
 }
   }
 }
diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Primitive.java 
b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Primitive.java
index b27c48b043..066b1a5f00 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Primitive.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Primitive.java
@@ -366,6 +366,35 @@ public enum Primitive {
 return (List) asList((Object) elements);
   }
 
+  /**
+   * Converts a number into a value of the type
+   * specified by this primitive.
+   *
+   * @param value  Value to convert.
+   * @return   The converted value, or null if the
+   *   conversion cannot be performed.
+   */
+  public @Nullable Object numberValue(Number value) {
+switch (this) {
+case BYTE:
+  return value.byteValue();
+case CHAR:
+  return (char) value.intValue();
+case SHORT:
+  return value.shortValue();
+case INT:
+  return value.intValue();
+case LONG:
+  return value.longValue();
+case FLOAT:
+  return value.floatValue();
+case DOUBLE:
+  return value.doubleValue();
+default:
+  return null;
+}
+  }
+
   /**
* Converts a collection of boxed primitives into an array of primitives.
*
diff --git a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java 
b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
index 53147eb9ac..4ae29895df 100644
--- a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
+++ b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
@@ -687,6 +687,17 @@ public class SqlOperatorTest {
 "654342432412312");
   }
 
+  /**
+   * Test case for https://issues.apache.org/jira/browse/CALCITE-5843;>
+   * Constant expression with nested casts causes a compiler crash. */
+  @Test public void testConstantCast() {
+SqlOperatorFixture f = fixture();
+f.checkScalarExact("CAST(CAST('32767.4' AS FLOAT) AS SMALLINT)",
+"SMALLINT NOT NULL", "32767");
+f.checkScalarExact("CAST(CAST('32767.4' AS FLOAT) AS CHAR)",
+"CHAR(1) NOT NULL", "3");
+  }
+
   @ParameterizedTest
   @MethodSource("safeParameters")
   void testCastStringToDecimal(CastType castType, SqlOperatorFixture f) {



[calcite] branch main updated: [CALCITE-5903] RelMdCollation does not define collations for EnumerableLimit

2023-08-08 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 0cea91b842 [CALCITE-5903] RelMdCollation does not define collations 
for EnumerableLimit
0cea91b842 is described below

commit 0cea91b8426d46e72b572d99f6007cf12535f575
Author: rubenada 
AuthorDate: Mon Aug 7 15:14:32 2023 +0100

[CALCITE-5903] RelMdCollation does not define collations for EnumerableLimit
---
 .../calcite/rel/metadata/RelMdCollation.java   |  6 
 .../org/apache/calcite/test/RelMetadataTest.java   | 36 ++
 .../janino/GeneratedMetadata_CollationHandler.java |  2 ++
 3 files changed, 44 insertions(+)

diff --git 
a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdCollation.java 
b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdCollation.java
index 815968d031..7c107d39d6 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdCollation.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdCollation.java
@@ -18,6 +18,7 @@ package org.apache.calcite.rel.metadata;
 
 import org.apache.calcite.adapter.enumerable.EnumerableCorrelate;
 import org.apache.calcite.adapter.enumerable.EnumerableHashJoin;
+import org.apache.calcite.adapter.enumerable.EnumerableLimit;
 import org.apache.calcite.adapter.enumerable.EnumerableMergeJoin;
 import org.apache.calcite.adapter.enumerable.EnumerableMergeUnion;
 import org.apache.calcite.adapter.enumerable.EnumerableNestedLoopJoin;
@@ -198,6 +199,11 @@ public class RelMdCollation
 join.getJoinType()));
   }
 
+  public @Nullable ImmutableList collations(EnumerableLimit rel,
+  RelMetadataQuery mq) {
+return mq.collations(rel.getInput());
+  }
+
   public @Nullable ImmutableList collations(Sort sort,
   RelMetadataQuery mq) {
 return copyOf(
diff --git a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java 
b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
index 19c5ebc0e6..57a58a3983 100644
--- a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.calcite.test;
 import org.apache.calcite.adapter.enumerable.EnumerableConvention;
+import org.apache.calcite.adapter.enumerable.EnumerableLimit;
 import org.apache.calcite.adapter.enumerable.EnumerableMergeJoin;
 import org.apache.calcite.adapter.enumerable.EnumerableRules;
 import org.apache.calcite.config.CalciteSystemProperty;
@@ -147,6 +148,7 @@ import static org.hamcrest.CoreMatchers.startsWith;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.hasToString;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.Assertions.fail;
@@ -1566,6 +1568,40 @@ public class RelMetadataTest {
 metadataConfig.applyMetadata(rel.getCluster());
   }
 
+  /**
+   * Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-5903;>[CALCITE-5903]
+   * RelMdCollation does not define collations for EnumerableLimit.
+   */
+  @Test void testCollationEnumerableLimit() {
+final RelNode result = sql("select * from emp order by empno limit 10")
+.withCluster(cluster -> {
+  final RelOptPlanner planner = new VolcanoPlanner();
+  planner.addRule(CoreRules.PROJECT_TO_CALC);
+  planner.addRule(EnumerableRules.ENUMERABLE_TABLE_SCAN_RULE);
+  planner.addRule(EnumerableRules.ENUMERABLE_CALC_RULE);
+  planner.addRule(EnumerableRules.ENUMERABLE_SORT_RULE);
+  planner.addRule(EnumerableRules.ENUMERABLE_LIMIT_RULE);
+  planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
+  return RelOptCluster.create(planner, cluster.getRexBuilder());
+})
+.withRelTransform(rel -> {
+  final RelOptPlanner planner = rel.getCluster().getPlanner();
+  planner.setRoot(rel);
+  final RelTraitSet requiredOutputTraits =
+  
rel.getCluster().traitSet().replace(EnumerableConvention.INSTANCE);
+  final RelNode rootRel = planner.changeTraits(rel, 
requiredOutputTraits);
+  planner.setRoot(rootRel);
+  return planner.findBestExp();
+}).toRel();
+
+assertThat(result, instanceOf(EnumerableLimit.class));
+final RelMetadataQuery mq = result.getCluster().getMetadataQuery();
+final ImmutableList collations = mq.collations(result);
+assertThat(collations, notNullValue());
+assertEquals("[[0]]", collations.toString());
+  }
+
   /** Unit test for
* {@link org.apache.calcite.rel.metadata.RelMdCollation#project}
* and other 

[calcite] branch main updated: [CALCITE-5882] Compile-time evaluation of SPLIT function returns incorrect result

2023-08-04 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 98f3048fb1 [CALCITE-5882] Compile-time evaluation of SPLIT function 
returns incorrect result
98f3048fb1 is described below

commit 98f3048fb1407e2878162ffc80388d4f9dd094b2
Author: Mihai Budiu 
AuthorDate: Thu Aug 3 14:39:39 2023 -0700

[CALCITE-5882] Compile-time evaluation of SPLIT function returns incorrect 
result

Signed-off-by: Mihai Budiu 
---
 .../calcite/sql/fun/SqlLibraryOperators.java   |  4 +++-
 .../org/apache/calcite/test/RelOptRulesTest.java   | 13 
 .../org/apache/calcite/test/RelOptRulesTest.xml| 23 +++---
 .../org/apache/calcite/test/SqlOperatorTest.java   | 18 -
 4 files changed, 45 insertions(+), 13 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java 
b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
index 7a5d116631..dce8eb81df 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
@@ -333,7 +333,9 @@ public abstract class SqlLibraryOperators {
   Static.RESOURCE.delimiterIsRequired(
   operatorBinding.getOperator().getName(), type.toString()));
 }
-return type;
+
+SqlTypeName typeName = SqlTypeUtil.isBinary(type) ? SqlTypeName.VARBINARY 
: SqlTypeName.VARCHAR;
+return operatorBinding.getTypeFactory().createSqlType(typeName);
   }
 
   /** The "STRPOS(string, substring)" function. */
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java 
b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index 762da94254..a9b66f1076 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -5130,6 +5130,19 @@ class RelOptRulesTest extends RelOptTestBase {
 .check();
   }
 
+  /** Test case for https://issues.apache.org/jira/browse/CALCITE-5882;>
+   * [CALCITE-5882] Compile-time evaluation of SPLIT function returns 
incorrect result. */
+  @Test public void testSplit() {
+final String query = "select split('1|2|3', '|')";
+sql(query)
+.withFactory(
+t -> t.withOperatorTable(opTab ->
+SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
+SqlLibrary.BIG_QUERY))) // needed for SPLIT function
+.withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS)
+.check();
+  }
+
   /** Test case for right outer join, group by on key same as join
* key, group by on (left)null generating side. */
   @Test void testPushAggregateThroughOuterJoin12() {
diff --git 
a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml 
b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
index ea33f58f4e..aa13309171 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -13899,6 +13899,23 @@ LogicalProject(B=[ST_BUFFER(ST_POINT(0.0:DECIMAL(2, 
1), 0.0:DECIMAL(2, 1)), 1, 4
   
+
+  
+  
+
+  
+
+
+  
+
+
+  
 
   
@@ -13914,7 +13931,7 @@ LogicalProject(EXPR$0=[SPLIT('1|2|3', null:NULL)])
 
 
   
 
@@ -13931,7 +13948,7 @@ LogicalProject(EXPR$0=[SPLIT(null:NULL, '|')])
 
 
   
 
@@ -13948,7 +13965,7 @@ LogicalProject(EXPR$0=[SPLIT(null:NULL, null:NULL)])
 
 
   
 
diff --git a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java 
b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
index 3fc1ec425a..36e4068c42 100644
--- a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
+++ b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
@@ -7651,27 +7651,27 @@ public class SqlOperatorTest {
 false);
 final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.BIG_QUERY);
 f.checkScalar("SPLIT('h,e,l,l,o')", "[h, e, l, l, o]",
-"CHAR(9) NOT NULL ARRAY NOT NULL");
+"VARCHAR NOT NULL ARRAY NOT NULL");
 f.checkScalar("SPLIT('h-e-l-l-o', '-')", "[h, e, l, l, o]",
-"CHAR(9) NOT NULL ARRAY NOT NULL");
+"VARCHAR NOT NULL ARRAY NOT NULL");
 f.checkScalar("SPLIT('hello', '-')", "[hello]",
-"CHAR(5) NOT NULL ARRAY NOT NULL");
+"VARCHAR NOT NULL ARRAY NOT NULL");
 f.checkScalar("SPLIT('')", "[]",
-"CHAR(0) NOT NULL ARRAY NOT NULL");
+"VARCHAR NOT NULL ARRAY NOT NULL");
 f.

[calcite] branch main updated: [CALCITE-5879] AssertionError during constant reduction of SPLIT expression that returns NULL

2023-08-03 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new ffd58e3b6d [CALCITE-5879] AssertionError during constant reduction of 
SPLIT expression that returns NULL
ffd58e3b6d is described below

commit ffd58e3b6d3824e141d76cbbc3664608e8d1bb4d
Author: Mihai Budiu 
AuthorDate: Mon Jul 31 11:51:24 2023 -0700

[CALCITE-5879] AssertionError during constant reduction of SPLIT expression 
that returns NULL

Signed-off-by: Mihai Budiu 
---
 .../calcite/sql/fun/SqlLibraryOperators.java   |  3 +-
 .../org/apache/calcite/test/RelOptRulesTest.java   | 40 +
 .../org/apache/calcite/test/RelOptRulesTest.xml| 51 ++
 3 files changed, 93 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java 
b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
index 749d12f978..4a720c8982 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
@@ -317,7 +317,8 @@ public abstract class SqlLibraryOperators {
   SqlBasicFunction.create("SPLIT",
   ReturnTypes.ARG0
   .andThen(SqlLibraryOperators::deriveTypeSplit)
-  .andThen(SqlTypeTransforms.TO_ARRAY),
+  .andThen(SqlTypeTransforms.TO_ARRAY)
+  .andThen(SqlTypeTransforms.TO_NULLABLE),
   OperandTypes.or(OperandTypes.CHARACTER_CHARACTER,
   OperandTypes.CHARACTER,
   OperandTypes.BINARY_BINARY,
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java 
b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index a1408f089a..762da94254 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -107,6 +107,7 @@ import org.apache.calcite.sql.SqlFunctionCategory;
 import org.apache.calcite.sql.SqlKind;
 import org.apache.calcite.sql.SqlOperator;
 import org.apache.calcite.sql.fun.SqlLibrary;
+import org.apache.calcite.sql.fun.SqlLibraryOperatorTableFactory;
 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
 import org.apache.calcite.sql.test.SqlTestFactory;
 import org.apache.calcite.sql.type.OperandTypes;
@@ -5090,6 +5091,45 @@ class RelOptRulesTest extends RelOptTestBase {
 .checkUnchanged();
   }
 
+  /** Test case for https://issues.apache.org/jira/browse/CALCITE-5879;>
+   * AssertionError during constant reduction of SPLIT expression that returns 
NULL. */
+  @Test public void testSplitNull() {
+final String query = "select split('1|2|3', NULL)";
+sql(query)
+.withFactory(
+t -> t.withOperatorTable(opTab ->
+SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
+SqlLibrary.BIG_QUERY))) // needed for SPLIT function
+.withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS)
+.check();
+  }
+
+  /** Test case for https://issues.apache.org/jira/browse/CALCITE-5879;>
+   * AssertionError during constant reduction of SPLIT expression that returns 
NULL. */
+  @Test public void testSplitNull1() {
+final String query = "select split(NULL, '|')";
+sql(query)
+.withFactory(
+t -> t.withOperatorTable(opTab ->
+SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
+SqlLibrary.BIG_QUERY))) // needed for SPLIT function
+.withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS)
+.check();
+  }
+
+  /** Test case for https://issues.apache.org/jira/browse/CALCITE-5879;>
+   * AssertionError during constant reduction of SPLIT expression that returns 
NULL. */
+  @Test public void testSplitNull2() {
+final String query = "select split(NULL, NULL)";
+sql(query)
+.withFactory(
+t -> t.withOperatorTable(opTab ->
+SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
+SqlLibrary.BIG_QUERY))) // needed for SPLIT function
+.withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS)
+.check();
+  }
+
   /** Test case for right outer join, group by on key same as join
* key, group by on (left)null generating side. */
   @Test void testPushAggregateThroughOuterJoin12() {
diff --git 
a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml 
b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
index bca8313b33..ea33f58f4e 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -13899,6 +13899,57 @@ LogicalProject(B=[ST_BUFFER(ST_POINT(0.0:DECIMAL(2, 
1), 0.0:DECIMAL(2, 1)), 1, 4
   
+
+  
+  
+
+  
+
+
+  
+
+
+  
+
+  
+  
+
+  
+
+
+  
+
+
+  
+
+  
+  
+
+  
+
+
+  
+
+
+  
 
   



[calcite] branch main updated: [CALCITE-5877] AssertionError during MOD operation if result scale is greater than maximum numeric scale

2023-08-02 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 5b9e768d72 [CALCITE-5877] AssertionError during MOD operation if 
result scale is greater than maximum numeric scale
5b9e768d72 is described below

commit 5b9e768d72bd5ed7aa3ca7aa6317060b6fc2b627
Author: Mihai Budiu 
AuthorDate: Tue Aug 1 10:59:40 2023 -0700

[CALCITE-5877] AssertionError during MOD operation if result scale is 
greater than maximum numeric scale

Signed-off-by: Mihai Budiu 
---
 .../org/apache/calcite/rel/type/RelDataTypeSystem.java |  4 +---
 .../apache/calcite/rel/rel2sql/RelToSqlConverterTest.java  | 14 --
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeSystem.java 
b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeSystem.java
index 9332eaba20..f67f1cd286 100644
--- a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeSystem.java
+++ b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeSystem.java
@@ -379,9 +379,7 @@ public interface RelDataTypeSystem {
   return type2;
 }
 
-int scale = Math.max(s1, s2);
-assert scale <= getMaxNumericScale();
-
+int scale = Math.min(Math.max(s1, s2), getMaxNumericScale());
 int precision = Math.min(p1 - s1, p2 - s2) + Math.max(s1, s2);
 precision = Math.min(precision, getMaxNumericPrecision());
 assert precision > 0;
diff --git 
a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java 
b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
index 8e57e64c9e..92a934c707 100644
--- 
a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
+++ 
b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
@@ -4760,8 +4760,18 @@ class RelToSqlConverterTest {
 sql(sql).ok(expected);
   }
 
-  // Test for [CALCITE-5651] Inferred scale for decimal should
-  // not exceed maximum allowed scale
+  /** Test for https://issues.apache.org/jira/browse/CALCITE-5877;>[CALCITE-5877]
+   *  AssertionError during MOD operation if result scale
+   * is greater than maximum numeric scale. */
+  @Test void testNumericScaleMod() {
+final String sql = "SELECT MOD(CAST(2 AS DECIMAL(39, 20)), 2)";
+final String expected = "SELECT MOD(2, 2)\nFROM (VALUES (0)) AS \"t\" 
(\"ZERO\")";
+sql(sql).withPostgresqlModifiedDecimalTypeSystem()
+.ok(expected);
+  }
+
+  /** Test for https://issues.apache.org/jira/browse/CALCITE-5651;>[CALCITE-5651]
+   * Inferred scale for decimal should not exceed maximum allowed scale. */
   @Test void testNumericScale() {
 final String sql = "WITH v(x) AS (VALUES('4.2')) "
 + " SELECT x1 + x2 FROM v AS v1(x1), v AS V2(x2)";



[calcite] branch main updated: [CALCITE-5865] ClassCastException with FLOOR and CEIL on conformances that are not builtin (follow-up)

2023-07-21 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new bdfb17029f [CALCITE-5865] ClassCastException with FLOOR and CEIL on 
conformances that are not builtin (follow-up)
bdfb17029f is described below

commit bdfb17029f7e205f895dc3dfd0f37c8ff2520823
Author: rubenada 
AuthorDate: Fri Jul 21 10:20:12 2023 +0100

[CALCITE-5865] ClassCastException with FLOOR and CEIL on conformances that 
are not builtin (follow-up)
---
 core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java 
b/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java
index 86a7cb0a0a..65bb44e9e7 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java
@@ -2702,7 +2702,7 @@ public class SqlStdOperatorTable extends 
ReflectiveSqlOperatorTable {
   /** Returns the operator for {@code FLOOR} and {@code CEIL} with given floor 
flag
* and library. */
   public static SqlOperator floorCeil(boolean floor, SqlConformance 
conformance) {
-if (SqlConformanceEnum.BIG_QUERY.equals(conformance)) {
+if (SqlConformanceEnum.BIG_QUERY == conformance) {
   return floor ? SqlLibraryOperators.FLOOR_BIG_QUERY : 
SqlLibraryOperators.CEIL_BIG_QUERY;
 } else {
   return floor ? SqlStdOperatorTable.FLOOR : SqlStdOperatorTable.CEIL;



[calcite] branch main updated: [CALCITE-5839] EnumerableInterpretable#StaticFieldDetector can overwrite its flag and return an incorrect result

2023-07-12 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 55f714cc37 [CALCITE-5839] EnumerableInterpretable#StaticFieldDetector 
can overwrite its flag and return an incorrect result
55f714cc37 is described below

commit 55f714cc37ca7d60a6c95196f404a370d6ff0dfd
Author: rubenada 
AuthorDate: Wed Jul 12 15:38:50 2023 +0100

[CALCITE-5839] EnumerableInterpretable#StaticFieldDetector can overwrite 
its flag and return an incorrect result
---
 .../enumerable/EnumerableInterpretable.java|   2 +-
 .../enumerable/StaticFieldDetectorTest.java| 115 +
 2 files changed, 116 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableInterpretable.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableInterpretable.java
index 922687df40..c92de30547 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableInterpretable.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableInterpretable.java
@@ -185,7 +185,7 @@ public class EnumerableInterpretable extends ConverterImpl
 boolean containsStaticField = false;
 
 @Override public Void visit(final FieldDeclaration fieldDeclaration) {
-  containsStaticField = (fieldDeclaration.modifier & Modifier.STATIC) != 0;
+  containsStaticField |= (fieldDeclaration.modifier & Modifier.STATIC) != 
0;
   return containsStaticField ? null : super.visit(fieldDeclaration);
 }
   }
diff --git 
a/core/src/test/java/org/apache/calcite/adapter/enumerable/StaticFieldDetectorTest.java
 
b/core/src/test/java/org/apache/calcite/adapter/enumerable/StaticFieldDetectorTest.java
new file mode 100644
index 00..ef28201912
--- /dev/null
+++ 
b/core/src/test/java/org/apache/calcite/adapter/enumerable/StaticFieldDetectorTest.java
@@ -0,0 +1,115 @@
+/*
+ * 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.adapter.enumerable;
+
+import org.apache.calcite.linq4j.tree.ClassDeclaration;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.FieldDeclaration;
+
+import com.google.common.collect.ImmutableList;
+
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Tests for {@link EnumerableInterpretable.StaticFieldDetector}.
+ */
+public final class StaticFieldDetectorTest {
+
+  @Test void testClassWithoutStaticFields() {
+ClassDeclaration classDeclaration =
+createClassDeclaration(
+new FieldDeclaration(
+Modifier.PUBLIC,
+Expressions.parameter(int.class, "x"),
+Expressions.constant(0)));
+
+EnumerableInterpretable.StaticFieldDetector detector =
+new EnumerableInterpretable.StaticFieldDetector();
+classDeclaration.accept(detector);
+assertThat(detector.containsStaticField, is(false));
+  }
+
+  @Test void testClassWithOnlyStaticFields() {
+ClassDeclaration classDeclaration =
+createClassDeclaration(
+new FieldDeclaration(
+Modifier.PUBLIC | Modifier.STATIC,
+Expressions.parameter(int.class, "x"),
+Expressions.constant(0)),
+new FieldDeclaration(
+Modifier.STATIC,
+Expressions.parameter(int.class, "y"),
+Expressions.constant(0)));
+
+EnumerableInterpretable.StaticFieldDetector detector =
+new EnumerableInterpretable.StaticFieldDetector();
+classDeclaration.accept(detector);
+assertThat(detector.containsStaticField, is(true));
+  }
+
+  @Test void testClassWithStaticAndNonStaticFields() {
+ClassDeclaration classDeclaration =
+createClassDeclaration(
+new FieldDeclaration(
+Modifier.PUBLIC | Modifier.STATIC,
+Expressions.parame

[calcite] branch main updated: [CALCITE-5789] Query with two nested subqueries where the inner-most references the outer-most table returns wrong result [CALCITE-5683] Two level nested correlated subq

2023-06-26 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 7dd3ecd5a6 [CALCITE-5789] Query with two nested subqueries where the 
inner-most references the outer-most table returns wrong result [CALCITE-5683] 
Two level nested correlated subquery throws an exception during decorrelation
7dd3ecd5a6 is described below

commit 7dd3ecd5a61e876d929a0f4dea6eac41efce7d0c
Author: rubenada 
AuthorDate: Wed Jun 21 10:03:04 2023 +0100

[CALCITE-5789] Query with two nested subqueries where the inner-most 
references the outer-most table returns wrong result
[CALCITE-5683] Two level nested correlated subquery throws an exception 
during decorrelation

Co-authored-by: HanumathRao 
---
 .../calcite/rel/rules/SubQueryRemoveRule.java  |   7 +
 .../apache/calcite/sql2rel/SqlToRelConverter.java  |  12 +-
 .../org/apache/calcite/test/RelOptRulesTest.java   |  71 +
 .../org/apache/calcite/test/RelOptRulesTest.xml| 160 +
 core/src/test/resources/sql/misc.iq|  19 +++
 core/src/test/resources/sql/sub-query.iq   |  74 ++
 6 files changed, 342 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java 
b/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java
index b0051231c7..46ac70f147 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java
@@ -850,6 +850,7 @@ public class SubQueryRemoveRule
   private static void matchFilter(SubQueryRemoveRule rule,
   RelOptRuleCall call) {
 final Filter filter = call.rel(0);
+final Set filterVariablesSet = filter.getVariablesSet();
 final RelBuilder builder = call.builder();
 builder.push(filter.getInput());
 int count = 0;
@@ -865,6 +866,12 @@ public class SubQueryRemoveRule
   LogicVisitor.find(RelOptUtil.Logic.TRUE, ImmutableList.of(c), e);
   final Set  variablesSet =
   RelOptUtil.getVariablesUsed(e.rel);
+  // Filter without variables could be handled before this change, we do 
not want
+  // to break it yet for compatibility reason.
+  if (!filterVariablesSet.isEmpty()) {
+// Only consider the correlated variables which originated from this 
sub-query level.
+variablesSet.retainAll(filterVariablesSet);
+  }
   final RexNode target =
   rule.apply(e, variablesSet, logic,
   builder, 1, builder.peek().getRowType().getFieldCount(), count);
diff --git 
a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java 
b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
index bea49d401f..6e44e8e764 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
@@ -3512,7 +3512,17 @@ public class SqlToRelConverter {
 
 // implement HAVING (we have already checked that it is non-trivial)
 relBuilder.push(bb.root());
-relBuilder.filter(havingExpr);
+// Set the correlation variables used in this sub-query to the filter node,
+// same logic is being used for the filter generated in where clause.
+Set variableSet = new HashSet<>();
+RexSubQuery subQ = RexUtil.SubQueryFinder.find(havingExpr);
+if (subQ != null) {
+  CorrelationUse p = getCorrelationUse(bb, subQ.rel);
+  if (p != null) {
+variableSet.add(p.id);
+  }
+}
+relBuilder.filter(variableSet, havingExpr);
 
 // implement the SELECT list
 relBuilder.project(projects.leftList(), projects.rightList())
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java 
b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index d131204cf8..f61185dbe4 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -6977,6 +6977,77 @@ class RelOptRulesTest extends RelOptTestBase {
 .checkUnchanged();
   }
 
+  /** Test case for CALCITE-5683 for two level nested decorrelate with 
standard program
+   * failing during the decorrelation phase. The correlation variable is used 
at two levels
+   * deep. */
+  @Test void testTwoLevelDecorrelate() {
+final String sql = "SELECT d1.name, d1.deptno + (\n"
++ "SELECT e1.empno\n"
++ "FROM emp e1\n"
++ "WHERE d1.deptno = e1.deptno and\n"
++ "e1.sal = (SELECT max(sal)\n"
++ "  FROM emp e2\n"
++ "  WHERE e1.sal = e2.sal and\n"
++ "  e1.deptno = e2.deptno and\n"
++ &

[calcite] branch main updated: [CALCITE-5728] Add ARRAY_TO_STRING function (enabled in BigQuery library)

2023-06-13 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 18ba66da96 [CALCITE-5728] Add ARRAY_TO_STRING function (enabled in 
BigQuery library)
18ba66da96 is described below

commit 18ba66da96aa5e68de542573e5509f1f937cf340
Author: zoudan 
AuthorDate: Fri Jun 2 15:25:31 2023 +0800

[CALCITE-5728] Add ARRAY_TO_STRING function (enabled in BigQuery library)
---
 .../calcite/adapter/enumerable/RexImpTable.java|  2 ++
 .../org/apache/calcite/runtime/SqlFunctions.java   | 36 ++
 .../main/java/org/apache/calcite/sql/SqlKind.java  |  3 ++
 .../calcite/sql/fun/SqlLibraryOperators.java   | 22 +++--
 .../calcite/sql/fun/SqlRegexpReplaceFunction.java  |  5 +--
 .../org/apache/calcite/sql/type/OperandTypes.java  | 27 
 .../org/apache/calcite/sql/type/ReturnTypes.java   | 13 
 site/_docs/reference.md|  1 +
 .../org/apache/calcite/test/SqlOperatorTest.java   | 25 +++
 9 files changed, 120 insertions(+), 14 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
index e7b80c68d6..f9ca53ecbe 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
@@ -131,6 +131,7 @@ import static 
org.apache.calcite.sql.fun.SqlLibraryOperators.ARRAY_MIN;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.ARRAY_REPEAT;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.ARRAY_REVERSE;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.ARRAY_SIZE;
+import static org.apache.calcite.sql.fun.SqlLibraryOperators.ARRAY_TO_STRING;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.ARRAY_UNION;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.ASINH;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.ATANH;
@@ -705,6 +706,7 @@ public class RexImpTable {
   defineMethod(ARRAY_REPEAT, BuiltInMethod.ARRAY_REPEAT.method, 
NullPolicy.NONE);
   defineMethod(ARRAY_REVERSE, BuiltInMethod.ARRAY_REVERSE.method, 
NullPolicy.STRICT);
   defineMethod(ARRAY_SIZE, BuiltInMethod.COLLECTION_SIZE.method, 
NullPolicy.STRICT);
+  defineMethod(ARRAY_TO_STRING, "arrayToString", NullPolicy.STRICT);
   defineMethod(ARRAY_UNION, BuiltInMethod.ARRAY_UNION.method, 
NullPolicy.ANY);
   defineMethod(MAP_ENTRIES, BuiltInMethod.MAP_ENTRIES.method, 
NullPolicy.STRICT);
   defineMethod(MAP_KEYS, BuiltInMethod.MAP_KEYS.method, NullPolicy.STRICT);
diff --git a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java 
b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
index 7547a5cbe1..401f98da5f 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
@@ -4119,6 +4119,42 @@ public class SqlFunctions {
 return list;
   }
 
+  /** SQL {@code ARRAY_TO_STRING(array, delimiter)} function. */
+  public static String arrayToString(List list, String delimiter) {
+return arrayToString(list, delimiter, null);
+  }
+
+  /** SQL {@code ARRAY_TO_STRING(array, delimiter, nullText)} function. */
+  public static String arrayToString(List list, String delimiter, @Nullable 
String nullText) {
+StringBuilder sb = new StringBuilder();
+boolean isFirst = true;
+for (Object item : list) {
+  String str;
+  if (item == null) {
+if (nullText == null) {
+  continue;
+} else {
+  str = nullText;
+}
+  } else if (item instanceof String) {
+str = (String) item;
+  } else if (item instanceof ByteString) {
+str = item.toString();
+  } else {
+throw new IllegalStateException(
+"arrayToString supports only String or ByteString, but got "
++ item.getClass().getName());
+  }
+
+  if (!isFirst) {
+sb.append(delimiter);
+  }
+  sb.append(str);
+  isFirst = false;
+}
+return sb.toString();
+  }
+
   /**
* Function that, given a certain List containing single-item structs (i.e. 
arrays / lists with
* a single item), builds an Enumerable that returns those single items 
inside the structs.
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlKind.java 
b/core/src/main/java/org/apache/calcite/sql/SqlKind.java
index 4861005730..9a3a4c806f 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlKind.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlKind.java
@@ -713,6 +713,9 @@ public enum SqlKind {
   /** {@code ARRAY_SIZE} function (Spark semantics). */
   ARRAY_SIZE,
 
+  /** {@code ARRAY

[calcite] branch main updated: [CALCITE-5401] Rule fired by HepPlanner can return Volcano's RelSubset

2023-06-09 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 2e3e4ae220 [CALCITE-5401] Rule fired by HepPlanner can return 
Volcano's RelSubset
2e3e4ae220 is described below

commit 2e3e4ae220a69a0936792caec1fae23d947e77f3
Author: rubenada 
AuthorDate: Mon Jun 5 12:36:45 2023 +0100

[CALCITE-5401] Rule fired by HepPlanner can return Volcano's RelSubset
---
 .../EnumerableBatchNestedLoopJoinRule.java |  4 ++--
 .../adapter/enumerable/EnumerableLimitRule.java|  3 ++-
 .../enumerable/EnumerableLimitSortRule.java|  2 +-
 .../enumerable/EnumerableMergeUnionRule.java   |  3 ++-
 .../java/org/apache/calcite/plan/RelOptRule.java   |  9 +++--
 .../calcite/rel/rules/AggregateRemoveRule.java |  2 +-
 .../apache/calcite/rel/rules/CalcRemoveRule.java   |  1 +
 .../calcite/rel/rules/ProjectRemoveRule.java   |  2 +-
 .../apache/calcite/rel/rules/SortRemoveRule.java   |  2 +-
 .../org/apache/calcite/test/HepPlannerTest.java| 22 ++
 .../calcite/adapter/geode/rel/GeodeRules.java  |  2 +-
 11 files changed, 41 insertions(+), 11 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableBatchNestedLoopJoinRule.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableBatchNestedLoopJoinRule.java
index 10d875d08e..d7accbd705 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableBatchNestedLoopJoinRule.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableBatchNestedLoopJoinRule.java
@@ -140,9 +140,9 @@ public class EnumerableBatchNestedLoopJoinRule
 
 call.transformTo(
 EnumerableBatchNestedLoopJoin.create(
-convert(join.getLeft(), join.getLeft().getTraitSet()
+convert(call.getPlanner(), join.getLeft(), 
join.getLeft().getTraitSet()
 .replace(EnumerableConvention.INSTANCE)),
-convert(right, right.getTraitSet()
+convert(call.getPlanner(), right, right.getTraitSet()
 .replace(EnumerableConvention.INSTANCE)),
 join.getCondition(),
 requiredColumns.build(),
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimitRule.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimitRule.java
index 4f84bd92cb..7cea6575cb 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimitRule.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimitRule.java
@@ -57,7 +57,8 @@ public class EnumerableLimitRule
 }
 call.transformTo(
 EnumerableLimit.create(
-convert(input, 
input.getTraitSet().replace(EnumerableConvention.INSTANCE)),
+convert(call.getPlanner(), input,
+input.getTraitSet().replace(EnumerableConvention.INSTANCE)),
 sort.offset,
 sort.fetch));
   }
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimitSortRule.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimitSortRule.java
index 6ea7e55115..1a03338001 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimitSortRule.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimitSortRule.java
@@ -43,7 +43,7 @@ public class EnumerableLimitSortRule extends 
RelRule
 input = call.getPlanner().register(input, calc);
 call.transformTo(
 convert(
+call.getPlanner(),
 input,
 calc.getTraitSet()));
   }
diff --git 
a/core/src/main/java/org/apache/calcite/rel/rules/ProjectRemoveRule.java 
b/core/src/main/java/org/apache/calcite/rel/rules/ProjectRemoveRule.java
index 551cae2086..d3e57230df 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/ProjectRemoveRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/ProjectRemoveRule.java
@@ -67,7 +67,7 @@ public class ProjectRemoveRule
   childProject.getInput(), childProject.getProjects(),
   project.getRowType());
 }
-stripped = convert(stripped, project.getConvention());
+stripped = convert(call.getPlanner(), stripped, project.getConvention());
 call.transformTo(stripped);
   }
 
diff --git 
a/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRule.java 
b/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRule.java
index c5ae9299cb..861a719094 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRule.java
@@ -70,7 +70,7 @@ public class SortRemoveRule
 .getTrait(RelCollationTraitDef.INSTANCE);
 final RelTraitSet traits = sort.getInput().getTraitSet

[calcite] branch main updated: [CALCITE-5730] Initial null values can be dropped by EnumerableLimitSort with offset

2023-06-02 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 295df907d1  [CALCITE-5730] Initial null values can be dropped by 
EnumerableLimitSort with offset
295df907d1 is described below

commit 295df907d126ffa059756e2e0cc8b69051ff6da7
Author: guofeng.my 
AuthorDate: Thu Jun 1 17:06:50 2023 +0800

 [CALCITE-5730] Initial null values can be dropped by EnumerableLimitSort 
with offset
---
 .../test/enumerable/EnumerableLimitSortTest.java   | 172 +
 .../apache/calcite/linq4j/EnumerableDefaults.java  |   4 +-
 .../apache/calcite/linq4j/test/LimitSortTest.java  |  23 +--
 3 files changed, 187 insertions(+), 12 deletions(-)

diff --git 
a/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableLimitSortTest.java
 
b/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableLimitSortTest.java
new file mode 100644
index 00..5c0d35ca4b
--- /dev/null
+++ 
b/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableLimitSortTest.java
@@ -0,0 +1,172 @@
+/*
+ * 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.test.enumerable;
+
+import org.apache.calcite.adapter.enumerable.EnumerableRules;
+import org.apache.calcite.adapter.java.ReflectiveSchema;
+import org.apache.calcite.config.CalciteConnectionProperty;
+import org.apache.calcite.config.Lex;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.runtime.Hook;
+import org.apache.calcite.test.CalciteAssert;
+import org.apache.calcite.test.schemata.hr.HrSchemaBig;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.function.Consumer;
+
+/** Tests for
+ * {@link org.apache.calcite.adapter.enumerable.EnumerableLimitSort}. */
+public class EnumerableLimitSortTest {
+
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-5730;>[CALCITE-5730]
+   * First nulls can be dropped by EnumerableLimitSort with offset. */
+  @Test void nullsFirstWithLimitAndOffset() {
+tester("select commission from emps order by commission nulls first limit 
1 offset 1 ")
+.explainContains("EnumerableCalc(expr#0..4=[{inputs}], 
commission=[$t4])\n"
++ "  EnumerableLimitSort(sort0=[$4], dir0=[ASC-nulls-first], 
offset=[1], fetch=[1])\n"
++ "EnumerableTableScan(table=[[s, emps]])")
+.returnsOrdered("commission=null");
+  }
+
+  @Test void nullsLastWithLimitAndOffset() {
+tester("select commission from emps order by commission desc nulls last 
limit 8 offset 10 ")
+.explainContains("EnumerableCalc(expr#0..4=[{inputs}], 
commission=[$t4])\n"
++ "  EnumerableLimitSort(sort0=[$4], dir0=[DESC-nulls-last], 
offset=[10], fetch=[8])\n"
++ "EnumerableTableScan(table=[[s, emps]])")
+.returnsOrdered(
+"commission=1000",
+"commission=1000",
+"commission=500",
+"commission=500",
+"commission=500",
+"commission=500",
+"commission=500",
+"commission=500");
+  }
+
+  @Test void nullsFirstWithLimit() {
+tester("select commission from emps order by commission nulls first limit 
13 ")
+.explainContains("EnumerableCalc(expr#0..4=[{inputs}], 
commission=[$t4])\n"
++ "  EnumerableLimitSort(sort0=[$4], dir0=[ASC-nulls-first], 
fetch=[13])\n"
++ "EnumerableTableScan(table=[[s, emps]])")
+.returnsOrdered(
+"commission=null",
+"commission=null",
+"commission=null",
+"commission=null",
+"commission=null",
+"commission=null",
+"commission=null",
+"commission=null",
+"commission=null",
+&quo

[calcite] branch main updated: [CALCITE-5608] Implement ASINH, ACOSH, ATANH functions

2023-05-27 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new af2fb7f02b [CALCITE-5608] Implement ASINH, ACOSH, ATANH functions
af2fb7f02b is described below

commit af2fb7f02b30bf853cf9f4c384fbcfeafefcebdf
Author: zoudan 
AuthorDate: Mon May 15 16:19:49 2023 +0800

[CALCITE-5608] Implement ASINH, ACOSH, ATANH functions
---
 .../calcite/adapter/enumerable/RexImpTable.java|  6 ++
 .../org/apache/calcite/runtime/SqlFunctions.java   | 56 ++
 .../calcite/sql/fun/SqlLibraryOperators.java   | 26 
 site/_docs/reference.md|  3 +
 .../org/apache/calcite/test/SqlOperatorTest.java   | 69 ++
 5 files changed, 160 insertions(+)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
index 6bc1dd18e7..4d8e51bb15 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
@@ -112,6 +112,7 @@ import static 
org.apache.calcite.linq4j.tree.ExpressionType.NotEqual;
 import static org.apache.calcite.linq4j.tree.ExpressionType.Subtract;
 import static org.apache.calcite.linq4j.tree.ExpressionType.UnaryPlus;
 import static org.apache.calcite.sql.fun.SqlInternalOperators.THROW_UNLESS;
+import static org.apache.calcite.sql.fun.SqlLibraryOperators.ACOSH;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.ARRAY;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.ARRAY_AGG;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.ARRAY_CONCAT;
@@ -121,6 +122,8 @@ import static 
org.apache.calcite.sql.fun.SqlLibraryOperators.ARRAY_LENGTH;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.ARRAY_REPEAT;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.ARRAY_REVERSE;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.ARRAY_SIZE;
+import static org.apache.calcite.sql.fun.SqlLibraryOperators.ASINH;
+import static org.apache.calcite.sql.fun.SqlLibraryOperators.ATANH;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.BOOL_AND;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.BOOL_OR;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.CHAR;
@@ -529,9 +532,12 @@ public class RexImpTable {
   map.put(RAND_INTEGER, new RandIntegerImplementor());
 
   defineMethod(ACOS, "acos", NullPolicy.STRICT);
+  defineMethod(ACOSH, "acosh", NullPolicy.STRICT);
   defineMethod(ASIN, "asin", NullPolicy.STRICT);
+  defineMethod(ASINH, "asinh", NullPolicy.STRICT);
   defineMethod(ATAN, "atan", NullPolicy.STRICT);
   defineMethod(ATAN2, "atan2", NullPolicy.STRICT);
+  defineMethod(ATANH, "atanh", NullPolicy.STRICT);
   defineMethod(CBRT, "cbrt", NullPolicy.STRICT);
   defineMethod(COS, "cos", NullPolicy.STRICT);
   defineMethod(COSH, "cosh", NullPolicy.STRICT);
diff --git a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java 
b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
index 1fc339fc07..d9621c5c1b 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
@@ -1854,6 +1854,20 @@ public class SqlFunctions {
 return Math.acos(b0);
   }
 
+  // ACOSH
+  /** SQL ACOSH operator applied to BigDecimal values. */
+  public static double acosh(BigDecimal b0) {
+return acosh(b0.doubleValue());
+  }
+
+  /** SQL ACOSH operator applied to double values. */
+  public static double acosh(double b0) {
+if (b0 < 1) {
+  throw new IllegalArgumentException("Input parameter of acosh cannot be 
less than 1!");
+}
+return Math.log(Math.sqrt(b0 * b0 - 1.0d) + b0);
+  }
+
   // ASIN
   /** SQL ASIN operator applied to BigDecimal values. */
   public static double asin(BigDecimal b0) {
@@ -1865,6 +1879,25 @@ public class SqlFunctions {
 return Math.asin(b0);
   }
 
+  // ASINH
+  /** SQL ASINH operator applied to BigDecimal values. */
+  public static double asinh(BigDecimal b0) {
+return asinh(b0.doubleValue());
+  }
+
+  /** SQL ASINH operator applied to double values. */
+  public static double asinh(double b0) {
+final double sign;
+// check the sign bit of the raw representation to handle -0.
+if (Double.doubleToRawLongBits(b0) < 0) {
+  b0 = Math.abs(b0);
+  sign = -1.0d;
+} else {
+  sign = 1.0d;
+}
+return sign * Math.log(Math.sqrt(b0 * b0 + 1.0d) + b0);
+  }
+
   // ATAN
   /** SQL ATAN operator applied to BigDecimal values. */
   public 

[calcite] branch main updated: [CALCITE-5674] CAST expr to target type should respect nullable when it is complex type (follow-up)

2023-05-24 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 3843ede3d2 [CALCITE-5674] CAST expr to target type should respect 
nullable when it is complex type (follow-up)
3843ede3d2 is described below

commit 3843ede3d28783235780c0f81f725dc7e64a7828
Author: rubenada 
AuthorDate: Wed May 24 14:02:06 2023 +0100

[CALCITE-5674] CAST expr to target type should respect nullable when it is 
complex type (follow-up)
---
 core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java | 2 +-
 core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java   | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java 
b/core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java
index ddc30ab295..81da37c7e7 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java
@@ -147,7 +147,7 @@ public class SqlCastFunction extends SqlFunction {
   RelDataType newElementType =
   createTypeWithNullabilityFromExpr(
   typeFactory, expressionElementType, targetElementType, safe);
-  return isArray(expressionType)
+  return isArray(targetType)
   ? SqlTypeUtil.createArrayType(typeFactory, newElementType, 
isNullable)
   : SqlTypeUtil.createMultisetType(typeFactory, newElementType, 
isNullable);
 }
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java 
b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index e58c7b29df..19b2b6a2d7 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -6990,6 +6990,8 @@ public class SqlValidatorTest extends 
SqlValidatorTestCase {
 .columnType("VARCHAR(5) ARRAY NOT NULL");
 sql("select cast(multiset[1,null,2] as int multiset) from (values (1))")
 .columnType("INTEGER MULTISET NOT NULL");
+sql("select cast(array[1,null,2] as int multiset) from (values (1))")
+.columnType("INTEGER MULTISET NOT NULL");
 
 // test array type.
 sql("select cast(\"intArrayType\" as int array) from COMPLEXTYPES.CTC_T1")



[calcite] branch main updated: [CALCITE-5691] IN sub-query inside FILTER clause throws IndexOutOfBoundsException

2023-05-23 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new d08b5cf73f [CALCITE-5691] IN sub-query inside FILTER clause throws 
IndexOutOfBoundsException
d08b5cf73f is described below

commit d08b5cf73f9bb438f282d2089dd92f6d380c0c47
Author: Runkang He 
AuthorDate: Thu May 11 08:59:29 2023 +0800

[CALCITE-5691] IN sub-query inside FILTER clause throws 
IndexOutOfBoundsException
---
 .../apache/calcite/plan/RelOptPredicateList.java   | 10 +++---
 .../apache/calcite/test/SqlToRelConverterTest.java | 13 
 .../apache/calcite/test/SqlToRelConverterTest.xml  | 32 ++
 core/src/test/resources/sql/sub-query.iq   | 38 ++
 4 files changed, 89 insertions(+), 4 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/plan/RelOptPredicateList.java 
b/core/src/main/java/org/apache/calcite/plan/RelOptPredicateList.java
index 405ac30b91..d6f1de5ce1 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptPredicateList.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptPredicateList.java
@@ -29,6 +29,7 @@ import com.google.common.collect.ImmutableMap;
 import org.checkerframework.checker.nullness.qual.Nullable;
 
 import java.util.Collection;
+import java.util.List;
 import java.util.Objects;
 
 /**
@@ -236,10 +237,11 @@ public class RelOptPredicateList {
 if (SqlKind.COMPARISON.contains(e.getKind())) {
   // A comparison with a (non-null) literal, such as 'ref < 10', is not 
null if 'ref'
   // is not null.
-  RexCall call = (RexCall) e;
-  if (call.getOperands().get(1) instanceof RexLiteral
-  && !((RexLiteral) call.getOperands().get(1)).isNull()) {
-return isEffectivelyNotNull(call.getOperands().get(0));
+  List operands = ((RexCall) e).getOperands();
+  // We can have just one operand in case e.g. of a RexSubQuery with IN 
operator.
+  if (operands.size() > 1 && operands.get(1) instanceof RexLiteral
+  && !((RexLiteral) operands.get(1)).isNull()) {
+return isEffectivelyNotNull(operands.get(0));
   }
 }
 return false;
diff --git 
a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java 
b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
index 3d36135ec6..546b222056 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -667,6 +667,13 @@ class SqlToRelConverterTest extends SqlToRelTestBase {
 sql(sql).ok();
   }
 
+  @Test void testAggFilterWithInSubQuery() {
+final String sql = "select\n"
++ "  count(*) filter (where empno in (select deptno from 
empnullables))\n"
++ "from empnullables";
+sql(sql).withExpand(false).ok();
+  }
+
   @Test void testFakeStar() {
 sql("SELECT * FROM (VALUES (0, 0)) AS T(A, \"*\")").ok();
   }
@@ -4652,6 +4659,12 @@ class SqlToRelConverterTest extends SqlToRelTestBase {
 sql(sql).ok();
   }
 
+  @Test void testProjectInSubQueryWithIsTruePredicate() {
+final String sql = "select deptno in (select deptno from empnullables) is 
true\n"
++ "from empnullables";
+sql(sql).withExpand(false).ok();
+  }
+
   @Test void testProjectAggregatesIgnoreNullsAndNot() {
 final String sql = "select lead(sal, 4) IGNORE NULLS, lead(sal, 4) over 
(w)\n"
 + "from emp window w as (order by empno)";
diff --git 
a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml 
b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
index d1581c2922..68aeb4885c 100644
--- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
@@ -86,6 +86,23 @@ group by deptno]]>
 LogicalAggregate(group=[{0}], EXPR$1=[SUM($1) FILTER $2], EXPR$2=[COUNT()])
   LogicalProject(DEPTNO=[$7], $f1=[*($5, 2)], $f2=[SEARCH($0, Sarg[(-∞..1), 
(1..2), (2..+∞)])])
 LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+
+  
+  
+
+  
+
+
+  
 
   
@@ -5871,6 +5888,21 @@ GROUP BY empno]]>
 LogicalAggregate(group=[{0}], EXPR$1=[COUNT(DISTINCT $1)], 
EXPR$2=[COUNT(APPROXIMATE DISTINCT $1)])
   LogicalProject(EMPNO=[$0], ENAME=[$1])
 LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+
+  
+  
+
+  
+
+
+  
 
   
diff --git a/core/src/test/resources/sql/sub-query.iq 
b/core/src/test/resources/sql/sub-query.iq
index 1cd28283c9..007e52cce0 100644
--- a/core/src/test/resources/sql/sub-query.iq
+++ b/core/src/test/resources/sql/sub-query.iq
@@ -3573,4 +3573,42 @@ or 20 in (
 
 !ok
 
+# Test

[calcite] branch main updated: [CALCITE-5602] Implement CSC and SEC functions

2023-05-18 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new dbefd68825 [CALCITE-5602] Implement CSC and SEC functions
dbefd68825 is described below

commit dbefd6882585e0044cd23784dd1bb2352554d391
Author: zoudan 
AuthorDate: Mon May 8 16:08:20 2023 +0800

[CALCITE-5602] Implement CSC and SEC functions
---
 .../calcite/adapter/enumerable/RexImpTable.java|  4 ++
 .../org/apache/calcite/runtime/SqlFunctions.java   | 22 +++
 .../calcite/sql/fun/SqlLibraryOperators.java   | 14 +++
 site/_docs/reference.md|  2 +
 .../org/apache/calcite/test/SqlOperatorTest.java   | 44 ++
 5 files changed, 86 insertions(+)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
index 16a9df8632..2bda9908bb 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
@@ -130,6 +130,7 @@ import static 
org.apache.calcite.sql.fun.SqlLibraryOperators.CONCAT2;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.CONCAT_FUNCTION;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.COSH;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.COTH;
+import static org.apache.calcite.sql.fun.SqlLibraryOperators.CSC;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.CSCH;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.DATE;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.DATEADD;
@@ -184,6 +185,7 @@ import static 
org.apache.calcite.sql.fun.SqlLibraryOperators.RPAD;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.SAFE_CAST;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.SAFE_OFFSET;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.SAFE_ORDINAL;
+import static org.apache.calcite.sql.fun.SqlLibraryOperators.SEC;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.SECH;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.SHA1;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.SHA256;
@@ -533,11 +535,13 @@ public class RexImpTable {
   defineMethod(COSH, "cosh", NullPolicy.STRICT);
   defineMethod(COT, "cot", NullPolicy.STRICT);
   defineMethod(COTH, "coth", NullPolicy.STRICT);
+  defineMethod(CSC, "csc", NullPolicy.STRICT);
   defineMethod(CSCH, "csch", NullPolicy.STRICT);
   defineMethod(DEGREES, "degrees", NullPolicy.STRICT);
   defineMethod(POW, "power", NullPolicy.STRICT);
   defineMethod(RADIANS, "radians", NullPolicy.STRICT);
   defineMethod(ROUND, "sround", NullPolicy.STRICT);
+  defineMethod(SEC, "sec", NullPolicy.STRICT);
   defineMethod(SECH, "sech", NullPolicy.STRICT);
   defineMethod(SIGN, "sign", NullPolicy.STRICT);
   defineMethod(SIN, "sin", NullPolicy.STRICT);
diff --git a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java 
b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
index 52c2da6878..29ba098dda 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
@@ -2138,6 +2138,28 @@ public class SqlFunctions {
 return Math.tanh(b);
   }
 
+  // CSC
+  /** SQL CSC operator applied to BigDecimal values. */
+  public static double csc(BigDecimal b0) {
+return 1.0d / Math.sin(b0.doubleValue());
+  }
+
+  /** SQL CSC operator applied to double values. */
+  public static double csc(double b0) {
+return 1.0d / Math.sin(b0);
+  }
+
+  // SEC
+  /** SQL SEC operator applied to BigDecimal values. */
+  public static double sec(BigDecimal b0) {
+return 1.0d / Math.cos(b0.doubleValue());
+  }
+
+  /** SQL SEC operator applied to double values. */
+  public static double sec(double b0) {
+return 1.0d / Math.cos(b0);
+  }
+
   // Helpers
 
   /** Helper for implementing MIN. Somewhat similar to LEAST operator. */
diff --git 
a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java 
b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
index 4ae48490e5..fe3269d18a 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
@@ -1288,6 +1288,20 @@ public abstract class SqlLibraryOperators {
   OperandTypes.NUMERIC,
   SqlFunctionCategory.NUMERIC);
 
+  @LibraryOperator(libraries = {ALL})
+  public static final SqlFunction CSC =
+  SqlBasicFunction.create("CSC&qu

[calcite] branch main updated: [CALCITE-5679] HepPlanner#buildFinalPlan: do not clear metadata cache if RelNode has not changed

2023-04-29 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new a833bd626c [CALCITE-5679] HepPlanner#buildFinalPlan: do not clear 
metadata cache if RelNode has not changed
a833bd626c is described below

commit a833bd626c5e781ccc27bd6fab1c636a3b944907
Author: rubenada 
AuthorDate: Fri Apr 28 15:22:28 2023 +0100

[CALCITE-5679] HepPlanner#buildFinalPlan: do not clear metadata cache if 
RelNode has not changed
---
 core/src/main/java/org/apache/calcite/plan/hep/HepPlanner.java | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/plan/hep/HepPlanner.java 
b/core/src/main/java/org/apache/calcite/plan/hep/HepPlanner.java
index 7e39b4399f..fc2f557c0b 100644
--- a/core/src/main/java/org/apache/calcite/plan/hep/HepPlanner.java
+++ b/core/src/main/java/org/apache/calcite/plan/hep/HepPlanner.java
@@ -944,6 +944,7 @@ public class HepPlanner extends AbstractRelOptPlanner {
 // Recursively process children, replacing this rel's inputs
 // with corresponding child rels.
 List inputs = rel.getInputs();
+boolean changed = false;
 for (int i = 0; i < inputs.size(); ++i) {
   RelNode child = inputs.get(i);
   if (!(child instanceof HepRelVertex)) {
@@ -952,9 +953,12 @@ public class HepPlanner extends AbstractRelOptPlanner {
   }
   child = buildFinalPlan((HepRelVertex) child);
   rel.replaceInput(i, child);
+  changed = true;
+}
+if (changed) {
+  RelMdUtil.clearCache(rel);
+  rel.recomputeDigest();
 }
-RelMdUtil.clearCache(rel);
-rel.recomputeDigest();
 
 return rel;
   }



[calcite] branch main updated: [CALCITE-5670] Assertion error in SemiJoinJoinTransposeRule when Semi-Join has keys from both tables of the bottom Join

2023-04-25 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new cc3c5fed07 [CALCITE-5670] Assertion error in SemiJoinJoinTransposeRule 
when Semi-Join has keys from both tables of the bottom Join
cc3c5fed07 is described below

commit cc3c5fed072dad2efc8d0961e66fea38ba8f3817
Author: Roman Kondakov 
AuthorDate: Sun Apr 23 18:35:12 2023 +0700

[CALCITE-5670] Assertion error in SemiJoinJoinTransposeRule when Semi-Join 
has keys from both tables of the bottom Join
---
 .../rel/rules/SemiJoinJoinTransposeRule.java   |  9 ---
 .../org/apache/calcite/test/RelOptRulesTest.java   | 12 +
 .../org/apache/calcite/test/RelOptRulesTest.xml| 31 ++
 3 files changed, 48 insertions(+), 4 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinJoinTransposeRule.java
 
b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinJoinTransposeRule.java
index 9ad23cc92e..d314b2819a 100644
--- 
a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinJoinTransposeRule.java
+++ 
b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinJoinTransposeRule.java
@@ -76,7 +76,6 @@ public class SemiJoinJoinTransposeRule
 if (join.isSemiJoin()) {
   return;
 }
-final ImmutableIntList leftKeys = semiJoin.analyzeCondition().leftKeys;
 
 // X is the left child of the join below the semi-join
 // Y is the right child of the join below the semi-join
@@ -102,6 +101,7 @@ public class SemiJoinJoinTransposeRule
 
 // determine which operands below the semi-join are the actual
 // Rels that participate in the semi-join
+final ImmutableIntList leftKeys = semiJoin.analyzeCondition().leftKeys;
 int nKeysFromX = 0;
 for (int leftKey : leftKeys) {
   if (leftKey < nFieldsX) {
@@ -109,9 +109,10 @@ public class SemiJoinJoinTransposeRule
   }
 }
 
-// the keys must all originate from either the left or right;
-// otherwise, a semi-join wouldn't have been created
-assert (nKeysFromX == 0) || (nKeysFromX == leftKeys.size());
+if (nKeysFromX != 0 && nKeysFromX != leftKeys.size()) {
+  // We can not push semi-join down if it has keys from both tables of the 
bottom join
+  return;
+}
 
 // need to convert the semi-join condition and possibly the keys
 final RexNode newSemiJoinFilter;
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java 
b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index 4fd8e82711..841c32a700 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -2666,6 +2666,18 @@ class RelOptRulesTest extends RelOptTestBase {
 .check();
   }
 
+  @Test void testPushSemiJoinPastJoinRuleNotHappensJoinKeysDifferentOrigin() {
+// tests the case where the semijoin is not pushed because it uses join 
keys from both tables
+// of the bottom join.
+final String sql = "select e.ename from emp e, dept d, bonus b\n"
++ "where e.deptno = d.deptno and e.ename = b.ename and d.name = b.job";
+sql(sql)
+.withRule(CoreRules.FILTER_INTO_JOIN,
+CoreRules.JOIN_ADD_REDUNDANT_SEMI_JOIN,
+CoreRules.SEMI_JOIN_JOIN_TRANSPOSE)
+.check();
+  }
+
   @Test void testPushSemiJoinPastFilter() {
 final String sql = "select e.ename from emp e, dept d\n"
 + "where e.deptno = d.deptno and e.ename = 'foo'";
diff --git 
a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml 
b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
index 91c54a496b..72567797e3 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -10533,6 +10533,37 @@ LogicalProject(ENAME=[$1])
 LogicalTableScan(table=[[CATALOG, SALES, EMP]])
   LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
 LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+
+  
+  
+
+  
+
+
+  
+
+
+  
 
   



[calcite] branch main updated: [CALCITE-5642] Add SHA256, SHA512 functions (enabled in BigQuery and PostgreSQL libraries)

2023-04-25 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new febd06b2cc [CALCITE-5642] Add SHA256, SHA512 functions (enabled in 
BigQuery and PostgreSQL libraries)
febd06b2cc is described below

commit febd06b2cc7815895c4d6aafc3712a63fe1c335f
Author: zoudan 
AuthorDate: Thu Apr 13 22:38:43 2023 +0800

[CALCITE-5642] Add SHA256, SHA512 functions (enabled in BigQuery and 
PostgreSQL libraries)
---
 .../calcite/adapter/enumerable/RexImpTable.java|  4 ++
 .../org/apache/calcite/runtime/SqlFunctions.java   | 20 
 .../calcite/sql/fun/SqlLibraryOperators.java   | 16 ++
 .../org/apache/calcite/util/BuiltInMethod.java |  2 +
 .../org/apache/calcite/test/SqlFunctionsTest.java  | 40 +++
 site/_docs/reference.md|  2 +
 .../org/apache/calcite/test/SqlOperatorTest.java   | 58 ++
 7 files changed, 142 insertions(+)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
index 02525cd38f..92b874ee11 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
@@ -170,6 +170,8 @@ import static 
org.apache.calcite.sql.fun.SqlLibraryOperators.RLIKE;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.RPAD;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.SAFE_CAST;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.SHA1;
+import static org.apache.calcite.sql.fun.SqlLibraryOperators.SHA256;
+import static org.apache.calcite.sql.fun.SqlLibraryOperators.SHA512;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.SINH;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.SOUNDEX;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.SPACE;
@@ -432,6 +434,8 @@ public class RexImpTable {
   defineMethod(FROM_BASE64, BuiltInMethod.FROM_BASE64.method, 
NullPolicy.STRICT);
   defineMethod(MD5, BuiltInMethod.MD5.method, NullPolicy.STRICT);
   defineMethod(SHA1, BuiltInMethod.SHA1.method, NullPolicy.STRICT);
+  defineMethod(SHA256, BuiltInMethod.SHA256.method, NullPolicy.STRICT);
+  defineMethod(SHA512, BuiltInMethod.SHA512.method, NullPolicy.STRICT);
   defineMethod(SUBSTRING, BuiltInMethod.SUBSTRING.method, 
NullPolicy.STRICT);
   defineMethod(LEFT, BuiltInMethod.LEFT.method, NullPolicy.ANY);
   defineMethod(RIGHT, BuiltInMethod.RIGHT.method, NullPolicy.ANY);
diff --git a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java 
b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
index cfd462ceaf..8f726822fd 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
@@ -273,6 +273,26 @@ public class SqlFunctions {
 return DigestUtils.sha1Hex(string.getBytes());
   }
 
+  /** SQL SHA256(string) function. */
+  public static String sha256(String string)  {
+return DigestUtils.sha256Hex(string.getBytes(UTF_8));
+  }
+
+  /** SQL SHA256(string) function for binary string. */
+  public static String sha256(ByteString string)  {
+return DigestUtils.sha256Hex(string.getBytes());
+  }
+
+  /** SQL SHA512(string) function. */
+  public static String sha512(String string)  {
+return DigestUtils.sha512Hex(string.getBytes(UTF_8));
+  }
+
+  /** SQL SHA512(string) function for binary string. */
+  public static String sha512(ByteString string)  {
+return DigestUtils.sha512Hex(string.getBytes());
+  }
+
   /** SQL {@code REGEXP_REPLACE} function with 3 arguments. */
   public static String regexpReplace(String s, String regex,
   String replacement) {
diff --git 
a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java 
b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
index c090845f58..ed3ebd5ff8 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
@@ -1188,6 +1188,22 @@ public abstract class SqlLibraryOperators {
   OperandTypes.STRING.or(OperandTypes.BINARY),
   SqlFunctionCategory.STRING);
 
+  @LibraryOperator(libraries = {BIG_QUERY, POSTGRESQL})
+  public static final SqlFunction SHA256 =
+  SqlBasicFunction.create("SHA256",
+  ReturnTypes.explicit(SqlTypeName.VARCHAR)
+  .andThen(SqlTypeTransforms.TO_NULLABLE),
+  OperandTypes.STRING.or(OperandTypes.BINARY),
+  SqlFunctionCategory.STRING);
+
+  @LibraryOperator(libraries = {BIG_QUERY, POSTGRESQL})
+  public static final SqlFunction SHA512 =
+  SqlBasicFunction.crea

[calcite] branch main updated (2822518713 -> f500e2f157)

2023-04-21 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


from 2822518713 Disable JIRA worklog notifications for GitHub PRs
 add f500e2f157 [CALCITE-5563] Reduce loops to optimize 
RelSubset#getParents and RelSubset#getParentSubsets

No new revisions were added by this update.

Summary of changes:
 .../org/apache/calcite/plan/volcano/RelSubset.java |  2 +
 .../calcite/plan/volcano/VolcanoPlannerTest.java   | 43 ++
 2 files changed, 45 insertions(+)



[calcite] branch main updated: [CALCITE-5651] Inferred scale for decimal should not exceed maximum allowed scale

2023-04-21 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 1fe1ce8845 [CALCITE-5651] Inferred scale for decimal should not exceed 
maximum allowed scale
1fe1ce8845 is described below

commit 1fe1ce88455f3bbae9ba9c032298695d9c6ffb2b
Author: Mihai Budiu 
AuthorDate: Wed Apr 19 09:32:42 2023 -0700

[CALCITE-5651] Inferred scale for decimal should not exceed maximum allowed 
scale
---
 .../org/apache/calcite/sql/type/SqlTypeUtil.java   |  3 ++-
 .../calcite/rel/rel2sql/RelToSqlConverterTest.java | 27 ++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java 
b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
index 9895c989f9..aef3fd0725 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
@@ -1773,8 +1773,9 @@ public abstract class SqlTypeUtil {
* type system. */
   public static RelDataType getMaxPrecisionScaleDecimal(RelDataTypeFactory 
factory) {
 int maxPrecision = factory.getTypeSystem().getMaxNumericPrecision();
+int maxScale = factory.getTypeSystem().getMaxNumericScale();
 // scale should not greater than precision.
-int scale = maxPrecision / 2;
+int scale = Math.min(maxPrecision / 2, maxScale);
 return factory.createSqlType(SqlTypeName.DECIMAL, maxPrecision, scale);
   }
 
diff --git 
a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java 
b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
index 18644c5672..8cae0d8deb 100644
--- 
a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
+++ 
b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
@@ -4487,6 +4487,19 @@ class RelToSqlConverterTest {
 sql(sql).ok(expected);
   }
 
+  // Test for [CALCITE-5651] Inferred scale for decimal should
+  // not exceed maximum allowed scale
+  @Test void testNumericScale() {
+final String sql = "WITH v(x) AS (VALUES('4.2')) "
++ " SELECT x1 + x2 FROM v AS v1(x1), v AS V2(x2)";
+final String expected = "SELECT CAST(\"t\".\"EXPR$0\" AS "
++ "DECIMAL(39, 10)) + CAST(\"t0\".\"EXPR$0\" AS "
++ "DECIMAL(39, 10))\nFROM (VALUES ('4.2')) AS "
++  "\"t\" (\"EXPR$0\"),\n(VALUES ('4.2')) AS \"t0\" (\"EXPR$0\")";
+sql(sql).withPostgresqlModifiedDecimalTypeSystem()
+.ok(expected);
+  }
+
   @Test void testMatchRecognizePatternExpression2() {
 final String sql = "select *\n"
 + "  from \"product\" match_recognize\n"
@@ -6944,6 +6957,20 @@ class RelToSqlConverterTest {
   return dialect(postgresqlSqlDialect);
 }
 
+Sql withPostgresqlModifiedDecimalTypeSystem() {
+  final PostgresqlSqlDialect postgresqlSqlDialect =
+  new PostgresqlSqlDialect(PostgresqlSqlDialect.DEFAULT_CONTEXT
+  .withDataTypeSystem(new RelDataTypeSystemImpl() {
+@Override public int getMaxNumericScale() {
+  return 10;
+}
+@Override public int getMaxNumericPrecision() {
+  return 39;
+}
+  }));
+  return dialect(postgresqlSqlDialect);
+}
+
 Sql withOracleModifiedTypeSystem() {
   // Oracle dialect with max length for varchar set to 512
   final OracleSqlDialect oracleSqlDialect =



[calcite-avatica] branch main updated: [CALCITE-5494] Time zone tests in DateTimeUtilsTest should pass in Europe/London

2023-01-25 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite-avatica.git


The following commit(s) were added to refs/heads/main by this push:
 new b57eb7cd3 [CALCITE-5494] Time zone tests in DateTimeUtilsTest should 
pass in Europe/London
b57eb7cd3 is described below

commit b57eb7cd31a90d3f46b65c13832b398be5b0dad9
Author: Greg Hart 
AuthorDate: Tue Jan 24 14:48:34 2023 -0800

[CALCITE-5494] Time zone tests in DateTimeUtilsTest should pass in 
Europe/London
---
 .../calcite/avatica/util/DateTimeUtilsTest.java  | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git 
a/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java 
b/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java
index acc08949e..7b03a64ac 100644
--- a/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java
+++ b/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java
@@ -1110,12 +1110,12 @@ public class DateTimeUtilsTest {
 assertThat(sqlDateToUnixDate(new java.sql.Date(utcCal.getTimeInMillis()), 
utcCal), is(0));
 
 final TimeZone minusDayZone = TimeZone.getDefault();
-minusDayZone.setRawOffset((int) (minusDayZone.getOffset(0L) - 
MILLIS_PER_DAY));
+minusDayZone.setRawOffset((int) (minusDayZone.getRawOffset() - 
MILLIS_PER_DAY));
 final Calendar minusDayCal = Calendar.getInstance(minusDayZone, 
Locale.ROOT);
 assertThat(sqlDateToUnixDate(epoch, minusDayCal), is(-1));
 
 final TimeZone plusDayZone = TimeZone.getDefault();
-plusDayZone.setRawOffset((int) (plusDayZone.getOffset(0L) + 
MILLIS_PER_DAY));
+plusDayZone.setRawOffset((int) (plusDayZone.getRawOffset() + 
MILLIS_PER_DAY));
 final Calendar plusDayCal = Calendar.getInstance(plusDayZone, Locale.ROOT);
 assertThat(sqlDateToUnixDate(epoch, plusDayCal), is(1));
   }
@@ -1358,12 +1358,12 @@ public class DateTimeUtilsTest {
 assertThat(sqlTimeToUnixTime(new Time(utcCal.getTimeInMillis()), utcCal), 
is(0));
 
 final TimeZone minusFiveZone = TimeZone.getDefault();
-minusFiveZone.setRawOffset((int) (minusFiveZone.getOffset(0L) - 5 * 
MILLIS_PER_HOUR));
+minusFiveZone.setRawOffset((int) (minusFiveZone.getRawOffset() - 5 * 
MILLIS_PER_HOUR));
 final Calendar minusFiveCal = Calendar.getInstance(minusFiveZone, 
Locale.ROOT);
 assertEquals(19 * MILLIS_PER_HOUR, sqlTimeToUnixTime(epoch, minusFiveCal));
 
 final TimeZone plusFiveZone = TimeZone.getDefault();
-plusFiveZone.setRawOffset((int) (plusFiveZone.getOffset(0L) + 5 * 
MILLIS_PER_HOUR));
+plusFiveZone.setRawOffset((int) (plusFiveZone.getRawOffset() + 5 * 
MILLIS_PER_HOUR));
 final Calendar plusFiveCal = Calendar.getInstance(plusFiveZone, 
Locale.ROOT);
 assertEquals(5 * MILLIS_PER_HOUR, sqlTimeToUnixTime(epoch, plusFiveCal));
   }
@@ -1399,12 +1399,12 @@ public class DateTimeUtilsTest {
 assertThat(unixTimeToSqlTime(0, utcCal).getTime(), 
is(utcCal.getTimeInMillis()));
 
 final TimeZone minusFiveZone = TimeZone.getDefault();
-minusFiveZone.setRawOffset((int) (minusFiveZone.getOffset(0L) - 5 * 
MILLIS_PER_HOUR));
+minusFiveZone.setRawOffset((int) (minusFiveZone.getRawOffset() - 5 * 
MILLIS_PER_HOUR));
 final Calendar minusFiveCal = Calendar.getInstance(minusFiveZone, 
Locale.ROOT);
 assertThat(unixTimeToSqlTime(0, minusFiveCal).toString(), is("05:00:00"));
 
 final TimeZone plusFiveZone = TimeZone.getDefault();
-plusFiveZone.setRawOffset((int) (plusFiveZone.getOffset(0L) + 5 * 
MILLIS_PER_HOUR));
+plusFiveZone.setRawOffset((int) (plusFiveZone.getRawOffset() + 5 * 
MILLIS_PER_HOUR));
 final Calendar plusFiveCal = Calendar.getInstance(plusFiveZone, 
Locale.ROOT);
 assertThat(unixTimeToSqlTime(0, plusFiveCal).toString(), is("19:00:00"));
   }
@@ -1451,13 +1451,13 @@ public class DateTimeUtilsTest {
 is(0L));
 
 final TimeZone minusFiveZone = TimeZone.getDefault();
-minusFiveZone.setRawOffset((int) (minusFiveZone.getOffset(0L) - 5 * 
MILLIS_PER_HOUR));
+minusFiveZone.setRawOffset((int) (minusFiveZone.getRawOffset() - 5 * 
MILLIS_PER_HOUR));
 final Calendar minusFiveCal = Calendar.getInstance(minusFiveZone, 
Locale.ROOT);
 assertThat(sqlTimestampToUnixTimestamp(epoch, minusFiveCal),
 is(-5 * MILLIS_PER_HOUR));
 
 final TimeZone plusFiveZone = TimeZone.getDefault();
-plusFiveZone.setRawOffset((int) (plusFiveZone.getOffset(0L) + 5 * 
MILLIS_PER_HOUR));
+plusFiveZone.setRawOffset((int) (plusFiveZone.getRawOffset() + 5 * 
MILLIS_PER_HOUR));
 final Calendar plusFiveCal = Calendar.getInstance(plusFiveZone, 
Locale.ROOT);
 assertThat(sqlTimestampToUnixTimestamp(epoch, plusFiveCal),
 is(5 * MILLIS_PER_HOUR));
@@ -1557,13 +1557,13 @@ public class DateTimeUtilsTest {
 assertThat(unixTimestampToSqlTimestamp

[calcite] branch main updated: [CALCITE-5471] RelSupplier.SqlRelSupplier#apply should use .project(), not .rel

2023-01-16 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 5607d6b68f [CALCITE-5471] RelSupplier.SqlRelSupplier#apply should use 
.project(), not .rel
5607d6b68f is described below

commit 5607d6b68f87a0bf61cb54ff59cac48fd63d8c0a
Author: Thomas Rebele 
AuthorDate: Fri Jan 13 11:08:42 2023 +0100

[CALCITE-5471] RelSupplier.SqlRelSupplier#apply should use .project(), not 
.rel
---
 .../org/apache/calcite/test/RelOptRulesTest.xml| 83 --
 .../org/apache/calcite/test/TopDownOptTest.xml | 56 ---
 .../java/org/apache/calcite/test/RelSupplier.java  |  2 +-
 3 files changed, 79 insertions(+), 62 deletions(-)

diff --git 
a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml 
b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
index 333a84b07d..321eebfb36 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -13011,16 +13011,18 @@ order by cast(d.deptno as integer) offset 1]]>
 
 
   
 
 
   
 
   
@@ -13031,16 +13033,18 @@ order by cast(d.deptno as double) offset 1]]>
 
 
   
 
 
   
 
   
@@ -13051,9 +13055,10 @@ order by cast(d.deptno as varchar(10)) offset 1]]>
 
 
   
 
 
@@ -13074,21 +13079,23 @@ order by deptno desc nulls last]]>
 
 
   
+
+
+  
-
-
-  
 
   
@@ -13102,22 +13109,24 @@ order by deptno, sal desc nulls first]]>
 
 
   
 
 
   
 
   
diff --git a/core/src/test/resources/org/apache/calcite/test/TopDownOptTest.xml 
b/core/src/test/resources/org/apache/calcite/test/TopDownOptTest.xml
index b84bee83ed..dc58bfac90 100644
--- a/core/src/test/resources/org/apache/calcite/test/TopDownOptTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/TopDownOptTest.xml
@@ -933,16 +933,18 @@ EnumerableSort(sort0=[$0], sort1=[$1], sort2=[$2], 
dir0=[DESC], dir1=[DESC], dir
 
 
   
 
 
   
 
   
@@ -952,16 +954,18 @@ EnumerableSort(sort0=[$1], dir0=[DESC])
 
 
   
 
 
   
 
   
@@ -1564,16 +1568,18 @@ EnumerableSort(sort0=[$0], sort1=[$1], sort2=[$2], 
dir0=[DESC], dir1=[DESC], dir
 
 
   
 
 
   
 
   
@@ -1583,16 +1589,18 @@ EnumerableSort(sort0=[$1], dir0=[DESC])
 
 
   
 
 
   
 
   
diff --git a/testkit/src/main/java/org/apache/calcite/test/RelSupplier.java 
b/testkit/src/main/java/org/apache/calcite/test/RelSupplier.java
index 6b50fe88c9..44a82f54df 100644
--- a/testkit/src/main/java/org/apache/calcite/test/RelSupplier.java
+++ b/testkit/src/main/java/org/apache/calcite/test/RelSupplier.java
@@ -97,7 +97,7 @@ interface RelSupplier {
   return fixture.tester
   .convertSqlToRel(fixture.factory, sql2, fixture.decorrelate,
   fixture.factory.sqlToRelConfig.isTrimUnusedFields())
-  .rel;
+  .project();
 }
 
 @Override public RelNode apply2(RelMetadataFixture metadataFixture) {



[calcite] branch main updated: [CALCITE-5394] RelToSql converter fails when semi-join is under a join node

2022-12-12 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 6bea101b66 [CALCITE-5394] RelToSql converter fails when semi-join is 
under a join node
6bea101b66 is described below

commit 6bea101b664b93d42f171d079a60a67dbbc22607
Author: xiejiajun 
AuthorDate: Sat Nov 26 15:46:45 2022 +0800

[CALCITE-5394] RelToSql converter fails when semi-join is under a join node
---
 .../calcite/rel/rel2sql/RelToSqlConverter.java |  2 +-
 .../calcite/rel/rel2sql/RelToSqlConverterTest.java | 33 ++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java 
b/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
index b877e1fe6f..41ca2e2290 100644
--- a/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
+++ b/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
@@ -298,7 +298,7 @@ public class RelToSqlConverter extends SqlImplementor
 final SqlNode resultNode =
 leftResult.neededAlias == null ? sqlSelect
 : as(sqlSelect, leftResult.neededAlias);
-return result(resultNode, leftResult, rightResult);
+return result(resultNode,  ImmutableList.of(Clause.FROM), e, null);
   }
 
   /** Returns whether this join should be unparsed as a {@link JoinType#COMMA}.
diff --git 
a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java 
b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
index fb89b310b6..940d4b34fa 100644
--- 
a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
+++ 
b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
@@ -1249,6 +1249,39 @@ class RelToSqlConverterTest {
 assertThat(toSql(root), isLinux(expectedSql));
   }
 
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-5394;>[CALCITE-5394]
+   * RelToSql converter fails when semi-join is under a join node. */
+  @Test void testSemiJoinUnderJoin() {
+final RelBuilder builder = relBuilder();
+final RelNode base = builder
+.scan("EMP")
+.scan("EMP")
+.join(
+JoinRelType.SEMI, builder.equals(
+builder.field(2, 0, "EMPNO"),
+builder.field(2, 1, "EMPNO")))
+.build();
+final RelNode root = builder
+.scan("DEPT")
+.push(base)
+.join(
+JoinRelType.INNER, builder.equals(
+builder.field(2, 1, "DEPTNO"),
+builder.field(2, 0, "DEPTNO")))
+.project(builder.field("DEPTNO"))
+.build();
+final String expectedSql = "SELECT \"DEPT\".\"DEPTNO\"\n"
++ "FROM \"scott\".\"DEPT\"\n"
++ "INNER JOIN (SELECT *\n"
++ "FROM \"scott\".\"EMP\"\n"
++ "WHERE EXISTS (SELECT 1\n"
++ "FROM \"scott\".\"EMP\" AS \"EMP0\"\n"
++ "WHERE \"EMP\".\"EMPNO\" = \"EMP0\".\"EMPNO\")) AS \"t\" ON 
\"DEPT\".\"DEPTNO\" = \"t\""
++ ".\"DEPTNO\"";
+assertThat(toSql(root), isLinux(expectedSql));
+  }
+
   /** Test case for
* https://issues.apache.org/jira/browse/CALCITE-2792;>[CALCITE-2792]
* StackOverflowError while evaluating filter with large number of OR



[calcite] branch main updated (81e6f4bf43 -> 0466bd5777)

2022-12-12 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


from 81e6f4bf43 [CALCITE-5388] tempList expression inside 
EnumerableWindow.getPartitionIterator should be unoptimized
 add 0466bd5777 [CALCITE-5395] RelToSql converter fails when SELECT * is 
under a semi-join node

No new revisions were added by this update.

Summary of changes:
 .../calcite/rel/rel2sql/RelToSqlConverter.java |  7 -
 .../calcite/rel/rel2sql/RelToSqlConverterTest.java | 32 ++
 2 files changed, 38 insertions(+), 1 deletion(-)



[calcite] branch main updated: [CALCITE-5377] RelFieldTrimmer support Sort with dynamic param

2022-11-25 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new ad77a20f28 [CALCITE-5377] RelFieldTrimmer support Sort with dynamic 
param
ad77a20f28 is described below

commit ad77a20f286d4b25b26e940e92b40a15acb2e333
Author: xiejiajun 
AuthorDate: Sun Nov 13 14:55:20 2022 +0800

[CALCITE-5377] RelFieldTrimmer support Sort with dynamic param
---
 .../java/org/apache/calcite/sql2rel/RelFieldTrimmer.java| 13 +
 .../java/org/apache/calcite/test/SqlToRelConverterTest.java |  9 +
 .../org/apache/calcite/test/SqlToRelConverterTest.xml   | 13 +
 3 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java 
b/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
index 1862725f84..f1560b7f81 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
@@ -48,7 +48,6 @@ import org.apache.calcite.rel.type.RelDataTypeField;
 import org.apache.calcite.rel.type.RelDataTypeImpl;
 import org.apache.calcite.rex.RexBuilder;
 import org.apache.calcite.rex.RexCorrelVariable;
-import org.apache.calcite.rex.RexDynamicParam;
 import org.apache.calcite.rex.RexFieldAccess;
 import org.apache.calcite.rex.RexLiteral;
 import org.apache.calcite.rex.RexNode;
@@ -666,20 +665,10 @@ public class RelFieldTrimmer implements ReflectiveVisitor 
{
   return result(sort, Mappings.createIdentity(fieldCount));
 }
 
-// leave the Sort unchanged in case we have dynamic limits
-if (sort.offset instanceof RexDynamicParam
-|| sort.fetch instanceof RexDynamicParam) {
-  return result(sort, inputMapping);
-}
-
 relBuilder.push(newInput);
-final int offset =
-sort.offset == null ? 0 : RexLiteral.intValue(sort.offset);
-final int fetch =
-sort.fetch == null ? -1 : RexLiteral.intValue(sort.fetch);
 final ImmutableList fields =
 relBuilder.fields(RexUtil.apply(inputMapping, collation));
-relBuilder.sortLimit(offset, fetch, fields);
+relBuilder.sortLimit(sort.offset, sort.fetch, fields);
 
 // The result has the same mapping as the input gave us. Sometimes we
 // return fields that the consumer didn't ask for, because the filter
diff --git 
a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java 
b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
index ad3c6cc0a5..63885e7a10 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -2598,6 +2598,15 @@ class SqlToRelConverterTest extends SqlToRelTestBase {
 sql(sql).withTrim(true).ok();
   }
 
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-5377;>[CALCITE-5377]
+   * RelFieldTrimmer support Sort with dynamic param. */
+  @Test void testDynamicParameterSortWithTrim() {
+final String sql = "select ename from "
++ "(select * from emp order by sal limit ? offset ?) a";
+sql(sql).withTrim(true).ok();
+  }
+
   /** Test case for
* https://issues.apache.org/jira/browse/CALCITE-3183;>[CALCITE-3183]
* Trimming method for Filter rel uses wrong traitSet. */
diff --git 
a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml 
b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
index bcb6066040..eb23e84764 100644
--- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
@@ -1616,6 +1616,19 @@ LogicalProject(FAKE2=[ITEM($0, 'fake_col2')])
   
+
+  
+  
+
+  
+
+
+  
 
   



[calcite-avatica] branch main updated: [CALCITE-5257] NVARCHAR is treated as 'UNKNOWN TYPE' when searching Oracle

2022-10-21 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite-avatica.git


The following commit(s) were added to refs/heads/main by this push:
 new af0e9e44c [CALCITE-5257] NVARCHAR is treated as 'UNKNOWN TYPE' when 
searching Oracle
af0e9e44c is described below

commit af0e9e44ccff4580c1560835da62e8d593181c86
Author: ILuffZhe 
AuthorDate: Sat Sep 3 12:09:10 2022 +0800

[CALCITE-5257] NVARCHAR is treated as 'UNKNOWN TYPE' when searching Oracle
---
 .../calcite/avatica/util/AbstractCursor.java   |  1 +
 .../calcite/avatica/CursorFactoryDeduceTest.java   | 27 ++
 2 files changed, 28 insertions(+)

diff --git 
a/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java 
b/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java
index b3f68020f..fed875035 100644
--- a/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java
+++ b/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java
@@ -129,6 +129,7 @@ public abstract class AbstractCursor implements Cursor {
 return new FixedStringAccessor(getter, columnMetaData.displaySize);
   }
 case Types.VARCHAR:
+case Types.NVARCHAR:
   return new StringAccessor(getter);
 case Types.BINARY:
 case Types.VARBINARY:
diff --git 
a/core/src/test/java/org/apache/calcite/avatica/CursorFactoryDeduceTest.java 
b/core/src/test/java/org/apache/calcite/avatica/CursorFactoryDeduceTest.java
index 11f0464ed..6050ba425 100644
--- a/core/src/test/java/org/apache/calcite/avatica/CursorFactoryDeduceTest.java
+++ b/core/src/test/java/org/apache/calcite/avatica/CursorFactoryDeduceTest.java
@@ -43,6 +43,8 @@ public class CursorFactoryDeduceTest {
   ColumnMetaData.scalar(Types.INTEGER, "INT", 
ColumnMetaData.Rep.PRIMITIVE_INT);
   static final ColumnMetaData.AvaticaType STRING_TYPE =
   ColumnMetaData.scalar(Types.VARCHAR, "STRING", 
ColumnMetaData.Rep.STRING);
+  static final ColumnMetaData.AvaticaType NVARCHAR_STRING_TYPE =
+  ColumnMetaData.scalar(Types.NVARCHAR, "STRING", 
ColumnMetaData.Rep.STRING);
   static final ColumnMetaData.AvaticaType DOUBLE_TYPE =
   ColumnMetaData.scalar(Types.DOUBLE, "DOUBLE", ColumnMetaData.Rep.DOUBLE);
 
@@ -217,6 +219,31 @@ public class CursorFactoryDeduceTest {
   assertFalse(cursor.next());
 }
   }
+
+  @Test public void deduceRecordCursorFactoryProjectedNvarcharField() throws 
Exception {
+List columnsMetaDataList = Arrays.asList(
+MetaImpl.columnMetaData("stringField", 1, NVARCHAR_STRING_TYPE, true),
+MetaImpl.columnMetaData("doubleField", 2, DOUBLE_TYPE, true)
+);
+Meta.CursorFactory cursorFactory =
+Meta.CursorFactory.deduce(columnsMetaDataList, SimplePOJO.class);
+
+try (Cursor cursor = MetaImpl.createCursor(cursorFactory, ROWS)) {
+  List accessors =
+  cursor.createAccessors(columnsMetaDataList, Unsafe.localCalendar(), 
null);
+
+  assertEquals(columnsMetaDataList.size(), accessors.size());
+  Cursor.Accessor strAccessor = accessors.get(0);
+
+  for (Object row : ROWS) {
+assertTrue(cursor.next());
+SimplePOJO pjo = (SimplePOJO) row;
+assertEquals(pjo.stringField, strAccessor.getObject());
+  }
+
+  assertFalse(cursor.next());
+}
+  }
 }
 
 // End CursorFactoryDeduceTest.java



[calcite-avatica] branch main updated: [CALCITE-4900] NullPointerException when send ExectuteRequest via protobuf with no parameters

2022-10-21 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite-avatica.git


The following commit(s) were added to refs/heads/main by this push:
 new 74a736472 [CALCITE-4900] NullPointerException when send 
ExectuteRequest via protobuf with no parameters
74a736472 is described below

commit 74a7364728b463ba347ad4f921d633a6141b66a7
Author: Aleksey Stavrov 
AuthorDate: Wed Nov 24 13:36:23 2021 +0500

[CALCITE-4900] NullPointerException when send ExectuteRequest via protobuf 
with no parameters
---
 .../org/apache/calcite/avatica/jdbc/JdbcMeta.java  |  4 +--
 .../apache/calcite/avatica/jdbc/JdbcMetaTest.java  | 30 ++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcMeta.java 
b/server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcMeta.java
index 257eead43..363ea4bac 100644
--- a/server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcMeta.java
+++ b/server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcMeta.java
@@ -846,11 +846,11 @@ public class JdbcMeta implements ProtobufMeta {
   @Override public ExecuteResult execute(StatementHandle h,
   List parameterValues, int maxRowsInFirstFrame) throws 
NoSuchStatementException {
 try {
-  if (MetaImpl.checkParameterValueHasNull(parameterValues)) {
+  if (parameterValues != null && 
MetaImpl.checkParameterValueHasNull(parameterValues)) {
 throw new SQLException("exception while executing query: unbound 
parameter");
   }
 
-  final StatementInfo statementInfo = statementCache.getIfPresent(h.id);
+  final StatementInfo statementInfo = 
getStatementCache().getIfPresent(h.id);
   if (null == statementInfo) {
 throw new NoSuchStatementException(h);
   }
diff --git 
a/server/src/test/java/org/apache/calcite/avatica/jdbc/JdbcMetaTest.java 
b/server/src/test/java/org/apache/calcite/avatica/jdbc/JdbcMetaTest.java
index 494b9ab69..7b6787ff7 100644
--- a/server/src/test/java/org/apache/calcite/avatica/jdbc/JdbcMetaTest.java
+++ b/server/src/test/java/org/apache/calcite/avatica/jdbc/JdbcMetaTest.java
@@ -123,6 +123,36 @@ public class JdbcMetaTest {
 Mockito.verify(statement).setMaxRows(maxRows);
   }
 
+  @Test public void testPrepareNoParams() throws Exception {
+final String id = UUID.randomUUID().toString();
+final int statementId = 12345;
+final int maxRows = 500;
+
+JdbcMeta meta = Mockito.mock(JdbcMeta.class);
+
+@SuppressWarnings("unchecked")
+Cache statementCache =
+(Cache) Mockito.mock(Cache.class);
+
+PreparedStatement statement = Mockito.mock(PreparedStatement.class);
+Signature signature = Mockito.mock(Signature.class);
+
+final StatementInfo statementInfo = new StatementInfo(statement);
+final StatementHandle statementHandle = new StatementHandle(id, 
statementId, signature);
+
+Mockito.when(meta.getStatementCache()).thenReturn(statementCache);
+
Mockito.when(statementCache.getIfPresent(statementId)).thenReturn(statementInfo);
+Mockito.when(statement.getResultSet()).thenReturn(null);
+// The real methods
+Mockito.when(meta.execute(statementHandle, null, 
maxRows)).thenCallRealMethod();
+
+// Call our method
+meta.execute(statementHandle, null, maxRows);
+
+// Make sure we call execute and there is no exception
+Mockito.verify(statement).execute();
+  }
+
   @Test public void testConcurrentConnectionOpening() throws Exception {
 final Map properties = Collections.emptyMap();
 final Connection conn = Mockito.mock(Connection.class);



[calcite] branch main updated: [CALCITE-5286] Join with parameterized LIMIT throws AssertionError "not a literal"

2022-10-03 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 3a38ebf40f [CALCITE-5286] Join with parameterized LIMIT throws 
AssertionError "not a literal"
3a38ebf40f is described below

commit 3a38ebf40f6dfc1170ba3d3acc5d8e1f234ed45c
Author: xiejiajun 
AuthorDate: Mon Sep 19 11:12:41 2022 +0800

[CALCITE-5286] Join with parameterized LIMIT throws AssertionError "not a 
literal"
---
 .../calcite/rel/metadata/RelMdMaxRowCount.java |  2 +-
 .../calcite/rel/metadata/RelMdMinRowCount.java |  2 +-
 .../org/apache/calcite/test/RelMetadataTest.java   | 37 ++
 3 files changed, 39 insertions(+), 2 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMaxRowCount.java 
b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMaxRowCount.java
index c8cec39f98..3fe8f4311a 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMaxRowCount.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMaxRowCount.java
@@ -208,7 +208,7 @@ public class RelMdMaxRowCount
 for (RelNode node : rel.getRels()) {
   if (node instanceof Sort) {
 Sort sort = (Sort) node;
-if (sort.fetch != null) {
+if (sort.fetch instanceof RexLiteral) {
   return (double) RexLiteral.intValue(sort.fetch);
 }
   }
diff --git 
a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMinRowCount.java 
b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMinRowCount.java
index 1d392aad13..9fff399917 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMinRowCount.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMinRowCount.java
@@ -168,7 +168,7 @@ public class RelMdMinRowCount
 for (RelNode node : rel.getRels()) {
   if (node instanceof Sort) {
 Sort sort = (Sort) node;
-if (sort.fetch != null) {
+if (sort.fetch instanceof RexLiteral) {
   return (double) RexLiteral.intValue(sort.fetch);
 }
   }
diff --git a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java 
b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
index ee73bcab6b..307c3a9ba9 100644
--- a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
@@ -16,9 +16,12 @@
  */
 package org.apache.calcite.test;
 
+import org.apache.calcite.adapter.enumerable.EnumerableConvention;
 import org.apache.calcite.adapter.enumerable.EnumerableMergeJoin;
+import org.apache.calcite.adapter.enumerable.EnumerableRules;
 import org.apache.calcite.config.CalciteSystemProperty;
 import org.apache.calcite.linq4j.tree.Types;
+import org.apache.calcite.plan.ConventionTraitDef;
 import org.apache.calcite.plan.RelOptCluster;
 import org.apache.calcite.plan.RelOptPlanner;
 import org.apache.calcite.plan.RelOptPredicateList;
@@ -27,6 +30,7 @@ import org.apache.calcite.plan.RelTraitSet;
 import org.apache.calcite.plan.hep.HepPlanner;
 import org.apache.calcite.plan.hep.HepProgram;
 import org.apache.calcite.plan.hep.HepProgramBuilder;
+import org.apache.calcite.plan.volcano.VolcanoPlanner;
 import org.apache.calcite.rel.RelCollation;
 import org.apache.calcite.rel.RelCollationTraitDef;
 import org.apache.calcite.rel.RelCollations;
@@ -644,6 +648,39 @@ public class RelMetadataTest {
 fixture.assertThatRowCount(is(9D), is(0D), is(10d));
   }
 
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-5286;>[CALCITE-5286]
+   * Join with parameterized LIMIT throws AssertionError "not a literal". 
. */
+  @Test void testRowCountJoinWithDynamicParameters() {
+final String sql = "select r.ename, s.sal from\n"
++ "(select * from emp limit ?) r join bonus s\n"
++ "on r.ename=s.ename where r.sal+1=s.sal";
+sql(sql)
+.withCluster(cluster -> {
+  RelOptPlanner planner = new VolcanoPlanner();
+  planner.addRule(EnumerableRules.ENUMERABLE_TABLE_SCAN_RULE);
+  planner.addRule(EnumerableRules.ENUMERABLE_PROJECT_RULE);
+  planner.addRule(EnumerableRules.ENUMERABLE_FILTER_RULE);
+  planner.addRule(EnumerableRules.ENUMERABLE_JOIN_RULE);
+  planner.addRule(EnumerableRules.ENUMERABLE_LIMIT_SORT_RULE);
+  planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
+  return RelOptCluster.create(planner, cluster.getRexBuilder());
+})
+.withRelTransform(rel -> {
+  RelOptPlanner planner = rel.getCluster().getPlanner();
+  planner.setRoot(rel);
+  RelTraitSet requiredOutputTraits =
+  
rel.getCluster().traitSet().replace(EnumerableConvention.INSTANCE);
+  final RelNode rootRel2 = planner.changeTrai

[calcite] branch main updated: [CALCITE-5274] Improve DocumentBuilderFactory in DiffRepository test class by using secure features

2022-09-08 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new d20fd09a1d [CALCITE-5274] Improve DocumentBuilderFactory in 
DiffRepository test class by using secure features
d20fd09a1d is described below

commit d20fd09a1d478a87559027c5f024214f70abb622
Author: rubenada 
AuthorDate: Thu Sep 8 09:49:33 2022 +0100

[CALCITE-5274] Improve DocumentBuilderFactory in DiffRepository test class 
by using secure features
---
 .../org/apache/calcite/test/DiffRepository.java| 32 --
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/testkit/src/main/java/org/apache/calcite/test/DiffRepository.java 
b/testkit/src/main/java/org/apache/calcite/test/DiffRepository.java
index 07bd6260cb..efb9e6718c 100644
--- a/testkit/src/main/java/org/apache/calcite/test/DiffRepository.java
+++ b/testkit/src/main/java/org/apache/calcite/test/DiffRepository.java
@@ -44,6 +44,7 @@ import org.xml.sax.SAXException;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.Writer;
 import java.net.URL;
 import java.util.AbstractList;
@@ -52,6 +53,7 @@ import java.util.List;
 import java.util.Objects;
 import java.util.SortedMap;
 import java.util.TreeMap;
+import javax.xml.XMLConstants;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
@@ -174,6 +176,22 @@ public class DiffRepository {
   private static final LoadingCache REPOSITORY_CACHE =
   CacheBuilder.newBuilder().build(CacheLoader.from(Key::toRepo));
 
+  private static final ThreadLocal<@Nullable DocumentBuilderFactory> 
DOCUMENT_BUILDER_FACTORY =
+  ThreadLocal.withInitial(() -> {
+final DocumentBuilderFactory documentBuilderFactory = 
DocumentBuilderFactory.newInstance();
+documentBuilderFactory.setXIncludeAware(false);
+documentBuilderFactory.setExpandEntityReferences(false);
+documentBuilderFactory.setNamespaceAware(true);
+try {
+  
documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+  documentBuilderFactory
+  
.setFeature("http://apache.org/xml/features/disallow-doctype-decl;, true);
+} catch (final ParserConfigurationException e) {
+  throw new IllegalStateException("Document Builder configuration 
failed", e);
+}
+return documentBuilderFactory;
+  });
+
   //~ Instance fields 
 
   private final DiffRepository baseRepository;
@@ -207,19 +225,17 @@ public class DiffRepository {
 this.modCount = 0;
 
 // Load the document.
-DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
 try {
-  DocumentBuilder docBuilder = fac.newDocumentBuilder();
-  try {
+  DocumentBuilder docBuilder =
+  
Nullness.castNonNull(DOCUMENT_BUILDER_FACTORY.get()).newDocumentBuilder();
+  try (InputStream inputStream = refFile.openStream()) {
 // Parse the reference file.
-this.doc = docBuilder.parse(refFile.openStream());
-// Don't write a log file yet -- as far as we know, it's still
-// identical.
+this.doc = docBuilder.parse(inputStream);
+// Don't write a log file yet -- as far as we know, it's still 
identical.
   } catch (IOException e) {
 // There's no reference file. Create and write a log file.
 this.doc = docBuilder.newDocument();
-this.doc.appendChild(
-doc.createElement(ROOT_TAG));
+this.doc.appendChild(doc.createElement(ROOT_TAG));
 flushDoc();
   }
   this.root = doc.getDocumentElement();



[calcite] branch main updated: [CALCITE-5277] Make EnumerableRelImplementor stashedParameters order deterministic to increase BINDABLE_CACHE hit rate

2022-09-08 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 6302e6fa85 [CALCITE-5277] Make EnumerableRelImplementor 
stashedParameters order deterministic to increase BINDABLE_CACHE hit rate
6302e6fa85 is described below

commit 6302e6fa85be1d8d9efd8277f6a2bf43195776ac
Author: rubenada 
AuthorDate: Thu Sep 8 10:29:05 2022 +0100

[CALCITE-5277] Make EnumerableRelImplementor stashedParameters order 
deterministic to increase BINDABLE_CACHE hit rate
---
 .../adapter/enumerable/EnumerableRelImplementor.java   | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java
index 34386cd030..2c82febd37 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java
@@ -50,6 +50,7 @@ import org.apache.calcite.sql.validate.SqlConformanceEnum;
 import org.apache.calcite.util.BuiltInMethod;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Equivalence;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
@@ -64,7 +65,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.IdentityHashMap;
+import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -80,8 +81,10 @@ public class EnumerableRelImplementor extends 
JavaRelImplementor {
   public final Map map;
   private final Map corrVars =
   new HashMap<>();
-  private final IdentityHashMap stashedParameters 
=
-  new IdentityHashMap<>();
+  private static final Equivalence IDENTITY = Equivalence.identity();
+  // A combination of IdentityHashMap + LinkedHashMap to ensure deterministic 
order
+  private final Map, ParameterExpression> 
stashedParameters =
+  new LinkedHashMap<>();
 
   @SuppressWarnings("methodref.receiver.bound.invalid")
   protected final Function1 
allCorrelateVariables =
@@ -439,7 +442,8 @@ public class EnumerableRelImplementor extends 
JavaRelImplementor {
 || input instanceof Double) {
   return Expressions.constant(input, clazz);
 }
-ParameterExpression cached = stashedParameters.get(input);
+final Equivalence.Wrapper key = IDENTITY.wrap(input);
+ParameterExpression cached = stashedParameters.get(key);
 if (cached != null) {
   return cached;
 }
@@ -448,7 +452,7 @@ public class EnumerableRelImplementor extends 
JavaRelImplementor {
 final String name = "v" + map.size() + "stashed";
 final ParameterExpression x = Expressions.variable(clazz, name);
 map.put(name, input);
-stashedParameters.put(input, x);
+stashedParameters.put(key, x);
 return x;
   }
 



[calcite] branch main updated: [CALCITE-5263] Improve XmlFunctions by using an XML DocumentBuilder

2022-09-07 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new ba80b9156a [CALCITE-5263] Improve XmlFunctions by using an XML 
DocumentBuilder
ba80b9156a is described below

commit ba80b9156afc0db26b194d97a031fcc0dc7f4c03
Author: rubenada 
AuthorDate: Sat Sep 3 19:25:25 2022 +0100

[CALCITE-5263] Improve XmlFunctions by using an XML DocumentBuilder

Co-authored-by: David Handermann 
---
 .../org/apache/calcite/runtime/XmlFunctions.java   | 67 +++---
 .../apache/calcite/test/SqlXmlFunctionsTest.java   | 48 
 2 files changed, 106 insertions(+), 9 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/runtime/XmlFunctions.java 
b/core/src/main/java/org/apache/calcite/runtime/XmlFunctions.java
index 8c81647525..03134321a4 100644
--- a/core/src/main/java/org/apache/calcite/runtime/XmlFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/XmlFunctions.java
@@ -24,7 +24,9 @@ import org.checkerframework.checker.nullness.qual.Nullable;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
 
+import java.io.IOException;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.util.ArrayList;
@@ -33,6 +35,10 @@ import java.util.List;
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.ErrorListener;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Source;
@@ -48,6 +54,7 @@ import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathExpression;
 import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
+import javax.xml.xpath.XPathFactoryConfigurationException;
 
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
 import static org.apache.calcite.util.Static.RESOURCE;
@@ -60,13 +67,41 @@ import static java.util.Objects.requireNonNull;
 public class XmlFunctions {
 
   private static final ThreadLocal<@Nullable XPathFactory> XPATH_FACTORY =
-  ThreadLocal.withInitial(XPathFactory::newInstance);
+  ThreadLocal.withInitial(() -> {
+final XPathFactory xPathFactory = XPathFactory.newInstance();
+try {
+  xPathFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, 
true);
+} catch (XPathFactoryConfigurationException e) {
+  throw new IllegalStateException("XPath Factory configuration 
failed", e);
+}
+return xPathFactory;
+  });
   private static final ThreadLocal<@Nullable TransformerFactory> 
TRANSFORMER_FACTORY =
   ThreadLocal.withInitial(() -> {
-TransformerFactory transformerFactory = 
TransformerFactory.newInstance();
+final TransformerFactory transformerFactory = 
TransformerFactory.newInstance();
 transformerFactory.setErrorListener(new InternalErrorListener());
+try {
+  
transformerFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+} catch (TransformerConfigurationException e) {
+  throw new IllegalStateException("Transformer Factory configuration 
failed", e);
+}
 return transformerFactory;
   });
+  private static final ThreadLocal<@Nullable DocumentBuilderFactory> 
DOCUMENT_BUILDER_FACTORY =
+  ThreadLocal.withInitial(() -> {
+final DocumentBuilderFactory documentBuilderFactory = 
DocumentBuilderFactory.newInstance();
+documentBuilderFactory.setXIncludeAware(false);
+documentBuilderFactory.setExpandEntityReferences(false);
+documentBuilderFactory.setNamespaceAware(true);
+try {
+  
documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+  documentBuilderFactory
+  
.setFeature("http://apache.org/xml/features/disallow-doctype-decl;, true);
+} catch (final ParserConfigurationException e) {
+  throw new IllegalStateException("Document Builder configuration 
failed", e);
+}
+return documentBuilderFactory;
+  });
 
   private static final Pattern VALID_NAMESPACE_PATTERN = Pattern
   .compile("^(([0-9a-zA-Z:_-]+=\"[^\"]*\")( 
[0-9a-zA-Z:_-]+=\"[^\"]*\")*)$");
@@ -81,10 +116,11 @@ public class XmlFunctions {
   return null;
 }
 try {
+  final Node documentNode = getDocumentNode(input);
   XPathExpression xpathExpression = 
castNonNull(XPATH_FACTORY.get()).newXPath().compile(xpath);
   try {
 NodeList nodes = (NodeList) xpathExpression
-  

[calcite] branch main updated: [CALCITE-4999] ARRAY, MULTISET functions should return a collection of scalars if a sub-query returns 1 column

2022-08-30 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 71e30e2c70 [CALCITE-4999] ARRAY, MULTISET functions should return a 
collection of scalars if a sub-query returns 1 column
71e30e2c70 is described below

commit 71e30e2c70e454bdd09eef12ad239ba510ce
Author: dssysolyatin 
AuthorDate: Mon Aug 29 12:13:50 2022 +0300

[CALCITE-4999] ARRAY, MULTISET functions should return a collection of 
scalars if a sub-query returns 1 column
---
 .../adapter/enumerable/EnumerableCollect.java  | 30 ++-
 .../java/org/apache/calcite/rel/core/Collect.java  | 45 ++
 .../apache/calcite/rel/mutable/MutableRels.java|  3 +-
 .../calcite/rel/rules/SubQueryRemoveRule.java  | 14 ++-
 .../java/org/apache/calcite/rex/RexSubQuery.java   |  9 -
 .../calcite/sql/fun/SqlArrayQueryConstructor.java  |  2 +-
 .../sql/fun/SqlMultisetQueryConstructor.java   |  2 +-
 .../apache/calcite/sql/type/SqlTypeTransforms.java | 21 ++
 .../org/apache/calcite/sql/type/SqlTypeUtil.java   | 22 +++
 .../apache/calcite/sql2rel/SqlToRelConverter.java  |  6 +--
 .../calcite/sql2rel/StandardConvertletTable.java   | 16 ++--
 .../java/org/apache/calcite/test/JdbcTest.java |  2 +-
 .../org/apache/calcite/test/SqlValidatorTest.java  | 32 ++-
 .../org/apache/calcite/test/SqlOperatorTest.java   | 31 +++
 14 files changed, 189 insertions(+), 46 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableCollect.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableCollect.java
index da50dff617..64ead33167 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableCollect.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableCollect.java
@@ -25,8 +25,11 @@ import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.core.Collect;
 import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.type.SqlTypeUtil;
 import org.apache.calcite.util.BuiltInMethod;
 
+import static java.util.Objects.requireNonNull;
+
 /** Implementation of {@link org.apache.calcite.rel.core.Collect} in
  * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention 
enumerable calling convention}. */
 public class EnumerableCollect extends Collect implements EnumerableRel {
@@ -91,15 +94,24 @@ public class EnumerableCollect extends Collect implements 
EnumerableRel {
 Expression child_ =
 builder.append(
 "child", result.block);
-// In the internal representation of multisets , every element must be a 
record. In case the
-// result above is a scalar type we have to wrap it around a physical type 
capable of
-// representing records. For this reason the following conversion is 
necessary.
-// REVIEW zabetak January 7, 2019: If we can ensure that the input to this 
operator
-// has the correct physical type (e.g., respecting the Prefer.ARRAY above) 
then this conversion
-// can be removed.
-Expression conv_ =
-builder.append(
-"converted", result.physType.convertTo(child_, 
JavaRowFormat.ARRAY));
+
+RelDataType collectionComponentType =
+
requireNonNull(rowType().getFieldList().get(0).getType().getComponentType());
+RelDataType childRecordType = 
result.physType.getRowType().getFieldList().get(0).getType();
+
+Expression conv_ = child_;
+if (!SqlTypeUtil.sameNamedType(collectionComponentType, childRecordType)) {
+  // In the internal representation of multisets , every element must be a 
record. In case the
+  // result above is a scalar type we have to wrap it around a physical 
type capable of
+  // representing records. For this reason the following conversion is 
necessary.
+  // REVIEW zabetak January 7, 2019: If we can ensure that the input to 
this operator
+  // has the correct physical type (e.g., respecting the Prefer.ARRAY 
above)
+  // then this conversion can be removed.
+  conv_ =
+  builder.append(
+  "converted", result.physType.convertTo(child_, 
JavaRowFormat.ARRAY));
+}
+
 Expression list_ =
 builder.append("list",
 Expressions.call(conv_,
diff --git a/core/src/main/java/org/apache/calcite/rel/core/Collect.java 
b/core/src/main/java/org/apache/calcite/rel/core/Collect.java
index 28b83c5ff5..50891d5a7e 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/Collect.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/Collect.java
@@ -25,6 +25,7 @@ import org.apache.calcite.rel.RelWriter;
 import org.apache.calcite.rel.SingleRel;
 import org.apac

[calcite-avatica] branch main updated: [CALCITE-5218] Verify HTTP client class before instantiating it

2022-07-26 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite-avatica.git


The following commit(s) were added to refs/heads/main by this push:
 new 0c097b6a6 [CALCITE-5218] Verify HTTP client class before instantiating 
it
0c097b6a6 is described below

commit 0c097b6a685fc1f97f151505a219976f15ed0c4c
Author: rubenada 
AuthorDate: Tue Jul 26 13:21:48 2022 +0100

[CALCITE-5218] Verify HTTP client class before instantiating it
---
 .../avatica/remote/AvaticaHttpClientFactoryImpl.java  | 19 ++-
 .../avatica/remote/AvaticaHttpClientFactoryTest.java  | 14 +-
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaHttpClientFactoryImpl.java
 
b/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaHttpClientFactoryImpl.java
index 420da0e63..e0f3446ae 100644
--- 
a/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaHttpClientFactoryImpl.java
+++ 
b/core/src/main/java/org/apache/calcite/avatica/remote/AvaticaHttpClientFactoryImpl.java
@@ -138,14 +138,23 @@ public class AvaticaHttpClientFactoryImpl implements 
AvaticaHttpClientFactory {
   }
 
   private AvaticaHttpClient instantiateClient(String className, URL url) {
+AvaticaHttpClient client = null;
+Exception clientCreationException = null;
 try {
-  Class clz = Class.forName(className);
-  Constructor constructor = clz.getConstructor(URL.class);
-  Object instance = constructor.newInstance(Objects.requireNonNull(url));
-  return AvaticaHttpClient.class.cast(instance);
+  // Ensure that the given class is actually a subclass of 
AvaticaHttpClient
+  Class clz =
+  Class.forName(className).asSubclass(AvaticaHttpClient.class);
+  Constructor constructor = 
clz.getConstructor(URL.class);
+  client = constructor.newInstance(Objects.requireNonNull(url));
 } catch (Exception e) {
+  clientCreationException = e;
+}
+
+if (client == null) {
   throw new RuntimeException("Failed to construct AvaticaHttpClient 
implementation "
-  + className, e);
+  + className, clientCreationException);
+} else {
+  return client;
 }
   }
 
diff --git 
a/core/src/test/java/org/apache/calcite/avatica/remote/AvaticaHttpClientFactoryTest.java
 
b/core/src/test/java/org/apache/calcite/avatica/remote/AvaticaHttpClientFactoryTest.java
index 8e1397c14..27c9bcbd6 100644
--- 
a/core/src/test/java/org/apache/calcite/avatica/remote/AvaticaHttpClientFactoryTest.java
+++ 
b/core/src/test/java/org/apache/calcite/avatica/remote/AvaticaHttpClientFactoryTest.java
@@ -43,7 +43,7 @@ public class AvaticaHttpClientFactoryTest {
 client instanceof AvaticaCommonsHttpClientImpl);
   }
 
-  @Test public void testOverridenHttpClient() throws Exception {
+  @Test public void testOverriddenHttpClient() throws Exception {
 Properties props = new Properties();
 props.setProperty(BuiltInConnectionProperty.HTTP_CLIENT_IMPL.name(),
 AvaticaHttpClientImpl.class.getName());
@@ -55,6 +55,18 @@ public class AvaticaHttpClientFactoryTest {
 assertTrue("Client was an instance of " + client.getClass(),
 client instanceof AvaticaHttpClientImpl);
   }
+
+  @Test(expected = RuntimeException.class) public void testInvalidHttpClient() 
throws Exception {
+Properties props = new Properties();
+props.setProperty(BuiltInConnectionProperty.HTTP_CLIENT_IMPL.name(),
+Properties.class.getName()); // Properties is intentionally *not* a 
valid class
+URL url = new URL("http://localhost:8765;);
+ConnectionConfig config = new ConnectionConfigImpl(props);
+AvaticaHttpClientFactory httpClientFactory = new 
AvaticaHttpClientFactoryImpl();
+
+// This should throw since the Properties class is invalid
+httpClientFactory.getClient(url, config, null);
+  }
 }
 
 // End AvaticaHttpClientFactoryTest.java



[calcite] branch main updated: [CALCITE-5045] Alias within GroupingSets throws type mis-match exception [CALCITE-5145] CASE statement within GROUPING SETS throws type mis-match exception

2022-06-28 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 44082a08a1 [CALCITE-5045] Alias within GroupingSets throws type 
mis-match exception [CALCITE-5145] CASE statement within GROUPING SETS throws 
type mis-match exception
44082a08a1 is described below

commit 44082a08a11a7a62a73fda7bf4e5f423130aabc5
Author: hannerwang 
AuthorDate: Fri Jun 24 11:38:44 2022 +0800

[CALCITE-5045] Alias within GroupingSets throws type mis-match exception 
[CALCITE-5145] CASE statement within GROUPING SETS throws type mis-match 
exception

Co-authored-by: yingyuwang 
---
 .../calcite/sql/validate/SqlValidatorImpl.java |  9 +++-
 .../apache/calcite/test/SqlToRelConverterTest.java | 48 +
 .../apache/calcite/test/SqlToRelConverterTest.xml  | 50 ++
 3 files changed, 106 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java 
b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
index 19ef6aadf2..a5df51b875 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
@@ -460,7 +460,14 @@ public class SqlValidatorImpl implements 
SqlValidatorWithHints {
 if (expanded != null) {
   inferUnknownTypes(targetType, scope, expanded);
 }
-final RelDataType type = deriveType(selectScope, expanded);
+RelDataType type = deriveType(selectScope, expanded);
+// Re-derive SELECT ITEM's data type that may be nullable in 
AggregatingSelectScope when it
+// appears in advanced grouping elements such as CUBE, ROLLUP , GROUPING 
SETS.
+// For example, SELECT CASE WHEN c = 1 THEN '1' ELSE '23' END AS x FROM t 
GROUP BY CUBE(x),
+// the 'x' should be nullable even if x's literal values are not null.
+if (selectScope instanceof AggregatingSelectScope) {
+  type = requireNonNull(selectScope.nullifyType(stripAs(expanded), type));
+}
 setValidatedNodeType(expanded, type);
 fields.add(Pair.of(alias, type));
 return false;
diff --git 
a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java 
b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
index d554a2a41e..a7e4c63643 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -4545,4 +4545,52 @@ class SqlToRelConverterTest extends SqlToRelTestBase {
 + "ROLLUP (deptno, job)";
 sql(sql).ok();
   }
+
+  /**
+   * Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-5045;>[CALCITE-5045]
+   * Alias within GroupingSets throws type mis-match exception.
+   */
+  @Test void testAliasWithinGroupingSets() {
+final String sql = "SELECT empno / 2 AS x\n"
++ "FROM emp\n"
++ "GROUP BY ROLLUP(x)";
+sql(sql)
+.withConformance(SqlConformanceEnum.LENIENT)
+.ok();
+  }
+
+  /**
+   * Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-5145;>[CALCITE-5145]
+   * CASE statement within GROUPING SETS throws type mis-match exception.
+   */
+  @Test public void testCaseAliasWithinGroupingSets() {
+sql("SELECT empno,\n"
++ "CASE\n"
++ "WHEN ename in ('Fred','Eric') THEN 'CEO'\n"
++ "ELSE 'Other'\n"
++ "END AS derived_col\n"
++ "FROM emp\n"
++ "GROUP BY GROUPING SETS ((empno, derived_col),(empno))")
+.withConformance(SqlConformanceEnum.LENIENT).ok();
+  }
+
+  /**
+   * Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-5145;>[CALCITE-5145]
+   * CASE statement within GROUPING SETS throws type mis-match exception.
+   */
+  @Test void testCaseWithinGroupingSets() {
+String sql = "SELECT empno,\n"
++ "CASE WHEN ename IN ('Fred','Eric') THEN 'Manager' ELSE 'Other' 
END\n"
++ "FROM emp\n"
++ "GROUP BY GROUPING SETS (\n"
++ "(empno, CASE WHEN ename IN ('Fred','Eric') THEN 'Manager' ELSE 
'Other' END),\n"
++ "(empno)\n"
++ ")";
+sql(sql)
+.withConformance(SqlConformanceEnum.LENIENT)
+.ok();
+  }
 }
diff --git 
a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml 
b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
index 85d87445e6..521ff3f251 100644
--- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
@@ -315,6 +315,20 @@ from dept_nested_expanded as d,
  UNNEST(d.employees) as t(employee)]]>
 
   
+  
+
+  
+
+
+  
+
+  
   
 
   
@@ -421,6 +435,42 @@ LogicalValues(tuples=[[{ 1 }]])
   
 
   
+  
+
+  
+
+
+  
+
+  
+  
+
+  
+
+
+  
+
+  
   
 
   

[calcite] branch main updated: [CALCITE-5177] Query loses hint after decorrelation (minor follow-up)

2022-06-21 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 4a01c99e9d [CALCITE-5177] Query loses hint after decorrelation (minor 
follow-up)
4a01c99e9d is described below

commit 4a01c99e9d1fdf8742e909159a2a0292d8519e7e
Author: rubenada 
AuthorDate: Mon Jun 13 09:57:55 2022 +0100

[CALCITE-5177] Query loses hint after decorrelation (minor follow-up)
---
 core/src/main/java/org/apache/calcite/plan/RelOptUtil.java | 4 
 core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java 
b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
index c7b5c7cbcc..0b5f1ddd12 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
@@ -475,6 +475,10 @@ public abstract class RelOptUtil {
* or {@code newRel} directly if one of them are not {@link Hintable}
*/
   public static RelNode copyRelHints(RelNode originalRel, RelNode newRel, 
boolean filterHints) {
+if (originalRel == newRel && !filterHints) {
+  return originalRel;
+}
+
 if (originalRel instanceof Hintable
 && newRel instanceof Hintable
 && ((Hintable) originalRel).getHints().size() > 0) {
diff --git a/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java 
b/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
index 3790026bf7..1862725f84 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
@@ -297,7 +297,7 @@ public class RelFieldTrimmer implements ReflectiveVisitor {
   assert newFieldCount > 0 : "rel has no fields after trim: " + rel;
 }
 if (newRel.equals(rel)) {
-  return result(rel, mapping, rel);
+  return result(rel, mapping);
 }
 return trimResult;
   }



[calcite] branch main updated: [CALCITE-4897] Implicit type conversion is not complete for set operation in DML

2022-06-21 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 9a102e77dd [CALCITE-4897] Implicit type conversion is not complete for 
set operation in DML
9a102e77dd is described below

commit 9a102e77dd2f7b566b0a4a8cb0d504c6c572e1e1
Author: xiejiajun 
AuthorDate: Sat Nov 20 16:37:58 2021 +0800

[CALCITE-4897] Implicit type conversion is not complete for set operation 
in DML
---
 .../sql/validate/implicit/TypeCoercionImpl.java|  9 +++--
 .../apache/calcite/test/TypeCoercionConverterTest.java | 18 ++
 .../apache/calcite/test/TypeCoercionConverterTest.xml  | 17 +
 3 files changed, 42 insertions(+), 2 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/sql/validate/implicit/TypeCoercionImpl.java
 
b/core/src/main/java/org/apache/calcite/sql/validate/implicit/TypeCoercionImpl.java
index ce562a9a51..1dd383f8ca 100644
--- 
a/core/src/main/java/org/apache/calcite/sql/validate/implicit/TypeCoercionImpl.java
+++ 
b/core/src/main/java/org/apache/calcite/sql/validate/implicit/TypeCoercionImpl.java
@@ -121,8 +121,13 @@ public class TypeCoercionImpl extends AbstractTypeCoercion 
{
   // Set operations are binary for now.
   final SqlCall operand0 = ((SqlCall) query).operand(0);
   final SqlCall operand1 = ((SqlCall) query).operand(1);
-  final boolean coerced = rowTypeCoercion(scope, operand0, columnIndex, 
targetType)
-  && rowTypeCoercion(scope, operand1, columnIndex, targetType);
+  // Operand1 should be coerced even if operand0 not need to be coerced.
+  // For example, we have one table named t:
+  // INSERT INTO t -- only one column is c(int).
+  // SELECT 1 UNION   -- operand0 not need to be coerced.
+  // SELECT 1.0  -- operand1 should be coerced.
+  boolean coerced = rowTypeCoercion(scope, operand0, columnIndex, 
targetType);
+  coerced = rowTypeCoercion(scope, operand1, columnIndex, targetType) || 
coerced;
   // Update the nested SET operator node type.
   if (coerced) {
 updateInferredColumnType(
diff --git 
a/core/src/test/java/org/apache/calcite/test/TypeCoercionConverterTest.java 
b/core/src/test/java/org/apache/calcite/test/TypeCoercionConverterTest.java
index ac7fbb185e..31584f8dbe 100644
--- a/core/src/test/java/org/apache/calcite/test/TypeCoercionConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/TypeCoercionConverterTest.java
@@ -126,6 +126,24 @@ class TypeCoercionConverterTest extends SqlToRelTestBase {
 sql(sql).ok();
   }
 
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-4897;>[CALCITE-4897]
+   * Set operation in DML, implicit type conversion is not complete. */
+  @Test void testInsertUnionQuerySourceCoercion() {
+final String sql = "insert into t1 "
++ "select 'a', 1, 1.0,"
++ " 0, 0, 0, 0, TIMESTAMP '2021-11-28 00:00:00', date '2021-11-28', 
x'0A', false union "
++ "select 'b', 2, 2,"
++ " 0, 0, 0, 0, TIMESTAMP '2021-11-28 00:00:00', date '2021-11-28', 
x'0A', false union "
++ "select 'c', CAST(3 AS SMALLINT), 3.0,"
++ " 0, 0, 0, 0, TIMESTAMP '2021-11-28 00:00:00', date '2021-11-28', 
x'0A', false union "
++ "select 'd', 4, 4.0,"
++ " 0, 0, 0, 0, TIMESTAMP '2021-11-28 00:00:00', date '2021-11-28', 
x'0A', false union "
++ "select 'e', 5, 5.0,"
++ " 0, 0, 0, 0, TIMESTAMP '2021-11-28 00:00:00', date '2021-11-28', 
x'0A', false";
+sql(sql).ok();
+  }
+
   @Test void testUpdateQuerySourceCoercion() {
 final String sql = "update t1 set t1_varchar20=123, "
 + "t1_date=TIMESTAMP '2020-01-03 10:14:34', t1_int=12.3";
diff --git 
a/core/src/test/resources/org/apache/calcite/test/TypeCoercionConverterTest.xml 
b/core/src/test/resources/org/apache/calcite/test/TypeCoercionConverterTest.xml
index 7e3fc66395..ad89bd778e 100644
--- 
a/core/src/test/resources/org/apache/calcite/test/TypeCoercionConverterTest.xml
+++ 
b/core/src/test/resources/org/apache/calcite/test/TypeCoercionConverterTest.xml
@@ -114,6 +114,23 @@ t2_double, t2_decimal, t2_int, t2_date, t2_timestamp, 
t2_varchar20, t2_int from
 LogicalTableModify(table=[[CATALOG, SALES, T1]], operation=[INSERT], 
flattened=[false])
   LogicalProject(t1_varchar20=[CAST($1):VARCHAR(20) NOT NULL], 
t1_smallint=[CAST($2):SMALLINT NOT NULL], t1_int=[CAST($3):INTEGER NOT NULL], 
t1_bigint=[CAST($4):BIGINT NOT NULL], t1_float=[CAST($5):FLOAT NOT NULL], 
t1_double=[CAST($6):DOUBLE NOT NULL], t1_decimal=[CAST($2):DECIMAL(19, 0) NOT 
NULL], t1_timestamp=[CAST($8):TIMESTAMP(0) NOT NULL], t1_date=[CAST($7):DATE 
NOT NULL], t1_binary=[CAST($0):BINARY(1) NOT NULL], t1_b

[calcite] branch main updated: [CALCITE-5134] Queries with subquery inside select list does not work if subquery uses table from left join

2022-06-17 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new de41df4d11 [CALCITE-5134] Queries with subquery inside select list 
does not work if subquery uses table from left join
de41df4d11 is described below

commit de41df4d117041fbee042e07f70e6043f1fe626d
Author: Benchao Li 
AuthorDate: Thu May 5 22:00:32 2022 +0800

[CALCITE-5134] Queries with subquery inside select list does not work if 
subquery uses table from left join
---
 .../org/apache/calcite/sql/validate/ListScope.java   | 18 ++
 .../apache/calcite/sql2rel/SqlToRelConverter.java|  8 +++-
 .../apache/calcite/test/SqlToRelConverterTest.java   |  8 
 .../apache/calcite/test/SqlToRelConverterTest.xml| 20 
 4 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java 
b/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java
index 656205b3c7..b86472d5b4 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java
@@ -80,6 +80,24 @@ public abstract class ListScope extends DelegatingScope {
 return Util.transform(children, scopeChild -> scopeChild.name);
   }
 
+  /**
+   * Whether the ith child namespace produces nullable result.
+   *
+   * For example, in below query,
+   * 
+   *   SELECT *
+   *   FROM EMPS
+   *   LEFT OUTER JOIN DEPT
+   * 
+   * the namespace which corresponding to 'DEPT' is nullable.
+   *
+   * @param i The child index.
+   * @return Whether it's nullable.
+   */
+  public boolean isChildNullable(int i) {
+return children.get(i).nullable;
+  }
+
   private @Nullable ScopeChild findChild(List names,
   SqlNameMatcher nameMatcher) {
 for (ScopeChild child : children) {
diff --git 
a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java 
b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
index 166b593f1f..b0b7bdfa77 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
@@ -4911,7 +4911,13 @@ public class SqlToRelConverter {
   int i = 0;
   int offset = 0;
   for (SqlValidatorNamespace c : ancestorScope1.getChildren()) {
-builder.addAll(c.getRowType().getFieldList());
+if (ancestorScope1.isChildNullable(i)) {
+  for (final RelDataTypeField f : c.getRowType().getFieldList()) {
+builder.add(f.getName(), 
typeFactory.createTypeWithNullability(f.getType(), true));
+  }
+} else {
+  builder.addAll(c.getRowType().getFieldList());
+}
 if (i == resolve.path.steps().get(0).i) {
   for (RelDataTypeField field : c.getRowType().getFieldList()) {
 fields.put(field.getName(), field.getIndex() + offset);
diff --git 
a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java 
b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
index f4954e6daa..b853bc3822 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -2639,6 +2639,14 @@ class SqlToRelConverterTest extends SqlToRelTestBase {
 sql(sql).withExpand(false).ok();
   }
 
+  @Test void testCorrelatedForOuterFields() {
+final String sql = "SELECT ARRAY(SELECT dept.deptno)\n"
++ "FROM emp\n"
++ "LEFT OUTER JOIN dept\n"
++ "ON emp.empno = dept.deptno";
+sql(sql).ok();
+  }
+
   /**
* Test case for
* https://issues.apache.org/jira/browse/CALCITE-614;>[CALCITE-614]
diff --git 
a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml 
b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
index 82465eaad8..1a23e65d0e 100644
--- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
@@ -624,6 +624,26 @@ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], 
HIREDATE=[$4], SAL=[$
 LogicalTableScan(table=[[CATALOG, SALES, EMP]])
 })])
   LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+]]>
+
+  
+  
+
+  
+
+
+  
 
   



[calcite] branch main updated: [CALCITE-5177] Query loses hint after decorrelation

2022-06-13 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new b0b3e3e64 [CALCITE-5177] Query loses hint after decorrelation
b0b3e3e64 is described below

commit b0b3e3e645b57ab22d7f9a31a00a3210be6e87a5
Author: rubenada 
AuthorDate: Tue Jun 7 11:18:45 2022 +0100

[CALCITE-5177] Query loses hint after decorrelation
---
 .../apache/calcite/sql2rel/RelDecorrelator.java|  8 +--
 .../apache/calcite/sql2rel/RelFieldTrimmer.java| 41 +++---
 .../sql2rel/RelStructuredTypeFlattener.java|  4 +-
 .../apache/calcite/test/SqlHintsConverterTest.java | 42 ++
 .../apache/calcite/test/SqlHintsConverterTest.xml  | 66 ++
 5 files changed, 133 insertions(+), 28 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java 
b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
index 7347eeb64..1786ffcaa 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
@@ -586,8 +586,6 @@ public class RelDecorrelator implements ReflectiveVisitor {
 .projectNamed(Pair.left(projects), Pair.right(projects), true)
 .build();
 
-newProject = RelOptUtil.copyRelHints(newInput, newProject);
-
 // update mappings:
 // oldInput > newInput
 //
@@ -682,7 +680,7 @@ public class RelDecorrelator implements ReflectiveVisitor {
   relBuilder.project(postProjects);
 }
 
-RelNode newRel = RelOptUtil.copyRelHints(rel, relBuilder.build());
+RelNode newRel = relBuilder.build();
 
 // Aggregate does not change input ordering so corVars will be
 // located at the same position as the input newProject.
@@ -793,8 +791,6 @@ public class RelDecorrelator implements ReflectiveVisitor {
 .projectNamed(Pair.left(projects), Pair.right(projects), true)
 .build();
 
-newProject = RelOptUtil.copyRelHints(rel, newProject);
-
 return register(rel, newProject, mapOldToNewOutputs, corDefOutputs);
   }
 
@@ -1305,7 +1301,6 @@ public class RelDecorrelator implements ReflectiveVisitor 
{
 .join(rel.getJoinType(),
 decorrelateExpr(castNonNull(currentRel), map, cm, 
rel.getCondition()),
 ImmutableSet.of())
-.hints(rel.getHints())
 .build();
 
 // Create the mapping between the output of the old correlation rel
@@ -1595,6 +1590,7 @@ public class RelDecorrelator implements ReflectiveVisitor 
{
   Frame register(RelNode rel, RelNode newRel,
   Map oldToNewOutputs,
   NavigableMap corDefOutputs) {
+newRel = RelOptUtil.copyRelHints(rel, newRel);
 final Frame frame = new Frame(rel, newRel, corDefOutputs, oldToNewOutputs);
 map.put(rel, frame);
 return frame;
diff --git a/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java 
b/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
index 2a53e9427..3790026bf 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
@@ -265,7 +265,7 @@ public class RelFieldTrimmer implements ReflectiveVisitor {
 relBuilder.push(trimResult.left)
 .project(exprList, nameList);
 return result(relBuilder.build(),
-Mappings.createIdentity(fieldList.size()));
+Mappings.createIdentity(fieldList.size()), rel);
   }
 
   /**
@@ -297,11 +297,15 @@ public class RelFieldTrimmer implements ReflectiveVisitor 
{
   assert newFieldCount > 0 : "rel has no fields after trim: " + rel;
 }
 if (newRel.equals(rel)) {
-  return result(rel, mapping);
+  return result(rel, mapping, rel);
 }
 return trimResult;
   }
 
+  protected TrimResult result(RelNode rel, final Mapping mapping, RelNode 
oldRel) {
+return result(RelOptUtil.copyRelHints(oldRel, rel), mapping);
+  }
+
   protected TrimResult result(RelNode r, final Mapping mapping) {
 final RexBuilder rexBuilder = relBuilder.getRexBuilder();
 for (final CorrelationId correlation : r.getVariablesSet()) {
@@ -370,7 +374,7 @@ public class RelFieldTrimmer implements ReflectiveVisitor {
   newInputs.add(trimResult.left);
 }
 RelNode newRel = rel.copy(rel.getTraitSet(), newInputs);
-return result(newRel, 
Mappings.createIdentity(newRel.getRowType().getFieldCount()));
+return result(newRel, 
Mappings.createIdentity(newRel.getRowType().getFieldCount()), rel);
   }
 
   /**
@@ -462,7 +466,7 @@ public class RelFieldTrimmer implements ReflectiveVisitor {
 newProjects, newConditionExpr, newRowType.getFieldNames(),
 newInputRelNode.getCluster().getRexBuilder());
 final Calc newCalc = calc.copy(calc.getTraitSet(), newInputRelNode, 
newRexProgram);
-retur

[calcite] branch main updated: [CALCITE-5061] Improve recursive application of the field trimming

2022-05-18 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new dc2e1af5c1 [CALCITE-5061] Improve recursive application of the field 
trimming
dc2e1af5c1 is described below

commit dc2e1af5c168f01a045edc3fb3f1970418b2a03a
Author: rubenada 
AuthorDate: Fri May 13 15:23:34 2022 +0100

[CALCITE-5061] Improve recursive application of the field trimming
---
 .../apache/calcite/sql2rel/RelFieldTrimmer.java| 24 +++--
 .../calcite/sql2rel/RelFieldTrimmerTest.java   | 29 +++
 .../java/org/apache/calcite/test/JdbcTest.java | 10 ++--
 .../java/org/apache/calcite/test/StreamTest.java   | 21 
 .../test/enumerable/EnumerableJoinTest.java| 16 +++---
 .../test/enumerable/EnumerableRepeatUnionTest.java |  6 +--
 .../org/apache/calcite/test/RelOptRulesTest.xml| 58 +++---
 7 files changed, 103 insertions(+), 61 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java 
b/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
index fff44d9694..2a53e9427c 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
@@ -352,11 +352,25 @@ public class RelFieldTrimmer implements ReflectiveVisitor 
{
   RelNode rel,
   ImmutableBitSet fieldsUsed,
   Set extraFields) {
-// We don't know how to trim this kind of relational expression, so give
-// it back intact.
+// We don't know how to trim this kind of relational expression
 Util.discard(fieldsUsed);
-return result(rel,
-Mappings.createIdentity(rel.getRowType().getFieldCount()));
+if (rel.getInputs().isEmpty()) {
+  return result(rel, 
Mappings.createIdentity(rel.getRowType().getFieldCount()));
+}
+
+// We don't know how to trim this RelNode, but we can try to trim inside 
its inputs
+List newInputs = new ArrayList<>(rel.getInputs().size());
+for (RelNode input : rel.getInputs()) {
+  ImmutableBitSet inputFieldsUsed = 
ImmutableBitSet.range(input.getRowType().getFieldCount());
+  TrimResult trimResult = dispatchTrimFields(input, inputFieldsUsed, 
extraFields);
+  if (!trimResult.right.isIdentity()) {
+throw new IllegalArgumentException("Expected identity mapping after 
processing RelNode "
++ input + "; but got " + trimResult.right);
+  }
+  newInputs.add(trimResult.left);
+}
+RelNode newRel = rel.copy(rel.getTraitSet(), newInputs);
+return result(newRel, 
Mappings.createIdentity(newRel.getRowType().getFieldCount()));
   }
 
   /**
@@ -914,7 +928,7 @@ public class RelFieldTrimmer implements ReflectiveVisitor {
 // They can not be trimmed because the comparison needs
 // complete fields.
 if (!(setOp.kind == SqlKind.UNION && setOp.all)) {
-  return result(setOp, Mappings.createIdentity(fieldCount));
+  return trimFields((RelNode) setOp, fieldsUsed, extraFields);
 }
 
 int changeCount = 0;
diff --git 
a/core/src/test/java/org/apache/calcite/sql2rel/RelFieldTrimmerTest.java 
b/core/src/test/java/org/apache/calcite/sql2rel/RelFieldTrimmerTest.java
index 81d3620ce6..8f10a2cef7 100644
--- a/core/src/test/java/org/apache/calcite/sql2rel/RelFieldTrimmerTest.java
+++ b/core/src/test/java/org/apache/calcite/sql2rel/RelFieldTrimmerTest.java
@@ -516,4 +516,33 @@ class RelFieldTrimmerTest {
   assertThat(trimmed, hasTree(expected));
 }
   }
+
+  @Test void testUnionFieldTrimmer() {
+final RelBuilder builder = RelBuilder.create(config().build());
+final RelNode root =
+builder.scan("EMP").as("t1")
+.project(builder.field("EMPNO"))
+.scan("EMP").as("t2")
+.scan("EMP").as("t3")
+.join(JoinRelType.INNER,
+builder.equals(
+builder.field(2, "t2", "EMPNO"),
+builder.field(2, "t3", "EMPNO")))
+.project(builder.field("t2", "EMPNO"))
+.union(false)
+.build();
+final RelFieldTrimmer fieldTrimmer = new RelFieldTrimmer(null, builder);
+final RelNode trimmed = fieldTrimmer.trim(root);
+final String expected = ""
++ "LogicalUnion(all=[false])\n"
++ "  LogicalProject(EMPNO=[$0])\n"
++ "LogicalTableScan(table=[[scott, EMP]])\n"
++ "  LogicalProject(EMPNO=[$0])\n"
++ "LogicalJoin(condition=[=($0, $1)], joinType=[inner])\n"
++ "  LogicalProject(EMPNO=[$0])\n"
++ "LogicalTableScan(table=[[scott, EMP]])\n&quo

[calcite] branch main updated: [CALCITE-5003] MergeUnion on types with different collators produces wrong result

2022-05-05 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
 new 2789f5e4c3 [CALCITE-5003] MergeUnion on types with different collators 
produces wrong result
2789f5e4c3 is described below

commit 2789f5e4c361b052967f42b87447f04cc1ce7896
Author: rubenada 
AuthorDate: Fri Apr 29 09:41:10 2022 +0100

[CALCITE-5003] MergeUnion on types with different collators produces wrong 
result
---
 .../enumerable/EnumerableMergeUnionRule.java   | 42 +-
 .../enumerable/EnumerableStringComparisonTest.java | 34 ++
 2 files changed, 75 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeUnionRule.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeUnionRule.java
index e72d9c63c4..2976f3e6dc 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeUnionRule.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeUnionRule.java
@@ -19,18 +19,24 @@ package org.apache.calcite.adapter.enumerable;
 import org.apache.calcite.plan.RelOptRuleCall;
 import org.apache.calcite.plan.RelRule;
 import org.apache.calcite.rel.RelCollation;
+import org.apache.calcite.rel.RelFieldCollation;
 import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.core.Sort;
 import org.apache.calcite.rel.core.Union;
 import org.apache.calcite.rel.logical.LogicalSort;
 import org.apache.calcite.rel.logical.LogicalUnion;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
 import org.apache.calcite.rex.RexLiteral;
 import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.ImmutableBitSet;
 
 import org.immutables.value.Value;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * Rule to convert a {@link org.apache.calcite.rel.logical.LogicalSort} on top 
of a
@@ -90,9 +96,43 @@ public class EnumerableMergeUnionRule extends 
RelRule unionFieldList = 
union.getRowType().getFieldList();
 final List inputs = new ArrayList<>(unionInputsSize);
 for (RelNode input : union.getInputs()) {
-  final RelNode newInput = sort.copy(sort.getTraitSet(), input, collation, 
null, inputFetch);
+  // Check if type collations match, otherwise store it in this bitset to 
generate a cast later
+  // to guarantee that all inputs will be sorted in the same way
+  final ImmutableBitSet.Builder fieldsRequiringCastBuilder = 
ImmutableBitSet.builder();
+  for (RelFieldCollation fieldCollation : collation.getFieldCollations()) {
+final int index = fieldCollation.getFieldIndex();
+final RelDataType unionType = unionFieldList.get(index).getType();
+final RelDataType inputType = 
input.getRowType().getFieldList().get(index).getType();
+if (!Objects.equals(unionType.getCollation(), 
inputType.getCollation())) {
+  fieldsRequiringCastBuilder.set(index);
+}
+  }
+  final ImmutableBitSet fieldsRequiringCast = 
fieldsRequiringCastBuilder.build();
+  final RelNode unsortedInput;
+  if (fieldsRequiringCast.isEmpty()) {
+unsortedInput = input;
+  } else {
+// At least one cast is required, generate the corresponding projection
+builder.push(input);
+final List fields = builder.fields();
+final List projFields = new ArrayList<>(fields.size());
+for (int i = 0; i < fields.size(); i++) {
+  RexNode node = fields.get(i);
+  if (fieldsRequiringCast.get(i)) {
+final RelDataType targetType = unionFieldList.get(i).getType();
+node = builder.getRexBuilder().makeCast(targetType, node);
+  }
+  projFields.add(node);
+}
+builder.project(projFields);
+unsortedInput = builder.build();
+  }
+  final RelNode newInput =
+  sort.copy(sort.getTraitSet(), unsortedInput, collation, null, 
inputFetch);
   inputs.add(
   convert(newInput, 
newInput.getTraitSet().replace(EnumerableConvention.INSTANCE)));
 }
diff --git 
a/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableStringComparisonTest.java
 
b/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableStringComparisonTest.java
index 1c591e4741..6f0fd0273a 100644
--- 
a/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableStringComparisonTest.java
+++ 
b/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableStringComparisonTest.java
@@ -166,6 +166,40 @@ class EnumerableStringComparisonTest {
 + "name=Marketing; name0=Marketing");
   }
 
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CA

[calcite] branch master updated: [CALCITE-5048] Query with parameterized LIMIT and correlated sub-query throws AssertionError "not a literal"

2022-04-18 Thread rubenql
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 5eb97411e [CALCITE-5048] Query with parameterized LIMIT and correlated 
sub-query throws AssertionError "not a literal"
5eb97411e is described below

commit 5eb97411ecb5df1c0fdfa5d3568d93468bff0fa1
Author: xiejiajun 
AuthorDate: Tue Apr 5 09:04:07 2022 +0800

[CALCITE-5048] Query with parameterized LIMIT and correlated sub-query 
throws AssertionError "not a literal"
---
 .../calcite/rel/metadata/RelMdMaxRowCount.java | 26 ++
 .../calcite/rel/metadata/RelMdMinRowCount.java | 26 ++
 .../org/apache/calcite/rel/metadata/RelMdUtil.java |  3 +-
 .../apache/calcite/sql2rel/RelDecorrelator.java|  9 ++---
 .../java/org/apache/calcite/tools/RelBuilder.java  | 32 +++--
 .../apache/calcite/rel/metadata/RelMdUtilTest.java | 29 +++
 .../java/org/apache/calcite/test/JdbcTest.java | 22 
 .../org/apache/calcite/test/RelBuilderTest.java| 41 ++
 .../org/apache/calcite/test/RelMetadataTest.java   |  9 +
 9 files changed, 155 insertions(+), 42 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMaxRowCount.java 
b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMaxRowCount.java
index e4801b64c..a3c4b18af 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMaxRowCount.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMaxRowCount.java
@@ -109,16 +109,13 @@ public class RelMdMaxRowCount
 if (rowCount == null) {
   rowCount = Double.POSITIVE_INFINITY;
 }
-final int offset = rel.offset == null ? 0 : 
RexLiteral.intValue(rel.offset);
+
+final int offset = rel.offset instanceof RexLiteral ? 
RexLiteral.intValue(rel.offset) : 0;
 rowCount = Math.max(rowCount - offset, 0D);
 
-if (rel.fetch != null) {
-  final int limit = RexLiteral.intValue(rel.fetch);
-  if (limit < rowCount) {
-return (double) limit;
-  }
-}
-return rowCount;
+final double limit =
+rel.fetch instanceof RexLiteral ? RexLiteral.intValue(rel.fetch) : 
rowCount;
+return limit < rowCount ? limit : rowCount;
   }
 
   public Double getMaxRowCount(EnumerableLimit rel, RelMetadataQuery mq) {
@@ -126,16 +123,13 @@ public class RelMdMaxRowCount
 if (rowCount == null) {
   rowCount = Double.POSITIVE_INFINITY;
 }
-final int offset = rel.offset == null ? 0 : 
RexLiteral.intValue(rel.offset);
+
+final int offset = rel.offset instanceof RexLiteral ? 
RexLiteral.intValue(rel.offset) : 0;
 rowCount = Math.max(rowCount - offset, 0D);
 
-if (rel.fetch != null) {
-  final int limit = RexLiteral.intValue(rel.fetch);
-  if (limit < rowCount) {
-return (double) limit;
-  }
-}
-return rowCount;
+final double limit =
+rel.fetch instanceof RexLiteral ? RexLiteral.intValue(rel.fetch) : 
rowCount;
+return limit < rowCount ? limit : rowCount;
   }
 
   public @Nullable Double getMaxRowCount(Aggregate rel, RelMetadataQuery mq) {
diff --git 
a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMinRowCount.java 
b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMinRowCount.java
index 21d55ad8b..131fec5de 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMinRowCount.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMinRowCount.java
@@ -108,16 +108,13 @@ public class RelMdMinRowCount
 if (rowCount == null) {
   rowCount = 0D;
 }
-final int offset = rel.offset == null ? 0 : 
RexLiteral.intValue(rel.offset);
+
+final int offset = rel.offset instanceof RexLiteral ? 
RexLiteral.intValue(rel.offset) : 0;
 rowCount = Math.max(rowCount - offset, 0D);
 
-if (rel.fetch != null) {
-  final int limit = RexLiteral.intValue(rel.fetch);
-  if (limit < rowCount) {
-return (double) limit;
-  }
-}
-return rowCount;
+final double limit =
+rel.fetch instanceof RexLiteral ? RexLiteral.intValue(rel.fetch) : 
rowCount;
+return limit < rowCount ? limit : rowCount;
   }
 
   public Double getMinRowCount(EnumerableLimit rel, RelMetadataQuery mq) {
@@ -125,16 +122,13 @@ public class RelMdMinRowCount
 if (rowCount == null) {
   rowCount = 0D;
 }
-final int offset = rel.offset == null ? 0 : 
RexLiteral.intValue(rel.offset);
+
+final int offset = rel.offset instanceof RexLiteral ? 
RexLiteral.intValue(rel.offset) : 0;
 rowCount = Math.max(rowCount - offset, 0D);
 
-if (rel.fetch != null) {
-  final int limit = RexLiteral.intValue(rel.fetch);
-  if (limit < rowCount) {
-return (double) limit;
-  }
-}
-return rowCount;
+final double limit =

[calcite] branch master updated: [CALCITE-5079] Update code demo of tutorial

2022-04-07 Thread rubenql
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 32babcb90 [CALCITE-5079] Update code demo of tutorial
32babcb90 is described below

commit 32babcb90aa5940bdd75760021abab6459a9cca4
Author: Ada Wang 
AuthorDate: Fri Apr 1 14:29:47 2022 +0800

[CALCITE-5079] Update code demo of tutorial
---
 site/_docs/tutorial.md | 81 --
 1 file changed, 45 insertions(+), 36 deletions(-)

diff --git a/site/_docs/tutorial.md b/site/_docs/tutorial.md
index 5eefce347..7b509bd62 100644
--- a/site/_docs/tutorial.md
+++ b/site/_docs/tutorial.md
@@ -197,17 +197,21 @@ schema, passing in the directory argument 
from the model file:
 {% highlight java %}
 public Schema create(SchemaPlus parentSchema, String name,
 Map operand) {
-  String directory = (String) operand.get("directory");
+  final String directory = (String) operand.get("directory");
+  final File base =
+  (File) operand.get(ModelHandler.ExtraOperand.BASE_DIRECTORY.camelName);
+  File directoryFile = new File(directory);
+  if (base != null && !directoryFile.isAbsolute()) {
+directoryFile = new File(base, directory);
+  }
   String flavorName = (String) operand.get("flavor");
   CsvTable.Flavor flavor;
   if (flavorName == null) {
 flavor = CsvTable.Flavor.SCANNABLE;
   } else {
-flavor = CsvTable.Flavor.valueOf(flavorName.toUpperCase());
+flavor = CsvTable.Flavor.valueOf(flavorName.toUpperCase(Locale.ROOT));
   }
-  return new CsvSchema(
-  new File(directory),
-  flavor);
+  return new CsvSchema(directoryFile, flavor);
 }
 {% endhighlight %}
 
@@ -230,17 +234,15 @@ Here is the relevant code from CsvSchema, 
overriding the
 method in the AbstractSchema base class.
 
 {% highlight java %}
-protected Map getTableMap() {
+private Map createTableMap() {
   // Look for files in the directory ending in ".csv", ".csv.gz", ".json",
   // ".json.gz".
-  File[] files = directoryFile.listFiles(
-  new FilenameFilter() {
-public boolean accept(File dir, String name) {
-  final String nameSansGz = trim(name, ".gz");
-  return nameSansGz.endsWith(".csv")
-  || nameSansGz.endsWith(".json");
-}
-  });
+  final Source baseSource = Sources.of(directoryFile);
+  File[] files = directoryFile.listFiles((dir, name) -> {
+final String nameSansGz = trim(name, ".gz");
+return nameSansGz.endsWith(".csv")
+|| nameSansGz.endsWith(".json");
+  });
   if (files == null) {
 System.out.println("directory " + directoryFile + " not found");
 files = new File[0];
@@ -248,31 +250,33 @@ protected Map getTableMap() {
   // Build a map from table name to table; each file becomes a table.
   final ImmutableMap.Builder builder = ImmutableMap.builder();
   for (File file : files) {
-String tableName = trim(file.getName(), ".gz");
-final String tableNameSansJson = trimOrNull(tableName, ".json");
-if (tableNameSansJson != null) {
-  JsonTable table = new JsonTable(file);
-  builder.put(tableNameSansJson, table);
-  continue;
+Source source = Sources.of(file);
+Source sourceSansGz = source.trim(".gz");
+final Source sourceSansJson = sourceSansGz.trimOrNull(".json");
+if (sourceSansJson != null) {
+  final Table table = new JsonScannableTable(source);
+  builder.put(sourceSansJson.relative(baseSource).path(), table);
+}
+final Source sourceSansCsv = sourceSansGz.trimOrNull(".csv");
+if (sourceSansCsv != null) {
+  final Table table = createTable(source);
+  builder.put(sourceSansCsv.relative(baseSource).path(), table);
 }
-tableName = trim(tableName, ".csv");
-final Table table = createTable(file);
-builder.put(tableName, table);
   }
   return builder.build();
 }
 
 /** Creates different sub-type of table based on the "flavor" attribute. */
-private Table createTable(File file) {
+private Table createTable(Source source) {
   switch (flavor) {
   case TRANSLATABLE:
-return new CsvTranslatableTable(file, null);
+return new CsvTranslatableTable(source, null);
   case SCANNABLE:
-return new CsvScannableTable(file, null);
+return new CsvScannableTable(source, null);
   case FILTERABLE:
-return new CsvFilterableTable(file, null);
+return new CsvFilterableTable(source, null);
   default:
-throw new AssertionError("Unknown flavor " + flavor);
+throw new AssertionError("Unknown flavor " + this.flavor);
   }
 }
 {% endhighlight %}
@@ -413,12 +417,14 @@ passing in the file argument from the model 
file:
 

[calcite] branch master updated: [CALCITE-5075] Build fails due to rat check on Gemfile.lock

2022-03-31 Thread rubenql
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 f731ca6  [CALCITE-5075] Build fails due to rat check on Gemfile.lock
f731ca6 is described below

commit f731ca6d9fa8032997a33c4da4cc27da540db262
Author: rubenada 
AuthorDate: Thu Mar 31 14:36:28 2022 +0100

[CALCITE-5075] Build fails due to rat check on Gemfile.lock
---
 .ratignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.ratignore b/.ratignore
index b6af226..5b7442f 100644
--- a/.ratignore
+++ b/.ratignore
@@ -39,6 +39,7 @@ site/_layouts/news.html
 site/_layouts/news_item.html
 site/_layouts/page.html
 site/_sass/**
+site/Gemfile.lock
 site/css/screen.scss
 site/fonts/**
 site/js/**


[calcite] branch master updated: [CALCITE-5019] Avoid multiple scans when table is ProjectableFilterableTable and projections and filters act on different columns

2022-03-03 Thread rubenql
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 dcbc493  [CALCITE-5019] Avoid multiple scans when table is 
ProjectableFilterableTable and projections and filters act on different columns
dcbc493 is described below

commit dcbc493bf699d961427952c5efc047b76d859096
Author: IceMimosa 
AuthorDate: Wed Feb 23 18:06:10 2022 +0800

[CALCITE-5019] Avoid multiple scans when table is 
ProjectableFilterableTable and projections and filters act on different columns
---
 .../apache/calcite/interpreter/TableScanNode.java  |  4 +--
 .../apache/calcite/test/ScannableTableTest.java| 29 --
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/interpreter/TableScanNode.java 
b/core/src/main/java/org/apache/calcite/interpreter/TableScanNode.java
index 2f552f1..ece2008 100644
--- a/core/src/main/java/org/apache/calcite/interpreter/TableScanNode.java
+++ b/core/src/main/java/org/apache/calcite/interpreter/TableScanNode.java
@@ -200,8 +200,6 @@ public class TableScanNode implements Node {
   } else {
 projectInts = projects.toIntArray();
   }
-  final Enumerable<@Nullable Object[]> enumerable1 =
-  pfTable.scan(root, mutableFilters, projectInts);
   for (RexNode filter : mutableFilters) {
 if (!filters.contains(filter)) {
   throw RESOURCE.filterableTableInventedFilter(filter.toString())
@@ -227,6 +225,8 @@ public class TableScanNode implements Node {
   continue;
 }
   }
+  final Enumerable<@Nullable Object[]> enumerable1 =
+  pfTable.scan(root, mutableFilters, projectInts);
   final Enumerable rowEnumerable = Enumerables.toRow(enumerable1);
   final ImmutableIntList rejectedProjects;
   if (originalProjects == null || originalProjects.equals(projects)) {
diff --git a/core/src/test/java/org/apache/calcite/test/ScannableTableTest.java 
b/core/src/test/java/org/apache/calcite/test/ScannableTableTest.java
index 2a64d97..0339cd4 100644
--- a/core/src/test/java/org/apache/calcite/test/ScannableTableTest.java
+++ b/core/src/test/java/org/apache/calcite/test/ScannableTableTest.java
@@ -155,7 +155,7 @@ public class ScannableTableTest {
 "j=Paul");
 // Only 2 rows came out of the table. If the value is 4, it means that the
 // planner did not pass the filter down.
-assertThat(buf.toString(), is("returnCount=2, filter=<0, 4>, 
projects=[1]"));
+assertThat(buf.toString(), is("returnCount=2, filter=<0, 4>, projects=[1, 
0]"));
   }
 
   @Test void testProjectableFilterableNonCooperative() throws Exception {
@@ -188,7 +188,7 @@ public class ScannableTableTest {
 .returnsUnordered("k=1940; j=John",
 "k=1942; j=Paul");
 assertThat(buf.toString(),
-is("returnCount=2, filter=<0, 4>, projects=[2, 1]"));
+is("returnCount=2, filter=<0, 4>, projects=[2, 1, 0]"));
   }
 
   /** A filter on a {@link 
org.apache.calcite.schema.ProjectableFilterableTable}
@@ -397,6 +397,25 @@ public class ScannableTableTest {
   }
 
   /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-5019;>[CALCITE-5019]
+   * Avoid multiple scans when table is ProjectableFilterableTable.*/
+  @Test void testProjectableFilterableWithScanCounter() throws Exception {
+final StringBuilder buf = new StringBuilder();
+final BeatlesProjectableFilterableTable table =
+new BeatlesProjectableFilterableTable(buf, false);
+final String explain = "PLAN="
++ "EnumerableInterpreter\n"
++ "  BindableTableScan(table=[[s, beatles]], filters=[[=($0, 4)]], 
projects=[[1]]";
+CalciteAssert.that()
+.with(newSchema("s", Pair.of("beatles", table)))
+.query("select \"j\" from \"s\".\"beatles\" where \"i\" = 4")
+.explainContains(explain)
+.returnsUnordered("j=John", "j=Paul");
+assertThat(table.getScanCount(), is(1));
+assertThat(buf.toString(), is("returnCount=4, projects=[1, 0]"));
+  }
+
+  /** Test case for
* https://issues.apache.org/jira/browse/CALCITE-1031;>[CALCITE-1031]
* In prepared statement, CsvScannableTable.scan is called twice. */
   @Test void testPrepared2() throws SQLException {
@@ -558,6 +577,7 @@ public class ScannableTableTest {
* interface. */
   public static class BeatlesProjectableFilterableTable
   extends AbstractTable implements ProjectableFilterableTable {
+private final AtomicInteger scanCounter = new AtomicInteger();
 private final StringBuilder buf;
 private final boolean coop

[calcite] branch master updated: [CALCITE-3673] ListTransientTable should not leave tables in the schema [CALCITE-4054] RepeatUnion containing a Correlate with a transientScan on its RHS causes NPE

2022-02-18 Thread rubenql
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 9c4f3bb  [CALCITE-3673] ListTransientTable should not leave tables in 
the schema [CALCITE-4054] RepeatUnion containing a Correlate with a 
transientScan on its RHS causes NPE
9c4f3bb is described below

commit 9c4f3bb540dd67a0ffefc09f4ebd98d2be65bb14
Author: rubenada 
AuthorDate: Thu Jan 13 14:12:29 2022 +

[CALCITE-3673] ListTransientTable should not leave tables in the schema
[CALCITE-4054] RepeatUnion containing a Correlate with a transientScan on 
its RHS causes NPE
---
 .../adapter/enumerable/EnumerableRepeatUnion.java  | 42 +-
 .../enumerable/EnumerableRepeatUnionRule.java  |  3 +-
 .../org/apache/calcite/jdbc/CalciteSchema.java |  4 +
 .../apache/calcite/prepare/RelOptTableImpl.java|  4 +
 .../org/apache/calcite/rel/core/RelFactories.java  |  6 +-
 .../org/apache/calcite/rel/core/RepeatUnion.java   | 23 +-
 .../calcite/rel/logical/LogicalRepeatUnion.java| 19 +++--
 .../java/org/apache/calcite/schema/SchemaPlus.java |  7 ++
 .../calcite/schema/impl/ListTransientTable.java| 11 ++-
 .../java/org/apache/calcite/tools/RelBuilder.java  |  2 +-
 .../org/apache/calcite/util/BuiltInMethod.java |  5 +-
 .../test/enumerable/EnumerableRepeatUnionTest.java | 91 ++
 .../apache/calcite/linq4j/EnumerableDefaults.java  |  7 +-
 13 files changed, 198 insertions(+), 26 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRepeatUnion.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRepeatUnion.java
index 9fc2764..c6e3fda 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRepeatUnion.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRepeatUnion.java
@@ -17,17 +17,23 @@
 package org.apache.calcite.adapter.enumerable;
 
 import org.apache.calcite.linq4j.function.Experimental;
+import org.apache.calcite.linq4j.function.Function0;
 import org.apache.calcite.linq4j.tree.BlockBuilder;
 import org.apache.calcite.linq4j.tree.Expression;
 import org.apache.calcite.linq4j.tree.Expressions;
 import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptTable;
 import org.apache.calcite.plan.RelTraitSet;
 import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.core.RepeatUnion;
+import org.apache.calcite.schema.TransientTable;
 import org.apache.calcite.util.BuiltInMethod;
 import org.apache.calcite.util.Util;
 
+import org.checkerframework.checker.nullness.qual.Nullable;
+
 import java.util.List;
+import java.util.Objects;
 
 /**
  * Implementation of {@link RepeatUnion} in
@@ -43,14 +49,15 @@ public class EnumerableRepeatUnion extends RepeatUnion 
implements EnumerableRel
* Creates an EnumerableRepeatUnion.
*/
   EnumerableRepeatUnion(RelOptCluster cluster, RelTraitSet traitSet,
-  RelNode seed, RelNode iterative, boolean all, int iterationLimit) {
-super(cluster, traitSet, seed, iterative, all, iterationLimit);
+  RelNode seed, RelNode iterative, boolean all, int iterationLimit,
+  @Nullable RelOptTable transientTable) {
+super(cluster, traitSet, seed, iterative, all, iterationLimit, 
transientTable);
   }
 
   @Override public EnumerableRepeatUnion copy(RelTraitSet traitSet, 
List inputs) {
 assert inputs.size() == 2;
 return new EnumerableRepeatUnion(getCluster(), traitSet,
-inputs.get(0), inputs.get(1), all, iterationLimit);
+inputs.get(0), inputs.get(1), all, iterationLimit, transientTable);
   }
 
   @Override public Result implement(EnumerableRelImplementor implementor, 
Prefer pref) {
@@ -61,6 +68,32 @@ public class EnumerableRepeatUnion extends RepeatUnion 
implements EnumerableRel
 RelNode seed = getSeedRel();
 RelNode iteration = getIterativeRel();
 
+Expression cleanUpFunctionExp = Expressions.constant(null);
+if (transientTable != null) {
+  // root.getRootSchema().add(tableName, table);
+  Expression tableExp = implementor.stash(
+  Objects.requireNonNull(transientTable.unwrap(TransientTable.class)),
+  TransientTable.class);
+  String tableName =
+  
transientTable.getQualifiedName().get(transientTable.getQualifiedName().size() 
- 1);
+  Expression tableNameExp = Expressions.constant(tableName, String.class);
+  builder.append(
+  Expressions.call(
+  Expressions.call(
+  implementor.getRootExpression(),
+  BuiltInMethod.DATA_CONTEXT_GET_ROOT_SCHEMA.method),
+  BuiltInMethod.SCHEMA_PLUS_ADD_TABLE.method,
+  tableNameExp,
+  tableExp));
+  // root.getRootSchema().removeTable(tableName);
+  cleanUpFunctionExp = Expressions.lambda

[calcite] branch master updated (4a6e222 -> 04029ff)

2022-02-15 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git.


from 4a6e222  [CALCITE-4988] ((A IS NOT NULL OR B) AND A IS NOT NULL) can't 
be simplify to (A IS NOT NULL) When A is deterministic
 add 04029ff  [CALCITE-4995] AssertionError caused by RelFieldTrimmer on 
SEMI/ANTI join

No new revisions were added by this update.

Summary of changes:
 .../apache/calcite/sql2rel/RelFieldTrimmer.java|  2 +-
 .../calcite/sql2rel/RelFieldTrimmerTest.java   | 32 ++
 2 files changed, 33 insertions(+), 1 deletion(-)


[calcite-site] branch master updated: Site: update PMC Chair

2022-01-30 Thread rubenql
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-site.git


The following commit(s) were added to refs/heads/master by this push:
 new 79b5131  Site: update PMC Chair
79b5131 is described below

commit 79b51311da7b470753958d14de184cd42293042f
Author: Ruben Quesada Lopez 
AuthorDate: Sun Jan 30 10:34:16 2022 +

Site: update PMC Chair
---
 community/index.html | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/community/index.html b/community/index.html
index 7bbe54d..e08ee4c 100644
--- a/community/index.html
+++ b/community/index.html
@@ -187,7 +187,7 @@
   Haisheng Yuan (https://people.apache.org/phonebook.html?uid=hyuan;>hyuan)
   https://github.com/hsyuan;>https://github.com/hsyuan.png;>
   Alibaba
-  PMC Chair
+  PMC
 
 
   Hongze Zhang (https://people.apache.org/phonebook.html?uid=hongze;>hongze)
@@ -329,7 +329,7 @@
   Ruben Quesada Lopez (https://people.apache.org/phonebook.html?uid=rubenql;>rubenql)
   https://github.com/rubenada;>https://github.com/rubenada.png;>
   TIBCO
-  PMC
+  PMC Chair
 
 
   Rui Wang (https://people.apache.org/phonebook.html?uid=amaliujia;>amaliujia)


[calcite] branch site updated: Site: update PMC Chair

2022-01-29 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch site
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/site by this push:
 new d132471  Site: update PMC Chair
d132471 is described below

commit d1324718fae633584a6c5f8e8f6238a0f851cbac
Author: Ruben Quesada Lopez 
AuthorDate: Sat Jan 29 19:04:14 2022 +

Site: update PMC Chair
---
 site/_data/contributors.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/site/_data/contributors.yml b/site/_data/contributors.yml
index c2be8d1..0a5d375 100644
--- a/site/_data/contributors.yml
+++ b/site/_data/contributors.yml
@@ -95,7 +95,7 @@
   apacheId: hyuan
   githubId: hsyuan
   org: Alibaba
-  role: PMC Chair
+  role: PMC
 - name: Hongze Zhang
   apacheId: hongze
   githubId: zhztheplayer
@@ -216,7 +216,7 @@
   apacheId: rubenql
   githubId: rubenada
   org: TIBCO
-  role: PMC
+  role: PMC Chair
 - name: Rui Wang
   apacheId: amaliujia
   githubId: amaliujia


[calcite] branch master updated: Site: update PMC Chair

2022-01-29 Thread rubenql
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 8570cf2  Site: update PMC Chair
8570cf2 is described below

commit 8570cf2b293e9acab9525fbe76709d970b9f7104
Author: Ruben Quesada Lopez 
AuthorDate: Sat Jan 29 19:04:14 2022 +

Site: update PMC Chair
---
 site/_data/contributors.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/site/_data/contributors.yml b/site/_data/contributors.yml
index c2be8d1..0a5d375 100644
--- a/site/_data/contributors.yml
+++ b/site/_data/contributors.yml
@@ -95,7 +95,7 @@
   apacheId: hyuan
   githubId: hsyuan
   org: Alibaba
-  role: PMC Chair
+  role: PMC
 - name: Hongze Zhang
   apacheId: hongze
   githubId: zhztheplayer
@@ -216,7 +216,7 @@
   apacheId: rubenql
   githubId: rubenada
   org: TIBCO
-  role: PMC
+  role: PMC Chair
 - name: Rui Wang
   apacheId: amaliujia
   githubId: amaliujia


[calcite] branch master updated: [CALCITE-4737] Add RelOptPlanner visualizer for debugging (Zuozhi Wang, Thomas Rebele)

2021-12-17 Thread rubenql
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 ce25311  [CALCITE-4737] Add RelOptPlanner visualizer for debugging 
(Zuozhi Wang, Thomas Rebele)
ce25311 is described below

commit ce2531148f0c9990792068b12000deac827fc831
Author: Thomas Rebele 
AuthorDate: Fri Dec 17 10:35:59 2021 +0100

[CALCITE-4737] Add RelOptPlanner visualizer for debugging (Zuozhi Wang, 
Thomas Rebele)
---
 .../plan/visualizer/InputExcludedRelWriter.java|  89 
 .../calcite/plan/visualizer/NodeUpdateHelper.java  | 107 +
 .../plan/visualizer/RuleMatchVisualizer.java   | 487 +
 .../apache/calcite/plan/visualizer/StepInfo.java   |  50 +++
 .../calcite/plan/visualizer/package-info.java  |  23 +
 .../calcite/plan/visualizer/viz-template.html  | 421 ++
 .../org/apache/calcite/test/RelOptTestBase.java|   4 +-
 .../calcite/test/RuleMatchVisualizerTest.java  | 138 ++
 .../calcite/test/RuleMatchVisualizerTest.xml   | 264 +++
 9 files changed, 1581 insertions(+), 2 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/plan/visualizer/InputExcludedRelWriter.java
 
b/core/src/main/java/org/apache/calcite/plan/visualizer/InputExcludedRelWriter.java
new file mode 100644
index 000..5608da8
--- /dev/null
+++ 
b/core/src/main/java/org/apache/calcite/plan/visualizer/InputExcludedRelWriter.java
@@ -0,0 +1,89 @@
+/*
+ * 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.plan.visualizer;
+
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.RelWriter;
+import org.apache.calcite.sql.SqlExplainLevel;
+import org.apache.calcite.util.Pair;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * An implement of RelWriter for explaining a single RelNode.
+ * The result only contains the properties of the RelNode,
+ * but does not explain the children.
+ *
+ * {@code
+ * InputExcludedRelWriter relWriter = new InputExcludedRelWriter();
+ * rel.explain(relWriter);
+ * String digest = relWriter.toString();
+ * }
+ *
+ */
+class InputExcludedRelWriter implements RelWriter {
+
+  private final Map values = new LinkedHashMap<>();
+
+  InputExcludedRelWriter() {
+  }
+
+
+  @Override public void explain(RelNode rel, List> valueList) {
+valueList.forEach(pair -> {
+  assert pair.left != null;
+  this.values.put(pair.left, pair.right);
+});
+  }
+
+  @Override public SqlExplainLevel getDetailLevel() {
+return SqlExplainLevel.EXPPLAN_ATTRIBUTES;
+  }
+
+  @Override public RelWriter input(String term, RelNode input) {
+// do nothing, ignore input
+return this;
+  }
+
+  @Override public RelWriter item(String term, @Nullable Object value) {
+this.values.put(term, value);
+return this;
+  }
+
+  @Override public RelWriter itemIf(String term, @Nullable Object value, 
boolean condition) {
+if (condition) {
+  this.values.put(term, value);
+}
+return this;
+  }
+
+  @Override public RelWriter done(RelNode node) {
+return this;
+  }
+
+  @Override public boolean nest() {
+return false;
+  }
+
+  @Override public String toString() {
+return values.toString();
+  }
+}
diff --git 
a/core/src/main/java/org/apache/calcite/plan/visualizer/NodeUpdateHelper.java 
b/core/src/main/java/org/apache/calcite/plan/visualizer/NodeUpdateHelper.java
new file mode 100644
index 000..cdbbb9d
--- /dev/null
+++ 
b/core/src/main/java/org/apache/calcite/plan/visualizer/NodeUpdateHelper.java
@@ -0,0 +1,107 @@
+/*
+ * 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 ob

[calcite] branch master updated: [CALCITE-4941] SemiJoinRule loses hints

2021-12-15 Thread rubenql
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 7d342b3  [CALCITE-4941] SemiJoinRule loses hints
7d342b3 is described below

commit 7d342b3eac92b34a9196a5486e4ebe172d843f2b
Author: rubenada 
AuthorDate: Tue Dec 14 17:52:37 2021 +

[CALCITE-4941] SemiJoinRule loses hints
---
 .../org/apache/calcite/rel/rules/SemiJoinRule.java |  2 +-
 .../org/apache/calcite/test/RelOptRulesTest.java   | 46 ++
 .../org/apache/calcite/test/RelOptRulesTest.xml| 21 ++
 3 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java 
b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java
index adf9a2f..fc84206 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java
@@ -109,7 +109,7 @@ public abstract class SemiJoinRule
   RelOptUtil.createEquiJoinCondition(relBuilder.peek(2, 0),
   joinInfo.leftKeys, relBuilder.peek(2, 1), newRightKeys,
   rexBuilder);
-  relBuilder.semiJoin(newCondition);
+  relBuilder.semiJoin(newCondition).hints(join.getHints());
   break;
 
 case LEFT:
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java 
b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index a01731a..e2276b5 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -58,6 +58,9 @@ import org.apache.calcite.rel.core.JoinRelType;
 import org.apache.calcite.rel.core.Minus;
 import org.apache.calcite.rel.core.Project;
 import org.apache.calcite.rel.core.Union;
+import org.apache.calcite.rel.hint.HintPredicates;
+import org.apache.calcite.rel.hint.HintStrategyTable;
+import org.apache.calcite.rel.hint.RelHint;
 import org.apache.calcite.rel.logical.LogicalAggregate;
 import org.apache.calcite.rel.logical.LogicalCorrelate;
 import org.apache.calcite.rel.logical.LogicalFilter;
@@ -147,6 +150,7 @@ import java.util.function.Supplier;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.Assertions.fail;
 
 /**
@@ -1078,6 +1082,48 @@ class RelOptRulesTest extends RelOptTestBase {
   }
 
   /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-4941;>[CALCITE-4941]
+   * SemiJoinRule loses hints. */
+  @Test void testSemiJoinRuleWithHint() {
+final RelHint noHashJoinHint = RelHint.builder("no_hash_join").build();
+final Function relFn = b -> {
+  b.getCluster().setHintStrategies(
+  HintStrategyTable.builder()
+  .hintStrategy("no_hash_join", HintPredicates.JOIN)
+  .build());
+  return b
+  .scan("DEPT")
+  .scan("EMP")
+  .project(b.field("DEPTNO"))
+  .distinct()
+  .join(
+  JoinRelType.INNER,
+  b.equals(
+  b.field(2, 0, "DEPTNO"),
+  b.field(2, 1, "DEPTNO"))).hints(noHashJoinHint)
+  .project(b.field("DNAME"))
+  .build();
+};
+
+// verify plan
+relFn(relFn)
+.withRule(CoreRules.PROJECT_TO_SEMI_JOIN)
+.check();
+
+// verify hint
+final RelBuilder relBuilder = 
RelBuilder.create(RelBuilderTest.config().build());
+final RelNode input = relFn.apply(relBuilder);
+final HepProgram program = new HepProgramBuilder()
+.addRuleInstance(CoreRules.PROJECT_TO_SEMI_JOIN)
+.build();
+final HepPlanner hepPlanner = new HepPlanner(program);
+hepPlanner.setRoot(input);
+final RelNode output = hepPlanner.findBestExp();
+final Join join = (Join) output.getInput(0);
+assertTrue(join.getHints().contains(noHashJoinHint));
+  }
+
+  /** Test case for
* https://issues.apache.org/jira/browse/CALCITE-438;>[CALCITE-438]
* Push predicates through SemiJoin. */
   @Test void testPushFilterThroughSemiJoin() {
diff --git 
a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml 
b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
index e9a4152..8991b55 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -11450,6 +11450,27 @@ LogicalProject(DEPTNO=[$0], NAME=[$1])
 ]]>
 
   
+  
+
+  
+
+
+  
+
+  
   
 
   

[calcite] branch master updated: [CALCITE-4848] Adding a HAVING condition to a query with a dynamic parameter makes the result always empty

2021-10-14 Thread rubenql
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 23e1b1f  [CALCITE-4848] Adding a HAVING condition to a query with a 
dynamic parameter makes the result always empty
23e1b1f is described below

commit 23e1b1fcae6614fb9b6600951251ba622b379b30
Author: Thomas Rebele 
AuthorDate: Thu Oct 14 09:44:33 2021 +0200

[CALCITE-4848] Adding a HAVING condition to a query with a dynamic 
parameter makes the result always empty
---
 .../apache/calcite/rel/rules/ReduceExpressionsRule.java  |  2 +-
 .../java/org/apache/calcite/test/RelOptRulesTest.java| 16 
 .../org/apache/calcite/test/RelOptRulesTest.xml  | 16 
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java 
b/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java
index 1177e16..67aa567 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java
@@ -1071,7 +1071,7 @@ public abstract class ReduceExpressionsRulehttps://issues.apache.org/jira/browse/CALCITE-4848;>[CALCITE-4848]
+   * Adding a HAVING condition to a query with a dynamic parameter makes the 
result always empty
+   . */
+  @Test void testAggregateWithDynamicParam() {
+HepProgramBuilder builder = new HepProgramBuilder();
+builder.addRuleClass(ReduceExpressionsRule.class);
+HepPlanner hepPlanner = new HepPlanner(builder.build());
+hepPlanner.addRule(CoreRules.FILTER_REDUCE_EXPRESSIONS);
+final String sql = "SELECT sal, COUNT(1) AS count_val\n"
++ "FROM emp t WHERE sal = ?\n"
++ "GROUP BY sal HAVING sal < 1000";
+sql(sql).with(hepPlanner)
+.checkUnchanged();
+  }
+
   @Test void testReduceCasts() {
 // Disable simplify in RelBuilder so that there are casts in 'before';
 // The resulting plan should have no cast expressions
diff --git 
a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml 
b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
index 12e944c..4a070d7 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -1097,6 +1097,22 @@ LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])
 ]]>
 
   
+  
+
+  
+
+
+  
+
+  
   
 
   

[calcite] branch master updated: [CALCITE-4834] JaninoRelMetadataProvider uses hardcoded class name

2021-10-06 Thread rubenql
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 50dbd12  [CALCITE-4834] JaninoRelMetadataProvider uses hardcoded class 
name
50dbd12 is described below

commit 50dbd12f14f330f57a321a2402a7dcb8124f5112
Author: rubenada 
AuthorDate: Wed Oct 6 16:45:52 2021 +0100

[CALCITE-4834] JaninoRelMetadataProvider uses hardcoded class name
---
 .../org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java| 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java
 
b/core/src/main/java/org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java
index 04a7af0..89af787 100644
--- 
a/core/src/main/java/org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java
+++ 
b/core/src/main/java/org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java
@@ -132,13 +132,13 @@ public class JaninoRelMetadataProvider implements 
RelMetadataProvider {
   }
 }
 
-buff.append("  private final org.apache.calcite.rel.metadata.MetadataDef 
def;\n");
+buff.append("  private final 
").append(MetadataDef.class.getName()).append(" def;\n");
 for (Map.Entry, String> handlerAndName : 
handlerToName.entrySet()) {
   buff.append("  public final 
").append(handlerAndName.getKey().getClass().getName())
   .append(' ').append(handlerAndName.getValue()).append(";\n");
 }
 buff.append("  public ").append(name).append("(\n")
-.append("  org.apache.calcite.rel.metadata.MetadataDef def");
+.append("  ").append(MetadataDef.class.getName()).append(" def");
 for (Map.Entry, String> handlerAndName : 
handlerToName.entrySet()) {
   buff.append(",\n")
   .append("  ")


[calcite] branch master updated (d4640d0 -> f4db84c)

2021-09-24 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git.


from d4640d0  [CALCITE-4793] 
CassandraAdapterDataTypesTest.testCollectionsInnerValues fails depending on the 
user timezone (Alessandro Solimando)
 add f4db84c  [CALCITE-4773] RelDecorrelator's RemoveSingleAggregateRule 
can produce result with wrong row type

No new revisions were added by this update.

Summary of changes:
 .../apache/calcite/sql2rel/RelDecorrelator.java| 55 ++
 core/src/test/resources/sql/unnest.iq  | 19 
 2 files changed, 54 insertions(+), 20 deletions(-)


[calcite] branch master updated: [CALCITE-4741] AbstractRelNode#getId can overflow into a negative value causing CompileException in certain Enumerable implement methods

2021-08-21 Thread rubenql
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 94e2f98  [CALCITE-4741] AbstractRelNode#getId can overflow into a 
negative value causing CompileException in certain Enumerable implement methods
94e2f98 is described below

commit 94e2f98d9769ea17b9e8a6a478802f78a745e3f0
Author: rubenada 
AuthorDate: Tue Aug 17 13:18:43 2021 +0100

[CALCITE-4741] AbstractRelNode#getId can overflow into a negative value 
causing CompileException in certain Enumerable implement methods
---
 .../calcite/adapter/enumerable/EnumerableBatchNestedLoopJoin.java   | 2 +-
 .../org/apache/calcite/adapter/enumerable/EnumerableMergeUnion.java | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableBatchNestedLoopJoin.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableBatchNestedLoopJoin.java
index 4dd3e1b..15e211a 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableBatchNestedLoopJoin.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableBatchNestedLoopJoin.java
@@ -167,7 +167,7 @@ public class EnumerableBatchNestedLoopJoin extends Join 
implements EnumerableRel
 ParameterExpression corrArg;
 final ParameterExpression corrArgList =
 Expressions.parameter(Modifier.FINAL,
-List.class, "corrList" + this.getId());
+List.class, "corrList" + Integer.toUnsignedString(this.getId()));
 
 // Declare batchSize correlation variables
 if (!Primitive.is(corrVarType)) {
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeUnion.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeUnion.java
index 182e0a5..b5a617a 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeUnion.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeUnion.java
@@ -73,7 +73,7 @@ public class EnumerableMergeUnion extends EnumerableUnion {
 
 final ParameterExpression inputListExp = Expressions.parameter(
 List.class,
-builder.newName("mergeUnionInputs" + getId()));
+builder.newName("mergeUnionInputs" + 
Integer.toUnsignedString(this.getId(;
 builder.add(Expressions.declare(0, inputListExp, 
Expressions.new_(ArrayList.class)));
 
 for (Ord ord : Ord.zip(inputs)) {


[calcite] branch master updated: RelOptRulesTest improvements: - Provide relFn pattern mechanism to test a RelNode function instead of a sql string - Refactor several tests to use relFn - Refactor sim

2021-07-07 Thread rubenql
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 d46137a  RelOptRulesTest improvements: - Provide relFn pattern 
mechanism to test a RelNode function instead of a sql string - Refactor several 
tests to use relFn - Refactor similar tests by using common auxiliary methods - 
Correct auxiliary methods names (use "check" prefix instead of "test" prefix)
d46137a is described below

commit d46137a197a2840ea5ff9f3b38bb86d423c9af11
Author: rubenada 
AuthorDate: Wed Jun 16 15:05:51 2021 +0100

RelOptRulesTest improvements:
- Provide relFn pattern mechanism to test a RelNode function instead of a 
sql string
- Refactor several tests to use relFn
- Refactor similar tests by using common auxiliary methods
- Correct auxiliary methods names (use "check" prefix instead of "test" 
prefix)
---
 .../org/apache/calcite/test/RelOptRulesTest.java   | 1266 ++--
 .../org/apache/calcite/test/RelOptTestBase.java|   58 +-
 .../org/apache/calcite/test/TopDownOptTest.java|2 +-
 .../org/apache/calcite/test/RelOptRulesTest.xml|  177 ++-
 4 files changed, 573 insertions(+), 930 deletions(-)

diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java 
b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index f76b62e..d2b53c1 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -134,6 +134,7 @@ import java.util.Collections;
 import java.util.EnumSet;
 import java.util.List;
 import java.util.Locale;
+import java.util.function.Function;
 import java.util.function.Predicate;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -391,105 +392,60 @@ class RelOptRulesTest extends RelOptTestBase {
* https://issues.apache.org/jira/browse/CALCITE-3170;>[CALCITE-3170]
* ANTI join on conditions push down generates wrong plan. */
   @Test void testCanNotPushAntiJoinConditionsToLeft() {
-final RelBuilder relBuilder = 
RelBuilder.create(RelBuilderTest.config().build());
 // build a rel equivalent to sql:
 // select * from emp
 // where emp.deptno
 // not in (select dept.deptno from dept where emp.deptno > 20)
-RelNode left = relBuilder.scan("EMP").build();
-RelNode right = relBuilder.scan("DEPT").build();
-RelNode relNode = relBuilder.push(left)
-.push(right)
-.antiJoin(
-relBuilder.call(SqlStdOperatorTable.IS_NOT_DISTINCT_FROM,
-relBuilder.field(2, 0, "DEPTNO"),
-relBuilder.field(2, 1, "DEPTNO")),
-relBuilder.call(SqlStdOperatorTable.GREATER_THAN,
-RexInputRef.of(0, left.getRowType()),
-relBuilder.literal(20)))
-.project(relBuilder.field(0))
-.build();
-
-HepProgram program = new HepProgramBuilder()
-.addRuleInstance(CoreRules.JOIN_CONDITION_PUSH)
-.build();
-
-HepPlanner hepPlanner = new HepPlanner(program);
-hepPlanner.setRoot(relNode);
-RelNode output = hepPlanner.findBestExp();
-
-final String planAfter = NL + RelOptUtil.toString(output);
-final DiffRepository diffRepos = getDiffRepos();
-diffRepos.assertEquals("planAfter", "${planAfter}", planAfter);
-SqlToRelTestBase.assertValid(output);
+checkCanNotPushSemiOrAntiJoinConditionsToLeft(JoinRelType.ANTI);
   }
 
   @Test void testCanNotPushAntiJoinConditionsToRight() {
-final RelBuilder relBuilder = 
RelBuilder.create(RelBuilderTest.config().build());
 // build a rel equivalent to sql:
 // select * from emp
 // where emp.deptno
 // not in (select dept.deptno from dept where dept.dname = 'ddd')
-RelNode relNode = relBuilder.scan("EMP")
+final Function relFn = b -> b
+.scan("EMP")
 .scan("DEPT")
 .antiJoin(
-relBuilder.call(SqlStdOperatorTable.IS_NOT_DISTINCT_FROM,
-relBuilder.field(2, 0, "DEPTNO"),
-relBuilder.field(2, 1, "DEPTNO")),
-relBuilder.equals(relBuilder.field(2, 1, "DNAME"),
-relBuilder.literal("ddd")))
-.project(relBuilder.field(0))
+b.call(SqlStdOperatorTable.IS_NOT_DISTINCT_FROM,
+b.field(2, 0, "DEPTNO"),
+b.field(2, 1, "DEPTNO")),
+b.equals(b.field(2, 1, "DNAME"),
+b.literal("ddd")))
+.project(b.field(0))
 .build();
-
-HepProgram program = new HepProgramBuilder()
-.addRuleInstance(CoreRules.JOIN_CONDITION_PUSH)
-.build();
-
-HepPlanner he

[calcite] branch master updated: [CALCITE-4621] SemiJoinRule throws AssertionError on ANTI join

2021-05-27 Thread rubenql
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 cac28e9  [CALCITE-4621] SemiJoinRule throws AssertionError on ANTI join
cac28e9 is described below

commit cac28e95762532538cd3d0dce9e933ef9e4d5228
Author: rubenada 
AuthorDate: Tue May 25 13:51:45 2021 +0100

[CALCITE-4621] SemiJoinRule throws AssertionError on ANTI join
---
 .../org/apache/calcite/rel/rules/SemiJoinRule.java | 10 +++---
 .../org/apache/calcite/test/RelOptRulesTest.java   | 39 ++
 2 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java 
b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java
index 16422d3..60c9f7a 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/SemiJoinRule.java
@@ -24,6 +24,7 @@ import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.core.Aggregate;
 import org.apache.calcite.rel.core.Join;
 import org.apache.calcite.rel.core.JoinInfo;
+import org.apache.calcite.rel.core.JoinRelType;
 import org.apache.calcite.rel.core.Project;
 import org.apache.calcite.rex.RexBuilder;
 import org.apache.calcite.rex.RexNode;
@@ -45,8 +46,9 @@ import java.util.List;
 public abstract class SemiJoinRule
 extends RelRule
 implements TransformationRule {
-  private static boolean notGenerateNullsOnLeft(Join join) {
-return !join.getJoinType().generatesNullsOnLeft();
+  private static boolean isJoinTypeSupported(Join join) {
+final JoinRelType type = join.getJoinType();
+return type == JoinRelType.INNER || type == JoinRelType.SEMI || type == 
JoinRelType.LEFT;
   }
 
   /**
@@ -170,7 +172,7 @@ public abstract class SemiJoinRule
 return withOperandSupplier(b ->
 b.operand(projectClass).oneInput(b2 ->
 b2.operand(joinClass)
-.predicate(SemiJoinRule::notGenerateNullsOnLeft).inputs(
+.predicate(SemiJoinRule::isJoinTypeSupported).inputs(
 b3 -> b3.operand(RelNode.class).anyInputs(),
 b4 -> b4.operand(aggregateClass).anyInputs(
 .as(Config.class);
@@ -219,7 +221,7 @@ public abstract class SemiJoinRule
   default Config withOperandFor(Class joinClass,
   Class aggregateClass) {
 return withOperandSupplier(b ->
-
b.operand(joinClass).predicate(SemiJoinRule::notGenerateNullsOnLeft).inputs(
+
b.operand(joinClass).predicate(SemiJoinRule::isJoinTypeSupported).inputs(
 b2 -> b2.operand(RelNode.class).anyInputs(),
 b3 -> b3.operand(aggregateClass).anyInputs()))
 .as(Config.class);
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java 
b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index e23e86f..d988d72 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -5513,6 +5513,45 @@ class RelOptRulesTest extends RelOptTestBase {
 assertEquals(planBefore, planAfter);
   }
 
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-4621;>[CALCITE-4621]
+   * SemiJoinRule throws AssertionError on ANTI join. */
+  @Test void testJoinToSemiJoinRuleOnAntiJoin() {
+testSemiJoinRuleOnAntiJoin(CoreRules.JOIN_TO_SEMI_JOIN);
+  }
+
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-4621;>[CALCITE-4621]
+   * SemiJoinRule throws AssertionError on ANTI join. */
+  @Test void testProjectToSemiJoinRuleOnAntiJoin() {
+testSemiJoinRuleOnAntiJoin(CoreRules.PROJECT_TO_SEMI_JOIN);
+  }
+
+  private void testSemiJoinRuleOnAntiJoin(RelOptRule rule) {
+final RelBuilder relBuilder = 
RelBuilder.create(RelBuilderTest.config().build());
+final RelNode input = relBuilder
+.scan("DEPT")
+.scan("EMP")
+.project(relBuilder.field("DEPTNO"))
+.distinct()
+.antiJoin(relBuilder
+.equals(
+relBuilder.field(2, 0, "DEPTNO"),
+relBuilder.field(2, 1, "DEPTNO")))
+.project(relBuilder.field("DNAME"))
+.build();
+
+final HepProgram program = new HepProgramBuilder()
+.addRuleInstance(rule)
+.build();
+final HepPlanner hepPlanner = new HepPlanner(program);
+hepPlanner.setRoot(input);
+final RelNode output = hepPlanner.findBestExp();
+final String planBefore = RelOptUtil.toString(input);
+final String planAfter = RelOptUtil.toString(output);
+assertEquals(planBefore, planAfter);
+  }
+
   @Test void testPushJoinCondDownToProject()

[calcite] branch master updated: Add generic info to Map & Array annotation

2021-05-26 Thread rubenql
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 2741cc5  Add generic info to Map & Array annotation
2741cc5 is described below

commit 2741cc5ab39f148917a2b53f023acd34975bb9a2
Author: tison 
AuthorDate: Sun May 9 22:31:49 2021 +0800

Add generic info to Map & Array annotation

Signed-off-by: tison 
---
 core/src/main/java/org/apache/calcite/adapter/java/Array.java | 7 +++
 core/src/main/java/org/apache/calcite/adapter/java/Map.java   | 9 -
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/adapter/java/Array.java 
b/core/src/main/java/org/apache/calcite/adapter/java/Array.java
index 40b163e..a7e786f 100644
--- a/core/src/main/java/org/apache/calcite/adapter/java/Array.java
+++ b/core/src/main/java/org/apache/calcite/adapter/java/Array.java
@@ -16,20 +16,19 @@
  */
 package org.apache.calcite.adapter.java;
 
+import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
-import static java.lang.annotation.ElementType.FIELD;
-
 /**
  * Annotation that indicates that a field is an array type.
  */
-@Target({FIELD })
+@Target(ElementType.FIELD)
 @Retention(RetentionPolicy.RUNTIME)
 public @interface Array {
   /** Component type. */
-  Class component();
+  Class component();
 
   /** Whether components may be null. */
   boolean componentIsNullable() default false;
diff --git a/core/src/main/java/org/apache/calcite/adapter/java/Map.java 
b/core/src/main/java/org/apache/calcite/adapter/java/Map.java
index 7aa198b..a3860ca 100644
--- a/core/src/main/java/org/apache/calcite/adapter/java/Map.java
+++ b/core/src/main/java/org/apache/calcite/adapter/java/Map.java
@@ -16,23 +16,22 @@
  */
 package org.apache.calcite.adapter.java;
 
+import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
-import static java.lang.annotation.ElementType.FIELD;
-
 /**
  * Annotation that indicates that a field is a map type.
  */
-@Target({FIELD })
+@Target(ElementType.FIELD)
 @Retention(RetentionPolicy.RUNTIME)
 public @interface Map {
   /** Key type. */
-  Class key();
+  Class key();
 
   /** Value type. */
-  Class value();
+  Class value();
 
   /** Whether keys may be null. */
   boolean keyIsNullable() default true;


[calcite] branch master updated: [CALCITE-2000] UNNEST a collection that has a field with nested data generates an Exception

2021-03-01 Thread rubenql
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 3cfeba8  [CALCITE-2000] UNNEST a collection that has a field with 
nested data generates an Exception
3cfeba8 is described below

commit 3cfeba8a4d3f5e0968820ba5a6571ceda191aa7f
Author: rubenada 
AuthorDate: Fri Feb 19 16:00:38 2021 +

[CALCITE-2000] UNNEST a collection that has a field with nested data 
generates an Exception
---
 .../org/apache/calcite/runtime/SqlFunctions.java   | 47 --
 .../test/enumerable/EnumerableUncollectTest.java   | 20 ++---
 2 files changed, 23 insertions(+), 44 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java 
b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
index c36f8a9..382e091 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
@@ -2792,40 +2792,8 @@ public class SqlFunctions {
* Function that, given a certain List containing single-item structs (i.e. 
arrays / lists with
* a single item), builds an Enumerable that returns those single items 
inside the structs.
*/
-  public static Function1> flatList() {
-return inputObject -> {
-  final List list = (List) inputObject;
-  final Enumerator> enumerator = Linq4j.enumerator(list);
-  return new AbstractEnumerable() {
-@Override public Enumerator enumerator() {
-  return new Enumerator() {
-
-@Override public boolean moveNext() {
-  return enumerator.moveNext();
-}
-
-@Override public Comparable current() {
-  final Object element = enumerator.current();
-  final Comparable comparable;
-  if (element.getClass().isArray()) {
-comparable = (Comparable) ((Object[]) element)[0];
-  } else {
-comparable = (Comparable) ((List) element).get(0);
-  }
-  return comparable;
-}
-
-@Override public void reset() {
-  enumerator.reset();
-}
-
-@Override public void close() {
-  enumerator.close();
-}
-  };
-}
-  };
-};
+  public static Function1, Enumerable> flatList() {
+return inputList -> Linq4j.asEnumerable(inputList).select(v -> 
structAccess(v, 0, null));
   }
 
   public static Function1>> 
flatProduct(
@@ -3038,8 +3006,8 @@ public class SqlFunctions {
* @param  element type */
   private static class ProductComparableListEnumerator
   extends CartesianProductEnumerator, FlatLists.ComparableList> 
{
-final E[] flatElements;
-final List list;
+final Object[] flatElements;
+final List list;
 private final boolean withOrdinality;
 private int ordinality;
 
@@ -3047,7 +3015,7 @@ public class SqlFunctions {
 int fieldCount, boolean withOrdinality) {
   super(enumerators);
   this.withOrdinality = withOrdinality;
-  flatElements = (E[]) new Comparable[fieldCount];
+  flatElements = new Object[fieldCount];
   list = Arrays.asList(flatElements);
 }
 
@@ -3073,9 +3041,10 @@ public class SqlFunctions {
 i += a.length;
   }
   if (withOrdinality) {
-flatElements[i] = (E) Integer.valueOf(ordinality);
+flatElements[i] = ordinality;
   }
-  return FlatLists.ofComparable(list);
+  //noinspection unchecked
+  return (FlatLists.ComparableList) FlatLists.of(list);
 }
 
 @Override public void reset() {
diff --git 
a/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableUncollectTest.java
 
b/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableUncollectTest.java
index 92508c9..78f6ebf 100644
--- 
a/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableUncollectTest.java
+++ 
b/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableUncollectTest.java
@@ -20,10 +20,9 @@ import org.apache.calcite.config.CalciteConnectionProperty;
 import org.apache.calcite.config.Lex;
 import org.apache.calcite.test.CalciteAssert;
 
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
-/** Test for {@link EnumerableUncollect}. */
+/** Test for {@link 
org.apache.calcite.adapter.enumerable.EnumerableUncollect}. */
 class EnumerableUncollectTest {
 
   @Test void simpleUnnestArray() {
@@ -90,12 +89,23 @@ class EnumerableUncollectTest {
 "y=4; o=2");
   }
 
-  @Disabled("CALCITE-4064")
   @Test void simpleUnnestArrayOfRows4() {
-final String sql = "select * from UNNEST(array[ROW(1, ROW(5, 10)), ROW(2, 
ROW(6, 12))])";
+final String sql = "select * from UNNEST(array[ROW(

[calcite] branch master updated: [CALCITE-4437] The Sort rel should be decorrelated even though it has fetch or limit when it is not inside a Correlate (Thomas Rebele)

2021-02-25 Thread rubenql
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 8e7d735d [CALCITE-4437] The Sort rel should be decorrelated even 
though it has fetch or limit when it is not inside a Correlate (Thomas Rebele)
8e7d735d is described below

commit 8e7d735da428f9b193e86333ebe11712340dfeda
Author: Thomas Rebele 
AuthorDate: Wed Dec 16 11:37:39 2020 +0100

[CALCITE-4437] The Sort rel should be decorrelated even though it has fetch 
or limit when it is not inside a Correlate (Thomas Rebele)
---
 .../apache/calcite/sql2rel/RelDecorrelator.java| 75 +++---
 .../apache/calcite/test/SqlToRelConverterTest.java | 20 ++
 .../apache/calcite/test/SqlToRelConverterTest.xml  | 27 
 3 files changed, 85 insertions(+), 37 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java 
b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
index 87f0adf..2fe9bd0 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
@@ -160,7 +160,8 @@ public class RelDecorrelator implements ReflectiveVisitor {
   protected final ReflectUtil.MethodDispatcher<@Nullable Frame> dispatcher =
   ReflectUtil.createMethodDispatcher(
   Frame.class, getVisitor(), "decorrelateRel",
-  RelNode.class);
+  RelNode.class,
+  boolean.class);
 
   // The rel which is being visited
   protected @Nullable RelNode currentRel;
@@ -288,7 +289,7 @@ public class RelDecorrelator implements ReflectiveVisitor {
 // Perform decorrelation.
 map.clear();
 
-final Frame frame = getInvoke(root, null);
+final Frame frame = getInvoke(root, false, null);
 if (frame != null) {
   // has been rewritten; apply rules post-decorrelation
   final HepProgramBuilder builder = HepProgram.builder()
@@ -401,14 +402,14 @@ public class RelDecorrelator implements ReflectiveVisitor 
{
   }
 
   /** Fallback if none of the other {@code decorrelateRel} methods match. */
-  public @Nullable Frame decorrelateRel(RelNode rel) {
+  public @Nullable Frame decorrelateRel(RelNode rel, boolean isCorVarDefined) {
 RelNode newRel = rel.copy(rel.getTraitSet(), rel.getInputs());
 
 if (rel.getInputs().size() > 0) {
   List oldInputs = rel.getInputs();
   List newInputs = new ArrayList<>();
   for (int i = 0; i < oldInputs.size(); ++i) {
-final Frame frame = getInvoke(oldInputs.get(i), rel);
+final Frame frame = getInvoke(oldInputs.get(i), isCorVarDefined, rel);
 if (frame == null || !frame.corDefOutputs.isEmpty()) {
   // if input is not rewritten, or if it produces correlated
   // variables, terminate rewrite
@@ -429,7 +430,7 @@ public class RelDecorrelator implements ReflectiveVisitor {
 ImmutableSortedMap.of());
   }
 
-  public @Nullable Frame decorrelateRel(Sort rel) {
+  public @Nullable Frame decorrelateRel(Sort rel, boolean isCorVarDefined) {
 //
 // Rewrite logic:
 //
@@ -446,7 +447,7 @@ public class RelDecorrelator implements ReflectiveVisitor {
 // need to call propagateExpr.
 
 final RelNode oldInput = rel.getInput();
-final Frame frame = getInvoke(oldInput, rel);
+final Frame frame = getInvoke(oldInput, isCorVarDefined, rel);
 if (frame == null) {
   // If input has not been rewritten, do not rewrite this rel.
   return null;
@@ -474,16 +475,16 @@ public class RelDecorrelator implements ReflectiveVisitor 
{
 return register(rel, newSort, frame.oldToNewOutputs, frame.corDefOutputs);
   }
 
-  public @Nullable Frame decorrelateRel(Values rel) {
+  public @Nullable Frame decorrelateRel(Values rel, boolean isCorVarDefined) {
 // There are no inputs, so rel does not need to be changed.
 return null;
   }
 
-  public @Nullable Frame decorrelateRel(LogicalAggregate rel) {
-return decorrelateRel((Aggregate) rel);
+  public @Nullable Frame decorrelateRel(LogicalAggregate rel, boolean 
isCorVarDefined) {
+return decorrelateRel((Aggregate) rel, isCorVarDefined);
   }
 
-  public @Nullable Frame decorrelateRel(Aggregate rel) {
+  public @Nullable Frame decorrelateRel(Aggregate rel, boolean 
isCorVarDefined) {
 //
 // Rewrite logic:
 //
@@ -497,7 +498,7 @@ public class RelDecorrelator implements ReflectiveVisitor {
 assert !cm.mapRefRelToCorRef.containsKey(rel);
 
 final RelNode oldInput = rel.getInput();
-final Frame frame = getInvoke(oldInput, rel);
+final Frame frame = getInvoke(oldInput, isCorVarDefined, rel);
 if (frame == null) {
   // If input has not been rewritten, do not rewrite this rel.
   return null;
@@ -692,10 +693,10 @@ public class RelDecorrelator 

[calcite] branch master updated: [CALCITE-3221] Add MergeUnion operator in Enumerable convention

2021-02-10 Thread rubenql
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 4cd90f3  [CALCITE-3221] Add MergeUnion operator in Enumerable 
convention
4cd90f3 is described below

commit 4cd90f36c3cf9a012e34f14129a907a4ce99c6f5
Author: rubenada 
AuthorDate: Mon Jan 18 16:30:07 2021 +

[CALCITE-3221] Add MergeUnion operator in Enumerable convention
---
 .../adapter/enumerable/EnumerableMergeUnion.java   | 118 +
 .../enumerable/EnumerableMergeUnionRule.java   | 105 +
 .../adapter/enumerable/EnumerableRules.java|   6 +
 .../calcite/rel/metadata/RelMdCollation.java   |  12 +
 .../java/org/apache/calcite/tools/Programs.java|   1 +
 .../org/apache/calcite/util/BuiltInMethod.java |   2 +
 .../apache/calcite/runtime/EnumerablesTest.java| 515 +
 .../test/enumerable/EnumerableMergeUnionTest.java  | 309 +
 .../apache/calcite/linq4j/EnumerableDefaults.java  |  37 +-
 .../calcite/linq4j/MergeUnionEnumerator.java   | 208 +
 10 files changed, 1311 insertions(+), 2 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeUnion.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeUnion.java
new file mode 100644
index 000..182e0a5
--- /dev/null
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeUnion.java
@@ -0,0 +1,118 @@
+/*
+ * 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.adapter.enumerable;
+
+import org.apache.calcite.linq4j.Ord;
+import org.apache.calcite.linq4j.tree.BlockBuilder;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.ParameterExpression;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelTraitSet;
+import org.apache.calcite.rel.RelCollation;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.util.BuiltInMethod;
+import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.Util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/** Implementation of {@link org.apache.calcite.rel.core.Union} in
+ * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention 
enumerable calling convention}.
+ * Performs a union (or union all) of all its inputs (which must be already 
sorted),
+ * respecting the order. */
+public class EnumerableMergeUnion extends EnumerableUnion {
+
+  protected EnumerableMergeUnion(RelOptCluster cluster, RelTraitSet traitSet, 
List inputs,
+  boolean all) {
+super(cluster, traitSet, inputs, all);
+final RelCollation collation = traitSet.getCollation();
+if (collation == null || collation.getFieldCollations().isEmpty()) {
+  throw new IllegalArgumentException("EnumerableMergeUnion with no 
collation");
+}
+for (RelNode input : inputs) {
+  final RelCollation inputCollation = input.getTraitSet().getCollation();
+  if (inputCollation == null || !inputCollation.satisfies(collation)) {
+throw new IllegalArgumentException("EnumerableMergeUnion input does 
not satisfy collation. "
++ "EnumerableMergeUnion collation: " + collation + ". Input 
collation: "
++ inputCollation + ". Input: " + input);
+  }
+}
+  }
+
+  public static EnumerableMergeUnion create(RelCollation collation, 
List inputs,
+  boolean all) {
+final RelOptCluster cluster = inputs.get(0).getCluster();
+final RelTraitSet traitSet = 
cluster.traitSetOf(EnumerableConvention.INSTANCE).replace(
+collation);
+return new EnumerableMergeUnion(cluster, traitSet, inputs, all);
+  }
+
+  @Override public EnumerableMergeUnion copy(RelTraitSet traitSet, 
List inputs,
+  boolean all) {
+return new EnumerableMergeUnion(getCluster(), traitSet, inputs, all);
+  }
+
+  @Override public Result implement(EnumerableRelImplementor implementor, 
Prefer pref) {
+final Block

[calcite-avatica] branch master updated: [CALCITE-4181] Avatica throws exception when select field is a List (Kent Nguyen)

2021-01-11 Thread rubenql
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-avatica.git


The following commit(s) were added to refs/heads/master by this push:
 new ed44494  [CALCITE-4181] Avatica throws exception when select field is 
a List (Kent Nguyen)
ed44494 is described below

commit ed444948659a55309860952e1bbb41ee77ff4699
Author: Kent Nguyen 
AuthorDate: Thu Aug 20 13:29:15 2020 +0700

[CALCITE-4181] Avatica throws exception when select field is a List 
(Kent Nguyen)
---
 .../calcite/avatica/util/AbstractCursor.java   |   1 +
 .../apache/calcite/avatica/util/ArrayImplTest.java | 214 +
 2 files changed, 215 insertions(+)

diff --git 
a/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java 
b/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java
index 5559f60..ce81049 100644
--- a/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java
+++ b/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java
@@ -1341,6 +1341,7 @@ public abstract class AbstractCursor implements Cursor {
   case Types.TIMESTAMP:
   case Types.STRUCT:
   case Types.JAVA_OBJECT:
+  case Types.OTHER:
 return componentAccessor.getObject();
   default:
 throw new IllegalStateException("Unhandled ARRAY component type: " + 
componentType.rep
diff --git 
a/core/src/test/java/org/apache/calcite/avatica/util/ArrayImplTest.java 
b/core/src/test/java/org/apache/calcite/avatica/util/ArrayImplTest.java
index 2ebd13b..9133270 100644
--- a/core/src/test/java/org/apache/calcite/avatica/util/ArrayImplTest.java
+++ b/core/src/test/java/org/apache/calcite/avatica/util/ArrayImplTest.java
@@ -33,6 +33,7 @@ import java.sql.Types;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -164,6 +165,219 @@ public class ArrayImplTest {
 }
   }
 
+  /**
+   * The same test as arrayOfStructs(), except we use List instead of 
ArrayImpl.
+   */
+  @Test public void listOfStructs() throws Exception {
+ColumnMetaData intMetaData = MetaImpl.columnMetaData("MY_INT", 1, 
int.class, false);
+ColumnMetaData stringMetaData = MetaImpl.columnMetaData("MY_STRING", 2, 
String.class, true);
+StructType structType = ColumnMetaData.struct(Arrays.asList(intMetaData, 
stringMetaData));
+Struct struct1 = new StructImpl(Arrays.asList(1, "one"));
+Struct struct2 = new StructImpl(Arrays.asList(2, "two"));
+Struct struct3 = new StructImpl(Arrays.asList(3));
+Struct struct4 = new StructImpl(Arrays.asList(4, "four"));
+ArrayType arrayType = ColumnMetaData.array(structType, "OBJECT", 
Rep.STRUCT);
+ColumnMetaData arrayMetaData = MetaImpl.columnMetaData("MY_ARRAY", 1, 
arrayType, false);
+ArrayImpl.Factory factory = new 
ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone());
+
+List list1 = Arrays.asList(struct1, struct2);
+List list2 = Arrays.asList(struct3, struct4);
+List> rows = Arrays.asList(Arrays.asList(list1), 
Arrays.asList(list2));
+
+try (Cursor cursor = new ListIteratorCursor(rows.iterator())) {
+  List accessors = 
cursor.createAccessors(Arrays.asList(arrayMetaData),
+  Unsafe.localCalendar(), factory);
+  assertEquals(1, accessors.size());
+  Accessor accessor = accessors.get(0);
+
+  assertTrue(cursor.next());
+  Array actualArray = accessor.getArray();
+
+  Object[] arrayData = (Object[]) actualArray.getArray();
+  assertEquals(2, arrayData.length);
+  Struct actualStruct = (Struct) arrayData[0];
+  Object[] o = actualStruct.getAttributes();
+  assertEquals(2, o.length);
+  assertEquals(1, o[0]);
+  assertEquals("one", o[1]);
+
+  actualStruct = (Struct) arrayData[1];
+  o = actualStruct.getAttributes();
+  assertEquals(2, o.length);
+  assertEquals(2, o[0]);
+  assertEquals("two", o[1]);
+
+  assertTrue(cursor.next());
+  actualArray = accessor.getArray();
+  arrayData = (Object[]) actualArray.getArray();
+  assertEquals(2, arrayData.length);
+  actualStruct = (Struct) arrayData[0];
+  o = actualStruct.getAttributes();
+  assertEquals(1, o.length);
+  assertEquals(3, o[0]);
+
+  actualStruct = (Struct) arrayData[1];
+  o = actualStruct.getAttributes();
+  assertEquals(2, o.length);
+  assertEquals(4, o[0]);
+  assertEquals("four", o[1]);
+}
+  }
+
+  /**
+   * Plain Java object class for the two tests that follow.
+   */
+  static class PlainJavaObject {
+public int intProperty;
+public String stringProperty;
+
+PlainJavaObject(int intProp, String stringProp) {
+  

[calcite] branch master updated: [CALCITE-4453] RexExecutorImpl#compile should use RexBuilder's type factory if possible

2021-01-07 Thread rubenql
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 1f39ffa  [CALCITE-4453] RexExecutorImpl#compile should use 
RexBuilder's type factory if possible
1f39ffa is described below

commit 1f39ffacb53dc6799edac61f72b23997cb8a88d9
Author: rubenada 
AuthorDate: Mon Jan 4 13:19:49 2021 +

[CALCITE-4453] RexExecutorImpl#compile should use RexBuilder's type factory 
if possible
---
 core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java 
b/core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java
index 0604954..9f9cf3f 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexExecutorImpl.java
@@ -76,8 +76,10 @@ public class RexExecutorImpl implements RexExecutor {
   programBuilder.addProject(
   node, "c" + programBuilder.getProjectList().size());
 }
-final JavaTypeFactoryImpl javaTypeFactory =
-new JavaTypeFactoryImpl(rexBuilder.getTypeFactory().getTypeSystem());
+final RelDataTypeFactory typeFactory = rexBuilder.getTypeFactory();
+final JavaTypeFactory javaTypeFactory = typeFactory instanceof 
JavaTypeFactory
+? (JavaTypeFactory) typeFactory
+: new JavaTypeFactoryImpl(typeFactory.getTypeSystem());
 final BlockBuilder blockBuilder = new BlockBuilder();
 final ParameterExpression root0_ =
 Expressions.parameter(Object.class, "root0");



[calcite] branch master updated: [CALCITE-4419] Posix regex operators cannot be used within RelBuilder

2020-12-03 Thread rubenql
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 d9b55b4  [CALCITE-4419] Posix regex operators cannot be used within 
RelBuilder
d9b55b4 is described below

commit d9b55b4300eb2959c4ed55e9b692ffb9f12dd1ef
Author: rubenada 
AuthorDate: Tue Nov 24 11:49:43 2020 +

[CALCITE-4419] Posix regex operators cannot be used within RelBuilder
---
 .../calcite/adapter/enumerable/RexImpTable.java| 34 ++---
 .../main/java/org/apache/calcite/runtime/Like.java | 21 +
 .../org/apache/calcite/runtime/SqlFunctions.java   | 19 ++--
 .../calcite/sql/fun/SqlPosixRegexOperator.java | 48 +--
 .../org/apache/calcite/util/BuiltInMethod.java |  2 +-
 .../test/enumerable/EnumerableCalcTest.java| 55 ++
 6 files changed, 128 insertions(+), 51 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
index 42aae7e..7ac4fb1 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
@@ -476,17 +476,18 @@ public class RexImpTable {
 map.put(SIMILAR_TO, similarImplementor);
 
 // POSIX REGEX
-final MethodImplementor posixRegexImplementor =
-new MethodImplementor(BuiltInMethod.POSIX_REGEX.method,
-NullPolicy.STRICT, false);
+final MethodImplementor posixRegexImplementorCaseSensitive =
+new PosixRegexMethodImplementor(true);
+final MethodImplementor posixRegexImplementorCaseInsensitive =
+new PosixRegexMethodImplementor(false);
 map.put(SqlStdOperatorTable.POSIX_REGEX_CASE_INSENSITIVE,
-posixRegexImplementor);
+posixRegexImplementorCaseInsensitive);
 map.put(SqlStdOperatorTable.POSIX_REGEX_CASE_SENSITIVE,
-posixRegexImplementor);
+posixRegexImplementorCaseSensitive);
 map.put(SqlStdOperatorTable.NEGATED_POSIX_REGEX_CASE_INSENSITIVE,
-NotImplementor.of(posixRegexImplementor));
+NotImplementor.of(posixRegexImplementorCaseInsensitive));
 map.put(SqlStdOperatorTable.NEGATED_POSIX_REGEX_CASE_SENSITIVE,
-NotImplementor.of(posixRegexImplementor));
+NotImplementor.of(posixRegexImplementorCaseSensitive));
 map.put(REGEXP_REPLACE, new RegexpReplaceImplementor());
 
 // Multisets & arrays
@@ -2001,6 +2002,25 @@ public class RexImpTable {
 }
   }
 
+  /** Implementor for {@link 
org.apache.calcite.sql.fun.SqlPosixRegexOperator}s. */
+  private static class PosixRegexMethodImplementor extends MethodImplementor {
+protected final boolean caseSensitive;
+
+PosixRegexMethodImplementor(boolean caseSensitive) {
+  super(BuiltInMethod.POSIX_REGEX.method, NullPolicy.STRICT, false);
+  this.caseSensitive = caseSensitive;
+}
+
+@Override Expression implementSafe(RexToLixTranslator translator,
+RexCall call, List argValueList) {
+  assert argValueList.size() == 2;
+  // Add extra parameter (caseSensitive boolean flag), required by 
SqlFunctions#posixRegex.
+  final List newOperands = new ArrayList<>(argValueList);
+  newOperands.add(Expressions.constant(caseSensitive));
+  return super.implementSafe(translator, call, newOperands);
+}
+  }
+
   /**
* Implementor for JSON_VALUE function, convert to solid format
* "JSON_VALUE(json_doc, path, empty_behavior, empty_default, 
error_behavior, error default)"
diff --git a/core/src/main/java/org/apache/calcite/runtime/Like.java 
b/core/src/main/java/org/apache/calcite/runtime/Like.java
index 8ebecb7..34f20de 100644
--- a/core/src/main/java/org/apache/calcite/runtime/Like.java
+++ b/core/src/main/java/org/apache/calcite/runtime/Like.java
@@ -18,6 +18,9 @@ package org.apache.calcite.runtime;
 
 import org.checkerframework.checker.nullness.qual.Nullable;
 
+import java.util.Arrays;
+import java.util.Locale;
+
 /**
  * Utilities for converting SQL {@code LIKE} and {@code SIMILAR} operators
  * to regular expressions.
@@ -42,6 +45,11 @@ public class Like {
   "[:alnum:]", "\\p{Alnum}"
   };
 
+  // It's important to have XDigit before Digit to match XDigit first
+  // (i.e. see the posixRegexToPattern method)
+  private static final String[] POSIX_CHARACTER_CLASSES = new String[] { 
"Lower", "Upper", "ASCII",
+  "Alpha", "XDigit", "Digit", "Alnum", "Punct", "Graph", "Print", "Blank", 
"Cntrl", "Space" };
+
   private Like() {
   }
 
@@ -303,4 +311,17 @@ public class Like {
 
 return javaPattern.toString();
   }
+
+  static java.uti

[calcite] branch master updated: [CALCITE-4415] SqlStdOperatorTable.NOT_LIKE has a wrong implementor

2020-11-29 Thread rubenql
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 f3a9f6f  [CALCITE-4415] SqlStdOperatorTable.NOT_LIKE has a wrong 
implementor
f3a9f6f is described below

commit f3a9f6f34cd8a0fb1475810e9bf7fcba27d90e06
Author: rubenada 
AuthorDate: Tue Nov 24 09:39:51 2020 +

[CALCITE-4415] SqlStdOperatorTable.NOT_LIKE has a wrong implementor
---
 .../calcite/adapter/enumerable/RexImpTable.java|  4 -
 .../apache/calcite/rel/rel2sql/SqlImplementor.java | 86 +++---
 .../apache/calcite/sql/fun/SqlLikeOperator.java|  8 ++
 .../java/org/apache/calcite/tools/RelBuilder.java  | 11 +++
 .../org/apache/calcite/test/RelBuilderTest.java| 64 
 .../adapter/elasticsearch/PredicateAnalyzer.java   | 26 ---
 6 files changed, 128 insertions(+), 71 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
index bb65054..0c17078 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
@@ -262,8 +262,6 @@ import static 
org.apache.calcite.sql.fun.SqlStdOperatorTable.MULTISET_UNION_DIST
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.NEXT_VALUE;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.NOT;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.NOT_EQUALS;
-import static org.apache.calcite.sql.fun.SqlStdOperatorTable.NOT_LIKE;
-import static org.apache.calcite.sql.fun.SqlStdOperatorTable.NOT_SIMILAR_TO;
 import static 
org.apache.calcite.sql.fun.SqlStdOperatorTable.NOT_SUBMULTISET_OF;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.NTH_VALUE;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.NTILE;
@@ -467,12 +465,10 @@ public class RexImpTable {
 new MethodImplementor(BuiltInMethod.LIKE.method, NullPolicy.STRICT,
 false);
 map.put(LIKE, likeImplementor);
-map.put(NOT_LIKE, likeImplementor);
 final MethodImplementor similarImplementor =
 new MethodImplementor(BuiltInMethod.SIMILAR.method, NullPolicy.STRICT,
 false);
 map.put(SIMILAR_TO, similarImplementor);
-map.put(NOT_SIMILAR_TO, NotImplementor.of(similarImplementor));
 
 // POSIX REGEX
 final MethodImplementor posixRegexImplementor =
diff --git 
a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java 
b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
index b61e4b8..582e60f 100644
--- a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
+++ b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
@@ -300,16 +300,6 @@ public abstract class SqlImplementor {
 final SqlOperator op;
 final Context joinContext;
 switch (node.getKind()) {
-case NOT:
-  final RexNode operand0 = ((RexCall) node).getOperands().get(0);
-  final SqlOperator notOperator = 
NOT_KIND_OPERATORS.get(operand0.getKind());
-  if (notOperator != null) {
-return convertConditionToSqlNode(
-leftContext.implementor().rexBuilder.makeCall(notOperator,
-((RexCall) operand0).operands), leftContext, rightContext,
-leftFieldCount, dialect);
-  }
-  // fall through
 case AND:
 case OR:
   operands = ((RexCall) node).getOperands();
@@ -331,6 +321,7 @@ public abstract class SqlImplementor {
 case LESS_THAN:
 case LESS_THAN_OR_EQUAL:
 case LIKE:
+case NOT:
   node = stripCastFromString(node, dialect);
   operands = ((RexCall) node).getOperands();
   op = ((RexCall) node).getOperator();
@@ -820,40 +811,53 @@ public abstract class SqlImplementor {
   return toSql(program, (RexOver) rex);
 }
 
-final RexCall call = (RexCall) stripCastFromString(rex, dialect);
-SqlOperator op = call.getOperator();
-switch (op.getKind()) {
-case SUM0:
-  op = SqlStdOperatorTable.SUM;
-  break;
-default:
-  break;
+return callToSql(program, (RexCall) rex, false);
+  }
+}
+
+private SqlNode callToSql(RexProgram program, RexCall rex, boolean not) {
+  final RexCall call = (RexCall) stripCastFromString(rex, dialect);
+  SqlOperator op = call.getOperator();
+  switch (op.getKind()) {
+  case SUM0:
+op = SqlStdOperatorTable.SUM;
+break;
+  case NOT:
+RexNode operand = call.operands.get(0);
+if (NOT_KIND_OPERATORS.containsKey(operand.getKind())) {
+  return callToSql(program, (RexCall) operand, !not);
 }
-final List nodeList = toSql(program, call.getOperands());
-switch

[calcite] branch master updated (b4e399c -> c9d7f5e)

2020-11-29 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git.


from b4e399c  [CALCITE-4414] RelMdSelectivity#getSelectivity for Calc can 
propagate a predicate with wrong references
 add c9d7f5e  [CALCITE-4317] RelFieldTrimmer after trimming all the fields 
in an aggregate should not return a zero field Aggregate (Rafay)

No new revisions were added by this update.

Summary of changes:
 .../apache/calcite/sql2rel/RelFieldTrimmer.java| 10 +++-
 .../org/apache/calcite/test/RelOptRulesTest.java   | 57 ++
 .../org/apache/calcite/test/SqlToRelTestBase.java  | 31 
 .../org/apache/calcite/test/RelOptRulesTest.xml| 34 +
 4 files changed, 131 insertions(+), 1 deletion(-)



[calcite] branch master updated: [CALCITE-4414] RelMdSelectivity#getSelectivity for Calc can propagate a predicate with wrong references

2020-11-26 Thread rubenql
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 b4e399c  [CALCITE-4414] RelMdSelectivity#getSelectivity for Calc can 
propagate a predicate with wrong references
b4e399c is described below

commit b4e399cb35224d8c8d55f02b7cf2b9649a3b28a4
Author: rubenada 
AuthorDate: Fri Nov 20 15:06:46 2020 +

[CALCITE-4414] RelMdSelectivity#getSelectivity for Calc can propagate a 
predicate with wrong references
---
 .../java/org/apache/calcite/plan/RelOptUtil.java   | 22 +++
 .../calcite/rel/metadata/RelMdSelectivity.java |  5 +-
 .../apache/calcite/test/RelMdSelectivityTest.java  | 75 ++
 3 files changed, 101 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java 
b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
index eec60ee..70181d6 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
@@ -3064,6 +3064,28 @@ public abstract class RelOptUtil {
   }
 
   /**
+   * Converts an expression that is based on the output fields of a
+   * {@link Calc} to an equivalent expression on the Calc's input fields.
+   *
+   * @param node The expression to be converted
+   * @param calc Calc underneath the expression
+   * @return converted expression
+   */
+  public static RexNode pushPastCalc(RexNode node, Calc calc) {
+return node.accept(pushShuttle(calc));
+  }
+
+  private static RexShuttle pushShuttle(final Calc calc) {
+final List projects = 
Util.transform(calc.getProgram().getProjectList(),
+calc.getProgram()::expandLocalRef);
+return new RexShuttle() {
+  @Override public RexNode visitInputRef(RexInputRef ref) {
+return projects.get(ref.getIndex());
+  }
+};
+  }
+
+  /**
* Creates a new {@link org.apache.calcite.rel.rules.MultiJoin} to reflect
* projection references from a
* {@link Project} that is on top of the
diff --git 
a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSelectivity.java 
b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSelectivity.java
index 192cca0..b87634a 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSelectivity.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSelectivity.java
@@ -123,10 +123,13 @@ public class RelMdSelectivity
   }
 
   public Double getSelectivity(Calc rel, RelMetadataQuery mq, RexNode 
predicate) {
+if (predicate != null) {
+  predicate = RelOptUtil.pushPastCalc(predicate, rel);
+}
 final RexProgram rexProgram = rel.getProgram();
 final RexLocalRef programCondition = rexProgram.getCondition();
 if (programCondition == null) {
-  return getSelectivity(rel.getInput(), mq, predicate);
+  return mq.getSelectivity(rel.getInput(), predicate);
 } else {
   return mq.getSelectivity(rel.getInput(),
   RelMdUtil.minusPreds(
diff --git 
a/core/src/test/java/org/apache/calcite/test/RelMdSelectivityTest.java 
b/core/src/test/java/org/apache/calcite/test/RelMdSelectivityTest.java
new file mode 100644
index 000..a086022
--- /dev/null
+++ b/core/src/test/java/org/apache/calcite/test/RelMdSelectivityTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.test;
+
+import org.apache.calcite.plan.hep.HepPlanner;
+import org.apache.calcite.plan.hep.HepProgram;
+import org.apache.calcite.plan.hep.HepProgramBuilder;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.rules.CoreRules;
+import org.apache.calcite.tools.RelBuilder;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test cases for {@link org.apache.calcite.rel.metadata.RelMdSelectivity}.
+ */
+class RelMdSelectivityTest {
+
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-4414;>[CALCITE-4414]
+   * RelMdSelectivity#getSelectivity for Calc can propagate a predicate with 
wrong reference. */
+  @Test void testCalcSelectivityWithPredicate() 

[calcite] branch master updated: [CALCITE-4409] Improve exception when RelBuilder tries to create a field on a non-struct expression

2020-11-26 Thread rubenql
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 fc912eb  [CALCITE-4409] Improve exception when RelBuilder tries to 
create a field on a non-struct expression
fc912eb is described below

commit fc912eb19d9ebbaee843dc1e9d3b4175e757cb53
Author: rubenada 
AuthorDate: Thu Nov 19 16:04:18 2020 +

[CALCITE-4409] Improve exception when RelBuilder tries to create a field on 
a non-struct expression
---
 .../java/org/apache/calcite/rel/type/RelDataTypeImpl.java |  4 
 .../test/java/org/apache/calcite/test/RelBuilderTest.java | 15 +++
 2 files changed, 19 insertions(+)

diff --git 
a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeImpl.java 
b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeImpl.java
index 512b0e6..b7333c1 100644
--- a/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeImpl.java
+++ b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeImpl.java
@@ -79,6 +79,10 @@ public abstract class RelDataTypeImpl
 
   @Override public RelDataTypeField getField(String fieldName, boolean 
caseSensitive,
   boolean elideRecord) {
+if (fieldList == null) {
+  throw new IllegalStateException("Trying to access field " + fieldName
+  + " in a type with no fields: " + this);
+}
 for (RelDataTypeField field : fieldList) {
   if (Util.matches(caseSensitive, field.getName(), fieldName)) {
 return field;
diff --git a/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java 
b/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
index 836a826..f1eaadb 100644
--- a/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
@@ -2597,6 +2597,21 @@ public class RelBuilderTest {
 assertThat(ex.getMessage(), allOf(containsString("Expression"), 
containsString("not found")));
   }
 
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-4409;>[CALCITE-4409]
+   * Improve exception when RelBuilder tries to create a field on a non-struct 
expression. */
+  @Test void testFieldOnNonStructExpression() {
+final RelBuilder builder = RelBuilder.create(config().build());
+IllegalStateException ex = assertThrows(IllegalStateException.class, () -> 
{
+  builder.scan("EMP")
+  .project(
+  builder.field(builder.field("EMPNO"), "abc"))
+  .build();
+}, "Field should fail since we are trying access a field on expression 
with non-struct type");
+assertThat(ex.getMessage(),
+is("Trying to access field abc in a type with no fields: SMALLINT"));
+  }
+
   @Test void testMultiLevelAlias() {
 final RelBuilder builder = RelBuilder.create(config().build());
 RelNode root =



[calcite] branch master updated: [CALCITE-4393] ExceptionInInitializerError due to NPE in SqlCallBinding caused by circular dependency

2020-11-24 Thread rubenql
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 fbe6982  [CALCITE-4393] ExceptionInInitializerError due to NPE in 
SqlCallBinding caused by circular dependency
fbe6982 is described below

commit fbe69824ffb13f847d1db6e26f0030ddec7b0e8c
Author: rubenada 
AuthorDate: Wed Nov 11 15:01:02 2020 +

[CALCITE-4393] ExceptionInInitializerError due to NPE in SqlCallBinding 
caused by circular dependency
---
 .../java/org/apache/calcite/sql/SqlCallBinding.java | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java 
b/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
index 00823bb..f85a5c4 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
@@ -56,8 +56,17 @@ import static java.util.Objects.requireNonNull;
  * analyzing to the operands of a {@link SqlCall} with a {@link SqlValidator}.
  */
 public class SqlCallBinding extends SqlOperatorBinding {
-  private static final SqlCall DEFAULT_CALL =
-  SqlStdOperatorTable.DEFAULT.createCall(SqlParserPos.ZERO);
+
+  /** Static nested class required due to
+   * https://issues.apache.org/jira/browse/CALCITE-4393;>[CALCITE-4393]
+   * ExceptionInInitializerError due to NPE in SqlCallBinding caused by 
circular dependency.
+   * The static field inside it cannot be part of the outer class: it must be 
defined
+   * within a nested class in order to break the cycle during class loading. */
+  private static class DefaultCallHolder {
+private static final SqlCall DEFAULT_CALL =
+SqlStdOperatorTable.DEFAULT.createCall(SqlParserPos.ZERO);
+  }
+
   //~ Instance fields 
 
   private final SqlValidator validator;
@@ -148,7 +157,7 @@ public class SqlCallBinding extends SqlOperatorBinding {
   while (list.size() < range.getMax()
   && checker.isOptional(list.size())
   && checker.isFixedParameters()) {
-list.add(DEFAULT_CALL);
+list.add(DefaultCallHolder.DEFAULT_CALL);
   }
   return list;
 }
@@ -201,7 +210,7 @@ public class SqlCallBinding extends SqlOperatorBinding {
 // with DEFAULT and then convert to nulls during sql-to-rel 
conversion.
 // Thus, there is no need to show the optional operands in the 
plan and
 // decide if the optional operand is null when code generation.
-permuted.add(DEFAULT_CALL);
+permuted.add(DefaultCallHolder.DEFAULT_CALL);
   }
 }
   }



[calcite] branch master updated (f3c173c -> 5a847ea)

2020-11-19 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git.


from f3c173c  [CALCITE-4251] Get the origin column, even if it is derived 
(xzh)
 add 5a847ea  [CALCITE-4402] SqlCall#equalsDeep does not take into account 
the function quantifier (Huang Qixiang)

No new revisions were added by this update.

Summary of changes:
 .../main/java/org/apache/calcite/sql/SqlCall.java  |  3 ++
 .../apache/calcite/sql/test/SqlEqualsDeepTest.java | 54 ++
 2 files changed, 57 insertions(+)
 create mode 100644 
core/src/test/java/org/apache/calcite/sql/test/SqlEqualsDeepTest.java



[calcite] branch master updated (3ccad7b -> b973aa4)

2020-11-18 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git.


from 3ccad7b  Following [CALCITE-4364], fix the plan diff of TpcdsTest
 add b973aa4  Update release instructions

No new revisions were added by this update.

Summary of changes:
 site/_docs/howto.md | 28 
 1 file changed, 24 insertions(+), 4 deletions(-)



[calcite] branch master updated (5e9943a -> 0ce7685)

2020-11-12 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git.


from 5e9943a  [CALCITE-4364] `a IN (1, 2) AND a = 1` should be simplified 
to `a = 1`
 add 0ce7685  [CALCITE-4390] SqlMatchRecognize returns wrong operand list 
(Dawid Wysakowicz)

No new revisions were added by this update.

Summary of changes:
 .../org/apache/calcite/sql/SqlMatchRecognize.java |  3 ++-
 .../org/apache/calcite/sql/parser/SqlParserTest.java  | 19 +++
 2 files changed, 21 insertions(+), 1 deletion(-)



[calcite] branch master updated (5e9943a -> 0ce7685)

2020-11-12 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git.


from 5e9943a  [CALCITE-4364] `a IN (1, 2) AND a = 1` should be simplified 
to `a = 1`
 add 0ce7685  [CALCITE-4390] SqlMatchRecognize returns wrong operand list 
(Dawid Wysakowicz)

No new revisions were added by this update.

Summary of changes:
 .../org/apache/calcite/sql/SqlMatchRecognize.java |  3 ++-
 .../org/apache/calcite/sql/parser/SqlParserTest.java  | 19 +++
 2 files changed, 21 insertions(+), 1 deletion(-)



[calcite] branch master updated: Fix grammatical errors in documentation (Geetha Rangaswamaiah)

2020-11-09 Thread rubenql
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 59a195f  Fix grammatical errors in documentation (Geetha Rangaswamaiah)
59a195f is described below

commit 59a195f1a566e6724acc8bda246faf2f4ad89dae
Author: Geetha Rangaswamaiah 
AuthorDate: Thu Nov 5 10:34:20 2020 +0530

Fix grammatical errors in documentation (Geetha Rangaswamaiah)
---
 site/_docs/adapter.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/site/_docs/adapter.md b/site/_docs/adapter.md
index 0b85916..bb2a14d 100644
--- a/site/_docs/adapter.md
+++ b/site/_docs/adapter.md
@@ -237,7 +237,7 @@ They are straightforward to write (you just write a Java 
class and register it
 in your schema) but do not offer much flexibility in the number and type of
 arguments, resolving overloaded functions, or deriving the return type.
 
-It you want that flexibility, you probably need to write you a
+If you want that flexibility, you probably need to write a
 *user-defined operator*
 (see [interface SqlOperator]({{ site.apiRoot 
}}/org/apache/calcite/sql/SqlOperator.html)).
 



[calcite] branch site updated: Site: change 1.25.0 release date to 2020-08-22

2020-10-07 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch site
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/site by this push:
 new 7238571  Site: change 1.25.0 release date to 2020-08-22
7238571 is described below

commit 7238571b4fab43c58615f7c7c3c629a7fd831d03
Author: Andrei Sereda <25229979+asereda...@users.noreply.github.com>
AuthorDate: Sat Aug 22 17:42:40 2020 -0400

Site: change 1.25.0 release date to 2020-08-22
---
 site/_docs/history.md| 2 +-
 site/_posts/2020-08-22-release-1.25.0.md | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/site/_docs/history.md b/site/_docs/history.md
index add8954..d89ba96 100644
--- a/site/_docs/history.md
+++ b/site/_docs/history.md
@@ -218,7 +218,7 @@ Change downloads page to use downloads.apache.org
 * Fix documentation errors
 * Site: Add Rui Wang as committer, Ruben Quesada Lopez as PMC
 
-## https://github.com/apache/calcite/releases/tag/calcite-1.25.0;>1.25.0 
/ 2020-08-08
+## https://github.com/apache/calcite/releases/tag/calcite-1.25.0;>1.25.0 
/ 2020-08-22
 {: #v1-25-0}
 
 This release comes shortly after [1.24.0](#v1-24-0) and removes methods
diff --git a/site/_posts/2020-08-22-release-1.25.0.md 
b/site/_posts/2020-08-22-release-1.25.0.md
index 100e71b..49d0141 100644
--- a/site/_posts/2020-08-22-release-1.25.0.md
+++ b/site/_posts/2020-08-22-release-1.25.0.md
@@ -31,7 +31,7 @@ is pleased to announce
 [Apache Calcite release 1.25.0]({{ site.baseurl }}/docs/history.html#v1-25-0).
 
 This release comes about one month after 1.24.0 and removes methods
-which were deprecated in the previous version. In addition, notable 
improvements in 
+which were deprecated in the previous version. In addition, notable 
improvements in
 this release are:
 
 * [Interval Expressions](https://issues.apache.org/jira/browse/CALCITE-4134)



[calcite] branch site updated (69e812f -> 2391c20)

2020-10-07 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a change to branch site
in repository https://gitbox.apache.org/repos/asf/calcite.git.


omit 69e812f  Site: change 1.25.0 release date to 2020-08-22
omit 1552765  [CALCITE-4314] Suppress the current CatchAndPrintStackTrace, 
MissingSummary, etc
omit 5bf678e  [CALCITE-4314] Use ThreadLocal for SimpleDateFormat in 
DruidJson
omit 5092095  [CALCITE-4314] Avoid excessive lambdas in SemiJoinRule
omit 0024fdb  [CALCITE-4314] Avoid Map modification in forEcah loop
omit be6fc6f  [CALCITE-4314] Escape quote in labels when printing RelNode 
in Dot format
omit 13c58ef  [CALCITE-4314] Align the order of parameters and arguments in 
WinAggResetContextImpl
omit c0ee886  [CALCITE-4314] Avoid misleading fall through
omit 179ccca  [CALCITE-4314] Suppress NonOverridingEquals
omit 2235149  [CALCITE-4314] Suppress WaitNotInLoop for Unsafe
omit fe7c1f5  [CALCITE-4314] Avoid importing of common names
omit cafe7ec  [CALCITE-4314] Resolve ProtectedMembersInFinalClass
omit 122db54  [CALCITE-4314] Use canonical class references
omit 5be8a9a  [CALCITE-4314] Correct (@link javadoc tag for 
SqlStdOperatorTable#OVER
omit e537246  [CALCITE-4314] Suppress JdkObsolete for Stack usage
omit 6917193  [CALCITE-4314] Suppress MutablePublicArray in Cassandra and 
Mongo adapters
omit 3fa4bf1  [CALCITE-4314] Suppress JdkObsolete warning for Date usage 
when used in converters
omit cff3695  [CALCITE-4314] Replace LinkedList with ArrayList, ArrayDeque, 
HashSet
omit 4dd81e9  [CALCITE-4314] Avoid MissingCasesInEnumSwitch
omit 042802f  [CALCITE-4314] Make inner classes static when possible
omit 995b90b  [CALCITE-4314] Suppress warnings on Guava's @Beta API usage
omit 2cbb0c4  [CALCITE-4314] Replace protected methods in final classes 
with package-private
omit c528771  [CALCITE-4314] Replace SortedSet with NavigableSet
omit b88bae9  [CALCITE-4314] Avoid Collection.equals(...) usage as its 
behavior is not specified
omit 0cdb485  [CALCITE-4314] Use exact parameter names in JavaDoc
omit 04f8a07  [CALCITE-4314] Avoid long = int + int in 
EnumerableDefaults.orderBy
omit 1435ed5  [CALCITE-4314] Avoid returning mutable and non-mutable lists 
from the same method
omit 5628311  [CALCITE-4314] Avoid escaping HTML entities in JavaDoc code 
blocks
omit 11d7594  [CALCITE-4314] Remove unused fields, methods, and variables
omit edbd35a  [CALCITE-4314] Avoid mutable enum fields
omit 1b94f37  [CALCITE-4314] Add missing default branches to switch 
statement
omit 69b12e0  [CALCITE-4314] Suppress HidingField warnings
omit d84bb71  [CALCITE-4314] Make abstract class constructors protected 
rather than public
omit b5a94de  [CALCITE-4314] Remove unnecessary parentheses
omit 66caa54  [CALCITE-4314] Add missing @Override annotations
omit 36b31ba  [CALCITE-4314] Add Error Prone code style verification

This update removed existing revisions from the reference, leaving the
reference pointing at a previous point in the repository history.

 * -- * -- N   refs/heads/site (2391c20)
\
 O -- O -- O   (69e812f)

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

No new revisions were added by this update.

Summary of changes:
 .github/workflows/main.yml |  18 -
 build.gradle.kts   |  37 +-
 .../adapter/cassandra/CassandraEnumerator.java |  12 +-
 .../calcite/adapter/cassandra/CassandraFilter.java |   4 +-
 .../calcite/adapter/cassandra/CassandraLimit.java  |   4 +-
 .../calcite/adapter/cassandra/CassandraMethod.java |   1 -
 .../adapter/cassandra/CassandraProject.java|   4 +-
 .../calcite/adapter/cassandra/CassandraRules.java  |  12 +-
 .../adapter/cassandra/CassandraSchemaFactory.java  |   2 +-
 .../calcite/adapter/cassandra/CassandraSort.java   |   2 +-
 .../calcite/adapter/cassandra/CassandraTable.java  |  12 +-
 .../adapter/cassandra/CassandraTableScan.java  |   2 +-
 .../cassandra/CassandraToEnumerableConverter.java  |   2 +-
 .../apache/calcite/adapter/clone/ArrayTable.java   | 160 
 .../apache/calcite/adapter/clone/CloneSchema.java  |   2 +-
 .../apache/calcite/adapter/clone/ColumnLoader.java |  23 +-
 .../apache/calcite/adapter/clone/ListTable.java|  16 +-
 .../calcite/adapter/enumerable/EnumUtils.java  |  26 +-
 .../adapter/enumerable/EnumerableAggregate.java|   2 +-
 .../enumerable/EnumerableAggregateBase.java|  24 +-
 .../adapter/enumerable/EnumerableBindable.java |   6 +-
 .../calcite/adapter/enumerable/EnumerableCalc.java |   4 +-
 .../adapter/enumerable/EnumerableCollect.java  |   2 +-
 .../adapter/enumerable/EnumerableConvention.java   |  16 +-
 .../adapter/enumerable/EnumerableCorrelate.java|   2 +-
 ..

[calcite] branch site updated (b659447 -> 69e812f)

2020-10-07 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a change to branch site
in repository https://gitbox.apache.org/repos/asf/calcite.git.


 discard b659447  Site: Add Rui Wang as committer, Ruben Quesada Lopez as PMC
 discard 8cf0701  Site: change release date to 2020-08-22
 add 39dba06  [CALCITE-4169] Prepare for next development iteration. Make 
current version 1.26 (instead of released 1.25)
 add 9cf829b  [CALCITE-3782] Bitwise functions BIT_AND, BIT_OR and BIT_XOR 
support binary and varbinary type (Hailong Wang)
 add 672ed7a  [CALCITE-4113] Support LEFT join in EnumerableMergeJoin
 add 468b111  [CALCITE-4172] Expand columnar identifiers before resolving 
(James Starr)
 add 401b018  [CALCITE-4190] OR simplification incorrectly loses term
 add 425f170  [CALCITE-4195] Cast between types with different collators 
must be evaluated as not monotonic
 add 368e579  Update Checkstyle from 8.27 to 8.28 to support package-info 
files with imports
 add cf99329  [CALCITE-4185] Remove dependency between 
:ubenchmark:checkstyleJmh and :ubenchmark:compileJava
 add f0aff98  Disable multiline parameter alignment in IDEA
 add 88d1818  [CALCITE-4015] Pass through parent collation request on 
subset or superset of join keys for EnumerableMergeJoin.
 add 175851b  Use merge=union strategy to avoid false merge conflicts on 
CalciteResource.properties
 add e9f9261  [CALCITE-4180] Supports Elasticsearch basic authentication 
(fageiguanbing)
 add 734a7ac  [CALCITE-4160] Add configuration(SqlToRelConverter.Config) to 
retain ORDER BY in sub-query (Jiatao Tao)
 add 103430b  [CALCITE-4203] RelMdUniqueKeys should not return empty when 
meeting Intersect and Minus if its input has unique keys
 add 42785e4  [CALCITE-4160] Add configuration(SqlToRelConverter.Config) to 
retain ORDER BY in sub-query (Jiatao Tao) (part2)
 add 103c73f  [CALCITE-3920] Improve ORDER BY computation in Enumerable 
convention by exploiting LIMIT (Thomas Rebele)
 add e0480a9  [CALCITE-3399] Field-pruning for set operators (except UNION 
ALL) changes query semantics (Jin Xing)
 add 6842b70  [CALCITE-4206] RelDecorrelator outputs wrong plan for 
correlate sort with fetch limit
 add 850f0f4  [CALCITE-4173] Add internal SEARCH operator and Sarg literal 
that represents a set of values or ranges
 add 962d9a2  Obsolete SqlToRelConverter.ConfigBuilder, and refactor 
SqlToRelConverterTest
 add 76f26b8  [CALCITE-4220] In SqlToRelConverter, use RelBuilder for 
creating Aggregate
 add 7353fa9  [CALCITE-4208] Improve metadata row count for Join
 add eaf0edf  [CALCITE-4229] Add Util.throwAsRuntime and Util.causeOrSelf 
to simplify exception re-throwing
 add 86b42f3  [CALCITE-4217] Unlock RelCrossType#getFieldCount()
 add ff169fb  [CALCITE-4228] FlatLists.Flat6List#append should not throw 
NPE if there are null elements in the list
 add 9422fd4  [CALCITE-4226] Add Mappings#asListNonNull as a null-safe 
alternative for Mappings#asList
 add ad164ed  [CALCITE-4227] ImmutableIntList#toArray(Integer[]) should 
support arguments larger than the collection itself
 add fb2a02f  Remove ArrayList allocation from Mappings#bijection, and add 
helpful message in case NPE is thrown
 add eb4011b  Update org.nosphere.apache.rat plugin from 0.5.2 to 0.7.0, 
and print files with unapproved licenses to console
 add 60aa74f  [CALCITE-4237] Following [CALCITE-4173], fix assertion error 
when RexSimplify generates Sarg with single null only
 add 7404445  [CALCITE-4200] ExceptionInInitializerError when initializing 
DruidRules
 add c09c080  [CALCITE-4201] AssertionError when registering Druid rules 
due to conflict in description
 add fb89615  [CALCITE-4221] Update stale integration tests in Druid adapter
 add 32ac731  Minor refactoring of DruidAdapterIT and DruidAdapter2IT
 add 0920796  Site: Add Rui Wang as committer, Ruben Quesada Lopez as PMC
 add 99c0fef  [CALCITE-4197] Provide utility to visualize RelNode plans
 add 1ae20f3  [CALCITE-4239] RelMdUniqueKeys returns wrong unique keys for 
Aggregate with grouping sets
 add 8250798  [CALCITE-4182] Support mv recognition when query has constant 
filter for missing columns in group by list of mv (Wang Yanlin)
 add ea2b32e  [CALCITE-4258] SqlToRelConverter: SELECT 1 IS [NOT] DISTINCT 
FROM NULL fails with AssertionError
 add 0c5bb1a  Refactor SqlParserTest
 add 76ff191  [CALCITE-4248] Deprecate SqlParser.ConfigBuilder
 add 5c012c5  [CALCITE-4230] When parsing SQL in BigQuery dialect, split 
quoted table names that contain dots
 add df571c9  [CALCITE-4246] When parsing SQL in BigQuery dialect, allow 
unquoted table names to contain hyphens
 add c1052b3  [CALCITE-4247] When parsing SQL in BigQuery dialect, 
character literals may be enclosed in single- or double-quotes, and use 
backslashes as escapes
 add 5419f12  [CALCITE-4254

[calcite] branch master updated: Site: change 1.25.0 release date to 2020-08-22

2020-10-07 Thread rubenql
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 69e812f  Site: change 1.25.0 release date to 2020-08-22
69e812f is described below

commit 69e812ff23b6f23a3737abeea5a8978a02bc2b5d
Author: Andrei Sereda <25229979+asereda...@users.noreply.github.com>
AuthorDate: Sat Aug 22 17:42:40 2020 -0400

Site: change 1.25.0 release date to 2020-08-22
---
 site/_docs/history.md| 2 +-
 site/_posts/2020-08-22-release-1.25.0.md | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/site/_docs/history.md b/site/_docs/history.md
index add8954..d89ba96 100644
--- a/site/_docs/history.md
+++ b/site/_docs/history.md
@@ -218,7 +218,7 @@ Change downloads page to use downloads.apache.org
 * Fix documentation errors
 * Site: Add Rui Wang as committer, Ruben Quesada Lopez as PMC
 
-## https://github.com/apache/calcite/releases/tag/calcite-1.25.0;>1.25.0 
/ 2020-08-08
+## https://github.com/apache/calcite/releases/tag/calcite-1.25.0;>1.25.0 
/ 2020-08-22
 {: #v1-25-0}
 
 This release comes shortly after [1.24.0](#v1-24-0) and removes methods
diff --git a/site/_posts/2020-08-22-release-1.25.0.md 
b/site/_posts/2020-08-22-release-1.25.0.md
index 100e71b..49d0141 100644
--- a/site/_posts/2020-08-22-release-1.25.0.md
+++ b/site/_posts/2020-08-22-release-1.25.0.md
@@ -31,7 +31,7 @@ is pleased to announce
 [Apache Calcite release 1.25.0]({{ site.baseurl }}/docs/history.html#v1-25-0).
 
 This release comes about one month after 1.24.0 and removes methods
-which were deprecated in the previous version. In addition, notable 
improvements in 
+which were deprecated in the previous version. In addition, notable 
improvements in
 this release are:
 
 * [Interval Expressions](https://issues.apache.org/jira/browse/CALCITE-4134)



[calcite] branch master updated: Add 1.26.0 release announcement

2020-10-06 Thread rubenql
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 2391c20  Add 1.26.0 release announcement
2391c20 is described below

commit 2391c20bfb10760f770c5c7cd6fc488b8c5a4130
Author: rubenada 
AuthorDate: Tue Oct 6 18:58:44 2020 +0100

Add 1.26.0 release announcement
---
 site/_posts/2020-10-06-release-1.26.0.md | 40 
 1 file changed, 40 insertions(+)

diff --git a/site/_posts/2020-10-06-release-1.26.0.md 
b/site/_posts/2020-10-06-release-1.26.0.md
new file mode 100644
index 000..e09bfe7
--- /dev/null
+++ b/site/_posts/2020-10-06-release-1.26.0.md
@@ -0,0 +1,40 @@
+---
+layout: news_item
+date: "2020-10-06 18:30:00 +"
+author: rubenql
+version: 1.26.0
+categories: [release]
+tag: v1-26-0
+sha: cfa37c3fd6ae18894035721d9f1eacde40e6b268
+---
+
+
+The [Apache Calcite PMC]({{ site.baseurl }})
+is pleased to announce
+[Apache Calcite release 1.26.0]({{ site.baseurl }}/docs/history.html#v1-26-0).
+
+This release comes about two months after 1.25.0 and includes more than 70 
resolved
+issues, comprising a lot of new features and bug-fixes. Among others, it is 
worth highlighting the following.
+
+* [SEARCH operator and Sarg 
literal](https://issues.apache.org/jira/browse/CALCITE-4173)
+* [PIVOT operator in SQL](https://issues.apache.org/jira/browse/CALCITE-3752)
+* [Spatial index based on Hilbert space-filling 
curve](https://issues.apache.org/jira/browse/CALCITE-1861)
+* [Provide utility to visualize 
RelNode](https://issues.apache.org/jira/browse/CALCITE-4197)
+* [Support JDK 15 and Guava version 
29.0-jre](https://issues.apache.org/jira/browse/CALCITE-4259)



[calcite] branch master updated: Correct 1.26.0 release date

2020-10-06 Thread rubenql
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 32c62ca  Correct 1.26.0 release date
32c62ca is described below

commit 32c62ca486665dcf9693e26120142bfbdbbcb1e6
Author: rubenada 
AuthorDate: Tue Oct 6 18:11:06 2020 +0100

Correct 1.26.0 release date
---
 site/_docs/history.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/site/_docs/history.md b/site/_docs/history.md
index 800444f..add8954 100644
--- a/site/_docs/history.md
+++ b/site/_docs/history.md
@@ -28,7 +28,7 @@ For a full list of releases, see
 Downloads are available on the
 [downloads page]({{ site.baseurl }}/downloads/).
 
-## https://github.com/apache/calcite/releases/tag/calcite-1.26.0;>1.26.0 
/ 2020-10-03
+## https://github.com/apache/calcite/releases/tag/calcite-1.26.0;>1.26.0 
/ 2020-10-06
 {: #v1-26-0}
 
 This release comes about two months after [1.25.0](#v1-25-0). It includes more 
than 70 resolved



[calcite] branch master updated: Prepare for next development iteration

2020-10-06 Thread rubenql
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 1909e9d  Prepare for next development iteration
1909e9d is described below

commit 1909e9d60c950e77f39bde20fff58f87a31ea4ea
Author: rubenada 
AuthorDate: Tue Oct 6 17:59:20 2020 +0100

Prepare for next development iteration
---
 gradle.properties | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gradle.properties b/gradle.properties
index e26cbd3..e69ea83 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -27,7 +27,7 @@ kotlin.parallel.tasks.in.project=true
 # This is version for Calcite itself
 # Note: it should not include "-SNAPSHOT" as it is automatically added by 
build.gradle.kts
 # Release version can be generated by using -Prelease or -Prc= arguments
-calcite.version=1.26.0
+calcite.version=1.27.0
 # This is a version to be used from Maven repository. It can be overridden by 
localAvatica below
 calcite.avatica.version=1.17.0
 



[calcite] branch master updated (64a0ca7 -> cfa37c3)

2020-10-06 Thread rubenql
This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git.


from 64a0ca7  [CALCITE-4279] SEARCH operator cannot be pushed into Druid
 add cfa37c3  [CALCITE-4291] Release Calcite 1.26.0

No new revisions were added by this update.

Summary of changes:
 README|   2 +-
 site/_docs/history.md | 188 --
 site/_docs/howto.md   |  10 +--
 3 files changed, 190 insertions(+), 10 deletions(-)



  1   2   >