-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make row its crate to make it accessible from physical-expr
- Loading branch information
Showing
14 changed files
with
201 additions
and
133 deletions.
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
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 datafusion::datasource::file_format::parquet::ParquetFormat; | ||
use datafusion::datasource::file_format::FileFormat; | ||
use datafusion::datasource::listing::local_unpartitioned_file; | ||
use datafusion::error::Result; | ||
use datafusion::physical_plan::file_format::FileScanConfig; | ||
use datafusion::physical_plan::{collect, ExecutionPlan}; | ||
use datafusion::prelude::SessionContext; | ||
use datafusion_data_access::object_store::local::LocalFileSystem; | ||
use datafusion_data_access::object_store::local::{ | ||
local_object_reader, local_object_reader_stream, | ||
}; | ||
use datafusion_row::layout::RowType::{Compact, WordAligned}; | ||
use datafusion_row::reader::read_as_batch; | ||
use datafusion_row::writer::write_batch_unchecked; | ||
use std::sync::Arc; | ||
|
||
#[tokio::test] | ||
async fn test_with_parquet() -> Result<()> { | ||
let session_ctx = SessionContext::new(); | ||
let task_ctx = session_ctx.task_ctx(); | ||
let projection = Some(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); | ||
let exec = get_exec("alltypes_plain.parquet", &projection, None).await?; | ||
let schema = exec.schema().clone(); | ||
|
||
let batches = collect(exec, task_ctx).await?; | ||
assert_eq!(1, batches.len()); | ||
let batch = &batches[0]; | ||
|
||
let mut vector = vec![0; 20480]; | ||
let row_offsets = | ||
{ write_batch_unchecked(&mut vector, 0, batch, 0, schema.clone(), Compact) }; | ||
let output_batch = { read_as_batch(&vector, schema, &row_offsets, Compact)? }; | ||
assert_eq!(*batch, output_batch); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_with_parquet_word_aligned() -> Result<()> { | ||
let session_ctx = SessionContext::new(); | ||
let task_ctx = session_ctx.task_ctx(); | ||
let projection = Some(vec![0, 1, 2, 3, 4, 5, 6, 7]); | ||
let exec = get_exec("alltypes_plain.parquet", &projection, None).await?; | ||
let schema = exec.schema().clone(); | ||
|
||
let batches = collect(exec, task_ctx).await?; | ||
assert_eq!(1, batches.len()); | ||
let batch = &batches[0]; | ||
|
||
let mut vector = vec![0; 20480]; | ||
let row_offsets = | ||
{ write_batch_unchecked(&mut vector, 0, batch, 0, schema.clone(), WordAligned) }; | ||
let output_batch = { read_as_batch(&vector, schema, &row_offsets, WordAligned)? }; | ||
assert_eq!(*batch, output_batch); | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn get_exec( | ||
file_name: &str, | ||
projection: &Option<Vec<usize>>, | ||
limit: Option<usize>, | ||
) -> Result<Arc<dyn ExecutionPlan>> { | ||
let testdata = datafusion::test_util::parquet_test_data(); | ||
let filename = format!("{}/{}", testdata, file_name); | ||
let format = ParquetFormat::default(); | ||
let file_schema = format | ||
.infer_schema(local_object_reader_stream(vec![filename.clone()])) | ||
.await | ||
.expect("Schema inference"); | ||
let statistics = format | ||
.infer_stats(local_object_reader(filename.clone()), file_schema.clone()) | ||
.await | ||
.expect("Stats inference"); | ||
let file_groups = vec![vec![local_unpartitioned_file(filename.clone())]]; | ||
let exec = format | ||
.create_physical_plan( | ||
FileScanConfig { | ||
object_store: Arc::new(LocalFileSystem {}), | ||
file_schema, | ||
file_groups, | ||
statistics, | ||
projection: projection.clone(), | ||
limit, | ||
table_partition_cols: vec![], | ||
}, | ||
&[], | ||
) | ||
.await?; | ||
Ok(exec) | ||
} |
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,45 @@ | ||
# 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 = "datafusion-row" | ||
description = "Row backed by raw bytes for DataFusion query engine" | ||
version = "7.0.0" | ||
homepage = "https://github.com/apache/arrow-datafusion" | ||
repository = "https://github.com/apache/arrow-datafusion" | ||
readme = "../README.md" | ||
authors = ["Apache Arrow <dev@arrow.apache.org>"] | ||
license = "Apache-2.0" | ||
keywords = [ "arrow", "query", "sql" ] | ||
edition = "2021" | ||
rust-version = "1.59" | ||
|
||
[lib] | ||
name = "datafusion_row" | ||
path = "src/lib.rs" | ||
|
||
[features] | ||
# Used to enable JIT code generation | ||
jit = ["datafusion-jit"] | ||
|
||
[dependencies] | ||
arrow = { version = "11.1" } | ||
datafusion-common = { path = "../common", version = "7.0.0" } | ||
datafusion-expr = { path = "../expr", version = "7.0.0" } | ||
datafusion-jit = { path = "../jit", version = "7.0.0", optional = true } | ||
paste = "^1.0" | ||
rand = "0.8" |
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
Oops, something went wrong.