yaooqinn opened a new pull request #27906: [SPARK-31150][SQL] Parsing seconds 
fraction with variable length for timestamp
URL: https://github.com/apache/spark/pull/27906
 
 
   ### What changes were proposed in this pull request?
   This PR is to support parsing timestamp values with variable length second 
fraction parts.
   
   e.g. 'yyyy-MM-dd HH:mm:ss.SSSSSS[zzz]' can parse timestamp with 0~6 
digit-length second fraction but fail >=7
   ```sql
   select to_timestamp(v, 'yyyy-MM-dd HH:mm:ss.SSSSSS[zzz]') from values
    ('2019-10-06 10:11:12.'),
    ('2019-10-06 10:11:12.0'),
    ('2019-10-06 10:11:12.1'),
    ('2019-10-06 10:11:12.12'),
    ('2019-10-06 10:11:12.123UTC'),
    ('2019-10-06 10:11:12.1234'),
    ('2019-10-06 10:11:12.12345CST'),
    ('2019-10-06 10:11:12.123456PST') t(v)
   2019-10-06 03:11:12.123
   2019-10-06 08:11:12.12345
   2019-10-06 10:11:12
   2019-10-06 10:11:12
   2019-10-06 10:11:12.1
   2019-10-06 10:11:12.12
   2019-10-06 10:11:12.1234
   2019-10-06 10:11:12.123456
   
   select to_timestamp('2019-10-06 10:11:12.1234567PST', 'yyyy-MM-dd 
HH:mm:ss.SSSSSS[zzz]')
   NULL
   ```
   Since 3.0, we use java 8 time API to parse and format timestamp values. when 
we create the `DateTimeFormatter`, we use `appendPattern` to create the build 
first, where the 'S..S' part will be parsed to a fixed-length(= 
`'S..S'.length`). This fits the formatting part but too strict for the parsing 
part because the trailing zeros are very likely to be truncated.
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   improve timestamp parsing
   
   ### Does this PR introduce any user-facing change?
   <!--
   If yes, please clarify the previous behavior and the change this PR proposes 
- provide the console output, description and/or an example to show the 
behavior difference if possible.
   If no, write 'No'.
   -->
   
   no, the related changes are newly added
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some 
test cases that check the changes thoroughly including negative and positive 
cases if possible.
   If it was tested in a way different from regular unit tests, please clarify 
how you tested step by step, ideally copy and paste-able, so that other 
reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why 
it was difficult to add.
   -->
   add uts

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to