(
ctx: &SessionContext,
path: impl AsRef<Path>,
replacement_mapping: &HashMap<String, String>,
)
| 1466 | } |
| 1467 | |
| 1468 | async fn read_query_from_file( |
| 1469 | ctx: &SessionContext, |
| 1470 | path: impl AsRef<Path>, |
| 1471 | replacement_mapping: &HashMap<String, String>, |
| 1472 | ) -> Result<BenchmarkQuery> { |
| 1473 | // Process replacements in file path |
| 1474 | let path = path.as_ref().to_string_lossy(); |
| 1475 | let path = process_replacements(&path, replacement_mapping)?; |
| 1476 | let df: DataFrame = ctx |
| 1477 | .read_csv( |
| 1478 | path.clone(), |
| 1479 | CsvReadOptions::new() |
| 1480 | .has_header(true) |
| 1481 | .delimiter(b'|') |
| 1482 | .null_regex(Some("NULL".to_string())) |
| 1483 | // we only want string values, we do not want to infer the schema |
| 1484 | .schema_infer_max_records(0), |
| 1485 | ) |
| 1486 | .await?; |
| 1487 | |
| 1488 | // Get schema to determine column count |
| 1489 | let schema = df.schema(); |
| 1490 | let column_count = schema.fields().len(); |
| 1491 | |
| 1492 | if column_count == 0 { |
| 1493 | return Err(exec_datafusion_err!( |
| 1494 | "Result file {path} did not contain any columns" |
| 1495 | )); |
| 1496 | } |
| 1497 | |
| 1498 | // Execute and collect results |
| 1499 | let batches = df.collect().await?; |
| 1500 | // Convert record batches to string vectors |
| 1501 | let expected_result = format_record_batches(&batches)?; |
| 1502 | |
| 1503 | Ok(BenchmarkQuery { |
| 1504 | path: Some(path), |
| 1505 | query: String::new(), |
| 1506 | column_count, |
| 1507 | expected_result, |
| 1508 | }) |
| 1509 | } |
| 1510 | |
| 1511 | fn format_record_batches( |
| 1512 | batches: &[RecordBatch], |
no test coverage detected
searching dependent graphs…