You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by gi...@apache.org on 2023/06/03 11:46:39 UTC

[calcite] branch site updated: [CALCITE-5746] Support JDK 19

This is an automated email from the ASF dual-hosted git repository.

github-bot pushed a commit to branch site
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/site by this push:
     new 586fe4bbb0 [CALCITE-5746] Support JDK 19
586fe4bbb0 is described below

commit 586fe4bbb0a1c43001bfd6e83777a3852c6d18dd
Author: Sergey Nuyanzin <sn...@gmail.com>
AuthorDate: Tue Mar 14 17:21:49 2023 +0100

    [CALCITE-5746] Support JDK 19
    
    Close apache/calcite#3113
---
 .github/workflows/main.yml                           | 16 ++++++++--------
 .../org/apache/calcite/sql/parser/SqlParserUtil.java | 20 ++++++++++----------
 core/src/main/java/org/apache/calcite/util/Util.java | 18 +++++++++---------
 .../test/java/org/apache/calcite/util/UtilTest.java  |  2 +-
 gradle.properties                                    |  4 ++--
 site/_docs/history.md                                |  9 ++++++---
 site/_docs/howto.md                                  |  6 +++---
 src/main/config/forbidden-apis/signatures.txt        |  5 +++++
 .../apache/calcite/testlib/WithLocaleExtension.kt    |  6 ++++--
 9 files changed, 48 insertions(+), 38 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index fd397a2405..efefeb30e3 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -189,9 +189,9 @@ jobs:
           remote-build-cache-proxy-enabled: false
           arguments: --scan --no-parallel --no-daemon -Pguava.version=${{ env.GUAVA }} build
 
-  linux-jdk18: # latest JDK version supported by ForbiddenAPIs plugin, keep this updated (see https://jdk.java.net/)
+  linux-jdk19: # latest JDK version supported by ForbiddenAPIs plugin, keep this updated (see https://jdk.java.net/)
     if: github.event.action != 'labeled'
-    name: 'Linux (JDK 18)'
+    name: 'Linux (JDK 19)'
     runs-on: ubuntu-latest
     env:
       GUAVA: '31.1-jre'
@@ -199,10 +199,10 @@ jobs:
       - uses: actions/checkout@v3
         with:
           fetch-depth: 50
-      - name: 'Set up JDK 18'
+      - name: 'Set up JDK 19'
         uses: actions/setup-java@v2
         with:
-          java-version: 18
+          java-version: 19
           distribution: 'zulu'
       - uses: burrunan/gradle-cache-action@v1
         name: Test
@@ -259,16 +259,16 @@ jobs:
 
   mac:
     if: github.event.action != 'labeled'
-    name: 'macOS (JDK 18)'
+    name: 'macOS (JDK 19)'
     runs-on: macos-latest
     steps:
       - uses: actions/checkout@v3
         with:
           fetch-depth: 50
-      - name: 'Set up JDK 18'
+      - name: 'Set up JDK 19'
         uses: actions/setup-java@v2
         with:
-          java-version: 18
+          java-version: 19
           distribution: 'zulu'
       - uses: burrunan/gradle-cache-action@v1
         name: Test
@@ -276,7 +276,7 @@ jobs:
           S3_BUILD_CACHE_ACCESS_KEY_ID: ${{ secrets.S3_BUILD_CACHE_ACCESS_KEY_ID }}
           S3_BUILD_CACHE_SECRET_KEY: ${{ secrets.S3_BUILD_CACHE_SECRET_KEY }}
         with:
-          job-id: jdk18
+          job-id: jdk19
           remote-build-cache-proxy-enabled: false
           arguments: --scan --no-parallel --no-daemon build javadoc
       - name: 'sqlline and sqllsh'
diff --git a/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java b/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java
index 1c304706fd..5f36342e81 100644
--- a/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java
+++ b/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java
@@ -62,10 +62,12 @@ import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.IllformedLocaleException;
 import java.util.List;
 import java.util.Locale;
 import java.util.StringTokenizer;
 import java.util.function.Predicate;
+import java.util.regex.Pattern;
 
 import static org.apache.calcite.util.Static.RESOURCE;
 
@@ -80,6 +82,8 @@ public final class SqlParserUtil {
 
   static final Logger LOGGER = CalciteTrace.getParserTracer();
 
+  private static final Pattern UNDERSCORE = Pattern.compile("_+");
+
   //~ Constructors -----------------------------------------------------------
 
   private SqlParserUtil() {
@@ -738,18 +742,14 @@ public final class SqlParserUtil {
     }
 
     Charset charset = SqlUtil.getCharset(charsetStr);
-    String[] localeParts = localeStr.split("_");
-    Locale locale;
-    if (1 == localeParts.length) {
-      locale = new Locale(localeParts[0]);
-    } else if (2 == localeParts.length) {
-      locale = new Locale(localeParts[0], localeParts[1]);
-    } else if (3 == localeParts.length) {
-      locale = new Locale(localeParts[0], localeParts[1], localeParts[2]);
-    } else {
+    try {
+      Locale locale =
+          new Locale.Builder().setLanguageTag(
+              UNDERSCORE.matcher(localeStr).replaceAll("-")).build();
+      return new ParsedCollation(charset, locale, strength);
+    } catch (IllformedLocaleException e) {
       throw RESOURCE.illegalLocaleFormat(localeStr).ex();
     }
-    return new ParsedCollation(charset, locale, strength);
   }
 
   @Deprecated // to be removed before 2.0
diff --git a/core/src/main/java/org/apache/calcite/util/Util.java b/core/src/main/java/org/apache/calcite/util/Util.java
index 0d76d416bf..2578a70d78 100644
--- a/core/src/main/java/org/apache/calcite/util/Util.java
+++ b/core/src/main/java/org/apache/calcite/util/Util.java
@@ -90,6 +90,7 @@ import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Hashtable;
+import java.util.IllformedLocaleException;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
@@ -123,6 +124,7 @@ import static java.util.Objects.requireNonNull;
 public class Util {
 
   private static final int QUICK_DISTINCT = 15;
+  private static final Pattern UNDERSCORE = Pattern.compile("_+");
 
   private Util() {}
 
@@ -1717,15 +1719,13 @@ public class Util {
    * @return Java locale object
    */
   public static Locale parseLocale(String localeString) {
-    String[] strings = localeString.split("_");
-    switch (strings.length) {
-    case 1:
-      return new Locale(strings[0]);
-    case 2:
-      return new Locale(strings[0], strings[1]);
-    case 3:
-      return new Locale(strings[0], strings[1], strings[2]);
-    default:
+    if (localeString.isEmpty()) {
+      return Locale.ROOT;
+    }
+    try {
+      return new Locale.Builder().setLanguageTag(
+          UNDERSCORE.matcher(localeString).replaceAll("-")).build();
+    } catch (IllformedLocaleException e) {
       throw new AssertionError("bad locale string '" + localeString + "'");
     }
   }
diff --git a/core/src/test/java/org/apache/calcite/util/UtilTest.java b/core/src/test/java/org/apache/calcite/util/UtilTest.java
index db113d162d..58a9cfcd62 100644
--- a/core/src/test/java/org/apache/calcite/util/UtilTest.java
+++ b/core/src/test/java/org/apache/calcite/util/UtilTest.java
@@ -913,7 +913,7 @@ class UtilTest {
     }
     // Example locale names in Locale.toString() javadoc.
     String[] localeNames = {
-        "en", "de_DE", "_GB", "en_US_WIN", "de__POSIX", "fr__MAC"
+        "en", "de_DE", "gb_GB", "en_US_WINDOWS", "de__POSIX", "fr__MACOS"
     };
     for (String localeName : localeNames) {
       assertEquals(localeName, Util.parseLocale(localeName).toString());
diff --git a/gradle.properties b/gradle.properties
index 08f73d27a6..9ebf99d9c5 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -50,8 +50,8 @@ com.github.johnrengelman.shadow.version=5.1.0
 com.github.spotbugs.version=2.0.0
 com.github.vlsi.vlsi-release-plugins.version=1.84
 com.google.protobuf.version=0.8.10
-de.thetaphi.forbiddenapis.version=3.4
-jacoco.version=0.8.8
+de.thetaphi.forbiddenapis.version=3.5.1
+jacoco.version=0.8.10
 kotlin.version=1.7.10
 net.ltgt.errorprone.version=1.3.0
 me.champeau.gradle.jmh.version=0.5.3
diff --git a/site/_docs/history.md b/site/_docs/history.md
index d82167ca02..ad16375c0b 100644
--- a/site/_docs/history.md
+++ b/site/_docs/history.md
@@ -43,8 +43,11 @@ z.
 #### Breaking Changes
 {: #breaking-1-35-0}
 
+The way of Locale parsing changed within [<a href="https://issues.apache.org/jira/browse/CALCITE-5567">CALCITE-5567</a>]
+Now locale's language tag should match IETF BCP 47 language tag or be empty.
+
 Compatibility: This release is tested on Linux, macOS, Microsoft Windows;
-using JDK/OpenJDK versions 8 to 18;
+using JDK/OpenJDK versions 8 to 19;
 Guava versions 16.0.1 to 31.1-jre;
 other software versions as specified in gradle.properties.
 
@@ -71,11 +74,11 @@ This release comes 1 month after [1.33.0](#v1-33-0),
 contains contributions from 18 contributors, and resolves 34 issues. It's worth highlighting the
 introduction of QUALIFY clause ([<a href="https://issues.apache.org/jira/browse/CALCITE-5268">CALCITE-5268</a>]),
 which facilitates filtering the results of window functions. Among other improvements and fixes, it
-adds roughly 15 new functions in BigQuery library for handling dates, times, and timestamps, and 
+adds roughly 15 new functions in BigQuery library for handling dates, times, and timestamps, and
 provides a fix ([<a href="https://issues.apache.org/jira/browse/CALCITE-5522">CALCITE-5522</a>])
 for a small breaking change in `DATE_TRUNC` function
 ([<a href="https://issues.apache.org/jira/browse/CALCITE-5447">CALCITE-5447</a>]), which was
-introduced accidentally in [1.33.0](#v1-33-0). 
+introduced accidentally in [1.33.0](#v1-33-0).
 
 Contributors to this release:
 Alessandro Solimando,
diff --git a/site/_docs/howto.md b/site/_docs/howto.md
index 02ee0cee9d..b93753ebba 100644
--- a/site/_docs/howto.md
+++ b/site/_docs/howto.md
@@ -31,8 +31,8 @@ adapters.
 
 ## Building from a source distribution
 
-Prerequisite is Java (JDK 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 or 18)
-and Gradle (version 7.4.2) on your path.
+Prerequisite is Java (JDK 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 or 19)
+and Gradle (version 7.6.1) on your path.
 
 Unpack the source distribution `.tar.gz` file,
 `cd` to the root directory of the unpacked source,
@@ -51,7 +51,7 @@ tests  (but you should use the `gradle` command rather than
 ## Building from Git
 
 Prerequisites are git
-and Java (JDK 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 or 18) on your path.
+and Java (JDK 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 or 19) on your path.
 
 Create a local copy of the GitHub repository,
 `cd` to its root directory,
diff --git a/src/main/config/forbidden-apis/signatures.txt b/src/main/config/forbidden-apis/signatures.txt
index c498312fc4..98d477ed4c 100644
--- a/src/main/config/forbidden-apis/signatures.txt
+++ b/src/main/config/forbidden-apis/signatures.txt
@@ -104,3 +104,8 @@ com.google.common.collect.Sets#newHashSet()
 
 @defaultMessage Use "assertThat(expected, matcher)", do not call Matcher#matches directly
 org.hamcrest.Matcher#matches(java.lang.Object)
+
+@defaultMessage Use "java.util.Locale.Builder.setLanguageTag"
+java.util.Locale#<init>(java.lang.String)
+java.util.Locale#<init>(java.lang.String,java.lang.String)
+java.util.Locale#<init>(java.lang.String,java.lang.String,java.lang.String)
diff --git a/testkit/src/main/kotlin/org/apache/calcite/testlib/WithLocaleExtension.kt b/testkit/src/main/kotlin/org/apache/calcite/testlib/WithLocaleExtension.kt
index fb491454eb..4a1f5c93ba 100644
--- a/testkit/src/main/kotlin/org/apache/calcite/testlib/WithLocaleExtension.kt
+++ b/testkit/src/main/kotlin/org/apache/calcite/testlib/WithLocaleExtension.kt
@@ -46,7 +46,8 @@ class WithLocaleExtension : BeforeAllCallback, AfterAllCallback, BeforeEachCallb
         // Save the value of WithLocale if it is present at the class level
         context.element
             .flatMap { AnnotationSupport.findAnnotation(it, WithLocale::class.java) }
-            .map { Locale(it.country, it.country, it.variant) }
+            .map { Locale.Builder().setLanguageTag(it.country + '-' + it.country +
+                    if (it.variant.isBlank()) "" else '-' + it.variant).build() }
             .orElseGet { defaultLocale }
             .let { context.store.put(CLASS_LOCALE, it) }
     }
@@ -62,7 +63,8 @@ class WithLocaleExtension : BeforeAllCallback, AfterAllCallback, BeforeEachCallb
         // Set locale based on
         context.element
             .flatMap { AnnotationSupport.findAnnotation(it, WithLocale::class.java) }
-            .map { Locale(it.country, it.country, it.variant) }
+            .map { Locale.Builder().setLanguageTag(it.country + '-' + it.country +
+                    if (it.variant.isBlank()) "" else '-' + it.variant).build() }
             .orElseGet { context.store.get(CLASS_LOCALE, Locale::class.java) }
             ?.let { Locale.setDefault(it) }
     }