Skip to content

Commit

Permalink
renamed :d2q-fcall-i to :d2q-fcall-j
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Waeselynck committed Oct 12, 2018
1 parent 64727c1 commit 65f372c
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 61 deletions.
10 changes: 5 additions & 5 deletions src/d2q/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]}>
Expand Down Expand Up @@ -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:
Expand All @@ -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))



Expand Down
2 changes: 1 addition & 1 deletion src/d2q/datatypes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
;; Resolvers datatypes

(defrecord ResultCell
[^int d2q-entcell-i
[^int d2q-entcell-j
^int d2q-fcall-i
d2q-rescell-value])

Expand Down
6 changes: 3 additions & 3 deletions src/d2q/helpers/resolvers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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)]
Expand Down
20 changes: 10 additions & 10 deletions src/d2q/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))

4 changes: 2 additions & 2 deletions src/d2q/impl/datatypes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))
18 changes: 9 additions & 9 deletions test/d2q/test/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}]}

Expand Down Expand Up @@ -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)
Expand Down
38 changes: 19 additions & 19 deletions test/d2q/test/example/persons.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 " "}]}
)


Expand Down Expand Up @@ -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"}}]}
)
Expand Down Expand Up @@ -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 []}]}

Expand Down Expand Up @@ -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"}]}]}
Expand Down
24 changes: 12 additions & 12 deletions test/d2q/test/helpers/resolvers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand Down Expand Up @@ -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},
Expand Down

0 comments on commit 65f372c

Please sign in to comment.