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

Serializing timestamp from int (json raw decoder) #4069

Closed
spebern opened this issue Apr 12, 2023 · 1 comment · Fixed by #4073
Closed

Serializing timestamp from int (json raw decoder) #4069

spebern opened this issue Apr 12, 2023 · 1 comment · Fixed by #4073
Labels
arrow Changes to the arrow crate question Further information is requested

Comments

@spebern
Copy link
Contributor

spebern commented Apr 12, 2023

Which part is this question about

arrow-json

Describe your question

This test fails in arrow-json/src/raw/mod.rs, because 1681319393 is parsed via string conversion. Should it be possible to parse timestamps from ints? I think it was possible in the old json decoder.

    #[test]
    fn test_serialize_timestamp() {
        let json = vec![
            json!({"timestamp": 1681319393}),
            json!({"timestamp": "1970-01-01T00:00:00+02:00"}),
        ];
        let schema = Schema::new(vec![Field::new(
            "timestamp",
            DataType::Timestamp(TimeUnit::Second, None),
            true,
        )]);
        let mut decoder = RawReaderBuilder::new(Arc::new(schema))
            .build_decoder()
            .unwrap();
        decoder.serialize(&json).unwrap();
        let batch = decoder.flush().unwrap().unwrap();
        assert_eq!(batch.num_rows(), 1);
        assert_eq!(batch.num_columns(), 2);
        let values = batch.column(0).as_primitive::<Int64Type>().values();
        assert_eq!(values, &[1681319393, 1599572549]);
    }

Errror:

---- raw::tests::test_serialize_timestamp stdout ----
thread 'raw::tests::test_serialize_timestamp' panicked at 'called `Result::unwrap()` on an `Err` value: JsonError("failed to parse \"1681319393\" as Timestamp(Second, None): Parser error: Error parsing timestamp from '1681319393': error parsing date")', arrow-json/src/raw/mod.rs:1294:37
```
@spebern spebern added the question Further information is requested label Apr 12, 2023
tustvold added a commit to tustvold/arrow-rs that referenced this issue Apr 12, 2023
@tustvold tustvold added the arrow Changes to the arrow crate label Apr 21, 2023
@tustvold
Copy link
Contributor

label_issue.py automatically added labels {'arrow'} from #4073

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants