Skip to content

Commit

Permalink
support VALUES patterns in an order-agnostic way
Browse files Browse the repository at this point in the history
Three approaches considered:

1) just document that :values needs to appear first
2) discard solutions that don't match the given solution
3) during the parse step, sort the patterns so :values is first

I don't like #1, though that's the most expedient. #2 is a bit wasteful as it forces us
to generate useless solutions. #3 is doable, and may be a minimal requirement in basic
query planning.

This implements solution #2.
  • Loading branch information
dpetran authored and JaceRockman committed Jul 2, 2024
1 parent 8cd63d0 commit b2660bc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
16 changes: 14 additions & 2 deletions src/clj/fluree/db/query/exec/where.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,20 @@

(defmethod match-pattern :values
[db fuel-tracker solution pattern error-ch]
(let [[_ inline-solutions] pattern]
(async/to-chan! (mapv (partial merge solution) inline-solutions))))
(let [[_ inline-solutions] pattern
;; need to compute sids on inline data so they can match equal solutions
inline-solutions* (mapv (fn [solution]
(->> solution
(mapv (fn [[var match]]
[var (if (matched-iri? match) (compute-sid match db) match)]))
(into {} )))
inline-solutions)]
;; filter out any solutions that don't match inline solution data
(if (every? (fn [inline-solution] (= (select-keys solution (keys inline-solution))
inline-solution))
inline-solutions*)
(async/to-chan! (mapv (partial merge solution) inline-solutions))
nil-channel)))

(defn with-default
"Return a transducer that transforms an input stream of solutions to include the
Expand Down
10 changes: 5 additions & 5 deletions test/fluree/db/query/values_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
(is (= [["Cam" "[email protected]"]]
@(fluree/query db1 {"@context" context
"select" ["?name" "?email"]
"where" [["values"
["?s" [{"@type" "xsd:anyURI" "@value" "ex:cam"}]]]
{"@id" "?s" "schema:name" "?name"}
{"@id" "?s" "schema:email" "?email"}]}))))
(testing "multiple vars"
"where" [{"@id" "?s" "schema:name" "?name"}
{"@id" "?s" "schema:email" "?email"}
["values"
["?s" [{"@type" "xsd:anyURI" "@value" "ex:cam"}]]]]}))))
#_(testing "multiple vars"
(is (= [["foo1" "bar1"] ["foo2" "bar2"] ["foo3" "bar3"]]
@(fluree/query db0 {"@context" context
"select" ["?foo" "?bar"]
Expand Down

0 comments on commit b2660bc

Please sign in to comment.