Skip to content

Apache DataFusion SQL Query Engine

Register table based on known schema (#872)

Daniël Heres5c7f1abe6f6b
diff --git a/benchmarks/src/bin/tpch.rs b/benchmarks/src/bin/tpch.rs
index a1594e56b4..29835e2665 100644
--- a/benchmarks/src/bin/tpch.rs
+++ b/benchmarks/src/bin/tpch.rs
@@ -475,7 +475,13 @@ fn get_table(
}
"parquet" => {
let path = format!("{}/{}", path, table);
- Ok(Arc::new(ParquetTable::try_new(&path, max_concurrency)?))
+ let schema = get_schema(table);
+ Ok(Arc::new(ParquetTable::try_new_with_schema(
+ &path,
+ schema,
+ max_concurrency,
+ false,
+ )?))
}
other => {
unimplemented!("Invalid file format '{}'", other);
diff --git a/datafusion/src/datasource/parquet.rs b/datafusion/src/datasource/parquet.rs
index 28f79a6ae8..d312c77245 100644
--- a/datafusion/src/datasource/parquet.rs
+++ b/datafusion/src/datasource/parquet.rs
@@ -56,6 +56,35 @@ impl ParquetTable {
})
}
+ /// Attempt to initialize a new `ParquetTable` from a file path and known schema.
+ /// If collect_statistics is `false`, doesn't read files until necessary by scan
+ pub fn try_new_with_schema(
+ path: impl Into<String>,
+ schema: Schema,
+ max_concurrency: usize,
+ collect_statistics: bool,
+ ) -> Result<Self> {
+ let path = path.into();
+ if collect_statistics {
+ let parquet_exec = ParquetExec::try_from_path(&path, None, None, 0, 1, None)?;
+ Ok(Self {
+ path,
+ schema: Arc::new(schema),
+ statistics: parquet_exec.statistics().to_owned(),
+ max_concurrency,
+ enable_pruning: true,
+ })
+ } else {
+ Ok(Self {
+ path,
+ schema: Arc::new(schema),
+ statistics: Statistics::default(),
+ max_concurrency,
+ enable_pruning: true,
+ })
+ }
+ }
+
/// Get the path for the Parquet file(s) represented by this ParquetTable instance
pub fn path(&self) -> &str {
&self.path