-
Notifications
You must be signed in to change notification settings - Fork 270
Experimental: Native CSV files read #3044
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
40
commits into
apache:main
Choose a base branch
from
kazantsev-maksim:native_csv_read
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.
+539
−61
Open
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
1c19b51
Work
062296f
Merge remote-tracking branch 'origin/main' into native_csv_read
0d9355f
Work
4479678
Merge remote-tracking branch 'origin/main' into native_csv_read
6c12812
Work
b601956
work
2ffd9cb
Merge remote-tracking branch 'origin/main' into native_csv_read
c685235
work
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 2be0069
Merge remote-tracking branch 'origin/main' into native_csv_read
7ea16ee
work
c521006
work
9500bbb
Merge branch 'apache:main' into main
kazantsev-maksim 9577481
Merge branch 'apache:main' into main
kazantsev-maksim 8796a68
Merge remote-tracking branch 'origin/main' into native_csv_read
0f06936
WIP
033ba8b
WIP
dafa0de
WIP
1809df8
Work
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 d8c7760
Final approach
88aeb33
Fix workflows
b2a0c28
Fix fmt
ba98e37
Fix params
cd449c5
Fix tests
a1801c1
Fix rust fmt
65251eb
Fix fmt
a151b2c
Merge branch 'apache:main' into main
kazantsev-maksim ad3e7f5
Merge branch 'apache:main' into main
kazantsev-maksim da73c27
Merge remote-tracking branch 'origin/main' into native_csv_read
a21ae07
Fix tests
bb5debe
Run tpch
ea92e4b
Merge branch 'apache:main' into main
kazantsev-maksim 2cc6a98
Merge remote-tracking branch 'origin/main' into native_csv_read
139ecff
Add spark options to tpcbench.py
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
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,86 @@ | ||
| // 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 crate::execution::operators::ExecutionError; | ||
| use arrow::datatypes::{Field, SchemaRef}; | ||
| use datafusion::common::DataFusionError; | ||
| use datafusion::common::Result; | ||
| use datafusion::datasource::object_store::ObjectStoreUrl; | ||
| use datafusion::datasource::physical_plan::CsvSource; | ||
| use datafusion_comet_proto::spark_operator::CsvOptions; | ||
| use datafusion_datasource::file_groups::FileGroup; | ||
| use datafusion_datasource::file_scan_config::{FileScanConfig, FileScanConfigBuilder}; | ||
| use datafusion_datasource::source::DataSourceExec; | ||
| use datafusion_datasource::PartitionedFile; | ||
| use itertools::Itertools; | ||
| use std::sync::Arc; | ||
|
|
||
| pub fn init_csv_datasource_exec( | ||
| object_store_url: ObjectStoreUrl, | ||
| file_groups: Vec<Vec<PartitionedFile>>, | ||
| data_schema: SchemaRef, | ||
| partition_schema: SchemaRef, | ||
| projection_vector: Vec<usize>, | ||
| csv_options: &CsvOptions, | ||
| ) -> Result<Arc<DataSourceExec>, ExecutionError> { | ||
| let csv_source = build_csv_source(csv_options.clone()); | ||
|
|
||
| let file_groups = file_groups | ||
| .iter() | ||
| .map(|files| FileGroup::new(files.clone())) | ||
| .collect(); | ||
|
|
||
| let partition_fields = partition_schema | ||
| .fields() | ||
| .iter() | ||
| .map(|field| Field::new(field.name(), field.data_type().clone(), field.is_nullable())) | ||
| .collect_vec(); | ||
|
|
||
| let file_scan_config: FileScanConfig = | ||
| FileScanConfigBuilder::new(object_store_url, data_schema, csv_source) | ||
| .with_file_groups(file_groups) | ||
| .with_table_partition_cols(partition_fields) | ||
| .with_projection_indices(Some(projection_vector)) | ||
| .build(); | ||
|
|
||
| Ok(Arc::new(DataSourceExec::new(Arc::new(file_scan_config)))) | ||
| } | ||
|
|
||
| fn build_csv_source(options: CsvOptions) -> Arc<CsvSource> { | ||
| let delimiter = string_to_u8(&options.delimiter, "delimiter").unwrap(); | ||
| let quote = string_to_u8(&options.quote, "quote").unwrap(); | ||
| let escape = string_to_u8(&options.escape, "escape").unwrap(); | ||
| let terminator = string_to_u8(&options.terminator, "terminator").unwrap(); | ||
| let comment = options | ||
| .comment | ||
| .map(|c| string_to_u8(&c, "comment").unwrap()); | ||
| let csv_source = CsvSource::new(options.has_header, delimiter, quote) | ||
| .with_escape(Some(escape)) | ||
| .with_comment(comment) | ||
| .with_terminator(Some(terminator)) | ||
| .with_truncate_rows(options.truncated_rows); | ||
| Arc::new(csv_source) | ||
| } | ||
|
|
||
| fn string_to_u8(option: &str, option_name: &str) -> Result<u8> { | ||
| match option.as_bytes().first() { | ||
| Some(&ch) if ch.is_ascii() => Ok(ch), | ||
| _ => Err(DataFusionError::Configuration(format!( | ||
| "invalid {option_name} character '{option}': must be an ASCII character" | ||
| ))), | ||
| } | ||
| } |
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
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.
It is necessary to add the ability to pass CSV reading options.
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.
For CSV:
tpcbench.py
--name spark
--benchmark tpch
--data $TPCH_DATA
--queries $TPCH_QUERIES
--output .
--iterations 1
--format csv
--options '{"header": "true", "delimiter": ","}'