Skip to content

Commit

Permalink
add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove committed Mar 14, 2019
1 parent aea9f8a commit c3f71d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions rust/datafusion/src/datasource/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl ParquetTable {
}

impl Table for ParquetTable {

fn schema(&self) -> &Arc<Schema> {
&self.schema
}
Expand Down
22 changes: 22 additions & 0 deletions rust/datafusion/tests/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// under the License.

use std::cell::RefCell;
use std::env;
use std::rc::Rc;
use std::sync::Arc;

Expand All @@ -27,9 +28,22 @@ use arrow::datatypes::{DataType, Field, Schema};

use datafusion::execution::context::ExecutionContext;
use datafusion::execution::relation::Relation;
use datafusion::datasource::parquet::ParquetFile;
use datafusion::datasource::parquet::ParquetTable;
use datafusion::datasource::{RecordBatchIterator, Table};

const DEFAULT_BATCH_SIZE: usize = 1024 * 1024;

#[test]
fn parquet_query() {
let mut ctx = ExecutionContext::new();
ctx.register_table("alltypes_plain", load_parquet_table("alltypes_plain.parquet"));
let sql = "SELECT id, string_col FROM alltypes_plain";
let actual = execute(&mut ctx, sql);
let expected = "tbd".to_string();
assert_eq!(expected, actual);
}

#[test]
fn csv_query_with_predicate() {
let mut ctx = ExecutionContext::new();
Expand Down Expand Up @@ -163,6 +177,14 @@ fn register_csv(
ctx.register_csv(name, filename, &schema, true);
}

fn load_parquet_table(name: &str) -> Rc<Table> {
let testdata = env::var("PARQUET_TEST_DATA").unwrap();
let filename = format!("{}/{}", testdata, name);
let table = ParquetTable::new(&filename);
println!("{:?}", table.schema());
Rc::new(table)
}

/// Execute query and return result set as tab delimited string
fn execute(ctx: &mut ExecutionContext, sql: &str) -> String {
let results = ctx.sql(&sql, DEFAULT_BATCH_SIZE).unwrap();
Expand Down

0 comments on commit c3f71d7

Please sign in to comment.