Re: [PR] [CALCITE-5387] Type-mismatch on nullability in JoinPushTransitivePredicatesRule RelRule [calcite]

2023-10-09 Thread via GitHub


ian-bertolacci commented on code in PR #3452:
URL: https://github.com/apache/calcite/pull/3452#discussion_r1350768855


##
core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java:
##
@@ -666,6 +666,29 @@ static class JoinConditionBasedPredicateInference {
   equivalence = BitSets.closure(equivalence);
 }
 
+/**
+ * As RexPermuteInputsShuttle, with one exception. When visiting an 
inputRef,
+ * it will replace the type of the InputRef with the type found in the 
input fields,
+ * instead of keeping the original type. This is used within
+ * when generating the Left/RightInferredPredicates, to avoid nullability 
mismatches
+ * between the types of the join and the types of the inputs.
+ */
+private class TypeChangingRexPermuteInputsShuttle
+extends org.apache.calcite.rex.RexPermuteInputsShuttle {

Review Comment:
   Maybe there are situations where fields is not empty, but also not the same 
size as the number of input columns?
   I could see something like this working:
   ```java
   RelDataType dataType = target < fields.size() ? local.getType() : 
fields.get(target).getType();
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6037] The function category of ARRAY/EXTRACT_VALUE/XML_TRANSFORM/EXTRACT_XML/EXISTSNODE is incorrect (Spark/MySQL/Oracle Library) [calcite]

2023-10-09 Thread via GitHub


chucheng92 commented on code in PR #3458:
URL: https://github.com/apache/calcite/pull/3458#discussion_r1350418693


##
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##
@@ -532,26 +532,30 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding 
operatorBinding,
   public static final SqlFunction EXTRACT_VALUE =
   SqlBasicFunction.create("EXTRACTVALUE",
   ReturnTypes.VARCHAR_2000.andThen(SqlTypeTransforms.FORCE_NULLABLE),
-  OperandTypes.STRING_STRING);
+  OperandTypes.STRING_STRING,

Review Comment:
   Hi, @mihaibudiu. thanks for reviewing. good point. 
   
   Frankly speaking, `SqlFunctionCategory` is a very loose field now. In fact, 
there is no strict verification during lookup, so no test cases cover it. 
However, it is currently widely used and cannot be deleted now (It is also for 
the sake of future scalability). 
   
   We can refer to the comments of the current `lookupOperatorOverloads`, it 
can immediately works if we need to use it. WDYT?
   
https://github.com/apache/calcite/blob/597b53dbb075ab72700d40f66db81d2ac9c182b8/core/src/main/java/org/apache/calcite/sql/util/ReflectiveSqlOperatorTable.java#L94



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-5948] Use explicit casting if element type in ARRAY/MAP does not equal derived component type [calcite]

2023-10-09 Thread via GitHub


chucheng92 commented on code in PR #3395:
URL: https://github.com/apache/calcite/pull/3395#discussion_r1350517693


##
core/src/test/java/org/apache/calcite/test/JdbcTest.java:
##
@@ -8144,10 +8144,9 @@ private void checkGetTimestamp(Connection con) throws 
SQLException {
* ClassCastException retrieving from ARRAY that has mixed INTEGER and 
DECIMAL
* elements. */
   @Test void testIntAndBigDecimalInArray() {
-// Result should be "EXPR$0=[1, 1.1]\n"; [CALCITE-4850] logged.
 CalciteAssert.that()
 .query("select array[1, 1.1]")
-.returns("EXPR$0=[0E+1, 1.1]\n");

Review Comment:
   @tanclary thanks for patient reviewing! btw, I think we can safely close 
CALCITE-4850. The result has been corrected.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6037] The function category of ARRAY/EXTRACT_VALUE/XML_TRANSFORM/EXTRACT_XML/EXISTSNODE is incorrect (Spark/MySQL/Oracle Library) [calcite]

2023-10-09 Thread via GitHub


LakeShen commented on code in PR #3458:
URL: https://github.com/apache/calcite/pull/3458#discussion_r1350493820


##
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##
@@ -1075,7 +1079,8 @@ private static RelDataType 
arrayReturnType(SqlOperatorBinding opBinding) {
   public static final SqlFunction ARRAY =
   SqlBasicFunction.create("ARRAY",
   SqlLibraryOperators::arrayReturnType,
-  OperandTypes.SAME_VARIADIC);
+  OperandTypes.SAME_VARIADIC,
+  SqlFunctionCategory.SYSTEM);

Review Comment:
   Get your point,I'm ok for that.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6011] Add the planner rule that pushes the Filter past a Window [calcite]

2023-10-09 Thread via GitHub


LakeShen commented on code in PR #3439:
URL: https://github.com/apache/calcite/pull/3439#discussion_r1350491085


##
core/src/main/java/org/apache/calcite/rel/rules/FilterWindowTransposeRule.java:
##
@@ -0,0 +1,131 @@
+/*
+ * 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.RelOptUtil;
+import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.calcite.rel.core.Window;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.ImmutableBitSet;
+
+import com.google.common.collect.ImmutableList;
+
+import org.immutables.value.Value;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Planner rule that pushes a {@link org.apache.calcite.rel.core.Filter}
+ * past a {@link org.apache.calcite.rel.core.Window}.
+ *
+ *  If {@code Filter} condition used columns belongs {@code Window} 
partition keys,
+ * then we could push the condition past the {@code Window}.
+ *
+ *  For example:
+ *  {@code
+ *LogicalProject(NAME=[$0], DEPTNO=[$1], EXPR$2=[$2])
+ * LogicalFilter(condition=[>($1, 0)])
+ *   LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[$2])
+ * LogicalWindow(window#0=[window(partition {0} aggs [COUNT()])])
+ *   LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ *  }
+ *
+ *  will convert to:
+ * {@code
+ *LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[$2])
+ *  LogicalWindow(window#0=[window(partition {0} aggs [COUNT()])])
+ *LogicalFilter(condition=[>($0, 0)])
+ *  LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ * }
+ *
+ * @see CoreRules#FILTER_PROJECT_TRANSPOSE
+ * @see CoreRules#PROJECT_TO_LOGICAL_PROJECT_AND_WINDOW
+ * @see CoreRules#FILTER_WINDOW_TRANSPOSE
+ */
+@Value.Enclosing
+public class FilterWindowTransposeRule

Review Comment:
   Get your point,I will take the advice.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6011] Add the planner rule that pushes the Filter past a Window [calcite]

2023-10-09 Thread via GitHub


zabetak commented on code in PR #3439:
URL: https://github.com/apache/calcite/pull/3439#discussion_r1350460404


##
core/src/main/java/org/apache/calcite/rel/rules/FilterWindowTransposeRule.java:
##
@@ -0,0 +1,131 @@
+/*
+ * 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.RelOptUtil;
+import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.calcite.rel.core.Window;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.ImmutableBitSet;
+
+import com.google.common.collect.ImmutableList;
+
+import org.immutables.value.Value;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Planner rule that pushes a {@link org.apache.calcite.rel.core.Filter}
+ * past a {@link org.apache.calcite.rel.core.Window}.
+ *
+ *  If {@code Filter} condition used columns belongs {@code Window} 
partition keys,
+ * then we could push the condition past the {@code Window}.
+ *
+ *  For example:
+ *  {@code
+ *LogicalProject(NAME=[$0], DEPTNO=[$1], EXPR$2=[$2])
+ * LogicalFilter(condition=[>($1, 0)])
+ *   LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[$2])
+ * LogicalWindow(window#0=[window(partition {0} aggs [COUNT()])])
+ *   LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ *  }
+ *
+ *  will convert to:
+ * {@code
+ *LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[$2])
+ *  LogicalWindow(window#0=[window(partition {0} aggs [COUNT()])])
+ *LogicalFilter(condition=[>($0, 0)])
+ *  LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ * }
+ *
+ * @see CoreRules#FILTER_PROJECT_TRANSPOSE
+ * @see CoreRules#PROJECT_TO_LOGICAL_PROJECT_AND_WINDOW
+ * @see CoreRules#FILTER_WINDOW_TRANSPOSE
+ */
+@Value.Enclosing
+public class FilterWindowTransposeRule
+extends RelRule
+implements TransformationRule {
+
+  protected FilterWindowTransposeRule(final Config config) {
+super(config);
+  }
+
+  @Override public void onMatch(final RelOptRuleCall call) {
+final Filter filterRel = call.rel(0);
+final Window windowRel = call.rel(1);
+
+// Get the window all groups
+List windowGroups = windowRel.groups;
+
+// The window may have multi groups,now we could only
+// deal one group case,so that we could know the partition keys.
+if (windowGroups.size() != 1) {
+  return;
+}

Review Comment:
   Sounds good. I am ok to explore this more in the future if necessary.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[calcite] branch main updated: [CALCITE-5948] Use explicit casting if element type in ARRAY/MAP does not equal derived component type

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

tanner 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 342cf606ac [CALCITE-5948] Use explicit casting if element type in 
ARRAY/MAP does not equal derived component type
342cf606ac is described below

commit 342cf606acc954228820f69f83d43298fd874184
Author: Ran Tao 
AuthorDate: Sun Aug 27 14:33:36 2023 +0800

[CALCITE-5948] Use explicit casting if element type in ARRAY/MAP does not 
equal derived component type
---
 babel/src/test/resources/sql/big-query.iq  |   4 +-
 .../calcite/sql/fun/SqlArrayValueConstructor.java  |   5 +
 .../calcite/sql/fun/SqlLibraryOperators.java   |   5 +
 .../calcite/sql/fun/SqlMapValueConstructor.java|   6 +
 .../calcite/sql/validate/SqlValidatorUtil.java |  89 ++
 .../java/org/apache/calcite/test/JdbcTest.java |   3 +-
 core/src/test/resources/sql/misc.iq|  12 +-
 .../org/apache/calcite/test/SqlOperatorTest.java   | 193 +++--
 8 files changed, 293 insertions(+), 24 deletions(-)

diff --git a/babel/src/test/resources/sql/big-query.iq 
b/babel/src/test/resources/sql/big-query.iq
index 5455de9f57..9dce6abdd0 100755
--- a/babel/src/test/resources/sql/big-query.iq
+++ b/babel/src/test/resources/sql/big-query.iq
@@ -1012,9 +1012,9 @@ FROM
 
 SELECT
   email,
-  REGEXP_CONTAINS(email, '^([\w.+-]+@foo\.com|[\w.+-]+@bar\.org)$')
+  REGEXP_CONTAINS(email, '^([\w.+-]+@foo\.com|[\w.+-]+@bar\.org)\s+$')
 AS valid_email_address,
-  REGEXP_CONTAINS(email, '^[\w.+-]+@foo\.com|[\w.+-]+@bar\.org$')
+  REGEXP_CONTAINS(email, '^[\w.+-]+@foo\.com|[\w.+-]+@bar\.org\s+$')
 AS without_parentheses
 FROM
   (SELECT
diff --git 
a/core/src/main/java/org/apache/calcite/sql/fun/SqlArrayValueConstructor.java 
b/core/src/main/java/org/apache/calcite/sql/fun/SqlArrayValueConstructor.java
index e291c41211..5f6eb5dd82 100644
--- 
a/core/src/main/java/org/apache/calcite/sql/fun/SqlArrayValueConstructor.java
+++ 
b/core/src/main/java/org/apache/calcite/sql/fun/SqlArrayValueConstructor.java
@@ -20,6 +20,7 @@ import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.sql.SqlKind;
 import org.apache.calcite.sql.SqlOperatorBinding;
 import org.apache.calcite.sql.type.SqlTypeUtil;
+import org.apache.calcite.sql.validate.SqlValidatorUtil;
 
 import static java.util.Objects.requireNonNull;
 
@@ -38,6 +39,10 @@ public class SqlArrayValueConstructor extends 
SqlMultisetValueConstructor {
 opBinding.getTypeFactory(),
 opBinding.collectOperandTypes());
 requireNonNull(type, "inferred array element type");
+
+// explicit cast elements to component type if they are not same
+SqlValidatorUtil.adjustTypeForArrayConstructor(type, opBinding);
+
 return SqlTypeUtil.createArrayType(
 opBinding.getTypeFactory(), type, false);
   }
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 d58ae302d2..cdf4f76808 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
@@ -43,6 +43,7 @@ import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.sql.type.SqlTypeTransforms;
 import org.apache.calcite.sql.type.SqlTypeUtil;
 import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorUtil;
 import org.apache.calcite.util.Litmus;
 import org.apache.calcite.util.Optionality;
 import org.apache.calcite.util.Static;
@@ -1066,6 +1067,10 @@ public abstract class SqlLibraryOperators {
   : opBinding.getTypeFactory().createUnknownType();
 }
 requireNonNull(type, "inferred array element type");
+
+// explicit cast elements to component type if they are not same
+SqlValidatorUtil.adjustTypeForArrayConstructor(type, opBinding);
+
 return SqlTypeUtil.createArrayType(opBinding.getTypeFactory(), type, 
false);
   }
 
diff --git 
a/core/src/main/java/org/apache/calcite/sql/fun/SqlMapValueConstructor.java 
b/core/src/main/java/org/apache/calcite/sql/fun/SqlMapValueConstructor.java
index d3c4e5840e..7f3da3bdb2 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlMapValueConstructor.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlMapValueConstructor.java
@@ -22,6 +22,7 @@ import org.apache.calcite.sql.SqlCallBinding;
 import org.apache.calcite.sql.SqlKind;
 import org.apache.calcite.sql.SqlOperatorBinding;
 import org.apache.calcite.sql.type.SqlTypeUtil;
+import org.apache.calcite.sql.validate.SqlValidatorUtil;
 import org.apache.calcite.util.Pair;
 import org.apache.calcite.util.Util;
 
@@ -44,10 +45,15 @@ public class SqlMapValueConstructor extends 
SqlMultisetValueConstructor {
 super("MAP", 

Re: [PR] [CALCITE-5948] Use explicit casting if element type in ARRAY/MAP does not equal derived component type [calcite]

2023-10-09 Thread via GitHub


tanclary merged PR #3395:
URL: https://github.com/apache/calcite/pull/3395


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6011] Add the planner rule that pushes the Filter past a Window [calcite]

2023-10-09 Thread via GitHub


zabetak commented on code in PR #3439:
URL: https://github.com/apache/calcite/pull/3439#discussion_r1350459092


##
core/src/main/java/org/apache/calcite/rel/rules/FilterWindowTransposeRule.java:
##
@@ -0,0 +1,131 @@
+/*
+ * 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.RelOptUtil;
+import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.calcite.rel.core.Window;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.ImmutableBitSet;
+
+import com.google.common.collect.ImmutableList;
+
+import org.immutables.value.Value;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Planner rule that pushes a {@link org.apache.calcite.rel.core.Filter}
+ * past a {@link org.apache.calcite.rel.core.Window}.
+ *
+ *  If {@code Filter} condition used columns belongs {@code Window} 
partition keys,
+ * then we could push the condition past the {@code Window}.
+ *
+ *  For example:
+ *  {@code
+ *LogicalProject(NAME=[$0], DEPTNO=[$1], EXPR$2=[$2])
+ * LogicalFilter(condition=[>($1, 0)])
+ *   LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[$2])
+ * LogicalWindow(window#0=[window(partition {0} aggs [COUNT()])])
+ *   LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ *  }
+ *
+ *  will convert to:
+ * {@code
+ *LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[$2])
+ *  LogicalWindow(window#0=[window(partition {0} aggs [COUNT()])])
+ *LogicalFilter(condition=[>($0, 0)])
+ *  LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ * }
+ *
+ * @see CoreRules#FILTER_PROJECT_TRANSPOSE
+ * @see CoreRules#PROJECT_TO_LOGICAL_PROJECT_AND_WINDOW
+ * @see CoreRules#FILTER_WINDOW_TRANSPOSE
+ */
+@Value.Enclosing
+public class FilterWindowTransposeRule

Review Comment:
   Thinking about it again, I would suggest to postpone the refactoring in a 
dedicated follow-up ticket.This would allow this PR to be merged faster; 
refactoring can more debatable so let's evaluate it separately :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6031] Add the planner rule that pushes the Filter past a Sample [calcite]

2023-10-09 Thread via GitHub


sonarcloud[bot] commented on PR #3453:
URL: https://github.com/apache/calcite/pull/3453#issuecomment-1753204046

   Kudos, SonarCloud Quality Gate passed!  [![Quality Gate 
passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png
 'Quality Gate 
passed')](https://sonarcloud.io/dashboard?id=apache_calcite=3453)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3453=false=BUG)
 
[![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png
 
'A')](https://sonarcloud.io/project/issues?id=apache_calcite=3453=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3453=false=BUG)
  
   
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png
 
'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_calcite=3453=false=VULNERABILITY)
 
[![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png
 
'A')](https://sonarcloud.io/project/issues?id=apache_calcite=3453=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3453=false=VULNERABILITY)
  
   [![Security 
Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png
 'Security 
Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3453=false=SECURITY_HOTSPOT)
 
[![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png
 
'A')](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3453=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3453=false=SECURITY_HOTSPOT)
  
   [![Code 
Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png
 'Code 
Smell')](https://sonarcloud.io/project/issues?id=apache_calcite=3453=false=CODE_SMELL)
 
[![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png
 
'A')](https://sonarcloud.io/project/issues?id=apache_calcite=3453=false=CODE_SMELL)
 [0 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_calcite=3453=false=CODE_SMELL)
   
   
[![100.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/100-16px.png
 
'100.0%')](https://sonarcloud.io/component_measures?id=apache_calcite=3453=new_coverage=list)
 [100.0% 
Coverage](https://sonarcloud.io/component_measures?id=apache_calcite=3453=new_coverage=list)
  
   
[![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png
 
'0.0%')](https://sonarcloud.io/component_measures?id=apache_calcite=3453=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3453=new_duplicated_lines_density=list)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6011] Add the planner rule that pushes the Filter past a Window [calcite]

2023-10-09 Thread via GitHub


LakeShen commented on code in PR #3439:
URL: https://github.com/apache/calcite/pull/3439#discussion_r1350441530


##
core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java:
##
@@ -920,6 +920,67 @@ private void 
checkJoinToMultiJoinDoesNotMatchSemiOrAntiJoin(JoinRelType type) {
 sql(sql).withRule(CoreRules.FILTER_AGGREGATE_TRANSPOSE).check();
   }
 
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-6011;>[CALCITE-6011]
+   * Add the planner rule that pushes the Filter past a Window. */
+  @Test void testPushFilterPastWindowWithOnePartitionColumn() {
+final String sql = "select * from\n"
++ "(select NAME, DEPTNO, count(*) over (partition by DEPTNO) from 
dept)\n"
++ "where DEPTNO > 0";
+sql(sql)
+.withPreRule(CoreRules.PROJECT_TO_LOGICAL_PROJECT_AND_WINDOW)
+.withRule(
+CoreRules.FILTER_PROJECT_TRANSPOSE,
+CoreRules.FILTER_WINDOW_TRANSPOSE,
+CoreRules.PROJECT_REMOVE).check();
+  }
+
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-6011;>[CALCITE-6011]
+   * Add the planner rule that pushes the Filter past a Window. */
+  @Test void testPushFilterPastWindowWithTwoPartitionColumns() {
+final String sql = "select * from\n"
++ "(select NAME, DEPTNO, count(*) over (partition by NAME, DEPTNO) 
from dept)\n"
++ "where DEPTNO > 0";
+sql(sql)
+.withPreRule(CoreRules.PROJECT_TO_LOGICAL_PROJECT_AND_WINDOW)
+.withRule(
+CoreRules.FILTER_PROJECT_TRANSPOSE,
+CoreRules.FILTER_WINDOW_TRANSPOSE,
+CoreRules.PROJECT_REMOVE).check();
+  }
+
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-6011;>[CALCITE-6011]
+   * Add the planner rule that pushes the Filter past a Window. */
+  @Test void testPushFilterPastWindowWithNoPredicatePush() {

Review Comment:
   It makes sense for me,I will take it,thanks for your advice.



##
core/src/test/java/org/apache/calcite/test/JdbcTest.java:
##
@@ -4798,6 +4798,28 @@ private void startOfGroupStep3(String startOfGroup) {
 "deptno=20; A=1; B=-1");
   }
 
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-6011;>[CALCITE-6011]
+   * Add the planner rule that pushes the Filter past a Window. */
+  @Test void testPushFilterToWindow() {
+CalciteAssert.hr()
+.query("select * from (select \"deptno\", sum(1) over (partition by 
\"deptno\"\n"
++ "  order by \"empid\" rows between unbounded preceding and 
current row) as a\n"
++ "from \"hr\".\"emps\")"
++ " where \"deptno\" = 10")
+.explainContains(""
++ "PLAN=EnumerableCalc(expr#0..2=[{inputs}], deptno=[$t1], 
$1=[$t2])\n"
++ "  EnumerableWindow(window#0=[window(partition {1} order by [0] 
rows between "
++ "UNBOUNDED PRECEDING and CURRENT ROW aggs [SUM($2)])])\n"
++ "EnumerableCalc(expr#0..4=[{inputs}], 
expr#5=[CAST($t1):INTEGER NOT NULL], "
++ "expr#6=[10], expr#7=[=($t5, $t6)], proj#0..1=[{exprs}], 
$condition=[$t7])\n"
++ "  EnumerableTableScan(table=[[hr, emps]])\n")
+.returnsUnordered(
+"deptno=10; A=1",
+"deptno=10; A=2",
+"deptno=10; A=3");
+  }
+

Review Comment:
   It makes sense for me,I will take it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6011] Add the planner rule that pushes the Filter past a Window [calcite]

2023-10-09 Thread via GitHub


LakeShen commented on code in PR #3439:
URL: https://github.com/apache/calcite/pull/3439#discussion_r1350440243


##
core/src/test/java/org/apache/calcite/test/JdbcTest.java:
##
@@ -4798,6 +4798,28 @@ private void startOfGroupStep3(String startOfGroup) {
 "deptno=20; A=1; B=-1");
   }
 
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-6011;>[CALCITE-6011]
+   * Add the planner rule that pushes the Filter past a Window. */
+  @Test void testPushFilterToWindow() {
+CalciteAssert.hr()
+.query("select * from (select \"deptno\", sum(1) over (partition by 
\"deptno\"\n"
++ "  order by \"empid\" rows between unbounded preceding and 
current row) as a\n"
++ "from \"hr\".\"emps\")"
++ " where \"deptno\" = 10")
+.explainContains(""
++ "PLAN=EnumerableCalc(expr#0..2=[{inputs}], deptno=[$t1], 
$1=[$t2])\n"
++ "  EnumerableWindow(window#0=[window(partition {1} order by [0] 
rows between "
++ "UNBOUNDED PRECEDING and CURRENT ROW aggs [SUM($2)])])\n"
++ "EnumerableCalc(expr#0..4=[{inputs}], 
expr#5=[CAST($t1):INTEGER NOT NULL], "
++ "expr#6=[10], expr#7=[=($t5, $t6)], proj#0..1=[{exprs}], 
$condition=[$t7])\n"
++ "  EnumerableTableScan(table=[[hr, emps]])\n")
+.returnsUnordered(
+"deptno=10; A=1",
+"deptno=10; A=2",
+"deptno=10; A=3");
+  }
+

Review Comment:
   It makes for me,I will take it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6011] Add the planner rule that pushes the Filter past a Window [calcite]

2023-10-09 Thread via GitHub


LakeShen commented on code in PR #3439:
URL: https://github.com/apache/calcite/pull/3439#discussion_r1350438826


##
core/src/main/java/org/apache/calcite/rel/rules/FilterWindowTransposeRule.java:
##
@@ -0,0 +1,131 @@
+/*
+ * 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.RelOptUtil;
+import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.calcite.rel.core.Window;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.ImmutableBitSet;
+
+import com.google.common.collect.ImmutableList;
+
+import org.immutables.value.Value;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Planner rule that pushes a {@link org.apache.calcite.rel.core.Filter}
+ * past a {@link org.apache.calcite.rel.core.Window}.
+ *
+ *  If {@code Filter} condition used columns belongs {@code Window} 
partition keys,
+ * then we could push the condition past the {@code Window}.
+ *
+ *  For example:
+ *  {@code
+ *LogicalProject(NAME=[$0], DEPTNO=[$1], EXPR$2=[$2])
+ * LogicalFilter(condition=[>($1, 0)])
+ *   LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[$2])
+ * LogicalWindow(window#0=[window(partition {0} aggs [COUNT()])])
+ *   LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ *  }
+ *
+ *  will convert to:
+ * {@code
+ *LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[$2])
+ *  LogicalWindow(window#0=[window(partition {0} aggs [COUNT()])])
+ *LogicalFilter(condition=[>($0, 0)])
+ *  LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ * }
+ *
+ * @see CoreRules#FILTER_PROJECT_TRANSPOSE
+ * @see CoreRules#PROJECT_TO_LOGICAL_PROJECT_AND_WINDOW
+ * @see CoreRules#FILTER_WINDOW_TRANSPOSE
+ */
+@Value.Enclosing
+public class FilterWindowTransposeRule
+extends RelRule
+implements TransformationRule {
+
+  protected FilterWindowTransposeRule(final Config config) {
+super(config);
+  }
+
+  @Override public void onMatch(final RelOptRuleCall call) {
+final Filter filterRel = call.rel(0);
+final Window windowRel = call.rel(1);
+
+// Get the window all groups
+List windowGroups = windowRel.groups;
+
+// The window may have multi groups,now we could only
+// deal one group case,so that we could know the partition keys.
+if (windowGroups.size() != 1) {
+  return;
+}

Review Comment:
   My current thinking is that it is a permanent limitation, because it is 
somewhat difficult to find the common intersection of multiple groups.And like 
other engine,such as Presto/Trino/StarRocks, they handle window with a single 
group.
   
   My idea is that in the future I would like to add a rule to split a Window 
with multiple Groups into multiple Window with a single Group,so the 
FilterWindowTransposeRule could also push the condition to below the bottom 
Window.
   
   But this is not the final conclusion. Once I have an idea in the future, it 
will be more versatile to handle multiple Group partitions at the same time, 
and if users using Calcite can use this optimization, I will continue to 
improve this optimization rule.
   
   WDYT?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6037] The function category of ARRAY/EXTRACT_VALUE/XML_TRANSFORM/EXTRACT_XML/EXISTSNODE is incorrect (Spark/MySQL/Oracle Library) [calcite]

2023-10-09 Thread via GitHub


chucheng92 commented on code in PR #3458:
URL: https://github.com/apache/calcite/pull/3458#discussion_r1350418693


##
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##
@@ -532,26 +532,30 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding 
operatorBinding,
   public static final SqlFunction EXTRACT_VALUE =
   SqlBasicFunction.create("EXTRACTVALUE",
   ReturnTypes.VARCHAR_2000.andThen(SqlTypeTransforms.FORCE_NULLABLE),
-  OperandTypes.STRING_STRING);
+  OperandTypes.STRING_STRING,

Review Comment:
   Hi, @mihaibudiu. thanks for reviewing. good point. 
   
   Frankly speaking, `SqlFunctionCategory` is a very loose field now. In fact, 
there is no strict verification during lookup, so no test cases cover it. 
However, it is currently widely used and cannot be deleted now (It is also for 
the sake of subsequent scalability). 
   
   We can refer to the comments of the current `lookupOperatorOverloads`, it 
can immediately works if we need to use it. WDYT?
   
https://github.com/apache/calcite/blob/597b53dbb075ab72700d40f66db81d2ac9c182b8/core/src/main/java/org/apache/calcite/sql/util/ReflectiveSqlOperatorTable.java#L94



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6037] The function category of ARRAY/EXTRACT_VALUE/XML_TRANSFORM/EXTRACT_XML/EXISTSNODE is incorrect (Spark/MySQL/Oracle Library) [calcite]

2023-10-09 Thread via GitHub


chucheng92 commented on code in PR #3458:
URL: https://github.com/apache/calcite/pull/3458#discussion_r1350418693


##
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##
@@ -532,26 +532,30 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding 
operatorBinding,
   public static final SqlFunction EXTRACT_VALUE =
   SqlBasicFunction.create("EXTRACTVALUE",
   ReturnTypes.VARCHAR_2000.andThen(SqlTypeTransforms.FORCE_NULLABLE),
-  OperandTypes.STRING_STRING);
+  OperandTypes.STRING_STRING,

Review Comment:
   Hi, @mihaibudiu. thanks for reviewing. good point. 
   
   Frankly speaking, `SqlFunctionCategory` is a very loose field now. In fact, 
there is no strict verification during lookup, so no test case covers it. 
However, it is currently widely used and cannot be deleted for subsequent 
expansion. We can refer to the comments of the current 
`lookupOperatorOverloads` and use it immediately when we need it. WDYT?
   
   
https://github.com/apache/calcite/blob/597b53dbb075ab72700d40f66db81d2ac9c182b8/core/src/main/java/org/apache/calcite/sql/util/ReflectiveSqlOperatorTable.java#L94



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6037] The function category of ARRAY/EXTRACT_VALUE/XML_TRANSFORM/EXTRACT_XML/EXISTSNODE is incorrect (Spark/MySQL/Oracle Library) [calcite]

2023-10-09 Thread via GitHub


chucheng92 commented on code in PR #3458:
URL: https://github.com/apache/calcite/pull/3458#discussion_r1350418693


##
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##
@@ -532,26 +532,30 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding 
operatorBinding,
   public static final SqlFunction EXTRACT_VALUE =
   SqlBasicFunction.create("EXTRACTVALUE",
   ReturnTypes.VARCHAR_2000.andThen(SqlTypeTransforms.FORCE_NULLABLE),
-  OperandTypes.STRING_STRING);
+  OperandTypes.STRING_STRING,

Review Comment:
   Hi, @mihaibudiu. thanks for reviewing. good question. 
   
   Frankly speaking, `SqlFunctionCategory` is a very loose field now. In fact, 
there is no strict verification during lookup, so no test case covers it. 
However, it is currently widely used and cannot be deleted for subsequent 
expansion. We can refer to the comments of the current 
`lookupOperatorOverloads` and use it immediately when we need it. WDYT?
   
   
https://github.com/apache/calcite/blob/597b53dbb075ab72700d40f66db81d2ac9c182b8/core/src/main/java/org/apache/calcite/sql/util/ReflectiveSqlOperatorTable.java#L94



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6037] The function category of ARRAY/EXTRACT_VALUE/XML_TRANSFORM/EXTRACT_XML/EXISTSNODE is incorrect (Spark/MySQL/Oracle Library) [calcite]

2023-10-09 Thread via GitHub


chucheng92 commented on code in PR #3458:
URL: https://github.com/apache/calcite/pull/3458#discussion_r1350418693


##
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##
@@ -532,26 +532,30 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding 
operatorBinding,
   public static final SqlFunction EXTRACT_VALUE =
   SqlBasicFunction.create("EXTRACTVALUE",
   ReturnTypes.VARCHAR_2000.andThen(SqlTypeTransforms.FORCE_NULLABLE),
-  OperandTypes.STRING_STRING);
+  OperandTypes.STRING_STRING,

Review Comment:
   Hi, @mihaibudiu. thanks for reviewing. good point. 
   
   Frankly speaking, `SqlFunctionCategory` is a very loose field now. In fact, 
there is no strict verification during lookup, so no test cases cover it. 
However, it is currently widely used and cannot be deleted for subsequent 
expansion. We can refer to the comments of the current 
`lookupOperatorOverloads` and use it immediately when we need it. WDYT?
   
   
https://github.com/apache/calcite/blob/597b53dbb075ab72700d40f66db81d2ac9c182b8/core/src/main/java/org/apache/calcite/sql/util/ReflectiveSqlOperatorTable.java#L94



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6037] The function category of ARRAY/EXTRACT_VALUE/XML_TRANSFORM/EXTRACT_XML/EXISTSNODE is incorrect (Spark/MySQL/Oracle Library) [calcite]

2023-10-09 Thread via GitHub


chucheng92 commented on code in PR #3458:
URL: https://github.com/apache/calcite/pull/3458#discussion_r1350418693


##
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##
@@ -532,26 +532,30 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding 
operatorBinding,
   public static final SqlFunction EXTRACT_VALUE =
   SqlBasicFunction.create("EXTRACTVALUE",
   ReturnTypes.VARCHAR_2000.andThen(SqlTypeTransforms.FORCE_NULLABLE),
-  OperandTypes.STRING_STRING);
+  OperandTypes.STRING_STRING,

Review Comment:
   Hi, @mihaibudiu. thanks for reviewing. good question. 
   
   Frankly speaking, `SqlFunctionCategory` is a very loose field now. In fact, 
there is no strict verification during lookup, so no test case covers it. 
However, it is currently widely used and cannot be deleted for subsequent 
expansion. We can refer to the comments of the current 
`lookupOperatorOverloads` and use it immediately when we need it.
   
   
https://github.com/apache/calcite/blob/597b53dbb075ab72700d40f66db81d2ac9c182b8/core/src/main/java/org/apache/calcite/sql/util/ReflectiveSqlOperatorTable.java#L94



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6011] Add the planner rule that pushes the Filter past a Window [calcite]

2023-10-09 Thread via GitHub


LakeShen commented on code in PR #3439:
URL: https://github.com/apache/calcite/pull/3439#discussion_r1350412897


##
core/src/main/java/org/apache/calcite/rel/rules/FilterWindowTransposeRule.java:
##
@@ -0,0 +1,131 @@
+/*
+ * 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.RelOptUtil;
+import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.calcite.rel.core.Window;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.ImmutableBitSet;
+
+import com.google.common.collect.ImmutableList;
+
+import org.immutables.value.Value;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Planner rule that pushes a {@link org.apache.calcite.rel.core.Filter}
+ * past a {@link org.apache.calcite.rel.core.Window}.
+ *
+ *  If {@code Filter} condition used columns belongs {@code Window} 
partition keys,
+ * then we could push the condition past the {@code Window}.
+ *
+ *  For example:
+ *  {@code
+ *LogicalProject(NAME=[$0], DEPTNO=[$1], EXPR$2=[$2])
+ * LogicalFilter(condition=[>($1, 0)])
+ *   LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[$2])
+ * LogicalWindow(window#0=[window(partition {0} aggs [COUNT()])])
+ *   LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ *  }
+ *
+ *  will convert to:
+ * {@code
+ *LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[$2])
+ *  LogicalWindow(window#0=[window(partition {0} aggs [COUNT()])])
+ *LogicalFilter(condition=[>($0, 0)])
+ *  LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ * }
+ *
+ * @see CoreRules#FILTER_PROJECT_TRANSPOSE
+ * @see CoreRules#PROJECT_TO_LOGICAL_PROJECT_AND_WINDOW
+ * @see CoreRules#FILTER_WINDOW_TRANSPOSE
+ */
+@Value.Enclosing
+public class FilterWindowTransposeRule

Review Comment:
   Yes,It make sense for me.
   
   In terms of the use of rules, I will still divide them into two Rules, but I 
will reuse the similar logic of the two rules as much as possible.
   
   My idea is to put similar logic into RelOptUtil.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6031] Add the planner rule that pushes the Filter past a Sample [calcite]

2023-10-09 Thread via GitHub


LakeShen commented on PR #3453:
URL: https://github.com/apache/calcite/pull/3453#issuecomment-1753148998

   Hi @libenchao ,Thank you for your review suggestions. I have modified 
according to the suggestions. If you have time, please help me review it again.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6031] Add the planner rule that pushes the Filter past a Sample [calcite]

2023-10-09 Thread via GitHub


LakeShen commented on code in PR #3453:
URL: https://github.com/apache/calcite/pull/3453#discussion_r1350391764


##
core/src/main/java/org/apache/calcite/rel/rules/CoreRules.java:
##
@@ -279,6 +279,10 @@ private CoreRules() {}
   public static final FilterProjectTransposeRule FILTER_PROJECT_TRANSPOSE =
   FilterProjectTransposeRule.Config.DEFAULT.toRule();
 
+  /** Rule that pushes a {@link Filter} past a {@link Sample}. */
+  public static final FilterSampleTransposeRule FILTER_SAMPLE_TRANSPOSE =

Review Comment:
   Hi @libenchao ,thanks for your reviewing.
   
   It makes sense to me,I will take it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6037] The function category of ARRAY/EXTRACT_VALUE/XML_TRANSFORM/EXTRACT_XML/EXISTSNODE is incorrect (Spark/MySQL/Oracle Library) [calcite]

2023-10-09 Thread via GitHub


mihaibudiu commented on code in PR #3458:
URL: https://github.com/apache/calcite/pull/3458#discussion_r1350375131


##
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##
@@ -532,26 +532,30 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding 
operatorBinding,
   public static final SqlFunction EXTRACT_VALUE =
   SqlBasicFunction.create("EXTRACTVALUE",
   ReturnTypes.VARCHAR_2000.andThen(SqlTypeTransforms.FORCE_NULLABLE),
-  OperandTypes.STRING_STRING);
+  OperandTypes.STRING_STRING,

Review Comment:
   I have a meta-question: what is this field used for?
   It doesn't seem to affect any of the tests.
   Clearly, the meaning of this field is ambiguous too - it's not clear what 
the right choice is in all cases.
   Can we just remove it completely?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6031] Add the planner rule that pushes the Filter past a Sample [calcite]

2023-10-09 Thread via GitHub


libenchao commented on code in PR #3453:
URL: https://github.com/apache/calcite/pull/3453#discussion_r1350183091


##
core/src/main/java/org/apache/calcite/rel/rules/CoreRules.java:
##
@@ -279,6 +279,10 @@ private CoreRules() {}
   public static final FilterProjectTransposeRule FILTER_PROJECT_TRANSPOSE =
   FilterProjectTransposeRule.Config.DEFAULT.toRule();
 
+  /** Rule that pushes a {@link Filter} past a {@link Sample}. */
+  public static final FilterSampleTransposeRule FILTER_SAMPLE_TRANSPOSE =

Review Comment:
   How about adding it to BASE_RUELS too? We already have many other transpose 
rules there.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6011] Add the planner rule that pushes the Filter past a Window [calcite]

2023-10-09 Thread via GitHub


zabetak commented on code in PR #3439:
URL: https://github.com/apache/calcite/pull/3439#discussion_r1350180602


##
core/src/test/java/org/apache/calcite/test/JdbcTest.java:
##
@@ -4798,6 +4798,28 @@ private void startOfGroupStep3(String startOfGroup) {
 "deptno=20; A=1; B=-1");
   }
 
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-6011;>[CALCITE-6011]
+   * Add the planner rule that pushes the Filter past a Window. */
+  @Test void testPushFilterToWindow() {
+CalciteAssert.hr()
+.query("select * from (select \"deptno\", sum(1) over (partition by 
\"deptno\"\n"
++ "  order by \"empid\" rows between unbounded preceding and 
current row) as a\n"
++ "from \"hr\".\"emps\")"
++ " where \"deptno\" = 10")
+.explainContains(""
++ "PLAN=EnumerableCalc(expr#0..2=[{inputs}], deptno=[$t1], 
$1=[$t2])\n"
++ "  EnumerableWindow(window#0=[window(partition {1} order by [0] 
rows between "
++ "UNBOUNDED PRECEDING and CURRENT ROW aggs [SUM($2)])])\n"
++ "EnumerableCalc(expr#0..4=[{inputs}], 
expr#5=[CAST($t1):INTEGER NOT NULL], "
++ "expr#6=[10], expr#7=[=($t5, $t6)], proj#0..1=[{exprs}], 
$condition=[$t7])\n"
++ "  EnumerableTableScan(table=[[hr, emps]])\n")
+.returnsUnordered(
+"deptno=10; A=1",
+"deptno=10; A=2",
+"deptno=10; A=3");
+  }
+

Review Comment:
   The new rule is not specific to JDBC so its not appropriate to add it here. 
For end-to-end tests please favor the `.iq` files. Consider moving this test to 
`winagg.iq` file.



##
core/src/main/java/org/apache/calcite/rel/rules/FilterWindowTransposeRule.java:
##
@@ -0,0 +1,131 @@
+/*
+ * 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.RelOptUtil;
+import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.calcite.rel.core.Window;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.ImmutableBitSet;
+
+import com.google.common.collect.ImmutableList;
+
+import org.immutables.value.Value;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Planner rule that pushes a {@link org.apache.calcite.rel.core.Filter}
+ * past a {@link org.apache.calcite.rel.core.Window}.
+ *
+ *  If {@code Filter} condition used columns belongs {@code Window} 
partition keys,
+ * then we could push the condition past the {@code Window}.
+ *
+ *  For example:
+ *  {@code
+ *LogicalProject(NAME=[$0], DEPTNO=[$1], EXPR$2=[$2])
+ * LogicalFilter(condition=[>($1, 0)])
+ *   LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[$2])
+ * LogicalWindow(window#0=[window(partition {0} aggs [COUNT()])])
+ *   LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ *  }
+ *
+ *  will convert to:
+ * {@code
+ *LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[$2])
+ *  LogicalWindow(window#0=[window(partition {0} aggs [COUNT()])])
+ *LogicalFilter(condition=[>($0, 0)])
+ *  LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ * }
+ *
+ * @see CoreRules#FILTER_PROJECT_TRANSPOSE
+ * @see CoreRules#PROJECT_TO_LOGICAL_PROJECT_AND_WINDOW
+ * @see CoreRules#FILTER_WINDOW_TRANSPOSE
+ */
+@Value.Enclosing
+public class FilterWindowTransposeRule
+extends RelRule
+implements TransformationRule {
+
+  protected FilterWindowTransposeRule(final Config config) {
+super(config);
+  }
+
+  @Override public void onMatch(final RelOptRuleCall call) {
+final Filter filterRel = call.rel(0);
+final Window windowRel = call.rel(1);
+
+// Get the window all groups
+List windowGroups = windowRel.groups;
+
+// The window may have multi groups,now we could only
+// deal one group case,so that we could know the partition keys.
+if (windowGroups.size() != 1) {
+  return;
+}

Review Comment:
   Is this a temporary (implementation) limitation or a permanent (semantic) 
limitation? IF 

[calcite-site] branch main updated: Website deployed from calcite@597b53dbb075ab72700d40f66db81d2ac9c182b8

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

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


The following commit(s) were added to refs/heads/main by this push:
 new 846bf5463 Website deployed from 
calcite@597b53dbb075ab72700d40f66db81d2ac9c182b8
846bf5463 is described below

commit 846bf5463acff9afabb4b4c0644155f8b31d
Author: libenchao 
AuthorDate: Mon Oct 9 11:07:30 2023 +

Website deployed from calcite@597b53dbb075ab72700d40f66db81d2ac9c182b8
---
 docs/powered_by.html | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/docs/powered_by.html b/docs/powered_by.html
index 26c4befb0..32ca96423 100644
--- a/docs/powered_by.html
+++ b/docs/powered_by.html
@@ -93,6 +93,7 @@
   Apache 
Phoenix
   Apache 
Samza
   Apache 
Storm
+  Apache 
Wayang
   AthenaX
   Cascading
   Dremio
@@ -168,6 +169,11 @@ uses Calcite for parsing streaming SQL and query 
optimization.
 https://storm.apache.org;>Apache Storm
 uses Calcite for parsing streaming SQL and query optimization.
 
+Apache Wayang
+
+https://wayang.apache.org;>Apache Wayang (Incubating)
+uses Calcite for SQL parsing and query optimization.
+
 AthenaX
 
 https://www.uber.com/;>Uber’s SQL-based streaming analytics 
platform



[calcite] branch site updated: Site: Add Apache Wayang (incubating) to powered-by page

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

github-bot 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 d0156c2050 Site: Add Apache Wayang (incubating) to powered-by page
d0156c2050 is described below

commit d0156c20504d2b775eef44c93d08379c82f43b9f
Author: Kaustubh Beedkar 
AuthorDate: Mon Oct 2 22:25:44 2023 +0530

Site: Add Apache Wayang (incubating) to powered-by page

Close apache/calcite#3450
---
 site/_docs/powered_by.md | 5 +
 1 file changed, 5 insertions(+)

diff --git a/site/_docs/powered_by.md b/site/_docs/powered_by.md
index b9721c1d0f..809c01ca93 100644
--- a/site/_docs/powered_by.md
+++ b/site/_docs/powered_by.md
@@ -95,6 +95,11 @@ uses Calcite for parsing streaming SQL and query 
optimization.
 https://storm.apache.org;>Apache Storm
 uses Calcite for parsing streaming SQL and query optimization.
 
+### Apache Wayang
+
+https://wayang.apache.org;>Apache Wayang (Incubating)
+uses Calcite for SQL parsing and query optimization.
+
 ### AthenaX
 
 https://www.uber.com/;>Uber's SQL-based streaming analytics 
platform



Re: [PR] Update powered_by.md [calcite]

2023-10-09 Thread via GitHub


libenchao closed pull request #3450: Update powered_by.md
URL: https://github.com/apache/calcite/pull/3450


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[calcite] branch main updated: Site: Add Apache Wayang (incubating) to powered-by page

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

libenchao 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 597b53dbb0 Site: Add Apache Wayang (incubating) to powered-by page
597b53dbb0 is described below

commit 597b53dbb075ab72700d40f66db81d2ac9c182b8
Author: Kaustubh Beedkar 
AuthorDate: Mon Oct 2 22:25:44 2023 +0530

Site: Add Apache Wayang (incubating) to powered-by page

Close apache/calcite#3450
---
 site/_docs/powered_by.md | 5 +
 1 file changed, 5 insertions(+)

diff --git a/site/_docs/powered_by.md b/site/_docs/powered_by.md
index b9721c1d0f..809c01ca93 100644
--- a/site/_docs/powered_by.md
+++ b/site/_docs/powered_by.md
@@ -95,6 +95,11 @@ uses Calcite for parsing streaming SQL and query 
optimization.
 https://storm.apache.org;>Apache Storm
 uses Calcite for parsing streaming SQL and query optimization.
 
+### Apache Wayang
+
+https://wayang.apache.org;>Apache Wayang (Incubating)
+uses Calcite for SQL parsing and query optimization.
+
 ### AthenaX
 
 https://www.uber.com/;>Uber's SQL-based streaming analytics 
platform



Re: [PR] [CALCITE-6022] Support "CREATE TABLE LIKE" DDL [calcite]

2023-10-09 Thread via GitHub


macroguo-ghy commented on code in PR #3442:
URL: https://github.com/apache/calcite/pull/3442#discussion_r1350142769


##
core/src/main/codegen/templates/Parser.jj:
##
@@ -4318,8 +4318,13 @@ SqlCreate SqlCreate() :
 (
 <#-- additional literal parser methods are included here -->
 <#list 
(parser.createStatementParserMethods!default.parser.createStatementParserMethods)
 as method>
+<#if method = "SqlCreateTableLike">

Review Comment:
   I'm afraid not, we need to use `LOOKAHEAD` to distinguish `CREATE TABLE` and 
`CREATE TABLE ... LIKE`.
   `create = ${method}(s, replace)`, in this line , `${method}` will be 
replaced by `createStatementParserMethod`, so we can not use `LOOKAHEAD(...) 
SqlCreateTableLike ` replace `SqlCreateTableLike`. This will result in 
compilation errors.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6022] Support "CREATE TABLE LIKE" DDL [calcite]

2023-10-09 Thread via GitHub


macroguo-ghy commented on code in PR #3442:
URL: https://github.com/apache/calcite/pull/3442#discussion_r1350142769


##
core/src/main/codegen/templates/Parser.jj:
##
@@ -4318,8 +4318,13 @@ SqlCreate SqlCreate() :
 (
 <#-- additional literal parser methods are included here -->
 <#list 
(parser.createStatementParserMethods!default.parser.createStatementParserMethods)
 as method>
+<#if method = "SqlCreateTableLike">

Review Comment:
   I'm afraid not, we need to use `LOOKAHEAD` to distinguish `CREATE TABLE` and 
`CREATE TABLE ... LIKE`.
   `create = ${method}(s, replace)`, In this line , `${method}` will be 
replaced by `createStatementParserMethod`, so we can not use `LOOKAHEAD(...) 
SqlCreateTableLike ` replace `SqlCreateTableLike`. This will result in 
compilation errors.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6022] Support "CREATE TABLE LIKE" DDL [calcite]

2023-10-09 Thread via GitHub


macroguo-ghy commented on code in PR #3442:
URL: https://github.com/apache/calcite/pull/3442#discussion_r1350142769


##
core/src/main/codegen/templates/Parser.jj:
##
@@ -4318,8 +4318,13 @@ SqlCreate SqlCreate() :
 (
 <#-- additional literal parser methods are included here -->
 <#list 
(parser.createStatementParserMethods!default.parser.createStatementParserMethods)
 as method>
+<#if method = "SqlCreateTableLike">

Review Comment:
   I'm afraid not, we need to use `LOOKAHEAD` to distinguish `CREATE TABLE` and 
`CREATE TABLE ... LIKE`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6006] RelToSqlConverter loses charset information [calcite]

2023-10-09 Thread via GitHub


JiajunBernoulli commented on code in PR #3429:
URL: https://github.com/apache/calcite/pull/3429#discussion_r1350124985


##
core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java:
##
@@ -1409,8 +1411,20 @@ public static SqlNode toSql(RexLiteral literal) {
 () -> "literal " + literal
 + " has null SqlTypeFamily, and is SqlTypeName is " + 
typeName);
 switch (family) {
-case CHARACTER:
+case CHARACTER: {
+  final NlsString value = literal.getValueAs(NlsString.class);

Review Comment:
   Maybe it is better?
   ```
   case CHARACTER:
 final NlsString value = literal.getValueAs(NlsString.class);
 if (value != null) {
   final String defaultCharset = 
CalciteSystemProperty.DEFAULT_CHARSET.value();
   final String charsetName = value.getCharsetName();
   if (!defaultCharset.equals(charsetName)) {
 // Do not set the charset if it is the same as the default charset
 return SqlLiteral.createCharString(
 castNonNull(value).getValue(), charsetName, POS);
   }
 }
 return SqlLiteral.createCharString((String) 
castNonNull(literal.getValue2()), POS);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6022] Support "CREATE TABLE LIKE" DDL [calcite]

2023-10-09 Thread via GitHub


JiajunBernoulli commented on code in PR #3442:
URL: https://github.com/apache/calcite/pull/3442#discussion_r1350090364


##
core/src/main/codegen/templates/Parser.jj:
##
@@ -4318,8 +4318,13 @@ SqlCreate SqlCreate() :
 (
 <#-- additional literal parser methods are included here -->
 <#list 
(parser.createStatementParserMethods!default.parser.createStatementParserMethods)
 as method>
+<#if method = "SqlCreateTableLike">

Review Comment:
   Oh, this makes things too complicated.
   
   Can we add it in createStatementParserMethods?
   
![image](https://github.com/apache/calcite/assets/45968640/b9bccd8b-3dfd-4d2b-8e80-e45de2ef52ad)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-5949] RexExecutable should return unchanged original expressions when it fails [calcite]

2023-10-09 Thread via GitHub


rubenada commented on code in PR #3390:
URL: https://github.com/apache/calcite/pull/3390#discussion_r1349920250


##
core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java:
##
@@ -378,4 +378,28 @@ public void run() {
   interface Action {
 void check(RexBuilder rexBuilder, RexExecutorImpl executor);
   }
+
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-5949;>[CALCITE-5949]
+   * RexExecutable should properly handle invalid constant expressions in 
reduction.

Review Comment:
   @arkanovicz we are approaching the preparation for the next release, could 
you please carry out these last details ⬆️  in order to merge this PR? thanks



##
core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java:
##
@@ -378,4 +378,28 @@ public void run() {
   interface Action {
 void check(RexBuilder rexBuilder, RexExecutorImpl executor);
   }
+
+  /** Test case for
+   * https://issues.apache.org/jira/browse/CALCITE-5949;>[CALCITE-5949]
+   * RexExecutable should properly handle invalid constant expressions in 
reduction.

Review Comment:
   @arkanovicz we are approaching the preparation for the next release, could 
you please carry out these last details ⬆️  in order to merge this PR? thanks



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[calcite-site] branch main updated: Website deployed from calcite@0291e1eeb4c5e01dccbac14e1a6eeeb79d87282b

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

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


The following commit(s) were added to refs/heads/main by this push:
 new 7a6f87dce Website deployed from 
calcite@0291e1eeb4c5e01dccbac14e1a6eeeb79d87282b
7a6f87dce is described below

commit 7a6f87dce9545b691b832497454de0e22ea71cdf
Author: rubenada 
AuthorDate: Mon Oct 9 06:58:41 2023 +

Website deployed from calcite@0291e1eeb4c5e01dccbac14e1a6eeeb79d87282b
---
 docs/adapter.html | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/docs/adapter.html b/docs/adapter.html
index d0849a700..1892d0fb2 100644
--- a/docs/adapter.html
+++ b/docs/adapter.html
@@ -116,7 +116,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
 
 
 
@@ -147,7 +147,7 @@ Connections can be local or remote (JSON over HTTP or 
Protobuf over HTTP).
 where property, 
property2 are 
properties as described below.
 (Connect strings are compliant with OLE DB Connect String syntax,
 as implemented by Avatica’s
-ConnectStringParser.)
+ConnectStringParser.)
 
 JDBC connect string parameters
 
@@ -503,7 +503,7 @@ over the previous 2 rows, of 4 rows with values 4, 7, 2 and 
3:
 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.
+interface
 SqlGroupedWindowFunction.
 
 Table functions and table macros
 
@@ -655,7 +655,7 @@ and covering conventional relational algebra) are
 LogicalProject
 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
+CassandraProject
 but there is no CassandraJoin.
 
 You can define your own sub-class of RelNode to add a new operator, or
@@ -748,7 +748,7 @@ Each kind of metadata has an interface with (usually) one 
method.
 For example, selectivity is defined by
 class
 RelMdSelectivity
 and the method
-getSelectivity(RelNode
 rel, RexNode predicate).
+getSelectivity(RelNode
 rel, RexNode predicate).
 
 There are many built-in kinds of metadata, including
 collation,



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

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

github-bot 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 e3e71d77ce [CALCITE-6033] Correct broken links on adapter page
e3e71d77ce is described below

commit e3e71d77ce14750beffefe802fa74589b02e435e
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-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),



Re: [PR] [CALCITE-6033] Correct broken links on adapter page [calcite]

2023-10-09 Thread via GitHub


rubenada merged PR #3456:
URL: https://github.com/apache/calcite/pull/3456


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6031] Add the planner rule that pushes the Filter past a Sample [calcite]

2023-10-09 Thread via GitHub


chucheng92 commented on PR #3453:
URL: https://github.com/apache/calcite/pull/3453#issuecomment-1752419781

   hi, @LakeShen thanks for the PR. LGTM. See if others have other opinions.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [CALCITE-6037] The function category of ARRAY/EXTRACT_VALUE/XML_TRANSFORM/EXTRACT_XML/EXISTSNODE is incorrect (Spark/MySQL/Oracle Library) [calcite]

2023-10-09 Thread via GitHub


chucheng92 commented on code in PR #3458:
URL: https://github.com/apache/calcite/pull/3458#discussion_r1349538846


##
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##
@@ -532,26 +532,30 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding 
operatorBinding,
   public static final SqlFunction EXTRACT_VALUE =
   SqlBasicFunction.create("EXTRACTVALUE",
   ReturnTypes.VARCHAR_2000.andThen(SqlTypeTransforms.FORCE_NULLABLE),
-  OperandTypes.STRING_STRING);
+  OperandTypes.STRING_STRING,

Review Comment:
   @LakeShen I get your point. Usually we classify functions according to the 
operands (in some cases, they can also be determined according to the return 
value type).
   
   more details pls see: ANSI sql function category: 
https://www.oreilly.com/library/view/sql-in-a/9780596155322/ch04s04.html. 
   
   The string function category can return string & numeric values. Generally 
speaking, these functions(in this PR) process XML text and conform to the 
definition of String category rather than Numeric.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org