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

Function collect_results

datafusion/core/tests/sql/unparser.rs:310–402  ·  view source on GitHub ↗

Executes a roundtrip test for a single SQL query. This is the core test logic that: 1. Parses the original SQL and creates a logical plan 2. Unparses the logical plan back to SQL 3. Executes both the original and unparsed queries 4. Compares the results (sorting if the query has no ORDER BY) This always uses [`DefaultDialect`] for unparsing. # Arguments `ctx` - Session context with tables regi

(ctx: &SessionContext, original: &str)

Source from the content-addressed store, hash-verified

308///
309/// A [`TestCaseResult`] indicating success or the specific failure mode.
310async fn collect_results(ctx: &SessionContext, original: &str) -> TestCaseResult {
311 let unparser = Unparser::new(&DefaultDialect {});
312
313 // Parse and create logical plan from original SQL
314 let df = match ctx.sql(original).await {
315 Ok(df) => df,
316 Err(e) => {
317 return TestCaseResult::ExecutionError {
318 original: original.to_string(),
319 error: e.to_string(),
320 };
321 }
322 };
323
324 // Unparse the logical plan back to SQL
325 let unparsed = match unparser.plan_to_sql(df.logical_plan()) {
326 Ok(sql) => format!("{sql:#}"),
327 Err(e) => {
328 return TestCaseResult::UnparseError {
329 original: original.to_string(),
330 error: e.to_string(),
331 };
332 }
333 };
334
335 // Collect results from original query
336 let mut expected = match df.collect().await {
337 Ok(batches) => batches,
338 Err(e) => {
339 return TestCaseResult::ExecutionError {
340 original: original.to_string(),
341 error: e.to_string(),
342 };
343 }
344 };
345
346 // Parse and execute the unparsed SQL
347 let actual_df = match ctx.sql(&unparsed).await {
348 Ok(df) => df,
349 Err(e) => {
350 return TestCaseResult::UnparsedExecutionError {
351 original: original.to_string(),
352 unparsed,
353 error: e.to_string(),
354 };
355 }
356 };
357
358 // Collect results from unparsed query
359 let mut actual = match actual_df.collect().await {
360 Ok(batches) => batches,
361 Err(e) => {
362 return TestCaseResult::UnparsedExecutionError {
363 original: original.to_string(),
364 unparsed,
365 error: e.to_string(),
366 };
367 }

Callers 1

run_roundtrip_testsFunction · 0.85

Calls 7

newFunction · 0.85
sort_batchesFunction · 0.85
sqlMethod · 0.80
plan_to_sqlMethod · 0.80
collectMethod · 0.80
to_stringMethod · 0.45
logical_planMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…