Repository navigation
fix(ddx-ad): write a plan as SQL as ddx reads it to differentiate it - #290
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
to_sql read a DuckDB plan's read with no column mask as every column of its table, where DuckDB means none, so the fields after it landed on the wrong column and the SQL gave another result, without an error (#288). #279 fixed that for programs only, in in_read_form. to_sql now reads a plan through in_read_form too. DuckDB means no columns only for a named table: its read of a virtual table, such as the empty one it plans `LIMIT 0` as, has no mask and reads every column. in_read_form now leaves such a read whole. Fixes #288. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CvszJhH8pn8H9G69wEPMU2
a9f1c9a to
3fc5013
Compare
∂ Claude (ddx):
Fixes #288.
Why
On DuckDB,
ddxdb.to_sqlof an engine's own plan gave SQL with another result, without an error. DuckDB's Substrait producer writes no column mask on a read whose query uses none of the table's columns, and counts that read as one column wide. #279 taught ddx that rule inin_read_form, the function that converts a producer's plan into the form ddx reads, but only on the way into differentiation.to_sqlread the plan as Substrait reads it, as every column, so each field after such a read landed on the wrong column. #282 madeto_sqlpublic, so a caller who writes an engine's plan as SQL hits this. ddx's own program steps don't, since ddx writes those plans itself.How
to_sqlreads the plan throughin_read_formbefore writing it. It then also writes, like differentiation reads them, a window relation as a projection of window functions, and a right semi or anti join as the left one with its sides swapped (#287). Both mean the same as before. With #280, DuckDB's one-argumentsubtractwill be written as negation too.#279's rule applied to every read with no mask, but DuckDB means no columns only for a named table. Its read of a virtual table, such as the empty one it plans
LIMIT 0as, has no mask and reads every column. ddxdb writes such a plan withto_sqlto make the placeholder table of a CTE a view reads twice, so onceto_sqlused the rule, three tests of such views failed. The rule now applies to named tables only.in_read_formborrows a plan it doesn't change, so ddx's own steps, whose producer isddx, aren't copied.Tests
s.v. Without the fix, it selectedx.w. The same test checks that a DuckDB read of a virtual table with no mask is left whole.test_duckdb.py: DuckDB: to_sql still reads a maskless read as every column (#279's fix, not in to_sql), giving wrong SQL silently #288's query, written byto_sqland run on DuckDB, gives the query's value (1.875).to_sql,to_sql_fuzz(300 seeds),ad_sql_textandsql_programspass.🤖 Generated with Claude Code
https://claude.ai/code/session_01CvszJhH8pn8H9G69wEPMU2
Summary by CodeRabbit