Skip to content

Fix SQLCompiler INSERT/FROM and slot AS direction (#48)#255

Open
amc-corey-cox wants to merge 1 commit into
mainfrom
fix-sqlcompiler-insert-from
Open

Fix SQLCompiler INSERT/FROM and slot AS direction (#48)#255
amc-corey-cox wants to merge 1 commit into
mainfrom
fix-sqlcompiler-insert-from

Conversation

@amc-corey-cox
Copy link
Copy Markdown
Contributor

Closes #48.

  • FROM clause now uses cd.populated_from (falling back to cd.name) instead of the target class name
  • Slot-level alias flipped from target AS source to source AS target

The two bugs balanced column counts in test_compile, hiding both. With the fix, that test surfaces SQLCompiler's missing target-shape handling (#150) — the INSERT execution is dropped from test_compile with a TODO pointer; coverage moves to focused tests below.

Test plan

  • test_from_clause_uses_class_populated_from — asserts FROM uses source class
  • test_slot_aliased_source_as_target — asserts AS direction is source AS target
  • test_compiled_sql_executes_against_duckdb — end-to-end: source rows land in target on a minimal spec
  • uv run pytest — 831 passed, 4 skipped
  • uv run ruff check . and uv run ruff format --check . — clean

The FROM clause used the target class name, producing self-INSERTs
that silently inserted zero rows. The slot-level alias direction was
also inverted, referencing target column names in the source table.

Existing test_compile previously passed because the two inverted bugs
balanced column counts by accident; with correct SQL the test exposes
SQLCompiler's missing target-column-shape handling (tracked in #150).
Copilot AI review requested due to automatic review settings June 2, 2026 15:43
@amc-corey-cox amc-corey-cox added this to the v0.5.3 milestone Jun 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes two correctness issues in SQLCompiler that previously produced self-INSERT statements and inverted column aliasing, preventing data from being inserted from the intended source tables. It also adds focused regression tests to validate the corrected SQL output and a minimal end-to-end execution against DuckDB.

Changes:

  • Fix FROM clause generation to use ClassDerivation.populated_from (falling back to cd.name).
  • Fix slot alias emission to source_expr AS target_slot (instead of the inverted form).
  • Add targeted tests for FROM behavior, alias direction, and a minimal DuckDB execution smoke test; adjust the broader test_compile to avoid executing INSERTs pending #150.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/linkml_map/compiler/sql_compiler.py Corrects the generated SELECT’s FROM table and slot alias direction to match the transformation specification semantics.
tests/test_compiler/test_duckdb_compiler.py Adds regression + end-to-end tests for the SQLCompiler fixes and updates the existing compile smoke test to avoid the known #150 limitation.

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.

INSERT INTO Individual SELECT ... FROM INDIVIDUAL

2 participants