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

Fix long overflow in extended_string_to_timestamp #36

Merged
merged 2 commits into from
Mar 15, 2022

Conversation

emavgl
Copy link
Collaborator

@emavgl emavgl commented Mar 15, 2022

Problem: Casting a very long string of numbers into timestamp cause long overflow exception.

How to reproduce:

sample_data_json = '''
[
{"input_value": "-5355957305054330880"},
{"input_value": "9223372036854775807"},
{"input_value": "1.547035982469E12"}
]
'''

df = spark.read.json(sc.parallelize([sample_data_json]))

display(df.withColumn("converted", F.col("input_value").cast(T.LongType())).withColumn("to_timestamp", extended_string_to_timestamp(F.col("input_value"), "to_timestamp")))

Fix:

  • Add extra condition that returns None if the input value exceed the maximum allowed timestamp value in seconds (MAX_TIMESTAMP_MS)

Bump to new version of spooq --> 3.3.7

@emavgl emavgl added the test-it Triggers github test action label Mar 15, 2022
@emavgl emavgl requested a review from Breaka84 March 15, 2022 13:16
@Breaka84 Breaka84 added test-it Triggers github test action and removed test-it Triggers github test action labels Mar 15, 2022
@emavgl emavgl merged commit d44eb5a into master Mar 15, 2022
@emavgl emavgl deleted the fix_string_to_timestamp branch March 15, 2022 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test-it Triggers github test action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants