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

[MLv2] Support replacing segments (#34547)

parent d721afee
No related branches found
No related tags found
No related merge requests found
......@@ -48,6 +48,10 @@
[metric-def]
(lib.ref/ref metric-def))
(defmethod ->op-arg :metadata/segment
[segment-def]
(lib.ref/ref segment-def))
(defmethod ->op-arg :lib/external-op
[{:keys [operator options args] :or {options {}}}]
(->op-arg (lib.options/ensure-uuid (into [(keyword operator) options]
......
......@@ -409,6 +409,28 @@
(first (lib/available-metrics query)))
(as-> $q (lib/replace-clause $q (first (lib/aggregations $q)) (lib/count)))))))))
(deftest ^:parallel replace-segment-test
(testing "replacing with segment should work"
(let [metadata-provider (lib.tu/mock-metadata-provider
meta/metadata-provider
{:segments [{:id 100
:name "Price is 4"
:definition {:filter
[:= [:field (meta/id :venues :price) nil] 4]}
:table-id (meta/id :venues)}
{:id 200
:name "Price is 5"
:definition {:filter
[:= [:field (meta/id :venues :price) nil] 5]}
:table-id (meta/id :venues)}]})
query (-> (lib/query metadata-provider (meta/table-metadata :venues))
(lib/filter (lib/segment 100)))]
(is (=? {:stages [{:filters [[:segment {:lib/uuid string?} 200]]}]}
(lib/replace-clause
query
(first (lib/filters query))
(second (lib/available-segments query))))))))
(deftest ^:parallel replace-clause-expression-test
(let [query (-> lib.tu/venues-query
(lib/expression "a" (meta/field-metadata :venues :id))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment