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

Parquet API: Could not convert timestamp before unix epoch to string/json #2897

Closed
AnthonyPoncet opened this issue Oct 19, 2022 · 2 comments · Fixed by #2899
Closed

Parquet API: Could not convert timestamp before unix epoch to string/json #2897

AnthonyPoncet opened this issue Oct 19, 2022 · 2 comments · Fixed by #2899
Labels
bug good first issue Good for newcomers help wanted parquet Changes to the parquet crate

Comments

@AnthonyPoncet
Copy link
Contributor

Describe the bug
Using the file::reader::SerializedFileReader in the parquet crate, I could not convert field of type timestamp with negative value (timestamp before UNIX epoch) to string. Issue exists with both micros and millis types. And I guess issue exist also while converting to JSON as it used same functions.

It seems to me that the i64 timestamp is converted into the Field enum as a u64. Then while using chrono to format it as string, it convert it back to i64 after divinding by 1000 where it should be before (see proposed fix bellow).

To Reproduce
In test test_convert_timestamp_to_string in file parquet/src/record/api.rs, change any tested date by something before 1970.
e.g: check_datetime_conversion(1969, 1, 2, 13, 12, 54);
-> Panic with the error No such local time

You could also create a parquet file with timestamp field and value before 1970 and then run

let file = File::open("<path>")?;
let reader = SerializedFileReader::new(file)?;
let mut row_iter = reader.get_row_iter(None)?;
while let Some(row) = row_iter.next() {
   let _ = row.get_column_iter()
                    .map(|c| c.1.to_string())
                    .collect::<Vec<String>>();
}

Expected behavior
Handling date before UNIX epoch but also do not panic.

Additional context
In the function convert_timestamp_millis_to_string changing let dt = Utc.timestamp((value / 1000) as i64, 0); to let dt = Utc.timestamp(value as i64 / 1000, 0); solve the issue.

Now I do not know the codeline enough to know if the fix should be the fix above or changing Field type to store a i64?

I could reproduce using both rust 1.63.0 and 1.64.0 on both Linux and Windows.

@AnthonyPoncet
Copy link
Contributor Author

Hello @nevi-me
I am new to contributing to this repo, sorry if it is a dummy question. I opened a PR #2899, what are the next steps ?
Thanks

@alamb alamb added the parquet Changes to the parquet crate label Oct 28, 2022
@alamb
Copy link
Contributor

alamb commented Oct 28, 2022

label_issue.py automatically added labels {'parquet'} from #2899

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Good for newcomers help wanted parquet Changes to the parquet crate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants