Skip to content

fix(text2sql): isolate missing databases in batch query comparison - #557

Merged
SunnyHaze merged 1 commit into
OpenDCAI:mainfrom
raams95:fix/text2sql-compare-missing-db
Oct 19, 2026
Merged

SunnyHaze merged 1 commit into
OpenDCAI:mainfrom
raams95:fix/text2sql-compare-missing-db

Conversation

@raams95

@raams95 raams95 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Summary

DatabaseManager.batch_compare_queries returns an error result for every triple in the batch as soon as any one db_id is not registered. One row that points at a missing database makes all the other comparisons fail too, even when their database exists and the SQL matches.

SQLExecutionClassifier passes the whole dataframe in a single call, so in practice one bad db_id marks every row as "Predicted SQL failed; Ground truth SQL failed" with cnt_true = 0.

manager.batch_compare_queries([
    ("concert", "SELECT name FROM singer", "SELECT name FROM singer"),
    ("missing_db", "SELECT 1", "SELECT 1"),
])
# both results: equal=False, ["Database 'missing_db' not found"]

Fix

The missing-database check now happens per triple. A triple whose db_id is not registered gets the same "Database '<id>' not found" error result as before. The other triples are executed and compared as usual, and results stay in input order. If every database exists, the behaviour doesn't change.

Tests

I added test/cpu_only/test_text2sql_compare_missing_db.py. It builds a small SQLite database under tmp_path and compares three triples: a matching pair, a pair on a missing database, and a non-matching pair. It checks that only the missing-database triple gets the error and the other two keep their real results in order.

  • Before the fix: 1 failed (the matching pair came back equal=False)
  • After the fix: 1 passed
pytest -m "cpu or api" test/cpu_only/test_text2sql_compare_missing_db.py -q
1 passed

I also checked SQLExecutionClassifier.execute_model_batch with the same data. The row on the existing database now gets cnt_true = 1 instead of being reported as failed.

Fixes #556

@SunnyHaze
SunnyHaze merged commit aaf2ad1 into OpenDCAI:main Oct 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DatabaseManager.batch_compare_queries fails every comparison when one db_id is missing

2 participants