Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested nodes in commits #385

Merged
merged 9 commits into from
Feb 14, 2023
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ NOTE: use `make -j` to run tasks in parallel.
* `make nodejs-test` - run node package in node
* `make browser-test` - run browser package in headless Chrome

#### Running specific tests

> This applies to CLJ tests only, not CLJS.

`clojure -X:cljtest :kaocha.filter/focus [focus-spec]`

...where `focus-spec` can be a test namespace or a fully-qualified `deftest`
var. Note that the square brackets around the `focus-spec` must be present in
the command, they are NOT there to indicate "optional" or "placeholder" in the
example.

This feature comes from the test runner kaocha which has
[additional features](https://cljdoc.org/d/lambdaisland/kaocha/1.77.1236/doc/6-focusing-and-skipping).

### CLJS REPL

In order to get a Node or web browser CLJS REPL running, you need to do the
Expand Down
2 changes: 1 addition & 1 deletion src/fluree/db/datatype.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
[x]
(cond
(string? x) const/$xsd:string
(integer? x) const/$xsd:integer
(integer? x) const/$xsd:long ; infer to long to prevent overflow
(number? x) const/$xsd:decimal
(boolean? x) const/$xsd:boolean))

Expand Down
2 changes: 1 addition & 1 deletion src/fluree/db/json_ld/commit.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
(if p-flakes
(let [fflake (first p-flakes)
p-iri (<? (get-s-iri (flake/p fflake) db iri-map compact-fn))
ref? (get-in schema [:pred (flake/p fflake) :ref?])
ref? (= const/$iri (flake/dt fflake))
list? (:i (flake/m fflake))
p-flakes* (if list?
(sort-by #(:i (flake/m %)) p-flakes)
Expand Down
4 changes: 2 additions & 2 deletions src/fluree/db/json_ld/reify.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,10 @@
{:status 500 :error :db/invalid-commit})))
assert (db-assert db-data)
retract (db-retract db-data)
retract-flakes (retract-flakes db retract t-new iris)
retract-flakes (<? (retract-flakes db retract t-new iris))
{:keys [flakes pid sid]} (<? (assert-flakes db assert t-new iris refs))
all-flakes (-> (empty (get-in db [:novelty :spot]))
(into (<? retract-flakes))
(into retract-flakes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the <? for retracts looked misplaced as it was, but it was intentional.

Its purpose was to run the fairly costly assert-flakes and retract-flakes in parallel on different threads, as opposed to serially.

This change makes it run serially.

Copy link
Contributor Author

@cap10morgan cap10morgan Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the original parallelization change here 3 weeks ago (in 64a7fd7) but recently noticed that it may not be safe b/c it's being passed a volatile map that is also being passed to assert-flakes.

So I reverted it back to the way it was before 64a7fd7.

(into flakes))
ecount* (assoc ecount const/$_predicate pid
const/$_default sid)]
Expand Down
3 changes: 1 addition & 2 deletions src/fluree/db/json_ld/transact.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@
datatype-map (get-in shacl-map [:datatype pid])
property-flakes* (if existing-pid
property-flakes
(cond-> (conj property-flakes (flake/create pid const/$iri k const/$xsd:string t true nil))
ref? (conj (flake/create pid const/$rdf:type const/$iri const/$xsd:anyURI t true nil))))
(conj property-flakes (flake/create pid const/$iri k const/$xsd:string t true nil)))
;; check-retracts? - a new subject or property don't require checking for flake retractions
check-retracts? (or (not new-subj?) existing-pid)
flakes* (if retract?
Expand Down
2 changes: 1 addition & 1 deletion src/fluree/db/query/exec/select.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@
format-ch))

(defn implicit-grouping?
"Returns true if the provide `selector` can only operate on grouped elements."
"Returns true if the provided `selector` can only operate on grouped elements."
[selector]
(instance? AggregateSelector selector))
17 changes: 0 additions & 17 deletions src/fluree/db/query/json_ld/response.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,6 @@
(vswap! cache assoc sid iri)
iri)))


(defn iri-only-ref
"Extracts result information from a ref predicate. If sub-select exists
and additional graph crawl is performed. If it doesn't exist, simply returns
{@id <iri>} for each object."
[db cache compact-fn p-flakes]
(go-try
(let [id-key (:as (wildcard-spec db cache compact-fn const/$iri))]
(loop [[next-flake & r] p-flakes
acc []]
(if next-flake
(let [iri (<? (dbproto/-iri db (flake/o next-flake) compact-fn))]
(recur r (conj acc {id-key iri})))
(if (= 1 (count acc))
(first acc)
acc))))))

(defn crawl-ref-item
[db compact-fn flake-sid sub-select cache fuel-vol max-fuel depth-i]
(go-try
Expand Down
2 changes: 1 addition & 1 deletion test/fluree/db/json_ld/api_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
:type :schema/Person
:schema/fname "Me"}])]
@(fluree/commit! ledger db)
(is @(fluree/exists? conn ledger-alias))
(is (test-utils/retry-exists? conn ledger-alias 10))
(is (not @(fluree/exists? conn "notaledger"))))

:cljs
Expand Down
32 changes: 16 additions & 16 deletions test/fluree/db/query/fql_parse_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
:spec {:depth 0 :wildcard? true}}
(de-recordify-select select)))
(is (= [[{::where/var '?s}
{::where/val 1002 ::where/datatype 7}
{::where/val 1002 ::where/datatype 8}
{::where/val "Alice" ::where/datatype 1}]]
patterns)))
(let [vars-query {:select {"?s" ["*"]}
Expand All @@ -70,7 +70,7 @@
(de-recordify-select select)))
(is (= [[{::where/var '?s}
{::where/val 1002
::where/datatype 7}
::where/datatype 8}
{::where/var '?name}]]
patterns)))
(let [query {:context {:ex "http://example.org/ns/"}
Expand All @@ -88,24 +88,24 @@
(de-recordify-select select)))
(is (= [[{::where/var '?s}
{::where/val 1002
::where/datatype 7}
::where/datatype 8}
{::where/val "Cam"
::where/datatype 1}]
[{::where/var '?s}
{::where/val 1008
::where/datatype 7}
::where/datatype 8}
{::where/var '?f}]
[{::where/var '?f}
{::where/val 1002
::where/datatype 7}
::where/datatype 8}
{::where/var '?name}]
[{::where/var '?f}
{::where/val 1004
::where/datatype 7}
::where/datatype 8}
{::where/var '?age}]
[{::where/var '?f}
{::where/val 1007
::where/datatype 7}
::where/datatype 8}
{::where/var '?email}]]
patterns)))
(testing "class, optional"
Expand All @@ -120,18 +120,18 @@
(is (= [[:class
[{::where/var '?s}
{::where/val 200
::where/datatype 7}
::where/datatype 8}
{::where/val 1001
::where/datatype 0}]]
[{::where/var '?s}
{::where/val 1002
::where/datatype 7}
::where/datatype 8}
{::where/var '?name}]
[:optional
{::where/patterns
[[{::where/var '?s}
{::where/val 1006
::where/datatype 7}
::where/datatype 8}
{::where/var '?favColor}]]
::where/filters {}}]]
patterns))))
Expand All @@ -147,20 +147,20 @@
(is (= [[:class
[{::where/var '?s}
{::where/val 200
::where/datatype 7}
::where/datatype 8}
{::where/val 1001
::where/datatype 0}]]
[:union
[{::where/patterns
[[{::where/var '?s}
{::where/val 1007
::where/datatype 7}
::where/datatype 8}
{::where/var '?email1}]]
::where/filters {}}
{::where/patterns
[[{::where/var '?s}
{::where/val 1003
::where/datatype 7}
::where/datatype 8}
{::where/var '?email2}]]
::where/filters {}}]]]
patterns))))
Expand All @@ -177,16 +177,16 @@
(is (= [[:class
[{::where/var '?s}
{::where/val 200
::where/datatype 7}
::where/datatype 8}
{::where/val 1001
::where/datatype 0}]]
[{::where/var '?s}
{::where/val 1004
::where/datatype 7}
::where/datatype 8}
{::where/var '?age}]
[{::where/var '?s}
{::where/val 1002
::where/datatype 7}
::where/datatype 8}
{::where/var '?name}]]
patterns))))
(testing "group-by, order-by"
Expand Down
22 changes: 11 additions & 11 deletions test/fluree/db/query/index_range_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -49,45 +49,45 @@
[alice-sid 200 1001 0 -1 true nil]
[alice-sid 1002 "Alice" 1 -1 true nil]
[alice-sid 1003 "[email protected]" 1 -1 true nil]
[alice-sid 1004 50 7 -1 true nil]
[alice-sid 1005 9 7 -1 true nil]
[alice-sid 1005 42 7 -1 true nil]
[alice-sid 1005 76 7 -1 true nil]]
[alice-sid 1004 50 8 -1 true nil]
[alice-sid 1005 9 8 -1 true nil]
[alice-sid 1005 42 8 -1 true nil]
[alice-sid 1005 76 8 -1 true nil]]
(->> @(fluree/slice db :spot [alice-sid])
(mapv flake/Flake->parts)))
"Slice should return a vector of flakes for only Alice")))

(testing "Slice for subject + predicate"
(let [alice-sid @(fluree/internal-id db :ex/alice)
favNums-pid @(fluree/internal-id db :ex/favNums)]
(is (= [[alice-sid favNums-pid 9 7 -1 true nil]
[alice-sid favNums-pid 42 7 -1 true nil]
[alice-sid favNums-pid 76 7 -1 true nil]]
(is (= [[alice-sid favNums-pid 9 8 -1 true nil]
[alice-sid favNums-pid 42 8 -1 true nil]
[alice-sid favNums-pid 76 8 -1 true nil]]
(->> @(fluree/slice db :spot [alice-sid favNums-pid])
(mapv flake/Flake->parts)))
"Slice should only return Alice's favNums (multi-cardinality)")))

(testing "Slice for subject + predicate + value"
(let [alice-sid @(fluree/internal-id db :ex/alice)
favNums-pid @(fluree/internal-id db :ex/favNums)]
(is (= [[alice-sid favNums-pid 42 7 -1 true nil]]
(is (= [[alice-sid favNums-pid 42 8 -1 true nil]]
(->> @(fluree/slice db :spot [alice-sid favNums-pid 42])
(mapv flake/Flake->parts)))
"Slice should only return the specified favNum value")))

(testing "Slice for subject + predicate + value + datatype"
(let [alice-sid @(fluree/internal-id db :ex/alice)
favNums-pid @(fluree/internal-id db :ex/favNums)]
(is (= [[alice-sid favNums-pid 42 7 -1 true nil]]
(->> @(fluree/slice db :spot [alice-sid favNums-pid [42 7]])
(is (= [[alice-sid favNums-pid 42 8 -1 true nil]]
(->> @(fluree/slice db :spot [alice-sid favNums-pid [42 8]])
(mapv flake/Flake->parts)))
"Slice should only return the specified favNum value with matching datatype")))

(testing "Slice for subject + predicate + value + mismatch datatype"
(let [alice-sid @(fluree/internal-id db :ex/alice)
favNums-pid @(fluree/internal-id db :ex/favNums)]
(is (= []
(->> @(fluree/slice db :spot [alice-sid favNums-pid [42 8]])
(->> @(fluree/slice db :spot [alice-sid favNums-pid [42 7]])
(mapv flake/Flake->parts)))
"We specify a different datatype for the value, nothing should be returned")))

Expand Down
42 changes: 27 additions & 15 deletions test/fluree/db/test_utils.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,32 @@
(->> @(fluree/stage (fluree/db ledger) data)
(fluree/commit! ledger)))

(defn retry-load
"Retry loading a ledger until max-attempts. Hopefully not needed once JSON-LD
code has an equivalent to :syncTo"
[conn ledger-alias max-attempts]
(defn retry-promise-wrapped
"Retries a fn that when deref'd might return a Throwable. Intended for
retrying promise-wrapped API fns. Do not deref the return value, this will do
it for you."
[pwrapped max-attempts]
(loop [attempt 0]
(let [ledger (try
(let [res @(fluree/load conn ledger-alias)]
(if (instance? Throwable res)
(throw res)
res))
(catch Exception e
(when (= (inc attempt) max-attempts)
(throw e)
(Thread/sleep 100))))]
(if ledger
ledger
(let [final (try
(let [res @(pwrapped)]
(if (instance? Throwable res)
(throw res)
res))
(catch Throwable t
(when (= (inc attempt) max-attempts)
(throw t)
(Thread/sleep 100))))]
(if final
final
(recur (inc attempt))))))

(defn retry-load
"Retry loading a ledger until it loads or max-attempts. Hopefully not needed
once JSON-LD code has an equivalent to :syncTo"
[conn ledger-alias max-attempts]
(retry-promise-wrapped #(fluree/load conn ledger-alias) max-attempts))

(defn retry-exists?
"Retry calling exists? until it returns true or max-attempts."
[conn ledger-alias max-atttemts]
(retry-promise-wrapped #(fluree/exists? conn ledger-alias) max-atttemts))