-
Notifications
You must be signed in to change notification settings - Fork 267
Feat: to_csv #3004
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
Open
kazantsev-maksim
wants to merge
25
commits into
apache:main
Choose a base branch
from
kazantsev-maksim:to_csv
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat: to_csv #3004
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
768b3e9
impl map_from_entries
c68c342
Revert "impl map_from_entries"
d887555
Merge branch 'apache:main' into main
kazantsev-maksim 231aa90
Merge branch 'apache:main' into main
kazantsev-maksim 9500bbb
Merge branch 'apache:main' into main
kazantsev-maksim 5d153e9
work
f0f03d4
WIP
4b02dd6
WIP
9577481
Merge branch 'apache:main' into main
kazantsev-maksim 0f98a3c
Add benchmark test
d7a6036
WIP
3791557
Merge branch 'apache:main' into main
kazantsev-maksim 7c2f082
Merge branch 'apache:main' into main
kazantsev-maksim 609a605
Merge branch 'apache:main' into main
kazantsev-maksim a151b2c
Merge branch 'apache:main' into main
kazantsev-maksim e89c8f2
Merge remote-tracking branch 'origin/main' into to_csv
902eb3a
Add benchmark
86c17e8
add more options
1bbc314
Revert
55388da
Work
c93d256
Work
3a51b62
Fix tests
93458cf
Fix tests
773aaba
Fix clippy warnings
cf544c7
Fix tests
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,108 @@ | ||
| // 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 arrow::array::{ | ||
| BooleanBuilder, Int16Builder, Int32Builder, Int64Builder, Int8Builder, StringBuilder, | ||
| StructArray, StructBuilder, | ||
| }; | ||
| use arrow::datatypes::{DataType, Field}; | ||
| use criterion::{criterion_group, criterion_main, Criterion}; | ||
| use datafusion_comet_spark_expr::{to_csv_inner, CsvWriteOptions, EvalMode, SparkCastOptions}; | ||
| use std::hint::black_box; | ||
|
|
||
| fn create_struct_array(array_size: usize) -> StructArray { | ||
| let fields = vec![ | ||
| Field::new("f1", DataType::Boolean, true), | ||
| Field::new("f2", DataType::Int8, true), | ||
| Field::new("f3", DataType::Int16, true), | ||
| Field::new("f4", DataType::Int32, true), | ||
| Field::new("f5", DataType::Int64, true), | ||
| Field::new("f6", DataType::Utf8, true), | ||
| ]; | ||
| let mut struct_builder = StructBuilder::from_fields(fields, array_size); | ||
| for i in 0..array_size { | ||
| struct_builder | ||
| .field_builder::<BooleanBuilder>(0) | ||
| .unwrap() | ||
| .append_option(if i % 10 == 0 { None } else { Some(i % 2 == 0) }); | ||
|
|
||
| struct_builder | ||
| .field_builder::<Int8Builder>(1) | ||
| .unwrap() | ||
| .append_option(if i % 10 == 0 { | ||
| None | ||
| } else { | ||
| Some((i % 128) as i8) | ||
| }); | ||
|
|
||
| struct_builder | ||
| .field_builder::<Int16Builder>(2) | ||
| .unwrap() | ||
| .append_option(if i % 10 == 0 { None } else { Some(i as i16) }); | ||
|
|
||
| struct_builder | ||
| .field_builder::<Int32Builder>(3) | ||
| .unwrap() | ||
| .append_option(if i % 10 == 0 { None } else { Some(i as i32) }); | ||
|
|
||
| struct_builder | ||
| .field_builder::<Int64Builder>(4) | ||
| .unwrap() | ||
| .append_option(if i % 10 == 0 { None } else { Some(i as i64) }); | ||
|
|
||
| struct_builder | ||
| .field_builder::<StringBuilder>(5) | ||
| .unwrap() | ||
| .append_option(if i % 10 == 0 { | ||
| None | ||
| } else { | ||
| Some(format!("string_{}", i)) | ||
| }); | ||
|
|
||
| struct_builder.append(true); | ||
| } | ||
| struct_builder.finish() | ||
| } | ||
|
|
||
| fn criterion_benchmark(c: &mut Criterion) { | ||
| let array_size = 8192; | ||
| let timezone = "UTC"; | ||
| let struct_array = create_struct_array(array_size); | ||
| let default_delimiter = ","; | ||
| let default_null_value = ""; | ||
| let default_quote = "\""; | ||
| let default_escape = "\\"; | ||
| let mut cast_options = SparkCastOptions::new(EvalMode::Legacy, timezone, false); | ||
| cast_options.null_string = default_null_value.to_string(); | ||
| let csv_write_options = CsvWriteOptions::new( | ||
| default_delimiter.to_string(), | ||
| default_quote.to_string(), | ||
| default_escape.to_string(), | ||
| default_null_value.to_string(), | ||
| false, | ||
| true, | ||
| true, | ||
| ); | ||
| c.bench_function("to_csv", |b| { | ||
| b.iter(|| { | ||
| black_box(to_csv_inner(&struct_array, &cast_options, &csv_write_options).unwrap()) | ||
| }) | ||
| }); | ||
| } | ||
|
|
||
| criterion_group!(benches, criterion_benchmark); | ||
| criterion_main!(benches); |
This file contains hidden or 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,61 @@ | ||
| // 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 std::fmt::{Display, Formatter}; | ||
|
|
||
| #[derive(Debug, Clone, Hash, PartialEq, Eq)] | ||
| pub struct CsvWriteOptions { | ||
| pub delimiter: String, | ||
| pub quote: String, | ||
| pub escape: String, | ||
| pub null_value: String, | ||
| pub quote_all: bool, | ||
| pub ignore_leading_white_space: bool, | ||
| pub ignore_trailing_white_space: bool, | ||
| } | ||
|
|
||
| impl Display for CsvWriteOptions { | ||
| fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
| write!( | ||
| f, | ||
| "csv_write_options(quote={}, escape={}, null_value={}, quote_all={}, ignore_leading_white_space={}, ignore_trailing_white_space={})", | ||
| self.quote, self.escape, self.null_value, self.quote_all, self.ignore_leading_white_space, self.ignore_trailing_white_space | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| impl CsvWriteOptions { | ||
| pub fn new( | ||
| delimiter: String, | ||
| quote: String, | ||
| escape: String, | ||
| null_value: String, | ||
| quote_all: bool, | ||
| ignore_leading_white_space: bool, | ||
| ignore_trailing_white_space: bool, | ||
| ) -> Self { | ||
| Self { | ||
| delimiter, | ||
| quote, | ||
| escape, | ||
| null_value, | ||
| quote_all, | ||
| ignore_leading_white_space, | ||
| ignore_trailing_white_space, | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,22 @@ | ||
| // 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. | ||
|
|
||
| mod csv_write_options; | ||
| mod to_csv; | ||
|
|
||
| pub use csv_write_options::CsvWriteOptions; | ||
| pub use to_csv::{to_csv_inner, ToCsv}; |
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.
All settings: https://spark.apache.org/docs/latest/sql-data-sources-csv.html