[GitHub] [calcite] sonarcloud[bot] commented on pull request #3399: [CALCITE-5962] Support parse Spark-style syntax LEFT ANTI JOIN in Babel parser

2023-08-30 Thread via GitHub


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

   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=3399)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3399=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=3399=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3399=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=3399=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=3399=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3399=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=3399=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=3399=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3399=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=3399=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=3399=false=CODE_SMELL)
 [6 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_calcite=3399=false=CODE_SMELL)
   
   
[![71.4%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png
 
'71.4%')](https://sonarcloud.io/component_measures?id=apache_calcite=3399=new_coverage=list)
 [71.4% 
Coverage](https://sonarcloud.io/component_measures?id=apache_calcite=3399=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=3399=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3399=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] jiefei30 commented on pull request #3399: [CALCITE-5962] Allow Spark-style syntax LEFT ANTI JOIN in Babel parser

2023-08-30 Thread via GitHub


jiefei30 commented on PR #3399:
URL: https://github.com/apache/calcite/pull/3399#issuecomment-1700317394

   > @jiefei30 If we only support parse this syntax, Maybe we should use 
`Support parse Spark-style syntax LEFT ANTI JOIN in Babel parser` . Also need 
to add parse test in PR.
   
   @NobiGo ok, thanks for your reply. I've already added parse test in it . And 
squash them into a single commit.


-- 
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] NobiGo commented on pull request #3399: [CALCITE-5962] Allow Spark-style syntax LEFT ANTI JOIN in Babel parser

2023-08-30 Thread via GitHub


NobiGo commented on PR #3399:
URL: https://github.com/apache/calcite/pull/3399#issuecomment-1700189732

   @jiefei30 If we only support parse this syntax, Maybe we should use `Support 
parse Spark-style syntax LEFT ANTI JOIN in Babel parser` . Also need to add 
parse test in PR.


-- 
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] NobiGo commented on a diff in pull request #3367: [CALCITE-5889] Add the RelRule that converts Minus into UNION ALL..GROUP BY...WHERE

2023-08-30 Thread via GitHub


NobiGo commented on code in PR #3367:
URL: https://github.com/apache/calcite/pull/3367#discussion_r1310992460


##
core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java:
##
@@ -2699,6 +2699,35 @@ private void 
checkPushJoinThroughUnionOnRightDoesNotMatchSemiOrAntiJoin(JoinRelT
 .check();
   }
 
+  /** Tests {@link org.apache.calcite.rel.rules.MinusToDistinctRule},

Review Comment:
   In set-op.iq we need to support using this Rule to work. As far as I know It 
didn't. But  we can try to read 

`https://github.com/apache/calcite/blob/main/core/src/test/java/org/apache/calcite/test/JdbcTest.java#L3749C14-L3749C27`.
 @LakeShen Can we add tests like this?



##
core/src/main/java/org/apache/calcite/rel/rules/MinusToDistinctRule.java:
##
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.rel.rules;
+
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Minus;
+import org.apache.calcite.rel.logical.LogicalMinus;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.tools.RelBuilderFactory;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.calcite.util.Util;
+
+import com.google.common.collect.ImmutableList;
+
+import org.immutables.value.Value;
+
+import java.math.BigDecimal;
+
+/**
+ * Planner rule that translates a distinct
+ * {@link org.apache.calcite.rel.core.Minus}
+ * (all = false)
+ * into a group of operators composed of
+ * {@link org.apache.calcite.rel.core.Union},
+ * {@link org.apache.calcite.rel.core.Aggregate},
+ * {@link org.apache.calcite.rel.core.Filter},etc.
+ *
+ * For example, the query
+
+ * {@code
+ *  select a,b from t1
+ *   except
+ *  select a,b from t2
+ *   except
+ *  select a,b from t3
+ * }
+ *
+ *  will convert to
+ *
+ * {@code

Review Comment:
   Yes, Looks good.



##
core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java:
##
@@ -2699,6 +2699,35 @@ private void 
checkPushJoinThroughUnionOnRightDoesNotMatchSemiOrAntiJoin(JoinRelT
 .check();
   }
 
+  /** Tests {@link org.apache.calcite.rel.rules.MinusToDistinctRule},

Review Comment:
   In set-op.iq we need to support using this Rule to work. As far as I know It 
didn't. But  we can try to read 

`https://github.com/apache/calcite/blob/main/core/src/test/java/org/apache/calcite/test/JdbcTest.java#L3749C14-L3749C27`.
 @LakeShen Can we add tests like this?



-- 
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 #3387: [CALCITE-5911] Add REGEXP_EXTRACT_ALL function (enabled in BigQuery library)

2023-08-30 Thread via GitHub


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

   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=3387)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3387=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=3387=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3387=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=3387=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=3387=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3387=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=3387=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=3387=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3387=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=3387=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=3387=false=CODE_SMELL)
 [4 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_calcite=3387=false=CODE_SMELL)
   
   
[![95.7%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/90-16px.png
 
'95.7%')](https://sonarcloud.io/component_measures?id=apache_calcite=3387=new_coverage=list)
 [95.7% 
Coverage](https://sonarcloud.io/component_measures?id=apache_calcite=3387=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=3387=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3387=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] Anthrino commented on a diff in pull request #3387: [CALCITE-5911] Add REGEXP_EXTRACT_ALL function (enabled in BigQuery library)

2023-08-30 Thread via GitHub


Anthrino commented on code in PR #3387:
URL: https://github.com/apache/calcite/pull/3387#discussion_r1310898531


##
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##
@@ -347,19 +347,119 @@ public static String sha512(ByteString string)  {
   }
 
   /** SQL {@code REGEXP_CONTAINS(value, regexp)} function.
-   * Throws a runtime exception for invalid regular expressions.*/
+   * Throws a runtime exception for invalid regular expressions. */
   public static boolean regexpContains(String value, String regex) {
 try {
   // Uses java.util.regex as a standard for regex processing
   // in Calcite instead of RE2 used by BigQuery/GoogleSQL
   Pattern regexp = Pattern.compile(regex);
   return regexp.matcher(value).find();
 } catch (PatternSyntaxException ex) {
-  throw 
RESOURCE.invalidInputForRegexpContains(ex.getMessage().replace("\r\n", " ")
-  .replace("\n", " ").replace("\r", " ")).ex();
+  throw RESOURCE.invalidRegexInputForRegexpFunctions(ex.getMessage()
+  .replace(System.lineSeparator(), " "), "REGEXP_CONTAINS").ex();
 }
   }
 
+  /** SQL {@code REGEXP_EXTRACT(value, regexp)} function.
+   *  Returns NULL if there is no match. Returns an exception if regex is 
invalid.
+   *  Uses position=1 and occurrence=1 as default values when not specified. */
+  public static @Nullable String regexpExtract(String value, String regex) {
+return regexpExtract(value, regex, 1, 1);
+  }
+
+  /** SQL {@code REGEXP_EXTRACT(value, regexp, position)} function.
+   *  Returns NULL if there is no match, or if position is beyond range.
+   *  Returns an exception if regex or position is invalid.
+   *  Uses occurrence=1 as default value when not specified. */
+  public static @Nullable String regexpExtract(String value, String regex, int 
position) {
+return regexpExtract(value, regex, position, 1);
+  }
+
+  /** SQL {@code REGEXP_EXTRACT(value, regexp, position, occurrence)} function.
+   *  Returns NULL if there is no match, or if position or occurrence are 
beyond range.
+   *  Returns an exception if regex, position or occurrence are invalid. */
+  public static @Nullable String regexpExtract(String value, String regex, int 
position,
+  int occurrence) {
+// Uses java.util.regex as a standard for regex processing
+// in Calcite instead of RE2 used by BigQuery/GoogleSQL
+Pattern regexp;
+String methodName = "REGEXP_EXTRACT";
+try {
+  regexp = Pattern.compile(regex);
+} catch (PatternSyntaxException ex) {
+  throw RESOURCE.invalidRegexInputForRegexpFunctions(ex.getMessage()
+  .replace(System.lineSeparator(), " "), methodName).ex();
+}
+
+Matcher matcher = regexp.matcher(value);
+
+if (position <= 0) {
+  throw 
RESOURCE.invalidIntegerInputForRegexpFunctions(Integer.toString(position),
+  "position", methodName).ex();
+}
+if (position > value.length()) {
+  return null;
+}
+matcher.region(position - 1, value.length());
+
+if (occurrence <= 0) {
+  throw 
RESOURCE.invalidIntegerInputForRegexpFunctions(Integer.toString(occurrence),
+  "occurrence", methodName).ex();
+}
+
+if (matcher.groupCount() > 1) {
+  throw RESOURCE.multipleCapturingGroupsForRegexpExtract(
+  Integer.toString(matcher.groupCount()), methodName).ex();
+}
+
+String match = null;
+while (occurrence > 0) {
+  if (matcher.find()) {
+if (matcher.groupCount() == 1) {
+  match = matcher.group(1);
+} else {
+  match = matcher.group(0);
+}
+  } else {
+return null;
+  }
+  occurrence--;
+}
+
+return match;
+  }
+
+  /** SQL {@code REGEXP_EXTRACT_ALL(value, regexp)} function.
+   *  Returns an empty array if there is no match, returns an exception if 
regex is invalid.*/
+  public static List regexpExtractAll(String value, String regex) {
+// Uses java.util.regex as a standard for regex processing
+// in Calcite instead of RE2 used by BigQuery/GoogleSQL
+Pattern regexp;
+String methodName = "REGEXP_EXTRACT_ALL";

Review Comment:
   @tanclary I've rebased the changes from previous PRs, also consolidated few 
of the redundant error checks into helper methods would be good if you can give 
it a review!



-- 
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 #3391: [CALCITE-5933] Add SAFE_DIVIDE function (enabled in BigQuery library)

2023-08-30 Thread via GitHub


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

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



[calcite] branch main updated (01467a1797 -> 1eb547c93e)

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

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


from 01467a1797 [CALCITE-5766] Add SAFE_NEGATE function (enabled for 
BigQuery library)
 add 1eb547c93e [CALCITE-5910] Add REGEXP_EXTRACT and REGEXP_SUBSTR 
functions (enabled in BigQuery library)

No new revisions were added by this update.

Summary of changes:
 babel/src/test/resources/sql/big-query.iq  | 262 -
 .../calcite/adapter/enumerable/RexImpTable.java|   3 +
 .../apache/calcite/runtime/CalciteResource.java|  12 +-
 .../org/apache/calcite/runtime/SqlFunctions.java   |  77 +-
 .../calcite/sql/fun/SqlLibraryOperators.java   |  19 +-
 .../org/apache/calcite/sql/type/OperandTypes.java  |   5 +
 .../calcite/sql2rel/StandardConvertletTable.java   |   1 +
 .../org/apache/calcite/util/BuiltInMethod.java |  10 +-
 .../calcite/runtime/CalciteResource.properties |   4 +-
 .../org/apache/calcite/test/SqlFunctionsTest.java  |  73 +-
 site/_docs/reference.md|   2 +
 .../org/apache/calcite/test/SqlOperatorTest.java   |  53 +
 12 files changed, 502 insertions(+), 19 deletions(-)



[GitHub] [calcite] tanclary merged pull request #3252: [CALCITE-5766] Add SAFE_NEGATE function (enabled for BigQuery library)

2023-08-30 Thread via GitHub


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


-- 
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] tanclary merged pull request #3369: [CALCITE-5910] Add REGEXP_EXTRACT and REGEXP_SUBSTR functions (enabled in BigQuery library)

2023-08-30 Thread via GitHub


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


-- 
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-5766] Add SAFE_NEGATE function (enabled for BigQuery library)

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

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


The following commit(s) were added to refs/heads/main by this push:
 new 01467a1797 [CALCITE-5766] Add SAFE_NEGATE function (enabled for 
BigQuery library)
01467a1797 is described below

commit 01467a17973c0f7b684c2662f81342ab5af3a62f
Author: Tanner Clary 
AuthorDate: Thu Aug 24 10:31:42 2023 -0700

[CALCITE-5766] Add SAFE_NEGATE function (enabled for BigQuery library)
---
 babel/src/test/resources/sql/big-query.iq  | 46 ++
 .../calcite/adapter/enumerable/RexImpTable.java| 17 ++--
 .../calcite/sql/fun/SqlLibraryOperators.java   |  9 +
 site/_docs/reference.md|  1 +
 .../org/apache/calcite/test/SqlOperatorTest.java   | 37 -
 5 files changed, 105 insertions(+), 5 deletions(-)

diff --git a/babel/src/test/resources/sql/big-query.iq 
b/babel/src/test/resources/sql/big-query.iq
index 515e083f6a..753ce6a5cd 100755
--- a/babel/src/test/resources/sql/big-query.iq
+++ b/babel/src/test/resources/sql/big-query.iq
@@ -737,6 +737,52 @@ SELECT SAFE_MULTIPLY(CAST('NaN' AS DOUBLE), CAST(3 as 
BIGINT)) as NaN_result;
 
 !ok
 
+#
+# SAFE_NEGATE
+#
+# SAFE_NEGATE(value)
+#
+# Returns value * -1, or NULL on overflow.
+SELECT SAFE_NEGATE(5) as result;
+++
+| result |
+++
+| -5 |
+++
+(1 row)
+
+!ok
+
+SELECT SAFE_NEGATE(-5) as result;
+++
+| result |
+++
+|  5 |
+++
+(1 row)
+
+!ok
+
+SELECT SAFE_NEGATE(-9223372036854775808) as overflow_result;
++-+
+| overflow_result |
++-+
+| |
++-+
+(1 row)
+
+!ok
+
+SELECT SAFE_NEGATE(1 + 2 + 3 + 4) as expr_result;
++-+
+| expr_result |
++-+
+| -10 |
++-+
+(1 row)
+
+!ok
+
 #
 # SAFE_SUBTRACT
 #
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 bfc6342a35..6a1184d86d 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
@@ -228,6 +228,7 @@ import static 
org.apache.calcite.sql.fun.SqlLibraryOperators.RPAD;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.SAFE_ADD;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.SAFE_CAST;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.SAFE_MULTIPLY;
+import static org.apache.calcite.sql.fun.SqlLibraryOperators.SAFE_NEGATE;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.SAFE_OFFSET;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.SAFE_ORDINAL;
 import static org.apache.calcite.sql.fun.SqlLibraryOperators.SAFE_SUBTRACT;
@@ -646,6 +647,8 @@ public class RexImpTable {
   new SafeArithmeticImplementor(BuiltInMethod.SAFE_ADD.method));
   map.put(SAFE_MULTIPLY,
   new SafeArithmeticImplementor(BuiltInMethod.SAFE_MULTIPLY.method));
+  map.put(SAFE_NEGATE,
+  new SafeArithmeticImplementor(BuiltInMethod.SAFE_MULTIPLY.method));
   map.put(SAFE_SUBTRACT,
   new SafeArithmeticImplementor(BuiltInMethod.SAFE_SUBTRACT.method));
 
@@ -2477,10 +2480,16 @@ public class RexImpTable {
 
 @Override Expression implementSafe(final RexToLixTranslator translator,
 final RexCall call, final List argValueList) {
-  Expression arg0 = convertType(argValueList.get(0), call.operands.get(0));
-  Expression arg1 = convertType(argValueList.get(1), call.operands.get(1));
-  return super.implementSafe(translator, call,
-  ImmutableList.of(arg0, arg1));
+  List args = new ArrayList();
+  args.add(convertType(argValueList.get(0), call.operands.get(0)));
+  // SAFE_NEGATE only has one argument so create constant -1L to use
+  // SAFE_MULTIPLY implementation.
+  if (argValueList.size() == 1) {
+args.add(Expressions.constant(-1L));
+  } else {
+args.add(convertType(argValueList.get(1), call.operands.get(1)));
+  }
+  return super.implementSafe(translator, call, args);
 }
 
 // Because BigQuery treats all int types as aliases for BIGINT (Java's 
long)
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 7cf793fc51..18ee78654f 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
@@ -1709,6 +1709,15 @@ public abstract class SqlLibraryOperators {
   OperandTypes.NUMERIC_NUMERIC,
   

[GitHub] [calcite] julianhyde commented on pull request #3252: [CALCITE-5766] Add SAFE_NEGATE function (enabled for BigQuery library)

2023-08-30 Thread via GitHub


julianhyde commented on PR #3252:
URL: https://github.com/apache/calcite/pull/3252#issuecomment-1699623273

   Two cosmetic things in  testSafeNegateFunc:
* There are too many '.' in the javadoc. The jira summary does not include 
a '.'
* Function arguments should be indented 4, not aligned with the '('
   
   +1 to merge without further review when you've fixed those


-- 
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 #3391: [CALCITE-5933] Add SAFE_DIVIDE function (enabled in BigQuery library)

2023-08-30 Thread via GitHub


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

   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=3391)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3391=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=3391=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3391=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=3391=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=3391=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3391=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=3391=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=3391=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3391=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=3391=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=3391=false=CODE_SMELL)
 [5 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_calcite=3391=false=CODE_SMELL)
   
   
[![96.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/90-16px.png
 
'96.0%')](https://sonarcloud.io/component_measures?id=apache_calcite=3391=new_coverage=list)
 [96.0% 
Coverage](https://sonarcloud.io/component_measures?id=apache_calcite=3391=new_coverage=list)
  
   
[![24.4%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/20plus-16px.png
 
'24.4%')](https://sonarcloud.io/component_measures?id=apache_calcite=3391=new_duplicated_lines_density=list)
 [24.4% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3391=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 #3252: [CALCITE-5766] Add SAFE_NEGATE function (enabled for BigQuery library)

2023-08-30 Thread via GitHub


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

   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=3252)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3252=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=3252=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3252=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=3252=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=3252=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3252=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=3252=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=3252=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3252=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=3252=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=3252=false=CODE_SMELL)
 [4 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_calcite=3252=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=3252=new_coverage=list)
 [100.0% 
Coverage](https://sonarcloud.io/component_measures?id=apache_calcite=3252=new_coverage=list)
  
   
[![5.2%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/10-16px.png
 
'5.2%')](https://sonarcloud.io/component_measures?id=apache_calcite=3252=new_duplicated_lines_density=list)
 [5.2% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3252=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 #3369: [CALCITE-5910] Add REGEXP_EXTRACT and REGEXP_SUBSTR functions (enabled in BigQuery library)

2023-08-30 Thread via GitHub


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

   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=3369)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3369=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=3369=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3369=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=3369=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=3369=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3369=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=3369=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=3369=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3369=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=3369=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=3369=false=CODE_SMELL)
 [4 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_calcite=3369=false=CODE_SMELL)
   
   
[![98.1%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/90-16px.png
 
'98.1%')](https://sonarcloud.io/component_measures?id=apache_calcite=3369=new_coverage=list)
 [98.1% 
Coverage](https://sonarcloud.io/component_measures?id=apache_calcite=3369=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=3369=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3369=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 #3391: [CALCITE-5933] Add SAFE_DIVIDE function (enabled in BigQuery library)

2023-08-30 Thread via GitHub


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

   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=3391)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3391=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=3391=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3391=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=3391=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=3391=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3391=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=3391=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=3391=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3391=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=3391=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=3391=false=CODE_SMELL)
 [5 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_calcite=3391=false=CODE_SMELL)
   
   
[![95.9%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/90-16px.png
 
'95.9%')](https://sonarcloud.io/component_measures?id=apache_calcite=3391=new_coverage=list)
 [95.9% 
Coverage](https://sonarcloud.io/component_measures?id=apache_calcite=3391=new_coverage=list)
  
   
[![23.6%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/20plus-16px.png
 
'23.6%')](https://sonarcloud.io/component_measures?id=apache_calcite=3391=new_duplicated_lines_density=list)
 [23.6% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3391=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] Anthrino commented on a diff in pull request #3369: [CALCITE-5910] Add REGEXP_EXTRACT and REGEXP_SUBSTR functions (enabled in BigQuery library)

2023-08-30 Thread via GitHub


Anthrino commented on code in PR #3369:
URL: https://github.com/apache/calcite/pull/3369#discussion_r1310631115


##
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java:
##
@@ -554,6 +555,7 @@ Builder populate() {
   defineMethod(SPLIT, "split", NullPolicy.STRICT);
   defineMethod(PARSE_URL, BuiltInMethod.PARSE_URL.method, 
NullPolicy.STRICT);
   defineMethod(REGEXP_CONTAINS, "regexpContains", NullPolicy.STRICT);
+  defineMethod(REGEXP_EXTRACT, "regexpExtract", NullPolicy.STRICT);

Review Comment:
   Rebased and aligned! :)



-- 
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] Anthrino commented on a diff in pull request #3369: [CALCITE-5910] Add REGEXP_EXTRACT and REGEXP_SUBSTR functions (enabled in BigQuery library)

2023-08-30 Thread via GitHub


Anthrino commented on code in PR #3369:
URL: https://github.com/apache/calcite/pull/3369#discussion_r1310628458


##
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##
@@ -4568,6 +4568,25 @@ private static void checkIf(SqlOperatorFixture f) {
 f.checkNull("regexp_contains(cast(null as varchar), cast(null as 
varchar))");
   }
 
+  @Test void testRegexpExtractFunc() {
+final SqlOperatorFixture f =
+
fixture().setFor(SqlLibraryOperators.REGEXP_EXTRACT).withLibrary(SqlLibrary.BIG_QUERY);
+
+f.checkString("regexp_extract('abc def ghi', 'def')", "def", "VARCHAR NOT 
NULL");
+f.checkString("regexp_extract('abcadcaecghi', 'a.c', 1, 3)", "aec", 
"VARCHAR NOT NULL");
+f.checkString("regexp_extract('abcadcaecghi', 'abc(a.c)')", "adc", 
"VARCHAR NOT NULL");
+f.checkString("regexp_extract('55as56664as422', '\\d{3}')", "566", 
"VARCHAR NOT NULL");
+
+f.checkNull("regexp_extract('abc def ghi', 'asd')");
+f.checkNull("regexp_extract('abc def ghi', cast(null as varchar))");

Review Comment:
   Added additional cases to cover the optional arguments, appreciate the 
feedback!



-- 
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] Anthrino commented on a diff in pull request #3369: [CALCITE-5910] Add REGEXP_EXTRACT and REGEXP_SUBSTR functions (enabled in BigQuery library)

2023-08-30 Thread via GitHub


Anthrino commented on code in PR #3369:
URL: https://github.com/apache/calcite/pull/3369#discussion_r1310617255


##
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java:
##
@@ -569,6 +570,8 @@ Builder populate() {
   defineReflective(PARSE_URL, BuiltInMethod.PARSE_URL2.method,
   BuiltInMethod.PARSE_URL3.method);
   defineReflective(REGEXP_CONTAINS, BuiltInMethod.REGEXP_CONTAINS.method);
+  defineReflective(REGEXP_EXTRACT, BuiltInMethod.REGEXP_EXTRACT2.method,

Review Comment:
   New for me too, followed the patterns Julian was using for the other 
functions.



-- 
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] tanclary commented on pull request #3252: [CALCITE-5766] Add SAFE_NEGATE function (enabled for BigQuery library)

2023-08-30 Thread via GitHub


tanclary commented on PR #3252:
URL: https://github.com/apache/calcite/pull/3252#issuecomment-1699581435

   @julianhyde I rebased to include your recent changes and no longer use 
strings to identify the safe functions' methods. Let me know what 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] tanclary commented on a diff in pull request #3369: [CALCITE-5910] Add REGEXP_EXTRACT and REGEXP_SUBSTR functions (enabled in BigQuery library)

2023-08-30 Thread via GitHub


tanclary commented on code in PR #3369:
URL: https://github.com/apache/calcite/pull/3369#discussion_r1308036102


##
core/src/test/java/org/apache/calcite/test/SqlFunctionsTest.java:
##
@@ -260,7 +261,75 @@ static  List list() {
 } catch (RuntimeException e) {
   assertThat(
   e.getMessage(), is("Invalid regular expression for REGEXP_CONTAINS: 
'Illegal "
-  + "repetition range near " + "index 4 {2,1} ^'"));
+  + "repetition range near index 4 {2,1} ^'"));
+}
+  }
+
+  @Test void testRegexpExtract() {
+

Review Comment:
   nit: Should newline at top of test be removed?



-- 
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 #3252: [CALCITE-5766] Add SAFE_NEGATE function (enabled for BigQuery library)

2023-08-30 Thread via GitHub


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

   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=3252)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3252=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=3252=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3252=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=3252=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=3252=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3252=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=3252=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=3252=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3252=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=3252=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=3252=false=CODE_SMELL)
 [4 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_calcite=3252=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=3252=new_coverage=list)
 [100.0% 
Coverage](https://sonarcloud.io/component_measures?id=apache_calcite=3252=new_coverage=list)
  
   
[![5.3%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/10-16px.png
 
'5.3%')](https://sonarcloud.io/component_measures?id=apache_calcite=3252=new_duplicated_lines_density=list)
 [5.3% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3252=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 #3252: [CALCITE-5766] Add SAFE_NEGATE function (enabled for BigQuery library)

2023-08-30 Thread via GitHub


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

   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=3252)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3252=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=3252=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3252=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=3252=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=3252=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3252=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=3252=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=3252=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3252=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=3252=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=3252=false=CODE_SMELL)
 [4 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_calcite=3252=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=3252=new_coverage=list)
 [100.0% 
Coverage](https://sonarcloud.io/component_measures?id=apache_calcite=3252=new_coverage=list)
  
   
[![5.3%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/10-16px.png
 
'5.3%')](https://sonarcloud.io/component_measures?id=apache_calcite=3252=new_duplicated_lines_density=list)
 [5.3% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3252=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] tanclary commented on a diff in pull request #3369: [CALCITE-5910] Add REGEXP_EXTRACT and REGEXP_SUBSTR functions (enabled in BigQuery library)

2023-08-30 Thread via GitHub


tanclary commented on code in PR #3369:
URL: https://github.com/apache/calcite/pull/3369#discussion_r1310568623


##
core/src/test/java/org/apache/calcite/test/SqlFunctionsTest.java:
##
@@ -254,18 +254,88 @@ static  List list() {
   final boolean b = f.regexpContains("abc def ghi", "[z-a]");
   fail("expected error, got " + b);
 } catch (RuntimeException e) {
-  assertThat(e.getMessage(),
-  is("Invalid regular expression for REGEXP_CONTAINS: 'Illegal "
-  + "character range near index" + " 3 [z-a]^'"));
+  assertThat(
+  e.getMessage(), is("Invalid regular expression for REGEXP_CONTAINS: 
'Illegal "

Review Comment:
   Is this formatting right?



-- 
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] tanclary commented on a diff in pull request #3369: [CALCITE-5910] Add REGEXP_EXTRACT and REGEXP_SUBSTR functions (enabled in BigQuery library)

2023-08-30 Thread via GitHub


tanclary commented on code in PR #3369:
URL: https://github.com/apache/calcite/pull/3369#discussion_r1308035240


##
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java:
##
@@ -554,6 +555,7 @@ Builder populate() {
   defineMethod(SPLIT, "split", NullPolicy.STRICT);
   defineMethod(PARSE_URL, BuiltInMethod.PARSE_URL.method, 
NullPolicy.STRICT);
   defineMethod(REGEXP_CONTAINS, "regexpContains", NullPolicy.STRICT);
+  defineMethod(REGEXP_EXTRACT, "regexpExtract", NullPolicy.STRICT);

Review Comment:
   Julian added a recent commit that makes defining a method using the string 
name (rather than BuiltInMethod) infeasible. If you rebase on top of 
upstream/main you should see. If you adjust it to use BuiltInMethod instead 
then it should work.



-- 
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] tanclary commented on a diff in pull request #3369: [CALCITE-5910] Add REGEXP_EXTRACT and REGEXP_SUBSTR functions (enabled in BigQuery library)

2023-08-30 Thread via GitHub


tanclary commented on code in PR #3369:
URL: https://github.com/apache/calcite/pull/3369#discussion_r1310567170


##
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java:
##
@@ -569,6 +570,8 @@ Builder populate() {
   defineReflective(PARSE_URL, BuiltInMethod.PARSE_URL2.method,
   BuiltInMethod.PARSE_URL3.method);
   defineReflective(REGEXP_CONTAINS, BuiltInMethod.REGEXP_CONTAINS.method);
+  defineReflective(REGEXP_EXTRACT, BuiltInMethod.REGEXP_EXTRACT2.method,

Review Comment:
   Didn't know about this, very cool!



-- 
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 #3391: [CALCITE-5933] Add SAFE_DIVIDE function (enabled in BigQuery library)

2023-08-30 Thread via GitHub


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

   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=3391)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3391=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=3391=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3391=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=3391=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=3391=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3391=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=3391=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=3391=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3391=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=3391=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=3391=false=CODE_SMELL)
 [5 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_calcite=3391=false=CODE_SMELL)
   
   
[![95.9%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/90-16px.png
 
'95.9%')](https://sonarcloud.io/component_measures?id=apache_calcite=3391=new_coverage=list)
 [95.9% 
Coverage](https://sonarcloud.io/component_measures?id=apache_calcite=3391=new_coverage=list)
  
   
[![23.6%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/20plus-16px.png
 
'23.6%')](https://sonarcloud.io/component_measures?id=apache_calcite=3391=new_duplicated_lines_density=list)
 [23.6% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3391=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] tanclary commented on a diff in pull request #3389: [CALCITE-5935] Add CODE_POINTS_TO_BYTES function (enabled in BigQuery…

2023-08-30 Thread via GitHub


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


##
core/src/main/java/org/apache/calcite/sql/type/OperandTypes.java:
##
@@ -510,6 +510,38 @@ public static SqlOperandTypeChecker variadic(
 }
   };
 
+  public static final SqlSingleOperandTypeChecker ARRAY_OF_INTEGER =

Review Comment:
   Sounds good, thanks for explaining!



-- 
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] kgyrtkirk commented on a diff in pull request #3396: [CALCITE-5940] Add the Rules to optimize Limit

2023-08-30 Thread via GitHub


kgyrtkirk commented on code in PR #3396:
URL: https://github.com/apache/calcite/pull/3396#discussion_r1310312042


##
core/src/main/java/org/apache/calcite/rel/rules/SortMergeRule.java:
##
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.rel.rules;
+
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.core.Sort;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.tools.RelBuilder;
+
+import com.google.common.collect.ImmutableList;
+
+import org.immutables.value.Value;
+
+/**
+ * This rule try to merge the double {@link Sort},one is Limit semantics,
+ * another sort is Limit or TOPN semantics.
+ *
+ *  It generally used with the {@link SortProjectTransposeRule} rule.
+ *
+ *  For example:
+ * {@code
+ * select
+ *   concat('-', N_REGIONKEY) from
+ *   (
+ * select
+ *   *
+ * from nation limit 1) limit 10}
+ *  
+ *
+ *  will convert to
+ * {@code
+ * select
+ *   concat('-', N_REGIONKEY)
+ * from
+ *   nation limit 10
+ * }
+ *
+ *  The sql :
+ * {@code
+ * select concat('-',N_REGIONKEY) from
+ * (SELECT * FROM nation order BY N_REGIONKEY DESC LIMIT 1) limit 10
+ * }
+ *
+ *  will convert to
+ * {@code
+ * SELECT concat('-',N_REGIONKEY) FROM nation order BY N_REGIONKEY DESC LIMIT 
10
+ * }
+ *
+ *  In the future,we could also extend other sort merge logic in this rule.
+ */
+@Value.Enclosing
+public class SortMergeRule
+extends RelRule
+implements TransformationRule {
+
+  protected SortMergeRule(final SortMergeRule.Config config) {
+super(config);
+  }
+
+  @Override public void onMatch(final RelOptRuleCall call) {
+config.matchHandler().accept(this, call);
+  }
+
+  private static void limitMerge(SortMergeRule rule,
+  RelOptRuleCall call) {
+final Sort sort = call.rel(0);
+final Sort child = call.rel(1);
+
+if (child.offset != null || child.fetch == null) {
+  // we could do nothing here
+  return;
+}
+
+final RelBuilder builder = call.builder();
+
+final int limitCnt = sort.fetch instanceof RexLiteral
+? RexLiteral.intValue(sort.fetch) : -1;
+
+final int childLimitCnt = child.fetch instanceof RexLiteral
+? RexLiteral.intValue(child.fetch) : -1;
+
+if (limitCnt == -1 || childLimitCnt == -1) {
+  return;
+}
+
+// Get the minimum limit value from parent and child sort RelNode
+int minLimit = limitCnt < childLimitCnt

Review Comment:
   nit: isn't `Math.min` is more readable?



##
core/src/main/java/org/apache/calcite/rel/rules/SortMergeRule.java:
##
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.rel.rules;
+
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.core.Sort;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.tools.RelBuilder;
+
+import com.google.common.collect.ImmutableList;
+
+import org.immutables.value.Value;
+
+/**
+ * This rule try to merge the double {@link Sort},one is Limit semantics,
+ * another sort is Limit or TOPN semantics.
+ *
+ *  It generally used with the {@link SortProjectTransposeRule} rule.
+ *
+ *  For example:
+ * {@code
+ * select
+ *   concat('-', N_REGIONKEY) from
+ *   (
+ * 

[GitHub] [calcite] sonarcloud[bot] commented on pull request #3404: [CALCITE-5968] Provide an interface class for RexExecutable to decouple janino runtime binding

2023-08-30 Thread via GitHub


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

   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=3404)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3404=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=3404=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3404=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=3404=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=3404=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3404=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=3404=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=3404=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3404=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=3404=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=3404=false=CODE_SMELL)
 [3 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_calcite=3404=false=CODE_SMELL)
   
   
[![82.6%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png
 
'82.6%')](https://sonarcloud.io/component_measures?id=apache_calcite=3404=new_coverage=list)
 [82.6% 
Coverage](https://sonarcloud.io/component_measures?id=apache_calcite=3404=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=3404=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3404=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] zhuwenzhuang opened a new pull request, #3404: [CALCITE-5968] Provide an interface class for RexExecutable to decouple janino runtime binding

2023-08-30 Thread via GitHub


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

   (no comment)


-- 
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] herunkang2018 commented on a diff in pull request #3367: [CALCITE-5889] Add the RelRule that converts Minus into UNION ALL..GROUP BY...WHERE

2023-08-30 Thread via GitHub


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


##
core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java:
##
@@ -2699,6 +2699,35 @@ private void 
checkPushJoinThroughUnionOnRightDoesNotMatchSemiOrAntiJoin(JoinRelT
 .check();
   }
 
+  /** Tests {@link org.apache.calcite.rel.rules.MinusToDistinctRule},

Review Comment:
   @LakeShen I think we could add the test in 
[set-op.iq](https://github.com/apache/calcite/blob/2a96512c352bda4a5d9c0c80730f5c115ac363d6/core/src/test/resources/sql/set-op.iq#L157).



-- 
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 #3401: [CALCITE-5965] Avoid unnecessary String concatenations in the RexFieldAccess constructor to improve the performance

2023-08-30 Thread via GitHub


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

   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=3401)
   
   
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png
 
'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite=3401=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=3401=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_calcite=3401=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=3401=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=3401=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite=3401=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=3401=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=3401=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite=3401=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=3401=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=3401=false=CODE_SMELL)
 [0 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_calcite=3401=false=CODE_SMELL)
   
   [![No Coverage 
information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png
 'No Coverage 
information')](https://sonarcloud.io/component_measures?id=apache_calcite=3401=coverage=list)
 No Coverage information  
   
[![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=3401=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_calcite=3401=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 #3403: [CALCITE-5967] UnsupportedOperationException while implementing a call that requires a special collator

2023-08-30 Thread via GitHub


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

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