You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "mihaibudiu (via GitHub)" <gi...@apache.org> on 2026/08/19 03:26:00 UTC

[PR] [CALCITE-7727] Comparing `UUID <> ''` always returns `FALSE` [calcite]

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

   ## Jira Link
   
   [CALCITE-7727](https://issues.apache.org/jira/browse/CALCITE-7727)
   
   ## Changes Proposed
   
   I had mistakenly implemented type coercion between UUID and CHAR/BINARY by converting UUID to CHAR/BINARY.
   Postgres does the opposite, and I think it's the right choice. The previous choice leads to the surprising behavior described by the current issue. The new behavior also parallels other type coercions, e.g. comparisons between INT and CHAR, which casts to INT.
   
   The documentation was actually silent about this behavior, so we can claim it was undocumented. I have added this change of semantics to the release notes.
   
   I have also made the cast from string to UUID behave closer to Postgres. 


-- 
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-unsubscribe@calcite.apache.org

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


Re: [PR] [CALCITE-7727] Comparing `UUID <> ''` always returns `FALSE` [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #5191:
URL: https://github.com/apache/calcite/pull/5191#issuecomment-5346244248

   > LGTM
   > 
   > nit: I think there's another occurrence of `UUID.fromString` in `RelWriterTest` that for consistency should be replaced with the new `SqlFunctions.stringToUuid`
   
   I will change 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-unsubscribe@calcite.apache.org

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


Re: [PR] [CALCITE-7727] Comparing `UUID <> ''` always returns `FALSE` [calcite]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #5191:
URL: https://github.com/apache/calcite/pull/5191#issuecomment-5337292600

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=5191) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=5191&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=5191&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=5191&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [88.5% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=5191&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=5191&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=5191)
   
   


-- 
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-unsubscribe@calcite.apache.org

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


Re: [PR] [CALCITE-7727] Comparing `UUID <> ''` always returns `FALSE` [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #5191:
URL: https://github.com/apache/calcite/pull/5191#discussion_r3815614187


##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -351,9 +351,74 @@ public static String uuidToString(UUID uuid) {
     return uuid.toString();
   }
 
+  /** Converts a string to a UUID: 32 hexadecimal digits. All of the following give
+   * the UUID {@code 123e4567-e89b-12d3-a456-426655440000}:
+   *
+   * <blockquote><pre>
+   * 123e4567-e89b-12d3-a456-426655440000
+   * 123E4567-E89B-12D3-A456-426655440000
+   * 123e4567e89b12d3a456426655440000
+   * {123e4567-e89b-12d3-a456-426655440000}
+   * {123e4567e89b12d3a456426655440000}
+   * 123e-4567-e89b-12d3-a456-4266-5544-0000
+   * 123e4567-e89b12d3-a4564266-55440000
+   * 123e-4567e89b-12d3a456426655440000
+   * </pre></blockquote>
+   *
+   * <p>and each of the following is an error:
+   *
+   * <blockquote><pre>
+   * 1-2-3-4-5                              a group is not four digits wide
+   * 123e456-7e89b-12d3-a456-426655440000   as above, though 36 characters long
+   * 123e4567--e89b-12d3-a456-426655440000  empty group
+   * -123e4567e89b12d3a456426655440000      leading hyphen
+   * 123e4567e89b12d3a456426655440000-      trailing hyphen
+   * {123e4567-e89b-12d3-a456-426655440000  unbalanced brace
+   * 123e4567-e89b-12d3-a456-42665544000    31 digits
+   * </pre></blockquote>
+   */
+  public static UUID stringToUuid(String s) {
+    String body = s;
+    if (body.length() > 1
+        && body.charAt(0) == '{'
+        && body.charAt(body.length() - 1) == '}') {
+      body = body.substring(1, body.length() - 1);
+    }
+    final StringBuilder digits = new StringBuilder(32);
+    for (int i = 0; i < body.length(); i++) {
+      final char c = body.charAt(i);
+      if (c == '-') {
+        // A hyphen separates groups, so it must follow a complete group of four
+        // digits and cannot be the last character
+        if (digits.length() == 0
+            || digits.length() % 4 != 0
+            || digits.length() == 32
+            || body.charAt(i - 1) == '-') {
+          throw new IllegalArgumentException("Invalid UUID string: " + s);
+        }
+      } else if (isHexDigit(c) && digits.length() < 32) {
+        digits.append(c);
+      } else {
+        throw new IllegalArgumentException("Invalid UUID string: " + s);
+      }
+    }
+    if (digits.length() != 32) {
+      throw new IllegalArgumentException("Invalid UUID string: " + s);
+    }
+    return new UUID(
+        Long.parseUnsignedLong(digits.substring(0, 16), 16),
+        Long.parseUnsignedLong(digits.substring(16), 16));
+  }
+
+  private static boolean isHexDigit(char c) {

Review Comment:
   I will remove the duplicate



-- 
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-unsubscribe@calcite.apache.org

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


Re: [PR] [CALCITE-7727] Comparing `UUID <> ''` always returns `FALSE` [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #5191:
URL: https://github.com/apache/calcite/pull/5191#discussion_r3815615654


##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -351,9 +351,74 @@ public static String uuidToString(UUID uuid) {
     return uuid.toString();
   }
 
+  /** Converts a string to a UUID: 32 hexadecimal digits. All of the following give
+   * the UUID {@code 123e4567-e89b-12d3-a456-426655440000}:
+   *
+   * <blockquote><pre>
+   * 123e4567-e89b-12d3-a456-426655440000
+   * 123E4567-E89B-12D3-A456-426655440000
+   * 123e4567e89b12d3a456426655440000
+   * {123e4567-e89b-12d3-a456-426655440000}
+   * {123e4567e89b12d3a456426655440000}
+   * 123e-4567-e89b-12d3-a456-4266-5544-0000
+   * 123e4567-e89b12d3-a4564266-55440000
+   * 123e-4567e89b-12d3a456426655440000
+   * </pre></blockquote>
+   *
+   * <p>and each of the following is an error:
+   *
+   * <blockquote><pre>
+   * 1-2-3-4-5                              a group is not four digits wide
+   * 123e456-7e89b-12d3-a456-426655440000   as above, though 36 characters long
+   * 123e4567--e89b-12d3-a456-426655440000  empty group
+   * -123e4567e89b12d3a456426655440000      leading hyphen
+   * 123e4567e89b12d3a456426655440000-      trailing hyphen
+   * {123e4567-e89b-12d3-a456-426655440000  unbalanced brace
+   * 123e4567-e89b-12d3-a456-42665544000    31 digits
+   * </pre></blockquote>
+   */
+  public static UUID stringToUuid(String s) {

Review Comment:
   Will add a test for 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-unsubscribe@calcite.apache.org

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


Re: [PR] [CALCITE-7727] Comparing `UUID <> ''` always returns `FALSE` [calcite]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #5191:
URL: https://github.com/apache/calcite/pull/5191#issuecomment-5346700291

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=5191) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=5191&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=5191&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=5191&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [89.2% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=5191&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=5191&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=5191)
   
   


-- 
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-unsubscribe@calcite.apache.org

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


Re: [PR] [CALCITE-7727] Comparing `UUID <> ''` always returns `FALSE` [calcite]

Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #5191:
URL: https://github.com/apache/calcite/pull/5191#discussion_r3811871421


##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -351,9 +351,74 @@ public static String uuidToString(UUID uuid) {
     return uuid.toString();
   }
 
+  /** Converts a string to a UUID: 32 hexadecimal digits. All of the following give
+   * the UUID {@code 123e4567-e89b-12d3-a456-426655440000}:
+   *
+   * <blockquote><pre>
+   * 123e4567-e89b-12d3-a456-426655440000
+   * 123E4567-E89B-12D3-A456-426655440000
+   * 123e4567e89b12d3a456426655440000
+   * {123e4567-e89b-12d3-a456-426655440000}
+   * {123e4567e89b12d3a456426655440000}
+   * 123e-4567-e89b-12d3-a456-4266-5544-0000
+   * 123e4567-e89b12d3-a4564266-55440000
+   * 123e-4567e89b-12d3a456426655440000
+   * </pre></blockquote>
+   *
+   * <p>and each of the following is an error:
+   *
+   * <blockquote><pre>
+   * 1-2-3-4-5                              a group is not four digits wide
+   * 123e456-7e89b-12d3-a456-426655440000   as above, though 36 characters long
+   * 123e4567--e89b-12d3-a456-426655440000  empty group
+   * -123e4567e89b12d3a456426655440000      leading hyphen
+   * 123e4567e89b12d3a456426655440000-      trailing hyphen
+   * {123e4567-e89b-12d3-a456-426655440000  unbalanced brace
+   * 123e4567-e89b-12d3-a456-42665544000    31 digits
+   * </pre></blockquote>
+   */
+  public static UUID stringToUuid(String s) {
+    String body = s;
+    if (body.length() > 1
+        && body.charAt(0) == '{'
+        && body.charAt(body.length() - 1) == '}') {
+      body = body.substring(1, body.length() - 1);
+    }
+    final StringBuilder digits = new StringBuilder(32);
+    for (int i = 0; i < body.length(); i++) {
+      final char c = body.charAt(i);
+      if (c == '-') {
+        // A hyphen separates groups, so it must follow a complete group of four
+        // digits and cannot be the last character
+        if (digits.length() == 0
+            || digits.length() % 4 != 0
+            || digits.length() == 32
+            || body.charAt(i - 1) == '-') {
+          throw new IllegalArgumentException("Invalid UUID string: " + s);
+        }
+      } else if (isHexDigit(c) && digits.length() < 32) {
+        digits.append(c);
+      } else {
+        throw new IllegalArgumentException("Invalid UUID string: " + s);
+      }
+    }
+    if (digits.length() != 32) {
+      throw new IllegalArgumentException("Invalid UUID string: " + s);
+    }
+    return new UUID(
+        Long.parseUnsignedLong(digits.substring(0, 16), 16),
+        Long.parseUnsignedLong(digits.substring(16), 16));
+  }
+
+  private static boolean isHexDigit(char c) {

Review Comment:
   This seems to duplicate the `SqlParserUtil.isHexDigit` method.



##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -351,9 +351,74 @@ public static String uuidToString(UUID uuid) {
     return uuid.toString();
   }
 
+  /** Converts a string to a UUID: 32 hexadecimal digits. All of the following give
+   * the UUID {@code 123e4567-e89b-12d3-a456-426655440000}:
+   *
+   * <blockquote><pre>
+   * 123e4567-e89b-12d3-a456-426655440000
+   * 123E4567-E89B-12D3-A456-426655440000
+   * 123e4567e89b12d3a456426655440000
+   * {123e4567-e89b-12d3-a456-426655440000}
+   * {123e4567e89b12d3a456426655440000}
+   * 123e-4567-e89b-12d3-a456-4266-5544-0000
+   * 123e4567-e89b12d3-a4564266-55440000
+   * 123e-4567e89b-12d3a456426655440000
+   * </pre></blockquote>
+   *
+   * <p>and each of the following is an error:
+   *
+   * <blockquote><pre>
+   * 1-2-3-4-5                              a group is not four digits wide
+   * 123e456-7e89b-12d3-a456-426655440000   as above, though 36 characters long
+   * 123e4567--e89b-12d3-a456-426655440000  empty group
+   * -123e4567e89b12d3a456426655440000      leading hyphen
+   * 123e4567e89b12d3a456426655440000-      trailing hyphen
+   * {123e4567-e89b-12d3-a456-426655440000  unbalanced brace
+   * 123e4567-e89b-12d3-a456-42665544000    31 digits
+   * </pre></blockquote>
+   */
+  public static UUID stringToUuid(String s) {

Review Comment:
   The handling of blank string does not appear to be clearly defined; it needs to be consistent with PostgreSQL.



-- 
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-unsubscribe@calcite.apache.org

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


Re: [PR] [CALCITE-7727] Comparing `UUID <> ''` always returns `FALSE` [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu merged PR #5191:
URL: https://github.com/apache/calcite/pull/5191


-- 
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-unsubscribe@calcite.apache.org

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


Re: [PR] [CALCITE-7727] Comparing `UUID <> ''` always returns `FALSE` [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #5191:
URL: https://github.com/apache/calcite/pull/5191#issuecomment-5346250859

   Since this is already approved, I will push an amended commit which performs all three suggested improvements and I will merge once CI passes. Thank you for 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-unsubscribe@calcite.apache.org

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