MCPcopy Create free account
hub / github.com/apache/datafusion / read_query_from_file

Function read_query_from_file

benchmarks/src/sql_benchmark.rs:1468–1509  ·  view source on GitHub ↗
(
    ctx: &SessionContext,
    path: impl AsRef<Path>,
    replacement_mapping: &HashMap<String, String>,
)

Source from the content-addressed store, hash-verified

1466}
1467
1468async 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
1511fn format_record_batches(
1512 batches: &[RecordBatch],

Callers 1

Calls 15

process_replacementsFunction · 0.85
newFunction · 0.85
format_record_batchesFunction · 0.85
read_csvMethod · 0.80
null_regexMethod · 0.80
collectMethod · 0.80
as_refMethod · 0.45
cloneMethod · 0.45
delimiterMethod · 0.45
has_headerMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…