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

[Enhancement] Make str_to_date and str2date function can parse format only with year and month #52218

Closed
wants to merge 1 commit into from

Conversation

duanyyyyyyy
Copy link
Contributor

[Enhancement] Make str_to_date and str2date function can parse format only with year and month

Why I'm doing:

StarRocks will not support select str_to_date('202410', '%Y%m') query but in trino it can work

What I'm doing:

Set the parseDefaulting for MONTH_OF_YEAR and DAY_OF_MONTH in unixDatetimeFormatBuilder when the pattern is year or year month format pattern

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.3
    • 3.2
    • 3.1
    • 3.0
    • 2.5

@duanyyyyyyy duanyyyyyyy requested a review from a team as a code owner October 22, 2024 18:13
Copy link

Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

pass : 10 / 10 (100.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/common/util/DateUtils.java 1 1 100.00% []
🔵 com/starrocks/sql/optimizer/rewrite/ScalarOperatorFunctions.java 9 9 100.00% []

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@Seaven
Copy link
Contributor

Seaven commented Oct 23, 2024

sorry, can't be supported only on FE, should supported on BE too. Consider this scenario:

CREATE TABLE `t4` (
  `v1` int(11) NOT NULL COMMENT "",
  `v2` string NOT NULL COMMENT ""
) ENGINE=OLAP 
DUPLICATE KEY(`v1`)
COMMENT "olap"
DISTRIBUTED BY HASH(`v1`) BUCKETS 1 
PROPERTIES (
"replication_num" = "1"
);
insert into t4 values (1, "202010");
select str2date(v2, '%Y%m') from t4;

@wangsimo0
Copy link
Contributor

wangsimo0 commented Oct 23, 2024

thanks for contributing! but would you mind me asking for some details first? which function do you use in trino? I recommend you use year, month, and concat function to extract year and week.
that depends on which function you use in trino, if the function name differs, I recommend you modify the trino's SQL function transformer instead of modify these two functions. since these two functions are widely used in sr's create materialized view, this modification may cause potential problems. also date that only contains year and month is not a typical DATE type.

@duanyyyyyyy
Copy link
Contributor Author

duanyyyyyyy commented Oct 23, 2024

thanks for contributing! but would you mind me asking for some details first? which function do you use in trino? I recommend you use year, month, and concat function to extract year and week. that depends on which function you use in trino, if the function name differs, I recommend you modify the trino's SQL function transformer instead of modify these two functions. since these two functions are widely used in sr's create materialized view, this modification may cause potential problems. also date that only contains year and month is not a typical DATE type.

How about just change the str_to_date? I checked the code the MV will use str2date function

@duanyyyyyyy
Copy link
Contributor Author

sorry, can't be supported only on FE, should supported on BE too. Consider this scenario:

CREATE TABLE `t4` (
  `v1` int(11) NOT NULL COMMENT "",
  `v2` string NOT NULL COMMENT ""
) ENGINE=OLAP 
DUPLICATE KEY(`v1`)
COMMENT "olap"
DISTRIBUTED BY HASH(`v1`) BUCKETS 1 
PROPERTIES (
"replication_num" = "1"
);
insert into t4 values (1, "202010");
select str2date(v2, '%Y%m') from t4;

I will add some UT for BE

@duanyyyyyyy duanyyyyyyy closed this Jan 7, 2025
@duanyyyyyyy duanyyyyyyy deleted the str_to_date_enhance branch January 7, 2025 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants