Skip to content

Commit

Permalink
Fix format. (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
whilo authored Jan 22, 2024
1 parent 3b19bdc commit 4d1b290
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 30 deletions.
6 changes: 2 additions & 4 deletions src/datahike/query.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,6 @@
stats? (assoc :tmp-stats {:type :rule
:branches tmp-stats}))))))


(defn resolve-pattern-lookup-entity-id [source e error-code]
(cond
(or (lookup-ref? e) (attr? e)) (dbu/entid-strict source e error-code)
Expand Down Expand Up @@ -1118,7 +1117,7 @@ which can be seen if we request 'Query stats' from Datomic:
https://docs.datomic.com/pro/api/query-stats.html"
[relprod]
{:pre [(relprod? relprod)]}
{:pre [(relprod? relprod)]}
(relprod-filter relprod (constantly true)))

(defn select-simple
Expand Down Expand Up @@ -1179,12 +1178,11 @@ than doing no expansion at all."
(binding [*lookup-attrs* (if (satisfies? dbi/IDB source)
(dynamic-lookup-attrs source pattern-before-expansion)
*lookup-attrs*)]

(cond-> (update context :rels collapse-rels relation)
(:stats context) (assoc :tmp-stats {:type :lookup
:lookup-stats lookup-stats})))))


(defn -resolve-clause*
([context clause]
(-resolve-clause* context clause clause))
Expand Down
3 changes: 1 addition & 2 deletions test/datahike/test/query_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@
(long-array [3 4])])))
(is (= [[3 4] [9 7]] (dq/distinct-tuples [[3 4] [9 7] [3 4]]))))


(defn simple-rel
([v values] (simple-rel v values {}))
([v values extra]
Expand Down Expand Up @@ -563,7 +562,7 @@
(is (= #{'?x '?y '?w} (prodks relprod-xy)))
(is (= #{'?x '?y '?w} (prodks relprod-xy2)))
(is (= #{'?y '?w} (prodks relprod-y)))

(doseq [{:keys [include exclude vars]} [relprod relprod-x relprod-xy relprod-xy2 relprod-y]]
(is (= 2 (+ (count include)
(count exclude))))
Expand Down
47 changes: 23 additions & 24 deletions test/datahike/test/strategy_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,10 @@
(fn [kv-pairs]
(mapv first kv-pairs)))]
(doseq [[k v] (sort-by val (update-vals groups count))]
(log/info k v))
(log/info k v))
(log/info "Total count:" (count concept-map))
groups))


(deftest synthetic-ssyk-tree-test

"In this test we construct a labor market taxonomy of occupations. Given
Expand All @@ -135,7 +134,7 @@ identity to perform well because there will always be some substitutions to be m
In the second query, we provide two input ids. This means that the select-simple
strategy will not perform the substitution that it performed in the first case where
we only had one one input id. Therefore, it will perform about as bad as identity."

(testing "Given some concepts, query concepts that are broader."
(let [conn (initialize-test-db0)
ssyk-data (make-forest
Expand Down Expand Up @@ -220,7 +219,7 @@ of those rows will be discarded. So it will be slower.
Finally, the select-simple and identity strategies will both run the query
`[?cc :concept/broader ?pc]` without any substitutions which will return 8000 rows
to be filtered."

(let [conn (initialize-test-db0)
ssyk-data (make-forest [4 "ssyk-level-1" 2000 "ssyk-level-2"])
ssyk-concept-map (:concept-map ssyk-data)
Expand All @@ -234,15 +233,15 @@ to be filtered."
_ (is (= 3 (count child-ids)))
result-map (evaluate-strategy-times
(fn [strategy]
(d/q {:query ' {:find [?parent-id ?child-id]
:keys [parent_id child_id]
:in [$
[?parent-id ...]
[?child-id ...]],
:where
[[?pc :concept/id ?parent-id]
[?cc :concept/id ?child-id]
[?cc :concept/broader ?pc]]}
(d/q {:query '{:find [?parent-id ?child-id]
:keys [parent_id child_id]
:in [$
[?parent-id ...]
[?child-id ...]],
:where
[[?pc :concept/id ?parent-id]
[?cc :concept/id ?child-id]
[?cc :concept/broader ?pc]]}
:settings {:relprod-strategy strategy}
:args [(d/db conn)
parent-ids
Expand Down Expand Up @@ -271,7 +270,7 @@ it will perform 40000 = 200*200 substitutions for all possible combinations of
`?cc` and `?pc`. Out of those 40000 combinations, only 200 will be valid. That means
39800 database backend queries that return nothing. All the other strategies, even
identity, perform better than that."

(let [conn (initialize-test-db0)
ssyk-data (make-forest [200 "ssyk-level-1" 1 "ssyk-level-2"])
ssyk-concept-map (:concept-map ssyk-data)
Expand All @@ -282,20 +281,20 @@ identity, perform better than that."
;; `expand-once`, `identity` and `select-simple` will perform roughly the same.
extra-data (make-forest [100 "skill-headline" 100 "skill"] (count ssyk-concept-map))
_ (d/transact conn {:tx-data (:tx-data extra-data)})

_concepts-per-type (group-concepts-by-type ssyk-concept-map)]
(testing "Query (parent,child) pairs from a *large* set of possible combinations in a labour market taxonomy."
(let [result-map (evaluate-strategy-times
(fn [strategy]
(d/q {:query ' {:find [?parent-id ?child-id]
:keys [parent_id child_id]
:in [$ %],
:where
[[?pc :concept/type "ssyk-level-1"]
[?cc :concept/type "ssyk-level-2"]
[?cc :concept/broader ?pc]
[?pc :concept/id ?parent-id]
[?cc :concept/id ?child-id]]}
(d/q {:query '{:find [?parent-id ?child-id]
:keys [parent_id child_id]
:in [$ %],
:where
[[?pc :concept/type "ssyk-level-1"]
[?cc :concept/type "ssyk-level-2"]
[?cc :concept/broader ?pc]
[?pc :concept/id ?parent-id]
[?cc :concept/id ?child-id]]}
:settings {:relprod-strategy strategy}
:args [(d/db conn)]
:stats? true})))
Expand Down

0 comments on commit 4d1b290

Please sign in to comment.