[calcite] branch main updated: [CALCITE-5310] JSON_OBJECT in scalar sub-query throws AssertionError

2022-11-14 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 28c5881c8d [CALCITE-5310] JSON_OBJECT in scalar sub-query throws 
AssertionError
28c5881c8d is described below

commit 28c5881c8de10751b415aaf3e3f50b3168c893d3
Author: Benchao Li 
AuthorDate: Thu Oct 6 15:43:51 2022 +0800

[CALCITE-5310] JSON_OBJECT in scalar sub-query throws AssertionError

Close #2929
---
 core/src/main/java/org/apache/calcite/rex/RexUtil.java | 14 ++
 .../org/apache/calcite/sql/type/SqlTypeAssignmentRule.java |  3 +++
 .../java/org/apache/calcite/sql2rel/RelDecorrelator.java   |  5 +++--
 core/src/test/resources/sql/sub-query.iq   | 14 ++
 4 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/rex/RexUtil.java 
b/core/src/main/java/org/apache/calcite/rex/RexUtil.java
index d5b4bc3cc7..b68eb43831 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexUtil.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexUtil.java
@@ -209,6 +209,20 @@ public class RexUtil {
 }
   }
 
+  /**
+   * Returns whether a node represents a {@link SqlTypeName#SYMBOL} literal.
+   */
+  public static boolean isSymbolLiteral(RexNode expr) {
+switch (expr.getKind()) {
+case LITERAL:
+  return ((RexLiteral) expr).getTypeName() == SqlTypeName.SYMBOL;
+case CAST:
+  return isSymbolLiteral(((RexCall) expr).operands.get(0));
+default:
+  return false;
+}
+  }
+
   /**
* Returns whether a node represents a literal.
*
diff --git 
a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRule.java 
b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRule.java
index 41791da14f..6504814355 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRule.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeAssignmentRule.java
@@ -193,6 +193,9 @@ public class SqlTypeAssignmentRule implements 
SqlTypeMappingRule {
 // MAP is assignable from ...
 rules.add(SqlTypeName.MAP, EnumSet.of(SqlTypeName.MAP));
 
+// SYMBOL is assignable from ...
+rules.add(SqlTypeName.SYMBOL, EnumSet.of(SqlTypeName.SYMBOL));
+
 // ANY is assignable from ...
 rule.clear();
 rule.add(SqlTypeName.TINYINT);
diff --git a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java 
b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
index 1786ffcaa1..7e7f2036ad 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
@@ -1790,10 +1790,11 @@ public class RelDecorrelator implements 
ReflectiveVisitor {
 
 @Override public RexNode visitLiteral(RexLiteral literal) {
   // Use nullIndicator to decide whether to project null.
-  // Do nothing if the literal is null.
+  // Do nothing if the literal is null or symbol.
   if (!RexUtil.isNull(literal)
   && projectPulledAboveLeftCorrelator
-  && (nullIndicator != null)) {
+  && (nullIndicator != null)
+  && !RexUtil.isSymbolLiteral(literal)) {
 return createCaseExpression(nullIndicator, null, literal);
   }
   return literal;
diff --git a/core/src/test/resources/sql/sub-query.iq 
b/core/src/test/resources/sql/sub-query.iq
index a22ee003f9..e464dba2e5 100644
--- a/core/src/test/resources/sql/sub-query.iq
+++ b/core/src/test/resources/sql/sub-query.iq
@@ -3569,4 +3569,18 @@ SELECT ARRAY(SELECT s.x) FROM (SELECT 1 as x) s;
 
 !ok
 
+# Test case for [CALCITE-5310] JSON_OBJECT in scalar sub-query throws 
AssertionError
+SELECT (SELECT json_object('1': (a.attidentity = 'a'), '2': v) FROM 
UNNEST(ARRAY[1]) as v) as options
+FROM UNNEST(ARRAY['a', 'b']) AS a(attidentity);
+
++---+
+| OPTIONS   |
++---+
+| {"1":false,"2":1} |
+| {"1":true,"2":1}  |
++---+
+(2 rows)
+
+!ok
+
 # End sub-query.iq



[GitHub] [calcite] libenchao closed pull request #2929: [CALCITE-5310] JSON_OBJECT in scalar sub-query throws AssertionError

2022-11-14 Thread GitBox


libenchao closed pull request #2929: [CALCITE-5310] JSON_OBJECT in scalar 
sub-query throws AssertionError
URL: https://github.com/apache/calcite/pull/2929


-- 
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 #2929: [CALCITE-5310] JSON_OBJECT in scalar sub-query throws AssertionError

2022-11-14 Thread GitBox


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


##
core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java:
##
@@ -1790,10 +1790,11 @@ private RexNode createCaseExpression(
 
 @Override public RexNode visitLiteral(RexLiteral literal) {
   // Use nullIndicator to decide whether to project null.
-  // Do nothing if the literal is null.
+  // Do nothing if the literal is null or symbol.
   if (!RexUtil.isNull(literal)

Review Comment:
   @dssysolyatin Thanks for your review.
   
   It's good to have such questions and discussions.



-- 
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] Pritam-Gote opened a new pull request, #2971: RTP 180 Support For MOD Function on Date Field

2022-11-14 Thread GitBox


Pritam-Gote opened a new pull request, #2971:
URL: https://github.com/apache/calcite/pull/2971

   RTP 180 support for mod function on date field


-- 
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 #2929: [CALCITE-5310] JSON_OBJECT in scalar sub-query throws AssertionError

2022-11-14 Thread GitBox


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


##
core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java:
##
@@ -1790,10 +1790,11 @@ private RexNode createCaseExpression(
 
 @Override public RexNode visitLiteral(RexLiteral literal) {
   // Use nullIndicator to decide whether to project null.
-  // Do nothing if the literal is null.
+  // Do nothing if the literal is null or symbol.
   if (!RexUtil.isNull(literal)

Review Comment:
   Ok, I was just trying to understand if we can reduce number of 
caseExpression. Anyway it is not directly related to this ticket.
   
   LGTM



-- 
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 closed pull request #2970: [CALCITE-5383] Update CONCAT_FUNCTION SqlLibary to include BIG_QUERY

2022-11-14 Thread GitBox


libenchao closed pull request #2970: [CALCITE-5383] Update CONCAT_FUNCTION 
SqlLibary to include BIG_QUERY
URL: https://github.com/apache/calcite/pull/2970


-- 
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-5383] Add CONCAT to BIG_QUERY dialect

2022-11-14 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 1c55ab0892 [CALCITE-5383] Add CONCAT to BIG_QUERY dialect
1c55ab0892 is described below

commit 1c55ab08925eb0943455998a306a74fd60d07ae3
Author: Oliver Lee 
AuthorDate: Fri Nov 11 18:19:36 2022 +

[CALCITE-5383] Add CONCAT to BIG_QUERY dialect

Close #2970
---
 core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java | 2 +-
 testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java 
b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
index 306a33b39f..1cde5d140f 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
@@ -539,7 +539,7 @@ public abstract class SqlLibraryOperators {
 
   /** The "CONCAT(arg, ...)" function that concatenates strings.
* For example, "CONCAT('a', 'bc', 'd')" returns "abcd". */
-  @LibraryOperator(libraries = {MYSQL, POSTGRESQL})
+  @LibraryOperator(libraries = {MYSQL, POSTGRESQL, BIG_QUERY})
   public static final SqlFunction CONCAT_FUNCTION =
   new SqlFunction("CONCAT",
   SqlKind.OTHER_FUNCTION,
diff --git a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java 
b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
index 9d011d7d50..70861df1c5 100644
--- a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
+++ b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
@@ -1834,6 +1834,7 @@ public class SqlOperatorTest {
 final SqlOperatorFixture f = fixture();
 checkConcatFunc(f.withLibrary(SqlLibrary.MYSQL));
 checkConcatFunc(f.withLibrary(SqlLibrary.POSTGRESQL));
+checkConcatFunc(f.withLibrary(SqlLibrary.BIG_QUERY));
 checkConcat2Func(f.withLibrary(SqlLibrary.ORACLE));
   }
 



[GitHub] [calcite] libenchao commented on a diff in pull request #2929: [CALCITE-5310] JSON_OBJECT in scalar sub-query throws AssertionError

2022-11-14 Thread GitBox


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


##
core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java:
##
@@ -1790,10 +1790,11 @@ private RexNode createCaseExpression(
 
 @Override public RexNode visitLiteral(RexLiteral literal) {
   // Use nullIndicator to decide whether to project null.
-  // Do nothing if the literal is null.
+  // Do nothing if the literal is null or symbol.
   if (!RexUtil.isNull(literal)

Review Comment:
   The whole story lies in `RelDecorrelator#RemoveCorrelationRexShuttle`. When 
`projectPulledAboveLeftCorrelator && (nullIndicator != null)` is `true`, 
currently it will add a case for all expressions.  
   
   Maybe your feeling is right, I haven't thought it thorough.



-- 
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 #2929: [CALCITE-5310] JSON_OBJECT in scalar sub-query throws AssertionError

2022-11-14 Thread GitBox


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


##
core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java:
##
@@ -1790,10 +1790,11 @@ private RexNode createCaseExpression(
 
 @Override public RexNode visitLiteral(RexLiteral literal) {
   // Use nullIndicator to decide whether to project null.
-  // Do nothing if the literal is null.
+  // Do nothing if the literal is null or symbol.
   if (!RexUtil.isNull(literal)

Review Comment:
   Ok, I got why calcite wraps literals if literal is in SELECT list like 
`SELEC (SELECT 1 )`. But I still don't understand why `CARDINALITY` 
arguments should be wrapped in case expression ?
   ```
   CARDINALITY(ARRAY[false, true, a.attidentity = 'a'])
   ```
   In my understanding only CARDINALITY should be wrapped to caseExpression



-- 
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] vijayjogi-dm opened a new pull request, #2969: Vijay.jogi/ravcom 40 wf vulnerabilities issues

2022-11-14 Thread GitBox


vijayjogi-dm opened a new pull request, #2969:
URL: https://github.com/apache/calcite/pull/2969

   Carry over changes from 
https://github.com/apache/calcite/commit/ba80b9156afc0db26b194d97a031fcc0dc7f4c03#
 commit to fix CVE-2022-39135 Vulnerability issue


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