-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
ARROW-5123: [Rust] Parquet derive for simple structs #4140
Closed
Closed
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
7c50980
Migrating from strings to smarter enum derive
xrl 90cd1ee
Aggressive reformat
xrl 7b54759
Refactor to pull out leaf type, comments of old code still present
xrl 09fb15e
Comments removed and code formatted
xrl 73317f6
ColumnWriter syn type from custom Type
xrl cff71c9
Tests pass
xrl ff626ca
No parquet data files in git
xrl e7fdbc4
Licenses
xrl 74d112f
rustfmt pass
xrl 5208f93
NaiveDateTime support behind a feature flag
xrl b14cda3
test optional timestamps, add panic for schema/struct field mismatch
xrl e844133
WIP
xrl 700dea4
Feedback from PR
xrl f964a1c
More feedback changes
xrl 13453ac
More feedback changes
xrl 98b3321
cargo fmt pass
xrl 021ec6f
reintroducing the records alias with a comment
xrl d93e84a
Release script uses wildcards for READMEs
xrl 934aa8f
Cast num_days to i32
xrl e8e3381
UUID feature and tests
xrl 8d557e5
Propagate errors
xrl ec7086c
Switch to parse_quote
xrl 4766b53
Less unwrap
xrl e91f9e5
Switch to simpler recursive definition
xrl c98cef7
nit
xrl 7bfa155
Some comments for a tricky bit
xrl 57a05b0
No more generic x variable, use better names
xrl 001ae1b
cargo fmt
xrl 63de331
another rust fmt
xrl bf0a468
Sample program for parquet derive in the rust doc
xrl 4ca84ad
Simplify checking length of generic args, skip using an iterator
xrl d04b112
- Update versions to latest
bryantbiggs 76c65ef
Update error messages
bryantbiggs 90a8f12
fix version in README
nevi-me abb8fe2
fix release script and failing test
nevi-me d1d7261
Update parquet_derive version
kou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use super::super::errors::ParquetError; | ||
use super::super::file::writer::RowGroupWriter; | ||
|
||
pub trait RecordWriter<T> { | ||
fn write_to_row_group( | ||
&self, | ||
row_group_writer: &mut Box<RowGroupWriter>, | ||
) -> Result<(), ParquetError>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we can import and use the result type from |
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
[package] | ||
name = "parquet_derive" | ||
version = "2.0.0-SNAPSHOT" | ||
authors = ["Apache Arrow <dev@arrow.apache.org>"] | ||
keywords = [ "parquet" ] | ||
edition = "2018" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[features] | ||
chrono = [] | ||
bigdecimal = [] | ||
uuid = [] | ||
|
||
[dependencies] | ||
proc-macro2 = "1.0.8" | ||
quote = "1.0.2" | ||
syn = { version = "1.0.14", features = ["full", "extra-traits"] } | ||
parquet = { path = "../parquet", version = "2.0.0-SNAPSHOT" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<!--- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
|
||
# Parquet Derive | ||
|
||
A crate for deriving `RecordWriter` for arbitrary, _simple_ structs. This does not generate writers for arbitrarily nested | ||
structures. It only works for primitives and a few generic structures and | ||
various levels of reference. Please see features checklist for what is currently | ||
supported. | ||
|
||
Derive also has some support for the chrono time library. You must must enable the `chrono` feature to get this support. | ||
|
||
## Usage | ||
Add this to your Cargo.toml: | ||
```toml | ||
[dependencies] | ||
parquet = "2.0.0-SNAPSHOT" | ||
parquet_derive = "2.0.0-SNAPSHOT" | ||
``` | ||
xrl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
and this to your crate root: | ||
```rust | ||
extern crate parquet; | ||
#[macro_use] extern crate parquet_derive; | ||
``` | ||
|
||
Example usage of deriving a `RecordWriter` for your struct: | ||
|
||
```rust | ||
use parquet; | ||
use parquet::record::RecordWriter; | ||
|
||
#[derive(ParquetRecordWriter)] | ||
struct ACompleteRecord<'a> { | ||
pub a_bool: bool, | ||
pub a_str: &'a str, | ||
pub a_string: String, | ||
pub a_borrowed_string: &'a String, | ||
pub maybe_a_str: Option<&'a str>, | ||
pub magic_number: i32, | ||
pub low_quality_pi: f32, | ||
pub high_quality_pi: f64, | ||
pub maybe_pi: Option<f32>, | ||
pub maybe_best_pi: Option<f64>, | ||
} | ||
|
||
// Initialize your parquet file | ||
let mut writer = SerializedFileWriter::new(file, schema, props).unwrap(); | ||
let mut row_group = writer.next_row_group().unwrap(); | ||
|
||
// Build up your records | ||
let chunks = vec![ACompleteRecord{...}]; | ||
|
||
// The derived `RecordWriter` takes over here | ||
(&chunks[..]).write_to_row_group(&mut row_group); | ||
|
||
writer.close_row_group(row_group).unwrap(); | ||
writer.close().unwrap(); | ||
``` | ||
|
||
## Features | ||
- [X] Support writing `String`, `&str`, `bool`, `i32`, `f32`, `f64`, `Vec<u8>` | ||
- [ ] Support writing dictionaries | ||
- [X] Support writing logical types like timestamp | ||
- [X] Derive definition_levels for `Option` | ||
- [ ] Derive definition levels for nested structures | ||
- [ ] Derive writing tuple struct | ||
- [ ] Derive writing `tuple` container types | ||
|
||
## Requirements | ||
- Same as `parquet-rs` | ||
|
||
## Test | ||
Testing a `*_derive` crate requires an intermediate crate. Go to `parquet_derive_test` and run `cargo test` for | ||
unit tests. | ||
|
||
## Docs | ||
To build documentation, run `cargo doc --no-deps`. | ||
To compile and view in the browser, run `cargo doc --no-deps --open`. | ||
|
||
## License | ||
Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Thinking whether we can have a higher API, so that users do not need to directly manipulate row groups. Instead, could we pass a file writer, like the following?
this internally will write a row group for each call.