Skip to content

Commit 5c189dc

Browse files
committed
[test] added proper integration tests
1 parent 1c7b0e7 commit 5c189dc

File tree

5 files changed

+287
-98
lines changed

5 files changed

+287
-98
lines changed

datafusion/src/execution/context.rs

-47
Original file line numberDiff line numberDiff line change
@@ -1153,8 +1153,6 @@ mod tests {
11531153
use crate::physical_plan::functions::{make_scalar_function, Volatility};
11541154
use crate::physical_plan::{collect, collect_partitioned};
11551155
use crate::test;
1156-
use crate::test::object_store::TestObjectStore;
1157-
use crate::test_util::arrow_test_data;
11581156
use crate::variable::VarType;
11591157
use crate::{
11601158
assert_batches_eq, assert_batches_sorted_eq,
@@ -3293,51 +3291,6 @@ mod tests {
32933291
Ok(())
32943292
}
32953293

3296-
#[tokio::test]
3297-
async fn read_files_from_partitioned_path() -> Result<()> {
3298-
let mut ctx = ExecutionContext::new();
3299-
3300-
let testdata = arrow_test_data();
3301-
let csv_file_path = format!("{}/csv/aggregate_test_100.csv", testdata);
3302-
let file_schema = aggr_test_schema();
3303-
let object_store = TestObjectStore::new_mirror(
3304-
csv_file_path,
3305-
&[
3306-
"mytable/date=2021-10-27/file.csv",
3307-
"mytable/date=2021-10-28/file.csv",
3308-
],
3309-
);
3310-
3311-
let mut options = ListingOptions::new(Arc::new(CsvFormat::default()));
3312-
options.table_partition_cols = vec!["date".to_owned()];
3313-
3314-
let table =
3315-
ListingTable::new(object_store, "mytable".to_owned(), file_schema, options);
3316-
3317-
ctx.register_table("t", Arc::new(table))?;
3318-
3319-
let result = ctx
3320-
.sql("SELECT c1, date FROM t WHERE date='2021-10-27' LIMIT 5")
3321-
.await?
3322-
.collect()
3323-
.await?;
3324-
3325-
let expected = vec![
3326-
"+----+------------+",
3327-
"| c1 | date |",
3328-
"+----+------------+",
3329-
"| a | 2021-10-27 |",
3330-
"| b | 2021-10-27 |",
3331-
"| b | 2021-10-27 |",
3332-
"| c | 2021-10-27 |",
3333-
"| d | 2021-10-27 |",
3334-
"+----+------------+",
3335-
];
3336-
assert_batches_sorted_eq!(expected, &result);
3337-
3338-
Ok(())
3339-
}
3340-
33413294
#[tokio::test]
33423295
async fn custom_query_planner() -> Result<()> {
33433296
let mut ctx = ExecutionContext::with_config(

datafusion/src/test/object_store.rs

+9-32
Original file line numberDiff line numberDiff line change
@@ -14,51 +14,35 @@
1414
// KIND, either express or implied. See the License for the
1515
// specific language governing permissions and limitations
1616
// under the License.
17-
1817
//! Object store implem used for testing
1918
2019
use std::{
21-
fs, io,
20+
io,
2221
io::{Cursor, Read},
2322
sync::Arc,
2423
};
2524

26-
use crate::datasource::object_store::{
27-
local::LocalFileSystem, FileMeta, FileMetaStream, ListEntryStream, ObjectReader,
28-
ObjectStore, SizedFile,
25+
use crate::{
26+
datasource::object_store::{
27+
FileMeta, FileMetaStream, ListEntryStream, ObjectReader, ObjectStore, SizedFile,
28+
},
29+
error::{DataFusionError, Result},
2930
};
30-
use crate::error::{DataFusionError, Result};
31-
3231
use async_trait::async_trait;
3332
use futures::{stream, AsyncRead, StreamExt};
3433

3534
#[derive(Debug)]
3635
/// An object store implem that is useful for testing.
37-
/// Can either generate `ObjectReader`s that are filled with zero-
38-
/// bytes or mirror a given file to multiple path.
36+
/// `ObjectReader`s are filled with zero bytes.
3937
pub struct TestObjectStore {
4038
/// The `(path,size)` of the files that "exist" in the store
4139
files: Vec<(String, u64)>,
42-
/// The file that will be read at all path. If none fille the
43-
/// file with zero-bytes.
44-
mirrored_file: Option<String>,
4540
}
4641

4742
impl TestObjectStore {
4843
pub fn new_arc(files: &[(&str, u64)]) -> Arc<dyn ObjectStore> {
4944
Arc::new(Self {
5045
files: files.iter().map(|f| (f.0.to_owned(), f.1)).collect(),
51-
mirrored_file: None,
52-
})
53-
}
54-
pub fn new_mirror(mirrored_file: String, paths: &[&str]) -> Arc<dyn ObjectStore> {
55-
let metadata = fs::metadata(&mirrored_file).expect("Local file metadata");
56-
Arc::new(Self {
57-
files: paths
58-
.iter()
59-
.map(|&f| (f.to_owned(), metadata.len()))
60-
.collect(),
61-
mirrored_file: Some(mirrored_file),
6246
})
6347
}
6448
}
@@ -96,15 +80,8 @@ impl ObjectStore for TestObjectStore {
9680

9781
fn file_reader(&self, file: SizedFile) -> Result<Arc<dyn ObjectReader>> {
9882
match self.files.iter().find(|item| file.path == item.0) {
99-
Some(&(_, size)) if size == file.size => {
100-
if let Some(mirrored_file) = &self.mirrored_file {
101-
Ok(LocalFileSystem {}.file_reader(SizedFile {
102-
path: mirrored_file.clone(),
103-
size,
104-
})?)
105-
} else {
106-
Ok(Arc::new(EmptyObjectReader(size)))
107-
}
83+
Some((_, size)) if *size == file.size => {
84+
Ok(Arc::new(EmptyObjectReader(*size)))
10885
}
10986
Some(_) => Err(DataFusionError::IoError(io::Error::new(
11087
io::ErrorKind::NotFound,

datafusion/tests/common.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
//! methods that are common to multiple integration test setups
19+
20+
use std::sync::Arc;
21+
22+
use arrow::datatypes::{DataType, Field, Schema, SchemaRef};
23+
24+
pub fn aggr_test_schema() -> SchemaRef {
25+
Arc::new(Schema::new(vec![
26+
Field::new("c1", DataType::Utf8, false),
27+
Field::new("c2", DataType::UInt32, false),
28+
Field::new("c3", DataType::Int8, false),
29+
Field::new("c4", DataType::Int16, false),
30+
Field::new("c5", DataType::Int32, false),
31+
Field::new("c6", DataType::Int64, false),
32+
Field::new("c7", DataType::UInt8, false),
33+
Field::new("c8", DataType::UInt16, false),
34+
Field::new("c9", DataType::UInt32, false),
35+
Field::new("c10", DataType::UInt64, false),
36+
Field::new("c11", DataType::Float32, false),
37+
Field::new("c12", DataType::Float64, false),
38+
Field::new("c13", DataType::Utf8, false),
39+
]))
40+
}

0 commit comments

Comments
 (0)