Skip to content

Commit ac1d6e1

Browse files
committed
feat: enhance error handling for missing tables in SQL queries
1 parent b9041ba commit ac1d6e1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

python/tests/test_context.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,18 @@ def test_sql_missing_table_without_auto_register(ctx):
268268
assert "arrow_table" in missing_tables
269269

270270

271+
def test_sql_missing_table_exposes_missing_table_names(ctx):
272+
ctx.set_python_table_lookup(False)
273+
274+
with pytest.raises(Exception) as excinfo:
275+
ctx.sql("SELECT * FROM missing_table").collect()
276+
277+
missing_tables = getattr(excinfo.value, "missing_table_names", None)
278+
assert missing_tables is not None
279+
normalized = [str(name).rsplit(".", 1)[-1] for name in missing_tables]
280+
assert normalized == ["missing_table"]
281+
282+
271283
def test_extract_missing_table_names_from_attribute():
272284
class MissingTablesError(Exception):
273285
def __init__(self) -> None:

src/context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,11 +1237,15 @@ fn collect_missing_table_names_recursive(err: &DataFusionError, acc: &mut HashSe
12371237
}
12381238

12391239
fn parse_missing_table_names_in_message(message: &str, acc: &mut HashSet<String>) {
1240-
const LOOKUPS: [(&str, char); 4] = [
1240+
const LOOKUPS: [(&str, char); 8] = [
12411241
("table '", '\''),
12421242
("view '", '\''),
12431243
("table \"", '"'),
12441244
("view \"", '"'),
1245+
("table named '", '\''),
1246+
("view named '", '\''),
1247+
("table named \"", '"'),
1248+
("view named \"", '"'),
12451249
];
12461250

12471251
let lower = message.to_ascii_lowercase();

0 commit comments

Comments
 (0)