diff --git a/src/clj/fluree/db/query/fql/parse.cljc b/src/clj/fluree/db/query/fql/parse.cljc index bd73d4ed6..b39d92c08 100644 --- a/src/clj/fluree/db/query/fql/parse.cljc +++ b/src/clj/fluree/db/query/fql/parse.cljc @@ -75,16 +75,20 @@ (defn match-value-binding-map [var-match binding-map context] (let [attrs (expand-keys binding-map context) + id (get attrs const/iri-id) val (get attrs const/iri-value)] - (if-let [dt-iri (get-expanded-datatype attrs context)] - (if (= const/iri-anyURI dt-iri) - (let [expanded (json-ld/expand-iri val context)] - (where/match-iri var-match expanded)) - (where/match-value var-match val dt-iri)) - (if-let [lang (get attrs const/iri-language)] - (where/match-value var-match val const/iri-lang-string {:lang lang}) - (let [dt (datatype/infer-iri val)] - (where/match-value var-match val dt)))))) + (cond id (let [expanded (json-ld/expand-iri id context)] + (where/match-iri var-match expanded)) + :else + (if-let [dt-iri (get-expanded-datatype attrs context)] + (if (= const/iri-anyURI dt-iri) + (let [expanded (json-ld/expand-iri val context)] + (where/match-iri var-match expanded)) + (where/match-value var-match val dt-iri)) + (if-let [lang (get attrs const/iri-language)] + (where/match-value var-match val const/iri-lang-string {:lang lang}) + (let [dt (datatype/infer-iri val)] + (where/match-value var-match val dt))))))) (defn match-value-binding [var-match value context] diff --git a/test/fluree/db/query/values_test.clj b/test/fluree/db/query/values_test.clj index ca5d0bef1..847275497 100644 --- a/test/fluree/db/query/values_test.clj +++ b/test/fluree/db/query/values_test.clj @@ -34,7 +34,18 @@ (is (= [["foo1"] ["foo2"] ["foo3"]] @(fluree/query db1 {"select" ["?foo"] "values" ["?foo" ["foo1" "foo2" "foo3" ]]})) - "syntactic form is parsed correctly")))) + "syntactic form is parsed correctly"))) + (testing "iri values" + (is (= [["Brian" "brian@example.org"] + ["Cam" "cam@example.org"]] + @(fluree/query db1 {"@context" context + "select" ["?name" "?email"] + "where" [{"@id" "?s" "schema:name" "?name"} + {"@id" "?s" "schema:email" "?email"} + ["values" + ["?s" [{"@id" "ex:cam"} + {"@id" "ex:brian"}]]]]})) + "id-maps can be used to distinguish iris"))) (testing "where pattern" (testing "single var" (is (= [["Brian" "brian@example.org"] @@ -56,7 +67,7 @@ {"@id" "?s" "schema:email" "?email"} ["values" [["?s"] [[{"@type" "xsd:anyURI" "@value" "ex:cam"}] - [{"@type" "xsd:anyURI" "@value" "ex:brian"}]]]]]})) + [{"@id" "ex:brian"}]]]]]})) "syntactic form is parsed correctly")) (testing "nested under optional clause" (is (= [["Nikola" nil true]]