-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
[FLINK-15602][table-planner-blink] Padding TIMESTAMP type to respect … #10877
Conversation
…the precision when casting timestamp to varchar
Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community Automated ChecksLast check on commit c53d150 (Fri Jan 17 06:19:25 UTC 2020) Warnings:
Mention the bot in a comment to re-run the automated checks. Review Progress
Please see the Pull Request Review Guide for a full explanation of the review process. The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required Bot commandsThe @flinkbot bot supports the following commands:
|
"MAP[TIME '14:15:16', TIMESTAMP '1985-04-11 14:15:16', " + | ||
"TIME '17:18:19', TIMESTAMP '2018-07-26 17:18:19']", | ||
"TIME '17:18:19', TIMESTAMP '2018-07-26 17:18:19']", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find that we have a lot of this changes that remove the toTimestamp
from the tests.
I'm wondering could we align the toTimestamp
with the SQL timestmap literal?
Currently "2018-07-26 17:18:19".toTimestamp
actually calls "2018-07-26 17:18:19".cast(DataTypes.TIMESTAMP(3))
, however, according to the javadoc of toTimestamp
, it should be the same with SQL TIMESTAMP string
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently toTimestamp in Table API can't align to Timestamp literal, because it use SqlTimeTypeInfo.TIMESTAMP
as the target type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no such thing in table API which align to Timestamp literal in SQL. I will add some comments to clarify this.
@@ -795,8 +794,8 @@ class TemporalTypesTest extends ExpressionTestBase { | |||
def testTemporalShanghai(): Unit = { | |||
config.setLocalTimeZone(ZoneId.of("Asia/Shanghai")) | |||
|
|||
testSqlApi(timestampTz("2018-03-14 19:01:02.123"), "2018-03-14 19:01:02.123") | |||
testSqlApi(timestampTz("2018-03-14 19:00:00.010"), "2018-03-14 19:00:00.01") | |||
testSqlApi(timestampTz("2018-03-14 19:01:02.123"), "2018-03-14 19:01:02.123000") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, we don't have a way to construct TIMESTAMP WITH LOCAL TIME ZONE literal. timestampTz
will lose the original timestamp literal precision and use a default 6 precision. The tests are counter-intuitive because we are padding zeros for a timestamp literal.
Could we improve the timestampTz
a little bit? It can extract precision from the literal string, and cast to the local timestamp with the extracted precison.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timestampTz(expr)
is a shortcut of CAST(expr AS TIMESTAMP WITH LOCAL TIME ZONE)
, Do you mean we should provide a builtin UDF to convert TIMESTAMP literal to TIMESTAMP WITH LOCAL TIME ZONE?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean we should improve timestampTz
to convert timestamp without precision loss.
private def timestampTz(str: String) = {
val precision = extractPrecision(str)
s"CAST(TIMESTAMP '$str' AS TIMESTAMP($precision) WITH LOCAL TIME ZONE)"
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, According to SQL standard, for timestamp literal, the length of the second fraction should be the precision.
…o respect the precision when casting timestamp to varchar This closes apache#10877
…o respect the precision when casting timestamp to varchar This closes apache#10877
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I also verified the e2e test in my local machine, need some modification on the e2e tests.
Will merge this.
…o respect the precision when casting timestamp to varchar This closes apache#10877
…o respect the precision when casting timestamp to varchar This closes #10877
…o respect the precision when casting timestamp to varchar This closes apache#10877
…o respect the precision when casting timestamp to varchar This closes apache#10877
…the precision when casting timestamp to varchar
What is the purpose of the change
According to SQL 2011 Part 2 Section 6.13 General Rules 11) d)
This PR padding the TIMESTAMP type to respect the precision when casting timestamp to varchar.
Brief change log
Verifying this change
This change is already covered by existing tests, such as TempralTypeTests.
Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: (yes / no)Documentation