Skip to content

[Enhancement] Convert sql function parse_datetime(...) to str_to_jodatime(...) with accepting 'T' and 'Z' in format for Trino transformer when sql_dialect='trino' #56565

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

Merged
merged 17 commits into from
Mar 10, 2025

Conversation

click9000
Copy link
Contributor

Why I'm doing:

For sql_dialect='trino' case, parse_datetime('2025-01-01T00:00:00.000Z', 'yyyy-MM-dd''T''HH:mm:ss.SSS''Z''') should be transformed

What I'm doing:

Replace 'T' to T and remove 'Z' in the format string for function parse_datetime()

Example:
parse_datetime('2025-01-01T00:00:00.000Z', 'yyyy-MM-dd''T''HH:mm:ss.SSS''Z''')

should be converted to

str_to_jodatime('2025-01-01T00:00:00.000Z',, 'yyyy-MM-ddTHH:mm:ss.SSS')

Fixes #issue

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.4
    • 3.3
    • 3.2
    • 3.1
    • 3.0

for function from_iso8601_timestamp -> timestamp

Signed-off-by: Craig <[email protected]>
unit test for transforming Trino function: from_iso8601_timestamp -> timestamp

Signed-off-by: Craig <[email protected]>
move function parse_datetime() transform to ComplexFunctionCallTransformer.java to process format string when needed

Signed-off-by: Craig <[email protected]>
Move function parse_datetime() transform to ComplexFunctionCallTransformer.java

Signed-off-by: Craig <[email protected]>
add a test case for str_to_jodatime() transform

Signed-off-by: Craig <[email protected]>
merge the if statement per SonarQube Cloud's check

Signed-off-by: Craig <[email protected]>
@click9000 click9000 changed the title Convert sql function parse_datetime(...) to str_to_jodatime(...) with accepting 'T' and 'Z' in format for Trino transformer when sql_dialect='trino' [Enhancement] Convert sql function parse_datetime(...) to str_to_jodatime(...) with accepting 'T' and 'Z' in format for Trino transformer when sql_dialect='trino' Mar 4, 2025
remove case for parse_datetime:
'yyyy-MM-dd''T''HH:mm:ss''Z'''

Signed-off-by: Craig <[email protected]>
Update per SonarQube check

Signed-off-by: Craig <[email protected]>
@stephen-shelby
Copy link
Contributor

@Youngwb please take a look

// parse_datetime -> str_to_jodatime
String formatString = ((StringLiteral) args[1]).getStringValue();
// "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" -> "yyyy-MM-ddTHH:mm:ss.SSS"
formatString = formatString.replace("'T'", "T").replace("'Z'", "");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should handle any character within the quotes, rather than just handling the character 'T'.
eg. select parse_datetime('2025-01-01ABC00:00:00.000Z', 'yyyy-MM-dd''ABC''HH:mm:ss.SSS''Z''');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can remove all ' characters for the format parameter, plus removing all Z characters because str_to_jodatime doesn't support it (when it's OK in Trino).
current example with Z in the format parameter:

mysql> set sql_dialect=trino;
mysql> select parse_datetime('2023-08-02T14:37:02Z', 'yyyy-MM-dd''T''HH:mm:ssZ');
ERROR 1064 (HY000): Invalid format 'yyyy-MM-ddTHH:mm:ssZ' for '2023-08-02T14:37:02Z'
mysql> select parse_datetime('2023-08-02T14:37:02Z', 'yyyy-MM-dd''T''HH:mm:ss''Z''');
+----------------------------------------------------------------+
| str_to_jodatime('2023-08-02T14:37:02Z', 'yyyy-MM-ddTHH:mm:ss') |
+----------------------------------------------------------------+
| 2023-08-02 14:37:02                                            |
+----------------------------------------------------------------+

Copy link
Contributor Author

Choose a reason for hiding this comment

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

code updated and add one more test for function parse_datetime()

@Youngwb
Copy link
Contributor

Youngwb commented Mar 7, 2025

@click9000 Could you plz add some test to cover this case?

Add one more test for function parse_datetime() to handle format case like   'yyyy-MM-dd''T''HH:mm:ss''Z'''

Signed-off-by: Craig <[email protected]>
Remove all ' characters for the format parameter, plus removing all Z characters because str_to_jodatime doesn't support it (when it's OK in Trino)

Signed-off-by: Craig <[email protected]>
Copy link

sonarqubecloud bot commented Mar 9, 2025

Copy link

github-actions bot commented Mar 9, 2025

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

github-actions bot commented Mar 9, 2025

[FE Incremental Coverage Report]

pass : 4 / 4 (100.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/connector/parser/trino/ComplexFunctionCallTransformer.java 4 4 100.00% []

Copy link

github-actions bot commented Mar 9, 2025

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@Youngwb Youngwb enabled auto-merge (squash) March 10, 2025 05:44
@Youngwb Youngwb merged commit b8e05fe into StarRocks:main Mar 10, 2025
54 checks passed
Copy link

@Mergifyio backport branch-3.4

Copy link

@Mergifyio backport branch-3.3

Copy link
Contributor

mergify bot commented Mar 10, 2025

Copy link
Contributor

mergify bot commented Mar 10, 2025

mergify bot pushed a commit that referenced this pull request Mar 10, 2025
…time(...) with accepting 'T' and 'Z' in format for Trino transformer when sql_dialect='trino' (#56565)

Signed-off-by: Craig <[email protected]>
(cherry picked from commit b8e05fe)
mergify bot pushed a commit that referenced this pull request Mar 10, 2025
…time(...) with accepting 'T' and 'Z' in format for Trino transformer when sql_dialect='trino' (#56565)

Signed-off-by: Craig <[email protected]>
(cherry picked from commit b8e05fe)
wanpengfei-git pushed a commit that referenced this pull request Mar 19, 2025
…time(...) with accepting 'T' and 'Z' in format for Trino transformer when sql_dialect='trino' (backport #56565) (#56789)

Co-authored-by: Craig <[email protected]>
wanpengfei-git pushed a commit that referenced this pull request Mar 19, 2025
…time(...) with accepting 'T' and 'Z' in format for Trino transformer when sql_dialect='trino' (backport #56565) (#56790)

Co-authored-by: Craig <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants