[GitHub] [calcite] JiajunBernoulli commented on a diff in pull request #3391: [CALCITE-5933] Add SAFE_DIVIDE function (enabled in BigQuery library)

2023-08-26 Thread via GitHub


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


##
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##
@@ -7332,81 +7332,153 @@ private static void checkIf(SqlOperatorFixture f) {
   @Test void testSafeAddFunc() {
 final SqlOperatorFixture f0 = 
fixture().setFor(SqlLibraryOperators.SAFE_ADD);
 f0.checkFails("^safe_add(2, 3)^",
-"No match found for function signature "

Review Comment:
   Sometimes, I encounter the same situation  if I commit by IntelliJ IDEA.
   
   I will manually restore them to avoid damaging the git history.



-- 
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



[GitHub] [calcite] LakeShen commented on a diff in pull request #3381: [CALCITE-5939] Support for rewriting different join types in UnifyRule

2023-08-26 Thread via GitHub


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


##
core/src/main/java/org/apache/calcite/plan/expand/ExpandJoinOnRightCalcToJoinUnifyRule.java:
##
@@ -0,0 +1,147 @@
+/*
+ * 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.expand;
+
+import org.apache.calcite.plan.SubstitutionVisitor;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.mutable.MutableCalc;
+import org.apache.calcite.rel.mutable.MutableJoin;
+import org.apache.calcite.rel.mutable.MutableRel;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexProgram;
+import org.apache.calcite.rex.RexShuttle;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.util.Pair;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.apache.calcite.plan.SubstitutionVisitor.explainCalc;
+import static org.apache.calcite.plan.SubstitutionVisitor.splitFilter;
+import static 
org.apache.calcite.plan.expand.JoinRexUtils.addJoinDerivePredicate;
+import static org.apache.calcite.plan.expand.JoinRexUtils.extractJoinContext;
+import static org.apache.calcite.plan.expand.JoinRexUtils.isJoinRewritable;
+import static org.apache.calcite.plan.expand.JoinRexUtils.isSupportedPredict;
+import static org.apache.calcite.plan.expand.JoinRexUtils.tryCastRexInputRef;
+import static 
org.apache.calcite.plan.expand.SubstitutionRuleUtils.canPullUpFilterUnderJoin;
+import static org.apache.calcite.plan.expand.SubstitutionRuleUtils.fieldCnt;
+import static 
org.apache.calcite.plan.expand.SubstitutionRuleUtils.referenceByMapping;
+import static 
org.apache.calcite.plan.expand.SubstitutionRuleUtils.tryMergeParentCalcAndGenResult;
+
+/**
+ * Enhancements to joinOnRightCalcToJoinUnifyRule.
+ */
+public class ExpandJoinOnRightCalcToJoinUnifyRule

Review Comment:
   
ExpandJoinOnRightCalcToJoinUnifyRule,ExpandJoinOnLeftCalcToJoinUnifyRule,ExpandJoinOnCalcToJoinUnifyRule,What
 is the difference between them?



##
core/src/main/java/org/apache/calcite/plan/expand/ExpandJoinOnRightCalcToJoinUnifyRule.java:
##
@@ -0,0 +1,147 @@
+/*
+ * 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.expand;
+
+import org.apache.calcite.plan.SubstitutionVisitor;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.mutable.MutableCalc;
+import org.apache.calcite.rel.mutable.MutableJoin;
+import org.apache.calcite.rel.mutable.MutableRel;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexProgram;
+import org.apache.calcite.rex.RexShuttle;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.util.Pair;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.apache.calcite.plan.SubstitutionVisitor.explainCalc;
+import static org.apache.calcite.plan.SubstitutionVisitor.splitFilter;
+import static 
org.apache.calcite.plan.expand.JoinRexUtils.addJoinDerivePredicate;
+import static org.apache.calcite.plan.expand.JoinRexUtils.extractJoinContext;
+import static 

[GitHub] [calcite] herunkang2018 commented on a diff in pull request #3389: [CALCITE-5935] Add CODE_POINTS_TO_BYTES function (enabled in BigQuery…

2023-08-26 Thread via GitHub


herunkang2018 commented on code in PR #3389:
URL: https://github.com/apache/calcite/pull/3389#discussion_r1306586106


##
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##
@@ -929,6 +929,29 @@ public static String charFromUtf8(int n) {
 return String.valueOf(Character.toChars(n));
   }
 
+  /**
+   * SQL CODE_POINTS_TO_BYTES function.
+   */
+  public static @Nullable ByteString codePointsToBytes(List codePoints) {

Review Comment:
   Thanks for clarification, I got 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



[calcite] 03/03: [CALCITE-5914] Cache compiled regular expressions in SQL function runtime

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

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

commit 2a96512c352bda4a5d9c0c80730f5c115ac363d6
Author: Julian Hyde 
AuthorDate: Tue Aug 22 23:22:13 2023 -0700

[CALCITE-5914] Cache compiled regular expressions in SQL function runtime

Functions/operators that now cache include REGEXP_CONTAINS,
PARSE_URL, SIMILAR TO, LIKE, ILIKE, RLIKE, posix regex,
PARSE_TIMESTAMP, FORMAT_DATE, TO_CHAR.

Introduce `class RegexFunction` and use it to implement
variants of REGEXP_REPLACE.

Add CalciteSystemProperty.FUNCTION_LEVEL_CACHE_MAX_SIZE to
limit the number of entries in a function's cache.

Close apache/calcite#3394
---
 .../calcite/adapter/enumerable/RexImpTable.java| 271 -
 .../calcite/config/CalciteSystemProperty.java  |  46 +-
 .../org/apache/calcite/rex/RexInterpreter.java |  19 +-
 .../main/java/org/apache/calcite/runtime/Like.java |  12 +-
 .../org/apache/calcite/runtime/SqlFunctions.java   | 647 ++---
 .../org/apache/calcite/util/BuiltInMethod.java |  69 ++-
 .../apache/calcite/util/format/FormatModel.java|   3 +
 .../apache/calcite/util/format/FormatModels.java   |   4 +-
 .../org/apache/calcite/test/SqlFunctionsTest.java  | 119 ++--
 .../main/java/org/apache/calcite/linq4j/Ord.java   |  19 +-
 10 files changed, 721 insertions(+), 488 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 df3073699f..bfc6342a35 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
@@ -385,6 +385,8 @@ import static 
org.apache.calcite.sql.fun.SqlStdOperatorTable.MULTISET_INTERSECT;
 import static 
org.apache.calcite.sql.fun.SqlStdOperatorTable.MULTISET_INTERSECT_DISTINCT;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.MULTISET_UNION;
 import static 
org.apache.calcite.sql.fun.SqlStdOperatorTable.MULTISET_UNION_DISTINCT;
+import static 
org.apache.calcite.sql.fun.SqlStdOperatorTable.NEGATED_POSIX_REGEX_CASE_INSENSITIVE;
+import static 
org.apache.calcite.sql.fun.SqlStdOperatorTable.NEGATED_POSIX_REGEX_CASE_SENSITIVE;
 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;
@@ -397,6 +399,8 @@ import static 
org.apache.calcite.sql.fun.SqlStdOperatorTable.OVERLAY;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.PI;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.PLUS;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.POSITION;
+import static 
org.apache.calcite.sql.fun.SqlStdOperatorTable.POSIX_REGEX_CASE_INSENSITIVE;
+import static 
org.apache.calcite.sql.fun.SqlStdOperatorTable.POSIX_REGEX_CASE_SENSITIVE;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.POWER;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.RADIANS;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.RAND;
@@ -562,9 +566,9 @@ public class RexImpTable {
   defineMethod(REVERSE, BuiltInMethod.REVERSE.method, NullPolicy.STRICT);
   defineMethod(LEVENSHTEIN, BuiltInMethod.LEVENSHTEIN.method, 
NullPolicy.STRICT);
   defineMethod(SPLIT, BuiltInMethod.SPLIT.method, NullPolicy.STRICT);
-  defineMethod(PARSE_URL, BuiltInMethod.PARSE_URL.method, 
NullPolicy.STRICT);
-  defineMethod(REGEXP_CONTAINS, BuiltInMethod.REGEXP_CONTAINS.method,
-  NullPolicy.STRICT);
+  defineReflective(PARSE_URL, BuiltInMethod.PARSE_URL2.method,
+  BuiltInMethod.PARSE_URL3.method);
+  defineReflective(REGEXP_CONTAINS, BuiltInMethod.REGEXP_CONTAINS.method);
 
   map.put(TRIM, new TrimImplementor());
 
@@ -603,8 +607,10 @@ public class RexImpTable {
   map.put(LOG, new LogImplementor());
   map.put(LOG10, new LogImplementor());
 
-  map.put(RAND, new RandImplementor());
-  map.put(RAND_INTEGER, new RandIntegerImplementor());
+  defineReflective(RAND, BuiltInMethod.RAND.method,
+  BuiltInMethod.RAND_SEED.method);
+  defineReflective(RAND_INTEGER, BuiltInMethod.RAND_INTEGER.method,
+  BuiltInMethod.RAND_INTEGER_SEED.method);
 
   defineMethod(ACOS, BuiltInMethod.ACOS.method, NullPolicy.STRICT);
   defineMethod(ACOSH, BuiltInMethod.ACOSH.method, NullPolicy.STRICT);
@@ -721,17 +727,13 @@ public class RexImpTable {
   NullPolicy.STRICT);
 
   // Datetime parsing methods
-  defineMethod(PARSE_DATE, BuiltInMethod.PARSE_DATE.method,
-  NullPolicy.STRICT);
-  defineMethod(PARSE_DATETIME, BuiltInMethod.PARSE_DATETIME.method,
-  NullPolicy.STRICT);
-  defineMethod(PARSE_TIME, 

[GitHub] [calcite] asfgit closed pull request #3394: [CALCITE-5914] Cache compiled regular expressions in SQL function runtime

2023-08-26 Thread via GitHub


asfgit closed pull request #3394: [CALCITE-5914] Cache compiled regular 
expressions in SQL function runtime
URL: https://github.com/apache/calcite/pull/3394


-- 
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] 01/03: Refactor: In RexImpTable, ensure that every method is in BuiltInMethod

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

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

commit a0a78f3fe10a1f425e895dec24025ddae273eb55
Author: Julian Hyde 
AuthorDate: Tue Aug 22 22:32:59 2023 -0700

Refactor: In RexImpTable, ensure that every method is in BuiltInMethod

Obsolete class MethodNameImplementor.
---
 .../calcite/adapter/enumerable/RexImpTable.java| 244 +++--
 .../org/apache/calcite/util/BuiltInMethod.java |  54 +
 2 files changed, 178 insertions(+), 120 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 4edb190505..1c66ffd180 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
@@ -561,9 +561,10 @@ public class RexImpTable {
   defineMethod(DIFFERENCE, BuiltInMethod.DIFFERENCE.method, 
NullPolicy.STRICT);
   defineMethod(REVERSE, BuiltInMethod.REVERSE.method, NullPolicy.STRICT);
   defineMethod(LEVENSHTEIN, BuiltInMethod.LEVENSHTEIN.method, 
NullPolicy.STRICT);
-  defineMethod(SPLIT, "split", NullPolicy.STRICT);
+  defineMethod(SPLIT, BuiltInMethod.SPLIT.method, NullPolicy.STRICT);
   defineMethod(PARSE_URL, BuiltInMethod.PARSE_URL.method, 
NullPolicy.STRICT);
-  defineMethod(REGEXP_CONTAINS, "regexpContains", NullPolicy.STRICT);
+  defineMethod(REGEXP_CONTAINS, BuiltInMethod.REGEXP_CONTAINS.method,
+  NullPolicy.STRICT);
 
   map.put(TRIM, new TrimImplementor());
 
@@ -593,10 +594,10 @@ public class RexImpTable {
   BuiltInMethod.BIG_DECIMAL_NEGATE.getMethodName());
   defineUnary(UNARY_PLUS, UnaryPlus, NullPolicy.STRICT, null);
 
-  defineMethod(MOD, "mod", NullPolicy.STRICT);
-  defineMethod(EXP, "exp", NullPolicy.STRICT);
-  defineMethod(POWER, "power", NullPolicy.STRICT);
-  defineMethod(ABS, "abs", NullPolicy.STRICT);
+  defineMethod(MOD, BuiltInMethod.MOD.method, NullPolicy.STRICT);
+  defineMethod(EXP, BuiltInMethod.EXP.method, NullPolicy.STRICT);
+  defineMethod(POWER, BuiltInMethod.POWER.method, NullPolicy.STRICT);
+  defineMethod(ABS, BuiltInMethod.ABS.method, NullPolicy.STRICT);
 
   map.put(LN, new LogImplementor());
   map.put(LOG, new LogImplementor());
@@ -605,39 +606,42 @@ public class RexImpTable {
   map.put(RAND, new RandImplementor());
   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);
-  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(IS_INF, "isInf", NullPolicy.STRICT);
-  defineMethod(IS_NAN, "isNaN", 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);
-  defineMethod(SINH, "sinh", NullPolicy.STRICT);
-  defineMethod(TAN, "tan", NullPolicy.STRICT);
-  defineMethod(TANH, "tanh", NullPolicy.STRICT);
-  defineMethod(TRUNC, "struncate", NullPolicy.STRICT);
-  defineMethod(TRUNCATE, "struncate", NullPolicy.STRICT);
-
-  map.put(SAFE_ADD, new SafeArithmeticImplementor("safeAdd"));
-  map.put(SAFE_MULTIPLY, new SafeArithmeticImplementor("safeMultiply"));
-  map.put(SAFE_SUBTRACT, new SafeArithmeticImplementor("safeSubtract"));
+  defineMethod(ACOS, BuiltInMethod.ACOS.method, NullPolicy.STRICT);
+  defineMethod(ACOSH, BuiltInMethod.ACOSH.method, NullPolicy.STRICT);
+  defineMethod(ASIN, BuiltInMethod.ASIN.method, NullPolicy.STRICT);
+  defineMethod(ASINH, BuiltInMethod.ASINH.method, NullPolicy.STRICT);
+  defineMethod(ATAN, BuiltInMethod.ATAN.method, NullPolicy.STRICT);
+  defineMethod(ATAN2, BuiltInMethod.ATAN2.method, NullPolicy.STRICT);
+  defineMethod(ATANH, BuiltInMethod.ATANH.method, NullPolicy.STRICT);
+  

[calcite] branch main updated (730361b664 -> 2a96512c35)

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

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


from 730361b664 [CALCITE-5922] The SQL generated for the POSITION 
function(with 3 input arguments) by the SparkSqlDialect is not recognized by 
Spark SQL
 new a0a78f3fe1 Refactor: In RexImpTable, ensure that every method is in 
BuiltInMethod
 new 4f69d9b3a4 Refactor: In ReflectUtil, add methods isStatic and isPublic
 new 2a96512c35 [CALCITE-5914] Cache compiled regular expressions in SQL 
function runtime

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../ReflectiveCallNotNullImplementor.java  |   5 +-
 .../calcite/adapter/enumerable/RexImpTable.java| 497 +++-
 .../calcite/config/CalciteSystemProperty.java  |  46 +-
 .../apache/calcite/interpreter/TableScanNode.java  |   5 +-
 .../apache/calcite/jdbc/JavaTypeFactoryImpl.java   |   8 +-
 .../calcite/rel/metadata/MetadataHandler.java  |   5 +-
 .../metadata/ReflectiveRelMetadataProvider.java|  13 +-
 .../calcite/rel/type/RelDataTypeFactoryImpl.java   |   5 +-
 .../org/apache/calcite/rex/RexInterpreter.java |  19 +-
 .../main/java/org/apache/calcite/runtime/Like.java |  12 +-
 .../java/org/apache/calcite/runtime/Resources.java |   6 +-
 .../org/apache/calcite/runtime/SqlFunctions.java   | 647 ++---
 .../calcite/schema/impl/AggregateFunctionImpl.java |  11 +-
 .../schema/impl/ReflectiveFunctionBase.java|   8 +-
 .../calcite/schema/impl/ScalarFunctionImpl.java|  10 +-
 .../calcite/schema/impl/TableFunctionImpl.java |   6 +-
 .../apache/calcite/schema/impl/TableMacroImpl.java |   6 +-
 .../calcite/sql2rel/ReflectiveConvertletTable.java |   7 +-
 .../org/apache/calcite/util/BuiltInMethod.java | 111 +++-
 .../java/org/apache/calcite/util/ReflectUtil.java  |  13 +-
 .../main/java/org/apache/calcite/util/Util.java|   8 +-
 .../apache/calcite/util/format/FormatModel.java|   3 +
 .../apache/calcite/util/format/FormatModels.java   |   4 +-
 .../apache/calcite/test/JdbcFrontLinqBackTest.java |   4 +-
 .../org/apache/calcite/test/SqlFunctionsTest.java  | 119 ++--
 .../java/org/apache/calcite/test/SqlTestGen.java   |   8 +-
 .../java/org/apache/calcite/util/UtilTest.java |   4 +-
 .../adapter/geode/util/JavaTypeFactoryExtImpl.java |   5 +-
 .../main/java/org/apache/calcite/linq4j/Ord.java   |  19 +-
 .../org/apache/calcite/piglet/PigUdfFinder.java|   5 +-
 30 files changed, 967 insertions(+), 652 deletions(-)



[calcite] 02/03: Refactor: In ReflectUtil, add methods isStatic and isPublic

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

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

commit 4f69d9b3a498112da67d51c98963781f76f83f8b
Author: Julian Hyde 
AuthorDate: Fri Aug 25 15:35:30 2023 -0700

Refactor: In ReflectUtil, add methods isStatic and isPublic
---
 .../enumerable/ReflectiveCallNotNullImplementor.java|  5 +++--
 .../org/apache/calcite/adapter/enumerable/RexImpTable.java  | 10 +-
 .../java/org/apache/calcite/interpreter/TableScanNode.java  |  5 ++---
 .../java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java   |  8 
 .../org/apache/calcite/rel/metadata/MetadataHandler.java|  5 +++--
 .../calcite/rel/metadata/ReflectiveRelMetadataProvider.java | 13 -
 .../org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java |  5 +++--
 .../src/main/java/org/apache/calcite/runtime/Resources.java |  6 --
 .../apache/calcite/schema/impl/AggregateFunctionImpl.java   | 11 ++-
 .../apache/calcite/schema/impl/ReflectiveFunctionBase.java  |  8 
 .../org/apache/calcite/schema/impl/ScalarFunctionImpl.java  | 10 +-
 .../org/apache/calcite/schema/impl/TableFunctionImpl.java   |  6 +++---
 .../java/org/apache/calcite/schema/impl/TableMacroImpl.java |  6 +++---
 .../apache/calcite/sql2rel/ReflectiveConvertletTable.java   |  7 ---
 core/src/main/java/org/apache/calcite/util/ReflectUtil.java | 13 -
 core/src/main/java/org/apache/calcite/util/Util.java|  8 
 .../java/org/apache/calcite/test/JdbcFrontLinqBackTest.java |  4 ++--
 core/src/test/java/org/apache/calcite/test/SqlTestGen.java  |  8 +---
 core/src/test/java/org/apache/calcite/util/UtilTest.java|  4 ++--
 .../calcite/adapter/geode/util/JavaTypeFactoryExtImpl.java  |  5 +++--
 .../main/java/org/apache/calcite/piglet/PigUdfFinder.java   |  5 +++--
 21 files changed, 88 insertions(+), 64 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/ReflectiveCallNotNullImplementor.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/ReflectiveCallNotNullImplementor.java
index 228ae48842..56dfe4cf22 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/ReflectiveCallNotNullImplementor.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/ReflectiveCallNotNullImplementor.java
@@ -21,9 +21,10 @@ import org.apache.calcite.linq4j.tree.Expressions;
 import org.apache.calcite.rex.RexCall;
 
 import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
 import java.util.List;
 
+import static org.apache.calcite.util.ReflectUtil.isStatic;
+
 /**
  * Implementation of
  * {@link org.apache.calcite.adapter.enumerable.NotNullImplementor}
@@ -51,7 +52,7 @@ public class ReflectiveCallNotNullImplementor implements 
NotNullImplementor {
 translatedOperands =
 EnumUtils.convertAssignableTypes(method.getParameterTypes(), 
translatedOperands);
 final Expression callExpr;
-if ((method.getModifiers() & Modifier.STATIC) != 0) {
+if (isStatic(method)) {
   callExpr = Expressions.call(method, translatedOperands);
 } else {
   final Expression target =
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 1c66ffd180..df3073699f 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
@@ -94,7 +94,6 @@ import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
@@ -440,6 +439,7 @@ import static 
org.apache.calcite.sql.fun.SqlStdOperatorTable.UNARY_MINUS;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.UNARY_PLUS;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.UPPER;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.USER;
+import static org.apache.calcite.util.ReflectUtil.isStatic;
 
 import static java.util.Objects.requireNonNull;
 
@@ -1882,7 +1882,7 @@ public class RexImpTable {
 private static NewExpression makeNew(AggregateFunctionImpl afi) {
   try {
 Constructor constructor = afi.declaringClass.getConstructor();
-Objects.requireNonNull(constructor, "constructor");
+requireNonNull(constructor, "constructor");
 return Expressions.new_(afi.declaringClass);
   } catch (NoSuchMethodException e) {
 // ignore, and try next constructor
@@ -1890,7 +1890,7 @@ public class RexImpTable {
   try {
 Constructor constructor =
 afi.declaringClass.getConstructor(FunctionContext.class);
-Objects.requireNonNull(constructor, "constructor");
+requireNonNull(constructor, "constructor");
 return 

[GitHub] [calcite] sonarcloud[bot] commented on pull request #3382: [CALCITE-5944] RelMdRowCount can return more accurate rowCount for Sample

2023-08-26 Thread via GitHub


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

   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=3382)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3382=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=3382=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3382=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=3382=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=3382=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3382=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=3382=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=3382=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3382=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=3382=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=3382=false=CODE_SMELL)
 [0 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_calcite=3382=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=3382=new_coverage=list)
 [100.0% 
Coverage](https://sonarcloud.io/component_measures?id=apache_calcite=3382=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=3382=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3382=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



[GitHub] [calcite] JiajunBernoulli commented on pull request #3382: [CALCITE-5944] RelMdRowCount can return more accurate rowCount for Sample

2023-08-26 Thread via GitHub


JiajunBernoulli commented on PR #3382:
URL: https://github.com/apache/calcite/pull/3382#issuecomment-1694244263

   This test case is unstable.
   ```
   
   FAILURE 311.7sec, org.apache.calcite.adapter.tpch.TpchTest > testQuery07()
   
   java.util.concurrent.TimeoutException: testQuery07() timed out after 5 
minutes
   
   at 
org.junit.jupiter.engine.extension.TimeoutExceptionFactory.create(TimeoutExceptionFactory.java:29)
   
   at 
org.junit.jupiter.engine.extension.SameThreadTimeoutInvocation.proceed(SameThreadTimeoutInvocation.java:58)
   
   at 
org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
   
   at 
org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
   
   at 
org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
   
   at 
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
   
   at 
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
   
   at 
org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
   
   at 
org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
   
   at 
org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
   
   at 
org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
   
   at 
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
   
   at 
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
   
   at 
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
   
   at 
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
   
   at 
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
   
   at 
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
   
   at 
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
   
   at 
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
   
   at 
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
   
   at 
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
   
   at 
org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
   
   at 
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
   
   at 
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
   
   at 
org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
   ```


-- 
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



[GitHub] [calcite] macroguo-ghy commented on a diff in pull request #3389: [CALCITE-5935] Add CODE_POINTS_TO_BYTES function (enabled in BigQuery…

2023-08-26 Thread via GitHub


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


##
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##
@@ -929,6 +929,29 @@ public static String charFromUtf8(int n) {
 return String.valueOf(Character.toChars(n));
   }
 
+  /**
+   * SQL CODE_POINTS_TO_BYTES function.
+   */
+  public static @Nullable ByteString codePointsToBytes(List codePoints) {

Review Comment:
   @herunkang2018 Thanks for your advice. Calcite often use 
`SqlTypeFamily.INTEGER`(which is collection of `INT_TYPES` in `SqlTypeName`) as 
a integer operand checker instead of `SqlTypeName.INTEGER`. This can easily be 
confusing. So `ARRAY_OF_INTEGER` means an array whose component could be 
`TINYINT, SMALLINT, INTEGER or BIGINT`.
   Back to your comment, array component could be any of the `INT_TYPES`, 
including `BIGINT`(Correspond Long in java). The reason I allow the `BIGINT` 
component to pass this checker is because if `BIGINT` component is invaild 
input type, `code_points_to_byte(array[cast(1 as bigint)])` will fail during 
operand type checking, this does not meet expectations. And  if I execute 
`select code_points_to_bytes(array[2147483648])` in BigQuery, BigQuery will 
throw a exception :`Input arguments of CODE_POINTS_TO_BYTES out of range: 
2147483648` rather than input type error(Actully BigQuery see all integers as 
int64).



-- 
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