1616// under the License.
1717
1818use std:: cell:: RefCell ;
19+ use std:: env;
1920use std:: rc:: Rc ;
2021use std:: sync:: Arc ;
2122
@@ -27,9 +28,22 @@ use arrow::datatypes::{DataType, Field, Schema};
2728
2829use datafusion:: execution:: context:: ExecutionContext ;
2930use datafusion:: execution:: relation:: Relation ;
31+ use datafusion:: datasource:: parquet:: ParquetFile ;
32+ use datafusion:: datasource:: parquet:: ParquetTable ;
33+ use datafusion:: datasource:: { RecordBatchIterator , Table } ;
3034
3135const DEFAULT_BATCH_SIZE : usize = 1024 * 1024 ;
3236
37+ #[ test]
38+ fn parquet_query ( ) {
39+ let mut ctx = ExecutionContext :: new ( ) ;
40+ ctx. register_table ( "alltypes_plain" , load_parquet_table ( "alltypes_plain.parquet" ) ) ;
41+ let sql = "SELECT id, string_col FROM alltypes_plain" ;
42+ let actual = execute ( & mut ctx, sql) ;
43+ let expected = "tbd" . to_string ( ) ;
44+ assert_eq ! ( expected, actual) ;
45+ }
46+
3347#[ test]
3448fn csv_query_with_predicate ( ) {
3549 let mut ctx = ExecutionContext :: new ( ) ;
@@ -163,6 +177,14 @@ fn register_csv(
163177 ctx. register_csv ( name, filename, & schema, true ) ;
164178}
165179
180+ fn load_parquet_table ( name : & str ) -> Rc < Table > {
181+ let testdata = env:: var ( "PARQUET_TEST_DATA" ) . unwrap ( ) ;
182+ let filename = format ! ( "{}/{}" , testdata, name) ;
183+ let table = ParquetTable :: new ( & filename) ;
184+ println ! ( "{:?}" , table. schema( ) ) ;
185+ Rc :: new ( table)
186+ }
187+
166188/// Execute query and return result set as tab delimited string
167189fn execute ( ctx : & mut ExecutionContext , sql : & str ) -> String {
168190 let results = ctx. sql ( & sql, DEFAULT_BATCH_SIZE ) . unwrap ( ) ;
0 commit comments