mihaibudiu commented on code in PR #3833:
URL: https://github.com/apache/calcite/pull/3833#discussion_r1672669904
##########
core/src/main/java/org/apache/calcite/util/format/postgresql/FormatPattern.java:
##########
@@ -36,6 +59,152 @@ public interface FormatPattern {
* @param dateTime datetime to convert
* @return the string representation of the datetime based on the format
pattern
*/
- @Nullable String convert(ParsePosition parsePosition, String formatString,
+ public abstract @Nullable String convert(ParsePosition parsePosition, String
formatString,
ZonedDateTime dateTime);
+
+ /**
+ * Get the ChronoUnitEnum value that this format pattern represents. For
example, the
+ * pattern YYYY is for YEAR.
+ *
+ * @return a ChronoUnitEnum value
+ */
+ protected abstract ChronoUnitEnum getChronoUnit();
+
+ /**
+ * Attempts to parse a single value from the input for this pattern. It will
start parsing
Review Comment:
this is much better
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -1690,22 +1690,40 @@ private static RelDataType
deriveTypeMapFromEntries(SqlOperatorBinding opBinding
/** The "TO_DATE(string1, string2)" function; casts string1
* to a DATE using the format specified in string2. */
- @LibraryOperator(libraries = {POSTGRESQL, ORACLE})
+ @LibraryOperator(libraries = {ORACLE})
public static final SqlFunction TO_DATE =
SqlBasicFunction.create("TO_DATE",
ReturnTypes.DATE_NULLABLE,
OperandTypes.STRING_STRING,
SqlFunctionCategory.TIMEDATE);
+ /** The "TO_DATE(string1, string2)" function for PostgreSQL; casts string1
+ * to a DATE using the format specified in string2. */
+ @LibraryOperator(libraries = {POSTGRESQL})
+ public static final SqlFunction TO_DATE_PG =
+ new SqlBasicFunction("TO_DATE", SqlKind.OTHER_FUNCTION,
+ SqlSyntax.FUNCTION, true, ReturnTypes.DATE_NULLABLE, null,
+ OperandHandlers.DEFAULT, OperandTypes.STRING_STRING, 0,
+ SqlFunctionCategory.TIMEDATE, call -> SqlMonotonicity.NOT_MONOTONIC,
false) { };
+
/** The "TO_TIMESTAMP(string1, string2)" function; casts string1
* to a TIMESTAMP using the format specified in string2. */
- @LibraryOperator(libraries = {POSTGRESQL, ORACLE})
+ @LibraryOperator(libraries = {ORACLE})
public static final SqlFunction TO_TIMESTAMP =
SqlBasicFunction.create("TO_TIMESTAMP",
ReturnTypes.TIMESTAMP_NULLABLE,
OperandTypes.STRING_STRING,
SqlFunctionCategory.TIMEDATE);
+ /** The "TO_TIMESTAMP(string1, string2)" function for PostgreSQL; casts
string1
+ * to a TIMESTAMP using the format specified in string2. */
+ @LibraryOperator(libraries = {POSTGRESQL})
+ public static final SqlFunction TO_TIMESTAMP_PG =
+ new SqlBasicFunction("TO_TIMESTAMP", SqlKind.OTHER_FUNCTION,
+ SqlSyntax.FUNCTION, true, ReturnTypes.TIMESTAMP_NULLABLE, null,
Review Comment:
I don't understand your question.
What prevents this function from returning TIMESTAMP_TZ?
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -1690,22 +1690,40 @@ private static RelDataType
deriveTypeMapFromEntries(SqlOperatorBinding opBinding
/** The "TO_DATE(string1, string2)" function; casts string1
* to a DATE using the format specified in string2. */
- @LibraryOperator(libraries = {POSTGRESQL, ORACLE})
+ @LibraryOperator(libraries = {ORACLE})
public static final SqlFunction TO_DATE =
SqlBasicFunction.create("TO_DATE",
ReturnTypes.DATE_NULLABLE,
OperandTypes.STRING_STRING,
SqlFunctionCategory.TIMEDATE);
+ /** The "TO_DATE(string1, string2)" function for PostgreSQL; casts string1
+ * to a DATE using the format specified in string2. */
+ @LibraryOperator(libraries = {POSTGRESQL})
+ public static final SqlFunction TO_DATE_PG =
+ new SqlBasicFunction("TO_DATE", SqlKind.OTHER_FUNCTION,
+ SqlSyntax.FUNCTION, true, ReturnTypes.DATE_NULLABLE, null,
+ OperandHandlers.DEFAULT, OperandTypes.STRING_STRING, 0,
+ SqlFunctionCategory.TIMEDATE, call -> SqlMonotonicity.NOT_MONOTONIC,
false) { };
+
/** The "TO_TIMESTAMP(string1, string2)" function; casts string1
* to a TIMESTAMP using the format specified in string2. */
- @LibraryOperator(libraries = {POSTGRESQL, ORACLE})
+ @LibraryOperator(libraries = {ORACLE})
public static final SqlFunction TO_TIMESTAMP =
SqlBasicFunction.create("TO_TIMESTAMP",
ReturnTypes.TIMESTAMP_NULLABLE,
OperandTypes.STRING_STRING,
SqlFunctionCategory.TIMEDATE);
+ /** The "TO_TIMESTAMP(string1, string2)" function for PostgreSQL; casts
string1
+ * to a TIMESTAMP using the format specified in string2. */
+ @LibraryOperator(libraries = {POSTGRESQL})
+ public static final SqlFunction TO_TIMESTAMP_PG =
+ new SqlBasicFunction("TO_TIMESTAMP", SqlKind.OTHER_FUNCTION,
+ SqlSyntax.FUNCTION, true, ReturnTypes.TIMESTAMP_NULLABLE, null,
Review Comment:
You can leave this for a future PR; you can probably file an issue about the
return type being not the expected one.
--
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]