Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CALCITE-6358] Support all PostgreSQL 14 date/time patterns for to_char #3792

Merged
merged 1 commit into from
May 30, 2024

Conversation

normanj-bitquill
Copy link
Contributor

  • Splits the PostgreSQL toChar function off to its own function
  • Does not implement SP suffix
  • Timezone patterns are supported but all datetimes are in local timezone

* Splits the PostgreSQL toChar function off to its own function
* Does not implement SP suffix
* Timezone patterns are supported but all datetimes are in local timezone
@normanj-bitquill normanj-bitquill changed the title TEST - [CALCITE-6358] Support all PostgreSQL 14 date/time patterns for to_char [CALCITE-6358] Support all PostgreSQL 14 date/time patterns for to_char May 15, 2024
@normanj-bitquill
Copy link
Contributor Author

This PR is the same as
#3773

Needed to recreate to fix CI issues.

Copy link

sonarcloud bot commented May 15, 2024

13
!ok

select to_char(timestamp '2022-06-03 13:15:48.678', 'MI');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rich unit tests 👍

* converts {@code timestamp} to string according to the given {@code format}. */
@LibraryOperator(libraries = {POSTGRESQL})
public static final SqlFunction TO_CHAR_PG =
new SqlBasicFunction("TO_CHAR", SqlKind.OTHER_FUNCTION,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be used directly?

SqlBasicFunction.create("TO_CHAR",
          ReturnTypes.VARCHAR_NULLABLE,
          OperandTypes.TIMESTAMP_STRING,
          SqlFunctionCategory.TIMEDATE);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YiwenWu Unfortunately not. The implementations of hashCode and equals are from SqlOperator and only looks at the name and kind.

There is also a TO_CHAR for MySQL/Oracle and this new one for PostgreSQL. Since they have the same name and kind they would conflict in a HashMap. Using a new class here gets around the collision. Another solution is to add equals and hashCode implementations to SqlBasicFunction.

Copy link
Contributor

@YiwenWu YiwenWu May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@normanj-bitquill Understood.

A small suggestion, I think the SqlBasicFunction constructor is designed to be as private as possible. Is it possible to add a method to create the corresponding anonymous class, for example:

  public static SqlBasicFunction overloadCreate(String name,
      SqlReturnTypeInference returnTypeInference,
      SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory category) {
    return new SqlBasicFunction(name, SqlKind.OTHER_FUNCTION,
        SqlSyntax.FUNCTION, true, returnTypeInference, null,
        OperandHandlers.DEFAULT, operandTypeChecker, 0,
        category, call -> SqlMonotonicity.NOT_MONOTONIC, false){};
  }

@mihaibudiu
Copy link
Contributor

This looks good, we can probably merge this one and close #3773

@mihaibudiu mihaibudiu merged commit 1fa4705 into apache:main May 30, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants