This repository has been archived by the owner on Jan 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
parquet_derive for the new RecordWriter trait #197
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
38ec590
parquet_derive WIP
xrl 5b0c5f4
Handles more combinations of data
xrl 44461f2
Writes simple types behind an Option
xrl 2bdbbfd
Basic README
xrl 313bd7e
Merge remote-tracking branch 'upstream/master' into parquet_derive
xrl 5c7e8fd
Put parquet_derive in the test harness
xrl 451c51c
Unused variables
xrl e4cee5b
cargo fmt pass to make travis happy
xrl a0c9792
Supports borrowed Option
xrl 99eb1d1
Merge remote-tracking branch 'upstream/master' into parquet_derive
xrl 3b0ae7a
cargo fmt
xrl 1f6d829
Avoid moves when emitting code for String
xrl 38326b6
edits from feedback
xrl 22e6653
The writer moved
xrl fcf86b7
removing whitespace
xrl 71ed787
newline at end of file
xrl 29b397c
cargo fmt
xrl 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Cargo.lock | ||
/target | ||
target | ||
**/*.rs.bk |
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,14 @@ | ||
[package] | ||
name = "parquet_derive" | ||
version = "0.1.0" | ||
authors = ["Xavier Lange <xrlange@gmail.com>"] | ||
edition = "2018" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
proc-macro2 = "0.4" | ||
quote = "0.6.10" | ||
syn = { version = "0.15.22", features = ["extra-traits"] } | ||
parquet = { path = ".." } |
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,91 @@ | ||
<!--- | ||
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-rs | ||
|
||
A crate for automatically deriving `RecordWriter` for arbitrary, _simple_ structs. This does not generate writers for nested structures but it will work great for shallow structures. | ||
|
||
## Usage | ||
Add this to your Cargo.toml: | ||
```toml | ||
[dependencies] | ||
parquet = "0.4" | ||
parquet_derive = "0.4" | ||
``` | ||
|
||
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 = ... | ||
|
||
// 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` | ||
- [ ] Support writing dictionaries | ||
- [ ] Support writing logical types like timestamp | ||
- [X] Derive definition_levels for `Option` | ||
- [ ] Derive definition levels for nested structures | ||
|
||
## 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.
Byte arrays and unsigned variants?
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.
Good call on the unsigned variants. To be clear, to satisfy that requirement I need to add
u32
/u64
, right? Parquet does not handle 8 or 16 bit values, right?And when it comes to "byte arrays", are you talking fixed-sized arrays like
let arr : [u8; 16] = [0; 16];
? Or do you meanlet vec : Vec<u8> = vec![0; 16];
? I haven't used either of those in parquet-rs so I need a little guidance.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.
By "byte arrays" I meant parquet type ByteArray, not just strings.
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.
@sadikovi how do I write unsigned variants? I don't see a column writer for that.