You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "normanj-bitquill (via GitHub)" <gi...@apache.org> on 2024/05/30 21:35:39 UTC
[PR] [CALCITE-6392] Support all PostgreSQL 14 date/time patterns for to_da… [calcite]
normanj-bitquill opened a new pull request, #3805:
URL: https://github.com/apache/calcite/pull/3805
…te/to_timestamp
* First phase, mostly reorganizing classes
* Does not yet implement to_date or to_timestamp
* Fixed up fill mode handling
* Isolated the unit test class so that it can make Locale changes safely
* Introduced some new classes split out handling of some formats strings
--
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-6392] Support all PostgreSQL 14 date/time patterns for to_da… [calcite]
Posted by "normanj-bitquill (via GitHub)" <gi...@apache.org>.
normanj-bitquill commented on code in PR #3805:
URL: https://github.com/apache/calcite/pull/3805#discussion_r1633827873
##########
core/src/main/java/org/apache/calcite/util/format/postgresql/DateStringFormatPattern.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.util.format.postgresql;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.time.DayOfWeek;
+import java.time.Month;
+import java.time.ZonedDateTime;
+import java.time.format.TextStyle;
+import java.util.Locale;
+
+/**
+ * Converts a non numeric value from a string to a datetime component and can generate
+ * a string representation of of a datetime component from a datetime. An example is
+ * converting to and from month names.
+ *
+ * @param <T> a type used by <code>java.time</code> to represent a datetime component
+ * that has a string representation
+ */
+public class DateStringFormatPattern<T> extends StringFormatPattern {
+ /**
+ * Provides an abstraction over datetime components that have string representations.
+ *
+ * @param <T> a type used by <code>java.time</code> to represent a datetime component
+ * that has a string representation
+ */
+ private interface DateStringConverter<T> {
+ T getValueFromDateTime(ZonedDateTime dateTime);
+
+ String getDisplayName(T value, TextStyle textStyle, boolean haveFillMode, Locale locale);
+ }
+
+ /**
+ * Can convert between a day of week name and the corresponding datetime component value.
+ */
+ private static class DayOfWeekConverter implements DateStringConverter<DayOfWeek> {
+ @Override public DayOfWeek getValueFromDateTime(ZonedDateTime dateTime) {
+ return dateTime.getDayOfWeek();
+ }
+
+ @Override public String getDisplayName(DayOfWeek value, TextStyle textStyle,
+ boolean haveFillMode, Locale locale) {
+ final String formattedValue = value.getDisplayName(textStyle, locale);
+
+ if (!haveFillMode && textStyle == TextStyle.FULL) {
+ return String.format(locale, "%-9s", formattedValue);
Review Comment:
@mihaibudiu Added comments to explain this in the code.
--
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-6392] Support all PostgreSQL 14 date/time patterns for to_da… [calcite]
Posted by "normanj-bitquill (via GitHub)" <gi...@apache.org>.
normanj-bitquill commented on code in PR #3805:
URL: https://github.com/apache/calcite/pull/3805#discussion_r1626266165
##########
core/src/main/java/org/apache/calcite/util/format/postgresql/DateStringFormatPattern.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.util.format.postgresql;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.time.DayOfWeek;
+import java.time.Month;
+import java.time.ZonedDateTime;
+import java.time.format.TextStyle;
+import java.util.Locale;
+
+/**
+ * Converts a non numeric value from a string to a datetime component and can generate
+ * a string representation of of a datetime component from a datetime. An example is
+ * converting to and from month names.
+ *
+ * @param <T> a type used by <code>java.time</code> to represent a datetime component
+ * that has a string representation
+ */
+public class DateStringFormatPattern<T> extends StringFormatPattern {
+ /**
+ * Provides an abstraction over datetime components that have string representations.
+ *
+ * @param <T> a type used by <code>java.time</code> to represent a datetime component
+ * that has a string representation
+ */
+ private interface DateStringConverter<T> {
+ T getValueFromDateTime(ZonedDateTime dateTime);
+
+ String getDisplayName(T value, TextStyle textStyle, boolean haveFillMode, Locale locale);
+ }
+
+ /**
+ * Can convert between a day of week name and the corresponding datetime component value.
+ */
+ private static class DayOfWeekConverter implements DateStringConverter<DayOfWeek> {
+ @Override public DayOfWeek getValueFromDateTime(ZonedDateTime dateTime) {
+ return dateTime.getDayOfWeek();
+ }
+
+ @Override public String getDisplayName(DayOfWeek value, TextStyle textStyle,
+ boolean haveFillMode, Locale locale) {
+ final String formattedValue = value.getDisplayName(textStyle, locale);
+
+ if (!haveFillMode && textStyle == TextStyle.FULL) {
+ return String.format(locale, "%-9s", formattedValue);
Review Comment:
From the PostgreSQL documentation, day of week names are blank padded to 9 characters.
https://www.postgresql.org/docs/14/functions-formatting.html#FUNCTIONS-FORMATTING-DATETIME-TABLE
Look for `DAY`, `Day` or `day`.
--
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-6392] Support all PostgreSQL 14 date/time patterns for to_da… [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #3805:
URL: https://github.com/apache/calcite/pull/3805#discussion_r1625176508
##########
core/src/main/java/org/apache/calcite/util/format/postgresql/DateStringFormatPattern.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.util.format.postgresql;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.time.DayOfWeek;
+import java.time.Month;
+import java.time.ZonedDateTime;
+import java.time.format.TextStyle;
+import java.util.Locale;
+
+/**
+ * Converts a non numeric value from a string to a datetime component and can generate
+ * a string representation of of a datetime component from a datetime. An example is
+ * converting to and from month names.
+ *
+ * @param <T> a type used by <code>java.time</code> to represent a datetime component
+ * that has a string representation
+ */
+public class DateStringFormatPattern<T> extends StringFormatPattern {
+ /**
+ * Provides an abstraction over datetime components that have string representations.
+ *
+ * @param <T> a type used by <code>java.time</code> to represent a datetime component
+ * that has a string representation
+ */
+ private interface DateStringConverter<T> {
+ T getValueFromDateTime(ZonedDateTime dateTime);
+
+ String getDisplayName(T value, TextStyle textStyle, boolean haveFillMode, Locale locale);
+ }
+
+ /**
+ * Can convert between a day of week name and the corresponding datetime component value.
+ */
+ private static class DayOfWeekConverter implements DateStringConverter<DayOfWeek> {
+ @Override public DayOfWeek getValueFromDateTime(ZonedDateTime dateTime) {
+ return dateTime.getDayOfWeek();
+ }
+
+ @Override public String getDisplayName(DayOfWeek value, TextStyle textStyle,
+ boolean haveFillMode, Locale locale) {
+ final String formattedValue = value.getDisplayName(textStyle, locale);
+
+ if (!haveFillMode && textStyle == TextStyle.FULL) {
+ return String.format(locale, "%-9s", formattedValue);
Review Comment:
why 9 exactly?
--
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-6392] Support all PostgreSQL 14 date/time patterns for to_da… [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #3805:
URL: https://github.com/apache/calcite/pull/3805#discussion_r1626267389
##########
core/src/main/java/org/apache/calcite/util/format/postgresql/DateStringFormatPattern.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.util.format.postgresql;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.time.DayOfWeek;
+import java.time.Month;
+import java.time.ZonedDateTime;
+import java.time.format.TextStyle;
+import java.util.Locale;
+
+/**
+ * Converts a non numeric value from a string to a datetime component and can generate
+ * a string representation of of a datetime component from a datetime. An example is
+ * converting to and from month names.
+ *
+ * @param <T> a type used by <code>java.time</code> to represent a datetime component
+ * that has a string representation
+ */
+public class DateStringFormatPattern<T> extends StringFormatPattern {
+ /**
+ * Provides an abstraction over datetime components that have string representations.
+ *
+ * @param <T> a type used by <code>java.time</code> to represent a datetime component
+ * that has a string representation
+ */
+ private interface DateStringConverter<T> {
+ T getValueFromDateTime(ZonedDateTime dateTime);
+
+ String getDisplayName(T value, TextStyle textStyle, boolean haveFillMode, Locale locale);
+ }
+
+ /**
+ * Can convert between a day of week name and the corresponding datetime component value.
+ */
+ private static class DayOfWeekConverter implements DateStringConverter<DayOfWeek> {
+ @Override public DayOfWeek getValueFromDateTime(ZonedDateTime dateTime) {
+ return dateTime.getDayOfWeek();
+ }
+
+ @Override public String getDisplayName(DayOfWeek value, TextStyle textStyle,
+ boolean haveFillMode, Locale locale) {
+ final String formattedValue = value.getDisplayName(textStyle, locale);
+
+ if (!haveFillMode && textStyle == TextStyle.FULL) {
+ return String.format(locale, "%-9s", formattedValue);
Review Comment:
I would put that into a 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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org