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

Handle trailing tbl column in TPCH benchmarks #4821

Merged
merged 3 commits into from
Jan 5, 2023
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
15 changes: 8 additions & 7 deletions benchmarks/src/bin/tpch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ async fn get_table(
unimplemented!("Invalid file format '{}'", other);
}
};
let schema = Arc::new(get_tpch_table_schema(table));

let options = ListingOptions::new(format)
.with_file_extension(extension)
Expand All @@ -412,10 +411,11 @@ async fn get_table(
let table_path = ListingTableUrl::parse(path)?;
let config = ListingTableConfig::new(table_path).with_listing_options(options);

let config = if table_format == "parquet" {
config.infer_schema(&state).await?
} else {
config.with_schema(schema)
let config = match table_format {
"parquet" => config.infer_schema(&state).await?,
"tbl" => config.with_schema(Arc::new(get_tbl_tpch_table_schema(table))),
"csv" => config.with_schema(Arc::new(get_tpch_table_schema(table))),
_ => unreachable!(),
};

Ok(Arc::new(ListingTable::try_new(config)?))
Expand Down Expand Up @@ -827,6 +827,7 @@ mod tests {
#[cfg(feature = "ci")]
mod ci {
use super::*;
use arrow::datatypes::{DataType, Field};
use datafusion_proto::bytes::{logical_plan_from_bytes, logical_plan_to_bytes};

async fn serde_round_trip(query: usize) -> Result<()> {
Expand Down Expand Up @@ -1086,7 +1087,6 @@ mod ci {
/// * the correct number of rows are returned
/// * the content of the rows is correct
async fn verify_query(n: usize) -> Result<()> {
use datafusion::arrow::datatypes::{DataType, Field};
use datafusion::common::ScalarValue;
use datafusion::logical_expr::expr::Cast;

Expand Down Expand Up @@ -1214,7 +1214,8 @@ mod ci {
}

fn get_tpch_data_path() -> Result<String> {
let path = std::env::var("TPCH_DATA").unwrap_or("benchmarks/data".to_string());
let path =
std::env::var("TPCH_DATA").unwrap_or_else(|_| "benchmarks/data".to_string());
if !Path::new(&path).exists() {
return Err(DataFusionError::Execution(format!(
"Benchmark data not found (set TPCH_DATA env var to override): {}",
Expand Down
21 changes: 20 additions & 1 deletion benchmarks/src/tpch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ pub const TPCH_TABLES: &[&str] = &[
"part", "supplier", "partsupp", "customer", "orders", "lineitem", "nation", "region",
];

/// The `.tbl` file contains a trailing column
pub fn get_tbl_tpch_table_schema(table: &str) -> Schema {
let mut schema = get_tpch_table_schema(table);
schema
.fields
.push(Field::new("__placeholder", DataType::Utf8, false));
schema
}

/// Get the schema for the benchmarks derived from TPC-H
pub fn get_tpch_table_schema(table: &str) -> Schema {
// note that the schema intentionally uses signed integers so that any generated Parquet
Expand Down Expand Up @@ -331,7 +340,7 @@ pub async fn convert_tbl(
let output_root_path = Path::new(output_path);
for table in TPCH_TABLES {
let start = Instant::now();
let schema = get_tpch_table_schema(table);
let schema = get_tbl_tpch_table_schema(table);

let input_path = format!("{input_path}/{table}.tbl");
let options = CsvReadOptions::new()
Expand All @@ -346,6 +355,16 @@ pub async fn convert_tbl(
// build plan to read the TBL file
let mut csv = ctx.read_csv(&input_path, options).await?;

// Select all apart from the padding column
let selection = csv
.schema()
.fields()
.iter()
.take(schema.fields.len() - 1)
.map(|d| Expr::Column(d.qualified_column()))
.collect();

csv = csv.select(selection)?;
// optionally, repartition the file
if partitions > 1 {
csv = csv.repartition(Partitioning::RoundRobinBatch(partitions))?
Expand Down