fix(reasoning): support Lakebase/Postgres dialect and rebuild class URIs against the current Base URI - #174
Open
benoitcayladbx wants to merge 1 commit into
Open
benoitcayladbx wants to merge 1 commit into
benoitcayladbx wants to merge 1 commit into
Conversation
…RIs against the current Base URI SQLHelpers.to_number() gains a dialect parameter: on Lakebase (Postgres) it emits a CASE/regex guard instead of TRY_CAST, which does not exist in PostgreSQL. AggregateRuleEngine and DecisionTableEngine now detect the triple-store backend and pass the right dialect through, so numeric comparisons in Aggregate Rules and Decision Tables work against both Databricks SQL and Lakebase. AggregateRuleEngine, DecisionTableEngine, SPARQLRuleEngine and SWRLEngine all reconstruct a rule's target class URI from its local name against the domain's *current* Base URI instead of trusting the class's stored uri field, which goes stale after the domain is re-based (Base URI changed after the class already existed). Without this, a rule silently stopped finding its target class and returned zero results/inferred triples. AggregateRuleEngine also now computes inferred triples whenever a rule has a Result Entity configured, not only when materialize=True — previously, clicking "Run" (preview, no materialize) on such a rule always showed 0 inferred triples even when matching rows existed. DecisionTableEngine additionally ignores an input column left without an associated property (blank mapping) instead of generating a SQL condition that references a table never joined, which raised a "missing FROM-clause entry" error.
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.
Reopened against
0.9.0afterdevelopwas deleted. GitHub cannot reopen #146 (closed PR + missing base), so this is a successor of #146 with the same commits. Original author: @jeremiaspf. Please rebase onto current0.9.0before review — expect conflicts.What
Two independent problems in the four reasoning-rule engines (Aggregate Rules, Decision Tables, SPARQL Rules, SWRL), found while running 0.7.1 in production:
1. Rules stop finding their target class after the domain is re-based.
When a domain's Base URI changes after a class already exists, that class can be left with a stale
uri(the old Base URI) in its stored field.AggregateRuleEngine,DecisionTableEngine,SPARQLRuleEngineandSWRLEngineall trusted that storedurias-is to find a rule's target/result class. All four now reconstruct the URI from the class's local name against the domain's current Base URI instead, matching what the rest of the codebase already does in this situation.2. Numeric comparisons fail entirely against Lakebase (Postgres).
SQLHelpers's numeric-cast helper (used by all four engines wherever a rule compares a value numerically — an Aggregate Rule threshold, a Decision Table numeric condition) usedTRY_CAST, which doesn't exist in PostgreSQL. Any such rule failed outright once the graph was stored in Lakebase.SQLHelpers.to_number()now takes adialectparameter; on"postgres"it emits aCASE WHEN <regex validates numeric> THEN CAST … ELSE NULL ENDinstead.Two smaller, engine-specific fixes rode along because they touch the same functions:
AggregateRuleEngine: inferred triples were only computed whenmaterialize=True. An Aggregate Rule with a Result Entity configured but previewed (Run, not materialized) always showed 0 inferred triples even with matching rows. Now computed whenever a Result Entity is configured, consistent with the other rule engines.DecisionTableEngine: an input column left without an associated property (blank mapping) generated a SQL condition referencing a table that was never joined, raisingmissing FROM-clause entry. That column is now skipped instead, and the rest of the row still evaluates.Why
All four are silent-failure modes: a rule that looks correctly configured in the UI either returns nothing or throws a raw SQL error, with no obvious link back to "the domain was renamed" or "the graph lives in Lakebase."
How to test
missing FROM-clause entry; after, that column is ignored and the rest of the table evaluates.Happy to add/adjust automated tests for any of these if that's useful — wanted to get the report and the fix out first rather than block on writing a full suite against your test fixtures.