fix: Derived where() on non-selected columns derived wrong results - #107
Merged
Merged
Conversation
compile_rule built body atoms before compiling the where-condition, so a column referenced only by the condition (not selected into the head) compiled to _ in its atom while the condition referenced an unbound variable: +gold(Name) <- customer(_, Name, _), Tier = "gold". The engine accepts that rule and silently satisfies the comparison, so the derived relation matched every row instead of filtering. Conditions now compile first, registering their columns in the variable environment before atoms are built: +gold(Name) <- customer(_, Name, Tier), Tier = "gold". Found by a live migration demo (a Derived with where(tier == "gold") returned silver customers). The existing test_with_condition passed because it never asserted the binding; it now does, plus a regression test for the condition-only column case. Engine-side acceptance of unbound comparison variables is filed separately.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
compile_rule built body atoms before compiling the where-condition. A column referenced only by the condition compiled to _ in its atom while the condition referenced an unbound variable:
The engine accepts that rule and silently satisfies the comparison, so the derived relation matched EVERY customer, silver included. Verified live before the fix; after the fix the clause binds the column and the engine filters correctly:
The fix is an ordering change: conditions compile first, registering their columns in the variable environment before atoms are built. This is the shared compiler, so it affects every Derived rule with a where() on a non-selected column - define_rules and migrations alike.
How it slipped through
test_with_condition asserted the head and the condition string but never that the condition column was bound in the atom. It now does, plus a regression test asserting the exact clause for the condition-only-column case. Full SDK suite: 958 passed.
Found while building a live demo of the migration strategy. The engine-side half (accepting rules with unbound comparison variables and silently satisfying them - a wrong-results landmine of the same family as #91) is filed separately.
Merge order
Independent - no conflicts with #98-#105.