Skip to content
Snippets Groups Projects
Unverified Commit b424ddba authored by Case Nelson's avatar Case Nelson Committed by GitHub
Browse files

Add current-limit setter for a query limit (#29376)

* Add current-limit setter for a query limit

* Add docstring
parent 3b69bba3
Branches
Tags
No related merge requests found
......@@ -89,6 +89,7 @@
join-clause
joins]
[lib.limit
current-limit
limit]
[lib.order-by
order-by
......
......@@ -24,3 +24,11 @@
(if n
(assoc stage :limit n)
(dissoc stage :limit))))))
(mu/defn current-limit :- [:maybe ::lib.schema.common/int-greater-than-zero]
"Get the maximum number of rows to be returned by a stage of a query. `nil` indicates there is no limit"
([query :- ::lib.schema/query]
(current-limit query -1))
([query :- ::lib.schema/query
stage-number :- :int]
(:limit (lib.util/query-stage query stage-number))))
......@@ -18,3 +18,19 @@
(is (= ::not-found
(limit (-> query
(lib/limit nil)))))))))
(deftest ^:parallel current-limit-test
(testing "Last stage"
(let [query (lib/query-for-table-name meta/metadata-provider "VENUES")]
(is (nil? (lib/current-limit query)))
(is (nil? (lib/current-limit query -1)))
(is (= 100 (lib/current-limit (lib/limit query 100))))
(is (= 100 (lib/current-limit (lib/limit query 100) -1)))))
(testing "First stage"
(let [query (lib/query meta/metadata-provider {:database (meta/id)
:type :query
:query {:source-query {:source-table (meta/id :venues)}}})]
(is (nil? (lib/current-limit query 0)))
(is (nil? (lib/current-limit query 1)))
(is (= 100 (lib/current-limit (lib/limit query 0 100) 0)))
(is (nil? (lib/current-limit query 1))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment