zabetak commented on code in PR #3113:
URL: https://github.com/apache/calcite/pull/3113#discussion_r1214176911
##########
core/src/main/java/org/apache/calcite/util/Util.java:
##########
@@ -1717,16 +1719,14 @@ private static void appendPosixTime(StringBuilder buf,
int millis) {
* @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:
- throw new AssertionError("bad locale string '" + localeString + "'");
+ 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 + "'", e);
Review Comment:
A `IllegalStateException` or `IllegalArgumentException` would be more
appropriate here but since it was an `AssertionError` before I am also fine
leaving it as is.
I don't think an `AssertionError` is appropriate cause we may arrive here by
user input.
##########
core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java:
##########
@@ -738,17 +741,7 @@ public static ParsedCollation parseCollation(String in) {
}
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 {
- throw RESOURCE.illegalLocaleFormat(localeStr).ex();
Review Comment:
Instead of throwing a new `AssertionError` I think it is better to restore
the `RESOURCE.illegalLocaleFormat`. Other than that the change 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]