Repository navigation
Reorganize the query IR module - #1219
Merged
Merged
Conversation
Merged
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.
Summary
This patch builds on #1215 and restructures
fluree-db-query's logical IR around a singleirmodule, collapses two redundant query types into one canonicalQuery, and replaces the free-standingpattern_contains_functionand dual-purposevariables()helpers with cleaner method APIs onPattern.Motivation
fluree-db-query/src/ir.rshad grown to ~4,400 lines holding the entire pattern AST, projection specs, expression AST, property paths, adapter scan patterns, and triple-pattern primitives in one file.triple.rslived a directory up.options.rslived at the crate root. There were two structs both called something like a "query": a tinyQuery { select, where_ }used by a handful of tests, and the much richerParsedQuerythat carried output spec, options, projection shape, construct templates, and post-VALUES — the type that actually flows through parse → plan → execute → format. Free-standing helpers (pattern_contains_function,variables) lived alongside the types they walked, andvariablesreturned a single set whose meaning ("referenced" vs "bound") was context-dependent at the call site.Key changes
ir.rsinto a module.fluree-db-query/src/ir/now contains:query.rs—Query,QueryOutput,ProjectionShape,ConstructTemplate(the resolved-and-lowered query)options.rs—QueryOptions(LIMIT/OFFSET/ORDER BY/GROUP BY/aggregates/HAVING/post-binds/DISTINCT) andReasoningModespattern.rs—Patternenum and theVec<Pattern>-wrapping variants (SubqueryPattern,ServicePattern,GraphName,ServiceEndpoint)expression.rs— filter/bind expression AST,CompareOp,ArithmeticOp,Functioncatalogpath.rs— property-path patternsprojection.rs— graph-crawl selection specs (GraphSelectSpec,NestedSelectSpec,SelectionSpec,Root)adapters.rs— non-graph scan patterns (BM25, vector, geo, S2, R2RML)triple.rs—TriplePattern,Ref,Term(moved in from the crate root)ir.rsbecomes a thin facade — module declarations and the public re-export surface.Query, not two. The simpleQuery { select, where_ }struct (used by ~2 tests) is removed;ParsedQueryis renamed toQueryand lives atir::Query. All consumers (planner, executor, formatter, SPARQL lower, transact stage, view layer) are migrated.QueryOptionsandReasoningModesmove into the IR. The crate-rootoptions.rsis gone; the rewriter's locally-definedReasoningModesis gone. Both now live inir/options.rsand re-export through theirfacade.pattern_contains_functionbecomes a method onPattern. Old:pattern_contains_function(&pattern, &target). New:pattern.contains_function(&target). Mirrors the existingExpression::contains_functionshape.variables()splits intoreferenced_vars()andproduced_vars(). Previously a single method whose semantics ("which variables does this pattern reference?" vs "which does it produce / bind?") had to be inferred per call site. Now explicit on every IR type that has both notions (Pattern,TriplePattern,PropertyPathPattern,IndexSearchPattern,VectorSearchPattern,GeoSearchPattern,S2SearchPattern,R2rmlPattern,SubqueryPattern,ServicePattern). Filter / Minus correctly return emptyproduced_vars; Subquery correctly exposes only its SELECT outwards.Querystruct.Behavior
No semantic changes. Pure structural reorganization: file moves, type renames, helper-shape changes. The
referenced_vars/produced_varssplit is a contract refinement — the underlying recursion walks the same set of pattern variants the oldvariables()did. All in-workspace consumers (fluree-db-sparql/src/lower/*,fluree-db-api/src/{format,view,query}/*,fluree-db-transact/src/stage.rs,fluree-db-reasoner/src/types.rs, the test suites) are migrated to the new APIs in this PR.