[GitHub] [calcite] sonarcloud[bot] commented on pull request #3054: (do not check in)

2023-05-20 Thread via GitHub


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

   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=3054)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3054=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=3054=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3054=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=3054=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=3054=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3054=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=3054=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=3054=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3054=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=3054=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=3054=false=CODE_SMELL)
 [1 Code 
Smell](https://sonarcloud.io/project/issues?id=apache_calcite=3054=false=CODE_SMELL)
   
   
[![85.7%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png
 
'85.7%')](https://sonarcloud.io/component_measures?id=apache_calcite=3054=new_coverage=list)
 [85.7% 
Coverage](https://sonarcloud.io/component_measures?id=apache_calcite=3054=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=3054=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3054=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 #3202: [CALCITE-5704] Add ARRAY_EXCEPT, ARRAY_INTERSECT, ARRAY_UNION function (enabled in Spark library)

2023-05-20 Thread via GitHub


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

   Please resolve conflicting files.


-- 
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-5695] Add MAP_KEYS, MAP_VALUES function (enabled in Spark library)

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

jiajunxie 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 9c33d7aeef [CALCITE-5695] Add MAP_KEYS, MAP_VALUES function (enabled 
in Spark library)
9c33d7aeef is described below

commit 9c33d7aeefe082bf5f7be617ef231e1285418a6c
Author: yongen.ly 
AuthorDate: Wed May 17 10:35:11 2023 +0800

[CALCITE-5695] Add MAP_KEYS, MAP_VALUES function (enabled in Spark library)
---
 .../calcite/adapter/enumerable/RexImpTable.java|  4 
 .../org/apache/calcite/runtime/SqlFunctions.java   | 10 
 .../main/java/org/apache/calcite/sql/SqlKind.java  |  6 +
 .../calcite/sql/fun/SqlLibraryOperators.java   | 14 +++
 .../org/apache/calcite/sql/type/OperandTypes.java  |  3 +++
 .../org/apache/calcite/sql/type/ReturnTypes.java   | 24 +++
 .../apache/calcite/sql/type/SqlTypeTransforms.java | 28 ++
 .../org/apache/calcite/util/BuiltInMethod.java |  2 ++
 site/_docs/reference.md|  2 ++
 .../org/apache/calcite/test/SqlOperatorTest.java   | 28 ++
 10 files changed, 121 insertions(+)

diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
index 1f833ad0a4..0d5090a93a 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
@@ -165,6 +165,8 @@ import static 
org.apache.calcite.sql.fun.SqlLibraryOperators.LOG;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.LOGICAL_AND;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.LOGICAL_OR;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.LPAD;
+import static org.apache.calcite.sql.fun.SqlLibraryOperators.MAP_KEYS;
+import static org.apache.calcite.sql.fun.SqlLibraryOperators.MAP_VALUES;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.MAX_BY;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.MD5;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.MIN_BY;
@@ -680,6 +682,8 @@ public class RexImpTable {
   defineMethod(ARRAY_REPEAT, BuiltInMethod.ARRAY_REPEAT.method, 
NullPolicy.NONE);
   defineMethod(ARRAY_REVERSE, BuiltInMethod.ARRAY_REVERSE.method, 
NullPolicy.STRICT);
   defineMethod(ARRAY_SIZE, BuiltInMethod.COLLECTION_SIZE.method, 
NullPolicy.STRICT);
+  defineMethod(MAP_KEYS, BuiltInMethod.MAP_KEYS.method, NullPolicy.STRICT);
+  defineMethod(MAP_VALUES, BuiltInMethod.MAP_VALUES.method, 
NullPolicy.STRICT);
   map.put(ARRAY_CONCAT, new ArrayConcatImplementor());
   final MethodImplementor isEmptyImplementor =
   new MethodImplementor(BuiltInMethod.IS_EMPTY.method, NullPolicy.NONE,
diff --git a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java 
b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
index 29ba098dda..1fc339fc07 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
@@ -3831,6 +3831,16 @@ public class SqlFunctions {
 return Collections.nCopies(numberOfElement, element);
   }
 
+  /** Support the MAP_KEYS function. */
+  public static List mapKeys(Map map) {
+return new ArrayList<>(map.keySet());
+  }
+
+  /** Support the MAP_VALUES function. */
+  public static List mapValues(Map map) {
+return new ArrayList<>(map.values());
+  }
+
   /** Support the SLICE function. */
   public static List slice(List list) {
 List result = new ArrayList(list.size());
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlKind.java 
b/core/src/main/java/org/apache/calcite/sql/SqlKind.java
index 9104af350c..d52322bd2f 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlKind.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlKind.java
@@ -692,6 +692,12 @@ public enum SqlKind {
   /** {@code ARRAY_SIZE} function (Spark semantics). */
   ARRAY_SIZE,
 
+  /** {@code MAP_KEYS} function (Spark semantics). */
+  MAP_KEYS,
+
+  /** {@code MAP_VALUES} function (Spark semantics). */
+  MAP_VALUES,
+
   /** {@code REVERSE} function (SQL Server, MySQL). */
   REVERSE,
 
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 fe3269d18a..a1952900eb 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
@@ -888,6 +888,20 @@ public abstract class SqlLibraryOperators {
   ReturnTypes.LEAST_RESTRICTIVE,
   OperandTypes.AT_LEAST_ONE_SAME_VARIADIC);
 
+  /** The "MAP_KEYS(map)" function. */
+  

[GitHub] [calcite] JiajunBernoulli merged pull request #3194: [CALCITE-5695] Add MAP_KEYS, MAP_VALUES function (enabled in Spark li…

2023-05-20 Thread via GitHub


JiajunBernoulli merged PR #3194:
URL: https://github.com/apache/calcite/pull/3194


-- 
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 a diff in pull request #3207: [CALCITE-5707] Add ARRAY_CONTAINS function (enabled in Spark library)

2023-05-20 Thread via GitHub


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


##
core/src/main/java/org/apache/calcite/sql/type/ArrayElementOperandTypeChecker.java:
##
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql.type;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlCallBinding;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperandCountRange;
+import org.apache.calcite.sql.SqlOperator;
+
+import com.google.common.collect.ImmutableList;
+
+import static 
org.apache.calcite.sql.type.NonNullableAccessors.getComponentTypeOrThrow;
+import static org.apache.calcite.util.Static.RESOURCE;
+
+/**
+ * Parameter type-checking strategy where types must be Array and Array 
element type.
+ */
+public class ArrayElementOperandTypeChecker implements SqlOperandTypeChecker {
+  //~ Methods 
+
+  @Override public boolean checkOperandTypes(
+  SqlCallBinding callBinding,
+  boolean throwOnFailure) {
+final SqlNode op0 = callBinding.operand(0);
+if (!OperandTypes.ARRAY.checkSingleOperandType(
+callBinding,
+op0,
+0,
+throwOnFailure)) {
+  return false;
+}
+
+RelDataType arrayComponentType =
+getComponentTypeOrThrow(SqlTypeUtil.deriveType(callBinding, op0));
+final SqlNode op1 = callBinding.operand(1);
+RelDataType aryType1 = SqlTypeUtil.deriveType(callBinding, op1);

Review Comment:
   Why `op1` not need?
   ```
   RelDataType biggest =
   callBinding.getTypeFactory().leastRestrictive(
   ImmutableList.of(
   getComponentTypeOrThrow(SqlTypeUtil.deriveType(callBinding, 
op0)),
   getComponentTypeOrThrow(SqlTypeUtil.deriveType(callBinding, 
op1;
   ```
   Here is code in MultisetOperandTypeChecker.
   
https://github.com/apache/calcite/blob/3e95a13b8c5d715298f469051f792286cea704fa/core/src/main/java/org/apache/calcite/sql/type/MultisetOperandTypeChecker.java#L66
   
   



-- 
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 a diff in pull request #3207: [CALCITE-5707] Add ARRAY_CONTAINS function (enabled in Spark library)

2023-05-20 Thread via GitHub


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


##
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##
@@ -3791,6 +3791,12 @@ private static AtomicLong getAtomicLong(String key) {
 return atomic;
   }
 
+  /** Support the ARRAY_CONTAINS function. */
+  public static boolean contains(List list, Object element) {
+final Set set = new HashSet(list);

Review Comment:
   In fact, set has not been reused, and I don't think it can improve speed.
   
   Because the construction time of the set may be longer than the search time 
of the 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 a diff in pull request #3215: When parsing SQL in PostgreSQL dialect, allow unquoted table names to contain dollar sign

2023-05-20 Thread via GitHub


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


##
babel/src/main/codegen/config.fmpp:
##
@@ -578,9 +578,14 @@ data: {
 ]
 
 # Custom identifier token.
-# Example: "< IDENTIFIER: (|)+ >".
-customIdentifierToken: "< IDENTIFIER: (|)+ >"
-
+# 
+# PostgreSQL allows letters with diacritical marks and non-Latin letters 
+# in the beginning of identifier and additionally dollar sign in the rest 
of identifier. 
+# See 
https://github.com/postgres/postgres/blob/master/src/backend/parser/scan.l
+#
+# MySQL allows digit in the beginning of identifier
+customIdentifierToken: "< IDENTIFIER: 
(||[\"\\200\"-\"\\377\"]) 
(|||[\"\\200\"-\"\\377\"])* >"

Review Comment:
   Is it octal?
   
   Here is char mapping link: 
https://learn.microsoft.com/zh-cn/office/vba/language/reference/user-interface-help/character-set-128255
   Octal  |  Decimal  |  
   377 |  255 |   ÿ
   
   
   
   



-- 
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] sonarcloud[bot] commented on pull request #3217: [CALCITE-5717] Prune Project's input if project has no InputRef and the input has 1 row

2023-05-20 Thread via GitHub


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

   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=3217)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3217=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=3217=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3217=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=3217=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=3217=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3217=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=3217=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=3217=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3217=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=3217=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=3217=false=CODE_SMELL)
 [0 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_calcite=3217=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=3217=new_coverage=list)
 [100.0% 
Coverage](https://sonarcloud.io/component_measures?id=apache_calcite=3217=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=3217=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3217=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] sonarcloud[bot] commented on pull request #3217: [CALCITE-5717] Prune Project's input if project has no InputRef and the input has 1 row

2023-05-20 Thread via GitHub


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

   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=3217)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3217=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=3217=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3217=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=3217=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=3217=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3217=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=3217=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=3217=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3217=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=3217=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=3217=false=CODE_SMELL)
 [0 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_calcite=3217=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=3217=new_coverage=list)
 [100.0% 
Coverage](https://sonarcloud.io/component_measures?id=apache_calcite=3217=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=3217=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3217=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] libenchao opened a new pull request, #3217: [CALCITE-5717] Prune Project's input if project has no InputRef and the input has 1 row

2023-05-20 Thread via GitHub


libenchao opened a new pull request, #3217:
URL: https://github.com/apache/calcite/pull/3217

   …


-- 
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] dssysolyatin commented on a diff in pull request #3215: When parsing SQL in PostgreSQL dialect, allow unquoted table names to contain dollar sign

2023-05-20 Thread via GitHub


dssysolyatin commented on code in PR #3215:
URL: https://github.com/apache/calcite/pull/3215#discussion_r1199601084


##
babel/src/main/codegen/config.fmpp:
##
@@ -578,9 +578,14 @@ data: {
 ]
 
 # Custom identifier token.
-# Example: "< IDENTIFIER: (|)+ >".
-customIdentifierToken: "< IDENTIFIER: (|)+ >"
-
+# 
+# PostgreSQL allows letters with diacritical marks and non-Latin letters 
+# in the beginning of identifier and additionally dollar sign in the rest 
of identifier. 
+# See 
https://github.com/postgres/postgres/blob/master/src/backend/parser/scan.l
+#
+# MySQL allows digit in the beginning of identifier
+customIdentifierToken: "< IDENTIFIER: 
(||[\"\\200\"-\"\\377\"]) 
(|||[\"\\200\"-\"\\377\"])* >"

Review Comment:
   @JiajunBernoulli 
   It is letters with diacritical marks and non-Latin letters.
   
   From 
https://github.com/postgres/postgres/blob/master/src/backend/parser/scan.l
   ```
   ident_start  [A-Za-z\200-\377_]
   ident_cont   [A-Za-z\200-\377_0-9\$]
   
   identifier   {ident_start}{ident_cont}*
   ```
   I will rename jira ticket and add `diacritical marks and non-Latin letters` 
to title. description has it already



-- 
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-5674] CAST expr to target type should respect nullable when it is complex type

2023-05-20 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 289d082055 [CALCITE-5674] CAST expr to target type should respect 
nullable when it is complex type
289d082055 is described below

commit 289d08205584efefa7b399318e7bb81c4f7f11aa
Author: yongen.ly 
AuthorDate: Fri May 5 20:31:50 2023 +0800

[CALCITE-5674] CAST expr to target type should respect nullable when it is 
complex type

Close apache/calcite#3189
---
 .../apache/calcite/sql/fun/SqlCastFunction.java| 66 +-
 .../org/apache/calcite/test/SqlValidatorTest.java  | 58 ++-
 2 files changed, 120 insertions(+), 4 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java 
b/core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java
index 74b1fc0236..04a05e7358 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java
@@ -43,12 +43,20 @@ import com.google.common.collect.ImmutableSetMultimap;
 import com.google.common.collect.SetMultimap;
 
 import java.text.Collator;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Objects;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
+import static org.apache.calcite.sql.type.SqlTypeUtil.isArray;
+import static org.apache.calcite.sql.type.SqlTypeUtil.isCollection;
+import static org.apache.calcite.sql.type.SqlTypeUtil.isMap;
+import static org.apache.calcite.sql.type.SqlTypeUtil.isRow;
 import static org.apache.calcite.util.Static.RESOURCE;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * SqlCastFunction. Note that the std functions are really singleton objects,
  * because they always get fetched via the StdOperatorTable. So you can't store
@@ -122,8 +130,62 @@ public class SqlCastFunction extends SqlFunction {
   /** Derives the type of "CAST(expression AS targetType)". */
   public static RelDataType deriveType(RelDataTypeFactory typeFactory,
   RelDataType expressionType, RelDataType targetType, boolean safe) {
-return typeFactory.createTypeWithNullability(targetType,
-expressionType.isNullable() || safe);
+return createTypeWithNullabilityFromExpr(typeFactory, expressionType, 
targetType, safe);
+  }
+
+  private static RelDataType 
createTypeWithNullabilityFromExpr(RelDataTypeFactory typeFactory,
+  RelDataType expressionType, RelDataType targetType, boolean safe) {
+boolean isNullable = expressionType.isNullable() || safe;
+
+if (isCollection(expressionType)) {
+  RelDataType expressionElementType = expressionType.getComponentType();
+  RelDataType targetElementType = targetType.getComponentType();
+  requireNonNull(expressionElementType, () -> "componentType of " + 
expressionType);
+  requireNonNull(targetElementType, () -> "componentType of " + 
targetType);
+  RelDataType newElementType =
+  createTypeWithNullabilityFromExpr(
+  typeFactory, expressionElementType, targetElementType, safe);
+  return isArray(expressionType)
+  ? SqlTypeUtil.createArrayType(typeFactory, newElementType, 
isNullable)
+  : SqlTypeUtil.createMultisetType(typeFactory, newElementType, 
isNullable);
+}
+
+if (isRow(expressionType)) {
+  final int fieldCount = expressionType.getFieldCount();
+  final List typeList = new ArrayList<>(fieldCount);
+  for (int i = 0; i < fieldCount; ++i) {
+RelDataType expressionElementType = 
expressionType.getFieldList().get(i).getType();
+RelDataType targetElementType = 
targetType.getFieldList().get(i).getType();
+typeList.add(
+createTypeWithNullabilityFromExpr(typeFactory, 
expressionElementType,
+targetElementType, safe));
+  }
+  return typeFactory.createTypeWithNullability(
+  typeFactory.createStructType(
+  typeList,
+  targetType.getFieldNames()), isNullable);
+}
+
+if (isMap(expressionType)) {
+  RelDataType expressionKeyType =
+  requireNonNull(expressionType.getKeyType(), () -> "keyType of " + 
expressionType);
+  RelDataType expressionValueType =
+  requireNonNull(expressionType.getValueType(), () -> "valueType of " 
+ expressionType);
+  RelDataType targetKeyType =
+  requireNonNull(targetType.getKeyType(), () -> "keyType of " + 
targetType);
+  RelDataType targetValueType =
+  requireNonNull(targetType.getValueType(), () -> "valueType of " + 
targetType);
+
+  RelDataType keyType =
+  createTypeWithNullabilityFromExpr(
+  typeFactory, expressionKeyType, targetKeyType, safe);
+  RelDataType valueType =
+  createTypeWithNullabilityFromExpr(
+  

[GitHub] [calcite] libenchao closed pull request #3189: [CALCITE-5674] Cast expr to target type should respect nullable when …

2023-05-20 Thread via GitHub


libenchao closed pull request #3189: [CALCITE-5674] Cast expr to target type 
should respect nullable when …
URL: https://github.com/apache/calcite/pull/3189


-- 
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] sonarcloud[bot] commented on pull request #3189: [CALCITE-5674] Cast expr to target type should respect nullable when …

2023-05-20 Thread via GitHub


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

   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=3189)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3189=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=3189=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3189=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=3189=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=3189=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3189=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=3189=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=3189=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3189=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=3189=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=3189=false=CODE_SMELL)
 [0 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_calcite=3189=false=CODE_SMELL)
   
   
[![73.1%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png
 
'73.1%')](https://sonarcloud.io/component_measures?id=apache_calcite=3189=new_coverage=list)
 [73.1% 
Coverage](https://sonarcloud.io/component_measures?id=apache_calcite=3189=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=3189=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3189=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] libenchao commented on a diff in pull request #3189: [CALCITE-5674] Cast expr to target type should respect nullable when …

2023-05-20 Thread via GitHub


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


##
core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java:
##
@@ -7033,7 +7036,7 @@ void testGroupExpressionEquivalenceParams() {
 sql("select cast(a as row(f0 int, f1 varchar)) from COMPLEXTYPES.CTC_T1")
 .withExtendedCatalog()
 .columnType("RecordType(INTEGER NOT NULL F0, VARCHAR NOT NULL F1) NOT 
NULL");
-sql("select cast(b as row(f0 int not null, f1 varchar null))\n"
+sql("select cast(b as row(f0 int, f1 varchar))\n"

Review Comment:
   sounds good to me, one commit should focus on one thing



-- 
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] liuyongvs commented on a diff in pull request #3189: [CALCITE-5674] Cast expr to target type should respect nullable when …

2023-05-20 Thread via GitHub


liuyongvs commented on code in PR #3189:
URL: https://github.com/apache/calcite/pull/3189#discussion_r1199589589


##
core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java:
##
@@ -7033,7 +7036,7 @@ void testGroupExpressionEquivalenceParams() {
 sql("select cast(a as row(f0 int, f1 varchar)) from COMPLEXTYPES.CTC_T1")
 .withExtendedCatalog()
 .columnType("RecordType(INTEGER NOT NULL F0, VARCHAR NOT NULL F1) NOT 
NULL");
-sql("select cast(b as row(f0 int not null, f1 varchar null))\n"
+sql("select cast(b as row(f0 int, f1 varchar))\n"

Review Comment:
   just for test row and i fallback it.
   then i will submit new pr to fix cast( type not null/ null) latter according 
sql standard, what do you think?



-- 
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] sonarcloud[bot] commented on pull request #3189: [CALCITE-5674] Cast expr to target type should respect nullable when …

2023-05-20 Thread via GitHub


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

   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=3189)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3189=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=3189=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3189=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=3189=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=3189=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3189=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=3189=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=3189=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3189=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=3189=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=3189=false=CODE_SMELL)
 [0 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_calcite=3189=false=CODE_SMELL)
   
   
[![73.1%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png
 
'73.1%')](https://sonarcloud.io/component_measures?id=apache_calcite=3189=new_coverage=list)
 [73.1% 
Coverage](https://sonarcloud.io/component_measures?id=apache_calcite=3189=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=3189=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3189=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] libenchao commented on a diff in pull request #3189: [CALCITE-5674] Cast expr to target type should respect nullable when …

2023-05-20 Thread via GitHub


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


##
core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java:
##
@@ -122,8 +130,62 @@ static SqlReturnTypeInference returnTypeInference(boolean 
safe) {
   /** Derives the type of "CAST(expression AS targetType)". */
   public static RelDataType deriveType(RelDataTypeFactory typeFactory,
   RelDataType expressionType, RelDataType targetType, boolean safe) {
-return typeFactory.createTypeWithNullability(targetType,
-expressionType.isNullable() || safe);
+return createTypeWithNullabilityFromExpr(typeFactory, expressionType, 
targetType, safe);
+  }
+
+  private static RelDataType 
createTypeWithNullabilityFromExpr(RelDataTypeFactory typeFactory,
+  RelDataType expressionType, RelDataType targetType, boolean safe) {
+boolean isNullable = expressionType.isNullable() || safe;
+
+if (isCollection(expressionType)) {
+  RelDataType expressionElementType = expressionType.getComponentType();
+  RelDataType targetElementType = targetType.getComponentType();
+  requireNonNull(expressionElementType, () -> "componentType of " + 
expressionType);
+  requireNonNull(targetElementType, () -> "componentType of " + 
targetType);
+  RelDataType newElementType =
+  createTypeWithNullabilityFromExpr(
+  typeFactory, expressionElementType, targetElementType, safe);
+  return isArray(expressionType)
+  ? SqlTypeUtil.createArrayType(typeFactory, newElementType, 
isNullable)
+  : SqlTypeUtil.createMultisetType(typeFactory, newElementType, 
isNullable);
+}
+
+if (isRow(expressionType)) {
+  final int fieldCount = expressionType.getFieldCount();
+  List typeList = new ArrayList<>();

Review Comment:
   NIT: add `final`, and initialize `ArrayList` with `fieldCount` 



##
core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java:
##
@@ -7033,7 +7036,7 @@ void testGroupExpressionEquivalenceParams() {
 sql("select cast(a as row(f0 int, f1 varchar)) from COMPLEXTYPES.CTC_T1")
 .withExtendedCatalog()
 .columnType("RecordType(INTEGER NOT NULL F0, VARCHAR NOT NULL F1) NOT 
NULL");
-sql("select cast(b as row(f0 int not null, f1 varchar null))\n"
+sql("select cast(b as row(f0 int, f1 varchar))\n"

Review Comment:
   why are you changing this test and the below one?



##
core/src/main/java/org/apache/calcite/sql/fun/SqlCastFunction.java:
##
@@ -122,8 +130,62 @@ static SqlReturnTypeInference returnTypeInference(boolean 
safe) {
   /** Derives the type of "CAST(expression AS targetType)". */
   public static RelDataType deriveType(RelDataTypeFactory typeFactory,
   RelDataType expressionType, RelDataType targetType, boolean safe) {
-return typeFactory.createTypeWithNullability(targetType,
-expressionType.isNullable() || safe);
+return createTypeWithNullabilityFromExpr(typeFactory, expressionType, 
targetType, safe);
+  }
+
+  private static RelDataType 
createTypeWithNullabilityFromExpr(RelDataTypeFactory typeFactory,
+  RelDataType expressionType, RelDataType targetType, boolean safe) {
+boolean isNullable = expressionType.isNullable() || safe;
+
+if (isCollection(expressionType)) {
+  RelDataType expressionElementType = expressionType.getComponentType();
+  RelDataType targetElementType = targetType.getComponentType();
+  requireNonNull(expressionElementType, () -> "componentType of " + 
expressionType);
+  requireNonNull(targetElementType, () -> "componentType of " + 
targetType);
+  RelDataType newElementType =
+  createTypeWithNullabilityFromExpr(
+  typeFactory, expressionElementType, targetElementType, safe);
+  return isArray(expressionType)
+  ? SqlTypeUtil.createArrayType(typeFactory, newElementType, 
isNullable)
+  : SqlTypeUtil.createMultisetType(typeFactory, newElementType, 
isNullable);
+}
+
+if (isRow(expressionType)) {
+  final int fieldCount = expressionType.getFieldCount();
+  List typeList = new ArrayList<>();
+  for (int i = 0; i < fieldCount; ++i) {
+RelDataType expressionElementType = 
expressionType.getFieldList().get(i).getType();
+RelDataType targetElementType = 
targetType.getFieldList().get(i).getType();
+typeList.add(
+createTypeWithNullabilityFromExpr(typeFactory, 
expressionElementType,
+targetElementType, safe));

Review Comment:
   NIT: add indent.



-- 
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] liuyongvs commented on a diff in pull request #3207: [CALCITE-5707] Add ARRAY_CONTAINS function (enabled in Spark library)

2023-05-20 Thread via GitHub


liuyongvs commented on code in PR #3207:
URL: https://github.com/apache/calcite/pull/3207#discussion_r1199577868


##
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##
@@ -3791,6 +3791,12 @@ private static AtomicLong getAtomicLong(String key) {
 return atomic;
   }
 
+  /** Support the ARRAY_CONTAINS function. */
+  public static boolean contains(List list, Object element) {
+final Set set = new HashSet(list);

Review Comment:
   yeap, it is no different with for loop, may cost some space. if you think it 
is need, i will change it to for loop 



##
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##
@@ -844,7 +844,14 @@ private static RelDataType 
arrayReturnType(SqlOperatorBinding opBinding) {
   SqlLibraryOperators::arrayReturnType,
   OperandTypes.SAME_VARIADIC);
 
-  /** The "ARRAY_DISTINCT(array)" function (Spark). */
+  /** The "ARRAY_CONTAINS(array)" function. */
+  @LibraryOperator(libraries = {SPARK})
+  public static final SqlFunction ARRAY_CONTAINS =
+  SqlBasicFunction.create(SqlKind.ARRAY_CONTAINS,
+  ReturnTypes.BOOLEAN_NULLABLE_IF_ARG0_NULLABLE,

Review Comment:
   because 
   1) array it null, result is null
   2) element is null, it is not . for example array_contains(array[null, 1] , 
null) -> true . type is not null
   
   flink implementation 
   
https://github.com/apache/flink/blob/06688f345f6793a8964ec2175f44cda13c33/flink-table/flink-table-common/src/main/java/org/apache/flink/table/functions/BuiltInFunctionDefinitions.java#L195
   ```
   public static final BuiltInFunctionDefinition ARRAY_CONTAINS =
   BuiltInFunctionDefinition.newBuilder()
   .name("ARRAY_CONTAINS")
   .kind(SCALAR)
   .inputTypeStrategy(
   sequence(
   Arrays.asList("haystack", "needle"),
   Arrays.asList(
   logical(LogicalTypeRoot.ARRAY), 
ARRAY_ELEMENT_ARG)))
   .outputTypeStrategy(
   nullableIfArgs(
   ConstantArgumentCount.of(0), 
explicit(DataTypes.BOOLEAN(
   .runtimeClass(
   
"org.apache.flink.table.runtime.functions.scalar.ArrayContainsFunction")
   .build();
   
   ```



##
core/src/main/java/org/apache/calcite/sql/type/ArrayElementOperandTypeChecker.java:
##
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql.type;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlCallBinding;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperandCountRange;
+import org.apache.calcite.sql.SqlOperator;
+
+import com.google.common.collect.ImmutableList;
+
+import static 
org.apache.calcite.sql.type.NonNullableAccessors.getComponentTypeOrThrow;
+import static org.apache.calcite.util.Static.RESOURCE;
+
+/**
+ * Parameter type-checking strategy where types must be Array and Array 
element type.
+ */
+public class ArrayElementOperandTypeChecker implements SqlOperandTypeChecker {

Review Comment:
   yes refer it.
   do not find a good idea to abstract it.
   MultisetOperandTypeChecker for two Multiset
   ArrayElementOperandTypeChecker for Array and element type



##
core/src/main/java/org/apache/calcite/sql/type/ArrayElementOperandTypeChecker.java:
##
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is 

[GitHub] [calcite] liuyongvs commented on a diff in pull request #3202: [CALCITE-5704] Add ARRAY_EXCEPT, ARRAY_INTERSECT, ARRAY_UNION function (enabled in Spark library)

2023-05-20 Thread via GitHub


liuyongvs commented on code in PR #3202:
URL: https://github.com/apache/calcite/pull/3202#discussion_r1199576905


##
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##
@@ -3809,6 +3809,29 @@ public static List distinct(List list) {
 return Collections.nCopies(numberOfElement, element);
   }
 
+  /** Support the ARRAY_EXCEPT function. */
+  public static List arrayExcept(List list1, List list2) {
+final Set result = new LinkedHashSet<>(list1);
+result.removeAll(list2);
+return new ArrayList<>(result);
+  }
+
+  /** Support the ARRAY_INTERSECT function. */
+  public static List arrayIntersect(List list1, List list2) {
+final Set result = new LinkedHashSet<>(list1);
+result.retainAll(list2);
+return new ArrayList<>(result);
+  }
+
+  /** Support the ARRAY_UNION function. */
+  public static List arrayUnion(List list1, List list2) {
+final Set result =
+new LinkedHashSet<>(Math.max((int) ((list1.size() + list2.size()) / 
.75f) + 1, 16));

Review Comment:
   refer to multisetUnionDistinct in SqlFunctions
   capacity calculation is in the same way like for new HashSet(Collection)



-- 
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] liuyongvs commented on a diff in pull request #3202: [CALCITE-5704] Add ARRAY_EXCEPT, ARRAY_INTERSECT, ARRAY_UNION function (enabled in Spark library)

2023-05-20 Thread via GitHub


liuyongvs commented on code in PR #3202:
URL: https://github.com/apache/calcite/pull/3202#discussion_r1199577024


##
core/src/main/java/org/apache/calcite/sql/type/ArrayOperandTypeChecker.java:
##
@@ -0,0 +1,87 @@
+/*
+ * 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.sql.type;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlCallBinding;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperandCountRange;
+import org.apache.calcite.sql.SqlOperator;
+
+import com.google.common.collect.ImmutableList;
+
+import static 
org.apache.calcite.sql.type.NonNullableAccessors.getComponentTypeOrThrow;
+import static org.apache.calcite.util.Static.RESOURCE;
+
+/**
+ * Parameter type-checking strategy where types must be ([nullable] Array,
+ * [nullable] Array), and the two types must have the same element type.
+ *
+ * @see ArraySqlType#getComponentType
+ */
+public class ArrayOperandTypeChecker implements SqlOperandTypeChecker {

Review Comment:
   yeap 



-- 
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] liuyongvs commented on a diff in pull request #3202: [CALCITE-5704] Add ARRAY_EXCEPT, ARRAY_INTERSECT, ARRAY_UNION function (enabled in Spark library)

2023-05-20 Thread via GitHub


liuyongvs commented on code in PR #3202:
URL: https://github.com/apache/calcite/pull/3202#discussion_r1199576905


##
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##
@@ -3809,6 +3809,29 @@ public static List distinct(List list) {
 return Collections.nCopies(numberOfElement, element);
   }
 
+  /** Support the ARRAY_EXCEPT function. */
+  public static List arrayExcept(List list1, List list2) {
+final Set result = new LinkedHashSet<>(list1);
+result.removeAll(list2);
+return new ArrayList<>(result);
+  }
+
+  /** Support the ARRAY_INTERSECT function. */
+  public static List arrayIntersect(List list1, List list2) {
+final Set result = new LinkedHashSet<>(list1);
+result.retainAll(list2);
+return new ArrayList<>(result);
+  }
+
+  /** Support the ARRAY_UNION function. */
+  public static List arrayUnion(List list1, List list2) {
+final Set result =
+new LinkedHashSet<>(Math.max((int) ((list1.size() + list2.size()) / 
.75f) + 1, 16));

Review Comment:
   refer to multisetUnionDistinct in SqlFunctions



-- 
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 a diff in pull request #3202: [CALCITE-5704] Add ARRAY_EXCEPT, ARRAY_INTERSECT, ARRAY_UNION function (enabled in Spark library)

2023-05-20 Thread via GitHub


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


##
core/src/main/java/org/apache/calcite/sql/type/ArrayOperandTypeChecker.java:
##
@@ -0,0 +1,87 @@
+/*
+ * 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.sql.type;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlCallBinding;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperandCountRange;
+import org.apache.calcite.sql.SqlOperator;
+
+import com.google.common.collect.ImmutableList;
+
+import static 
org.apache.calcite.sql.type.NonNullableAccessors.getComponentTypeOrThrow;
+import static org.apache.calcite.util.Static.RESOURCE;
+
+/**
+ * Parameter type-checking strategy where types must be ([nullable] Array,
+ * [nullable] Array), and the two types must have the same element type.
+ *
+ * @see ArraySqlType#getComponentType
+ */
+public class ArrayOperandTypeChecker implements SqlOperandTypeChecker {

Review Comment:
   Look like `MultisetOperandTypeChecker`



##
core/src/main/java/org/apache/calcite/sql/type/ArrayOperandTypeChecker.java:
##
@@ -0,0 +1,87 @@
+/*
+ * 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.sql.type;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlCallBinding;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperandCountRange;
+import org.apache.calcite.sql.SqlOperator;
+
+import com.google.common.collect.ImmutableList;
+
+import static 
org.apache.calcite.sql.type.NonNullableAccessors.getComponentTypeOrThrow;
+import static org.apache.calcite.util.Static.RESOURCE;
+
+/**
+ * Parameter type-checking strategy where types must be ([nullable] Array,
+ * [nullable] Array), and the two types must have the same element type.
+ *
+ * @see ArraySqlType#getComponentType
+ */
+public class ArrayOperandTypeChecker implements SqlOperandTypeChecker {

Review Comment:
   Look like `MultisetOperandTypeChecker`.



-- 
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 a diff in pull request #3202: [CALCITE-5704] Add ARRAY_EXCEPT, ARRAY_INTERSECT, ARRAY_UNION function (enabled in Spark library)

2023-05-20 Thread via GitHub


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


##
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##
@@ -3809,6 +3809,29 @@ public static List distinct(List list) {
 return Collections.nCopies(numberOfElement, element);
   }
 
+  /** Support the ARRAY_EXCEPT function. */
+  public static List arrayExcept(List list1, List list2) {
+final Set result = new LinkedHashSet<>(list1);
+result.removeAll(list2);
+return new ArrayList<>(result);
+  }
+
+  /** Support the ARRAY_INTERSECT function. */
+  public static List arrayIntersect(List list1, List list2) {
+final Set result = new LinkedHashSet<>(list1);
+result.retainAll(list2);
+return new ArrayList<>(result);
+  }
+
+  /** Support the ARRAY_UNION function. */
+  public static List arrayUnion(List list1, List list2) {
+final Set result =
+new LinkedHashSet<>(Math.max((int) ((list1.size() + list2.size()) / 
.75f) + 1, 16));

Review Comment:
   Defining some variables will make it easier to understand.
   `Math.max((int) ((list1.size() + list2.size()) / .75f) + 1, 16)`.
why `.75f`, why `16`?



-- 
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 a diff in pull request #3202: [CALCITE-5704] Add ARRAY_EXCEPT, ARRAY_INTERSECT, ARRAY_UNION function (enabled in Spark library)

2023-05-20 Thread via GitHub


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


##
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##
@@ -3809,6 +3809,29 @@ public static List distinct(List list) {
 return Collections.nCopies(numberOfElement, element);
   }
 
+  /** Support the ARRAY_EXCEPT function. */
+  public static List arrayExcept(List list1, List list2) {
+final Set result = new LinkedHashSet<>(list1);
+result.removeAll(list2);
+return new ArrayList<>(result);
+  }
+
+  /** Support the ARRAY_INTERSECT function. */
+  public static List arrayIntersect(List list1, List list2) {
+final Set result = new LinkedHashSet<>(list1);
+result.retainAll(list2);
+return new ArrayList<>(result);
+  }
+
+  /** Support the ARRAY_UNION function. */
+  public static List arrayUnion(List list1, List list2) {
+final Set result =
+new LinkedHashSet<>(Math.max((int) ((list1.size() + list2.size()) / 
.75f) + 1, 16));

Review Comment:
   Defining some variables will make it easier to understand, why `.75f`, why 
16?
   `Math.max((int) ((list1.size() + list2.size()) / .75f) + 1, 16)`.



-- 
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 a diff in pull request #3207: [CALCITE-5707] Add ARRAY_CONTAINS function (enabled in Spark library)

2023-05-20 Thread via GitHub


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


##
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##
@@ -844,7 +844,14 @@ private static RelDataType 
arrayReturnType(SqlOperatorBinding opBinding) {
   SqlLibraryOperators::arrayReturnType,
   OperandTypes.SAME_VARIADIC);
 
-  /** The "ARRAY_DISTINCT(array)" function (Spark). */
+  /** The "ARRAY_CONTAINS(array)" function. */
+  @LibraryOperator(libraries = {SPARK})
+  public static final SqlFunction ARRAY_CONTAINS =
+  SqlBasicFunction.create(SqlKind.ARRAY_CONTAINS,
+  ReturnTypes.BOOLEAN_NULLABLE_IF_ARG0_NULLABLE,

Review Comment:
   I don't understand why is `ARG0`.



-- 
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 a diff in pull request #3207: [CALCITE-5707] Add ARRAY_CONTAINS function (enabled in Spark library)

2023-05-20 Thread via GitHub


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


##
core/src/main/java/org/apache/calcite/sql/type/ArrayElementOperandTypeChecker.java:
##
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql.type;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlCallBinding;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperandCountRange;
+import org.apache.calcite.sql.SqlOperator;
+
+import com.google.common.collect.ImmutableList;
+
+import static 
org.apache.calcite.sql.type.NonNullableAccessors.getComponentTypeOrThrow;
+import static org.apache.calcite.util.Static.RESOURCE;
+
+/**
+ * Parameter type-checking strategy where types must be Array and Array 
element type.
+ */
+public class ArrayElementOperandTypeChecker implements SqlOperandTypeChecker {

Review Comment:
   Many codes are same as `MultisetOperandTypeChecker`, Can we extract them?



-- 
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 a diff in pull request #3207: [CALCITE-5707] Add ARRAY_CONTAINS function (enabled in Spark library)

2023-05-20 Thread via GitHub


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


##
core/src/main/java/org/apache/calcite/sql/type/ArrayElementOperandTypeChecker.java:
##
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql.type;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlCallBinding;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperandCountRange;
+import org.apache.calcite.sql.SqlOperator;
+
+import com.google.common.collect.ImmutableList;
+
+import static 
org.apache.calcite.sql.type.NonNullableAccessors.getComponentTypeOrThrow;
+import static org.apache.calcite.util.Static.RESOURCE;
+
+/**
+ * Parameter type-checking strategy where types must be Array and Array 
element type.
+ */
+public class ArrayElementOperandTypeChecker implements SqlOperandTypeChecker {
+  //~ Methods 
+
+  @Override public boolean checkOperandTypes(
+  SqlCallBinding callBinding,
+  boolean throwOnFailure) {
+final SqlNode op0 = callBinding.operand(0);
+if (!OperandTypes.ARRAY.checkSingleOperandType(
+callBinding,
+op0,
+0,
+throwOnFailure)) {
+  return false;
+}
+
+RelDataType arrayComponentType =
+getComponentTypeOrThrow(SqlTypeUtil.deriveType(callBinding, op0));
+final SqlNode op1 = callBinding.operand(1);
+RelDataType aryType1 = SqlTypeUtil.deriveType(callBinding, op1);

Review Comment:
   Why not use `getComponentTypeOrThrow`?



-- 
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 a diff in pull request #3207: [CALCITE-5707] Add ARRAY_CONTAINS function (enabled in Spark library)

2023-05-20 Thread via GitHub


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


##
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##
@@ -3791,6 +3791,12 @@ private static AtomicLong getAtomicLong(String key) {
 return atomic;
   }
 
+  /** Support the ARRAY_CONTAINS function. */
+  public static boolean contains(List list, Object element) {
+final Set set = new HashSet(list);

Review Comment:
   Is this for faster search?



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