diff --git a/src/d2q/api.clj b/src/d2q/api.clj index 2adc25a..756254a 100644 --- a/src/d2q/api.clj +++ b/src/d2q/api.clj @@ -79,7 +79,7 @@ In a pseudo type notation, the signature of a :d2q.resolver/compute function would be: (QCtx, [[FieldCallIndex, FieldCall, FieldMeta]], [[EntityIndex, Entity]]) - -> manifold.Deferred<{:d2q-res-cells [{:d2q-entcell-i EntityIndex, + -> manifold.Deferred<{:d2q-res-cells [{:d2q-entcell-j EntityIndex, :d2q-fcall-i FieldCallIndex, :d2q-rescell-value V}], :d2q-errors [Throwable]}> @@ -119,7 +119,7 @@ (QCtx, Query, [[EntityIndex, Entity]]) -> manifold.Deferred<{:d2q-ent-selection [[EntityIndex, Entity]], :d2q-errors [Throwable] ;; TODO inconsistent naming (Val, 07 Apr 2018) - :d2q-early-results [{:d2q-entcell-i EntityIndex ;; TODO maybe also use a tuple here? (Val, 07 Apr 2018) + :d2q-early-results [{:d2q-entcell-j EntityIndex ;; TODO maybe also use a tuple here? (Val, 07 Apr 2018) :d2q-rescell-value V}]}> Notes: @@ -140,10 +140,10 @@ (defn result-cell "A representation of d2q Result Cells more efficient than using a plain Clojure map. Should be called from a d2q Resolver's :d2q.resolver/compute function." - [d2q-entcell-i d2q-fcall-i d2q-rescell-value] - {:pre [(integer? d2q-entcell-i) + [d2q-entcell-j d2q-fcall-i d2q-rescell-value] + {:pre [(integer? d2q-entcell-j) (integer? d2q-fcall-i)]} - (d2q.datatypes/->ResultCell d2q-entcell-i d2q-fcall-i d2q-rescell-value)) + (d2q.datatypes/->ResultCell d2q-entcell-j d2q-fcall-i d2q-rescell-value)) diff --git a/src/d2q/datatypes.clj b/src/d2q/datatypes.clj index c3b8d6e..33dc946 100644 --- a/src/d2q/datatypes.clj +++ b/src/d2q/datatypes.clj @@ -21,7 +21,7 @@ ;; Resolvers datatypes (defrecord ResultCell - [^int d2q-entcell-i + [^int d2q-entcell-j ^int d2q-fcall-i d2q-rescell-value]) diff --git a/src/d2q/helpers/resolvers.clj b/src/d2q/helpers/resolvers.clj index 38a1136..541e740 100644 --- a/src/d2q/helpers/resolvers.clj +++ b/src/d2q/helpers/resolvers.clj @@ -38,7 +38,7 @@ resolver-fn must be a function with arguments [qctx i+fcalls] (like an ordinary Resolver function, without the last j+entities argument), and returns the same results as an ordinary - resolver function, with dummy values for :d2q-entcell-i in Result Cells (typically -1 or nil). + resolver function, with dummy values for :d2q-entcell-j in Result Cells (typically -1 or nil). Each Result Cell returned by resolver-fn will be repeated once per input Entity." [resolver-fn] (fn [qctx i+fcalls j+entities] @@ -53,7 +53,7 @@ (->> js (mapv (fn [j] - (assoc partial-res-cell :d2q-entcell-i j)))))) + (assoc partial-res-cell :d2q-entcell-j j)))))) res-cells))))))) (defn fields-independent-resolver @@ -168,7 +168,7 @@ " To fix, make sure your `check-entity` function is correct, " " and that the upstream Resolver returns valid Entities." " See the cause of this Exception for details.") - {:d2q-entcell-i j} + {:d2q-entcell-j j} err)]))))) first second j+entities)] diff --git a/src/d2q/impl.clj b/src/d2q/impl.clj index bf78963..3fc96be 100644 --- a/src/d2q/impl.clj +++ b/src/d2q/impl.clj @@ -222,7 +222,7 @@ ;; scalar-typed case (d2q.impl.datatypes/->FinalResultCell scalar-k - (:d2q-entcell-i rcell) ;; IMPROVEMENT read primitive int for performance (Val, 06 Apr 2018) + (:d2q-entcell-j rcell) ;; IMPROVEMENT read primitive int for performance (Val, 06 Apr 2018) (:d2q-rescell-value rcell)))) (catch Throwable err ;; TODO enrich error with contextual data (Val, 05 Apr 2018) @@ -322,7 +322,7 @@ frcell (d2q.impl.datatypes/->FinalResultCell fck - (:d2q-entcell-i parent-cell) ;; IMPROVEMENT read primitive int for performance (Val, 06 Apr 2018) + (:d2q-entcell-j parent-cell) ;; IMPROVEMENT read primitive int for performance (Val, 06 Apr 2018) (subvec vs offset next-offset))] (recur (unchecked-inc-int i) @@ -339,7 +339,7 @@ frcell (d2q.impl.datatypes/->FinalResultCell fck - (:d2q-entcell-i parent-cell) ;; IMPROVEMENT read primitive int for performance (Val, 06 Apr 2018) + (:d2q-entcell-j parent-cell) ;; IMPROVEMENT read primitive int for performance (Val, 06 Apr 2018) (subvec vs offset next-offset))] (recur (next parent-cells) @@ -367,7 +367,7 @@ (fn [parent-cell child-v] (d2q.impl.datatypes/->FinalResultCell fck - (:d2q-entcell-i parent-cell) ;; IMPROVEMENT read primitive int for performance (Val, 06 Apr 2018) + (:d2q-entcell-j parent-cell) ;; IMPROVEMENT read primitive int for performance (Val, 06 Apr 2018) child-v)) res-cells d2q-results) @@ -386,7 +386,7 @@ (let [a-res (object-array n-ents)] (impl.utils/doarr-indexed! [[i _] a-res] (aset a-res i (transient {}))) - ;; PERFORMANCE IDEA would it be faster to sort by :d2q-entcell-i first? (Val, 05 Apr 2018) + ;; PERFORMANCE IDEA would it be faster to sort by :d2q-entcell-j first? (Val, 05 Apr 2018) (transduce (comp cat @@ -401,7 +401,7 @@ (when (seq early-results) (reduce (fn [_ early-result-cell] - (let [i (int (:d2q-entcell-i early-result-cell)) ;; IMPROVEMENT read primitive int for performance (Val, 06 Apr 2018) + (let [i (int (:d2q-entcell-j early-result-cell)) ;; IMPROVEMENT read primitive int for performance (Val, 06 Apr 2018) v (:d2q-rescell-value early-result-cell)] (aset a-res i v)) nil) @@ -578,7 +578,7 @@ (let [get-early-result (fn [[i e]] (when-let [res (get (meta e) :myapp/early-result)] - {:d2q-entcell-i i :d2q-rescell-value res})) + {:d2q-entcell-j i :d2q-rescell-value res})) early-results (into [] (keep get-early-result) @@ -941,7 +941,7 @@ (.write wtr (pr-str (into {} v)))) (defn read-result-cell - [{:as m, :keys [:d2q-entcell-i :d2q-fcall-i :d2q-rescell-value]}] - {:pre [(integer? d2q-entcell-i) (integer? d2q-fcall-i)]} - (d2q.datatypes/->ResultCell d2q-entcell-i d2q-fcall-i d2q-rescell-value)) + [{:as m, :keys [:d2q-entcell-j :d2q-fcall-i :d2q-rescell-value]}] + {:pre [(integer? d2q-entcell-j) (integer? d2q-fcall-i)]} + (d2q.datatypes/->ResultCell d2q-entcell-j d2q-fcall-i d2q-rescell-value)) diff --git a/src/d2q/impl/datatypes.clj b/src/d2q/impl/datatypes.clj index babce6a..8c088ed 100644 --- a/src/d2q/impl/datatypes.clj +++ b/src/d2q/impl/datatypes.clj @@ -5,12 +5,12 @@ (defrecord FinalResultCell [d2q-fcall-key - ^int d2q-entcell-i + ^int d2q-entcell-j d2q-rescell-value] IMergeInResultArray (merge-in-result-array [this arr] (let [^objects a arr - i d2q-entcell-i] + i d2q-entcell-j] (aset a i (assoc! (aget a i) d2q-fcall-key d2q-rescell-value))))) diff --git a/test/d2q/test/api.clj b/test/d2q/test/api.clj index 64a6855..cb49e43 100644 --- a/test/d2q/test/api.clj +++ b/test/d2q/test/api.clj @@ -95,18 +95,18 @@ [1 (->SynthEnt "b")]]) tu/errors->ex-data) => - '{:d2q-res-cells [#d2q/result-cell{:d2q-entcell-i 0, :d2q-fcall-i 0, :d2q-rescell-value "a"} - #d2q/result-cell{:d2q-entcell-i 1, :d2q-fcall-i 0, :d2q-rescell-value "b"} - #d2q/result-cell{:d2q-entcell-i 0, :d2q-fcall-i 1, :d2q-rescell-value "hello"} - #d2q/result-cell{:d2q-entcell-i 1, :d2q-fcall-i 1, :d2q-rescell-value "hello"} - #d2q/result-cell{:d2q-entcell-i 0, + '{:d2q-res-cells [#d2q/result-cell{:d2q-entcell-j 0, :d2q-fcall-i 0, :d2q-rescell-value "a"} + #d2q/result-cell{:d2q-entcell-j 1, :d2q-fcall-i 0, :d2q-rescell-value "b"} + #d2q/result-cell{:d2q-entcell-j 0, :d2q-fcall-i 1, :d2q-rescell-value "hello"} + #d2q/result-cell{:d2q-entcell-j 1, :d2q-fcall-i 1, :d2q-rescell-value "hello"} + #d2q/result-cell{:d2q-entcell-j 0, :d2q-fcall-i 2, :d2q-rescell-value #d2q.test.api.SynthEnt{:ent-id "a/a"}} - #d2q/result-cell{:d2q-entcell-i 1, + #d2q/result-cell{:d2q-entcell-j 1, :d2q-fcall-i 2, :d2q-rescell-value #d2q.test.api.SynthEnt{:ent-id "b/a"}} - #d2q/result-cell{:d2q-entcell-i 0, :d2q-fcall-i 5, :d2q-rescell-value :qctx} - #d2q/result-cell{:d2q-entcell-i 1, :d2q-fcall-i 5, :d2q-rescell-value :qctx}], + #d2q/result-cell{:d2q-entcell-j 0, :d2q-fcall-i 5, :d2q-rescell-value :qctx} + #d2q/result-cell{:d2q-entcell-j 1, :d2q-fcall-i 5, :d2q-rescell-value :qctx}], :d2q-errors [{:error/type clojure.lang.ExceptionInfo, :error/message "", :error/data {:error-tag "FZDSgjeizo"}} {:error/type clojure.lang.ExceptionInfo, :error/message "", :error/data {:error-tag "FZDSgjeizo"}}]} @@ -223,7 +223,7 @@ (let [err (ex-info msg data)] {:d2q-errors err}) (if-let [res (:synth.ent/early-result ent)] - {:d2q-early-results {:d2q-entcell-i ent-i :d2q-rescell-value res}} + {:d2q-early-results {:d2q-entcell-j ent-i :d2q-rescell-value res}} {:d2q-ent-selection cell})))) (reduce #(merge-with conj %1 %2) diff --git a/test/d2q/test/example/persons.clj b/test/d2q/test/example/persons.clj index c2df5a5..c96eeb9 100644 --- a/test/d2q/test/example/persons.clj +++ b/test/d2q/test/example/persons.clj @@ -358,15 +358,15 @@ [3 (->Person "non-existing-person")]]] @(resolve-person-fields qctx i+fcalls j+entities)) => - {:d2q-res-cells [#d2q/result-cell{:d2q-entcell-i 1, :d2q-fcall-i -1, :d2q-rescell-value "luke-skywalker"} - #d2q/result-cell{:d2q-entcell-i 1, :d2q-fcall-i -2, :d2q-rescell-value "Luke"} - #d2q/result-cell{:d2q-entcell-i 1, :d2q-fcall-i -3, :d2q-rescell-value "Skywalker"} - #d2q/result-cell{:d2q-entcell-i 1, :d2q-fcall-i -4, :d2q-rescell-value "Luke Skywalker"} - #d2q/result-cell{:d2q-entcell-i 2, :d2q-fcall-i -1, :d2q-rescell-value "padme-amidala"} - #d2q/result-cell{:d2q-entcell-i 2, :d2q-fcall-i -2, :d2q-rescell-value "Padme"} - #d2q/result-cell{:d2q-entcell-i 2, :d2q-fcall-i -3, :d2q-rescell-value "Amidala"} - #d2q/result-cell{:d2q-entcell-i 2, :d2q-fcall-i -4, :d2q-rescell-value "Padme Amidala"} - #d2q/result-cell{:d2q-entcell-i 3, :d2q-fcall-i -4, :d2q-rescell-value " "}]} + {:d2q-res-cells [#d2q/result-cell{:d2q-entcell-j 1, :d2q-fcall-i -1, :d2q-rescell-value "luke-skywalker"} + #d2q/result-cell{:d2q-entcell-j 1, :d2q-fcall-i -2, :d2q-rescell-value "Luke"} + #d2q/result-cell{:d2q-entcell-j 1, :d2q-fcall-i -3, :d2q-rescell-value "Skywalker"} + #d2q/result-cell{:d2q-entcell-j 1, :d2q-fcall-i -4, :d2q-rescell-value "Luke Skywalker"} + #d2q/result-cell{:d2q-entcell-j 2, :d2q-fcall-i -1, :d2q-rescell-value "padme-amidala"} + #d2q/result-cell{:d2q-entcell-j 2, :d2q-fcall-i -2, :d2q-rescell-value "Padme"} + #d2q/result-cell{:d2q-entcell-j 2, :d2q-fcall-i -3, :d2q-rescell-value "Amidala"} + #d2q/result-cell{:d2q-entcell-j 2, :d2q-fcall-i -4, :d2q-rescell-value "Padme Amidala"} + #d2q/result-cell{:d2q-entcell-j 3, :d2q-fcall-i -4, :d2q-rescell-value " "}]} ) @@ -397,16 +397,16 @@ @(resolve-persons-by-ids qctx i+fcalls j+entities)) => - {:d2q-res-cells [#d2q/result-cell{:d2q-entcell-i 1, + {:d2q-res-cells [#d2q/result-cell{:d2q-entcell-j 1, :d2q-fcall-i -1, :d2q-rescell-value #d2q.test.example.persons.Person{:person-id "luke-skywalker"}} - #d2q/result-cell{:d2q-entcell-i 2, + #d2q/result-cell{:d2q-entcell-j 2, :d2q-fcall-i -1, :d2q-rescell-value #d2q.test.example.persons.Person{:person-id "luke-skywalker"}} - #d2q/result-cell{:d2q-entcell-i 1, + #d2q/result-cell{:d2q-entcell-j 1, :d2q-fcall-i -2, :d2q-rescell-value #d2q.test.example.persons.Person{:person-id "leia-organa"}} - #d2q/result-cell{:d2q-entcell-i 2, + #d2q/result-cell{:d2q-entcell-j 2, :d2q-fcall-i -2, :d2q-rescell-value #d2q.test.example.persons.Person{:person-id "leia-organa"}}]} ) @@ -453,17 +453,17 @@ [2 (->Person "anakin-skywalker")]]] ;; NOTE has no parents in our DB @(resolve-person-parents qctx i+fcalls j+entities)) => - {:d2q-res-cells [#d2q/result-cell{:d2q-entcell-i 1, + {:d2q-res-cells [#d2q/result-cell{:d2q-entcell-j 1, :d2q-fcall-i -1, :d2q-rescell-value #d2q.test.example.persons.Person{:person-id "padme-amidala"}} - #d2q/result-cell{:d2q-entcell-i 1, + #d2q/result-cell{:d2q-entcell-j 1, :d2q-fcall-i -2, :d2q-rescell-value #d2q.test.example.persons.Person{:person-id "anakin-skywalker"}} - #d2q/result-cell{:d2q-entcell-i 1, + #d2q/result-cell{:d2q-entcell-j 1, :d2q-fcall-i -3, :d2q-rescell-value [#d2q.test.example.persons.Person{:person-id "padme-amidala"} #d2q.test.example.persons.Person{:person-id "padme-amidala"}]} - #d2q/result-cell{:d2q-entcell-i 2, + #d2q/result-cell{:d2q-entcell-j 2, :d2q-fcall-i -3, :d2q-rescell-value []}]} @@ -501,10 +501,10 @@ [2 (->Person "anakin-skywalker")]]] @(resolve-person-children qctx i+fcalls j+entities)) => - {:d2q-res-cells [#d2q/result-cell{:d2q-entcell-i 1, + {:d2q-res-cells [#d2q/result-cell{:d2q-entcell-j 1, :d2q-fcall-i -1, :d2q-rescell-value []} - #d2q/result-cell{:d2q-entcell-i 2, + #d2q/result-cell{:d2q-entcell-j 2, :d2q-fcall-i -1, :d2q-rescell-value [#d2q.test.example.persons.Person{:person-id "luke-skywalker"} #d2q.test.example.persons.Person{:person-id "leia-organa"}]}]} diff --git a/test/d2q/test/helpers/resolvers.clj b/test/d2q/test/helpers/resolvers.clj index fc6c394..0f52685 100644 --- a/test/d2q/test/helpers/resolvers.clj +++ b/test/d2q/test/helpers/resolvers.clj @@ -23,10 +23,10 @@ tu/errors->ex-data) => - '{:d2q-res-cells [#d2q/result-cell{:d2q-entcell-i 0, :d2q-fcall-i 0, :d2q-rescell-value -1/2} - #d2q/result-cell{:d2q-entcell-i 1, :d2q-fcall-i 0, :d2q-rescell-value -1} - #d2q/result-cell{:d2q-entcell-i 3, :d2q-fcall-i 0, :d2q-rescell-value 1} - #d2q/result-cell{:d2q-entcell-i 4, :d2q-fcall-i 0, :d2q-rescell-value 1/2}], + '{:d2q-res-cells [#d2q/result-cell{:d2q-entcell-j 0, :d2q-fcall-i 0, :d2q-rescell-value -1/2} + #d2q/result-cell{:d2q-entcell-j 1, :d2q-fcall-i 0, :d2q-rescell-value -1} + #d2q/result-cell{:d2q-entcell-j 3, :d2q-fcall-i 0, :d2q-rescell-value 1} + #d2q/result-cell{:d2q-entcell-j 4, :d2q-fcall-i 0, :d2q-rescell-value 1/2}], :d2q-errors [{:error/type clojure.lang.ExceptionInfo, :error/message "aaaaaarrrrg", :error/data {:n 0}, @@ -49,10 +49,10 @@ (range -2 3))) tu/errors->ex-data) => - '{:d2q-res-cells [#d2q/result-cell{:d2q-entcell-i 0, :d2q-fcall-i 0, :d2q-rescell-value -1/2} - #d2q/result-cell{:d2q-entcell-i 1, :d2q-fcall-i 0, :d2q-rescell-value -1} - #d2q/result-cell{:d2q-entcell-i 3, :d2q-fcall-i 0, :d2q-rescell-value 1} - #d2q/result-cell{:d2q-entcell-i 4, :d2q-fcall-i 0, :d2q-rescell-value 1/2}], + '{:d2q-res-cells [#d2q/result-cell{:d2q-entcell-j 0, :d2q-fcall-i 0, :d2q-rescell-value -1/2} + #d2q/result-cell{:d2q-entcell-j 1, :d2q-fcall-i 0, :d2q-rescell-value -1} + #d2q/result-cell{:d2q-entcell-j 3, :d2q-fcall-i 0, :d2q-rescell-value 1} + #d2q/result-cell{:d2q-entcell-j 4, :d2q-fcall-i 0, :d2q-rescell-value 1/2}], :d2q-errors [{:error/type clojure.lang.ExceptionInfo, :error/message "aaaaaarrrrg", :error/data {:n 0}, @@ -87,10 +87,10 @@ [20 :entity-2]]) tu/errors->ex-data (supd/supdate {:d2q-res-cells set})) - => '{:d2q-res-cells #{#d2q/result-cell{:d2q-entcell-i 20, :d2q-fcall-i 1, :d2q-rescell-value 2.0} - #d2q/result-cell{:d2q-entcell-i 20, :d2q-fcall-i 0, :d2q-rescell-value 0.0} - #d2q/result-cell{:d2q-entcell-i 10, :d2q-fcall-i 0, :d2q-rescell-value 0.0} - #d2q/result-cell{:d2q-entcell-i 10, :d2q-fcall-i 1, :d2q-rescell-value 2.0}}, + => '{:d2q-res-cells #{#d2q/result-cell{:d2q-entcell-j 20, :d2q-fcall-i 1, :d2q-rescell-value 2.0} + #d2q/result-cell{:d2q-entcell-j 20, :d2q-fcall-i 0, :d2q-rescell-value 0.0} + #d2q/result-cell{:d2q-entcell-j 10, :d2q-fcall-i 0, :d2q-rescell-value 0.0} + #d2q/result-cell{:d2q-entcell-j 10, :d2q-fcall-i 1, :d2q-rescell-value 2.0}}, :d2q-errors [{:error/type clojure.lang.ExceptionInfo, :error/message "Failed to take square root of -1.0", :error/data {:d2q-fcall-i 2},