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

Function iterate_queries

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

Reads all `.sql` files from a directory and converts them to test queries. Skips files that: - Are not regular files - Don't have a `.sql` extension - Contain multiple SQL statements (indicated by `;\n`) Multi-statement files are skipped because the unparser doesn't support DML statements like `CREATE VIEW` that appear in multi-statement Clickbench queries.

(dir: ReadDir)

Source from the content-addressed store, hash-verified

61/// Multi-statement files are skipped because the unparser doesn't support
62/// DML statements like `CREATE VIEW` that appear in multi-statement Clickbench queries.
63fn iterate_queries(dir: ReadDir) -> Vec<TestQuery> {
64 let mut queries = vec![];
65 for entry in dir.flatten() {
66 let Ok(file_type) = entry.file_type() else {
67 continue;
68 };
69 if !file_type.is_file() {
70 continue;
71 }
72 let path = entry.path();
73 let Some(ext) = path.extension() else {
74 continue;
75 };
76 if ext != "sql" {
77 continue;
78 }
79 let name = path.file_stem().unwrap().to_string_lossy().to_string();
80 if let Ok(mut contents) = std::fs::read_to_string(entry.path()) {
81 // If the query contains ;\n it has DML statements like CREATE VIEW which the unparser doesn't support; skip it
82 contents = contents.trim().to_string();
83 if contents.contains(";\n") {
84 println!("Skipping query with multiple statements: {name}");
85 continue;
86 }
87 queries.push(TestQuery {
88 sql: contents,
89 name,
90 });
91 }
92 }
93 queries
94}
95
96/// A SQL query loaded from a benchmark file for roundtrip testing.
97///

Callers 2

clickbench_queriesFunction · 0.85
tpch_queriesFunction · 0.85

Calls 9

flattenMethod · 0.80
extensionMethod · 0.80
file_stemMethod · 0.80
trimMethod · 0.80
file_typeMethod · 0.45
pathMethod · 0.45
to_stringMethod · 0.45
containsMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…