Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register table based on known schema without file IO #872

Merged
merged 1 commit into from
Aug 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion benchmarks/src/bin/tpch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions datafusion/src/datasource/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down