Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Differentiate different geographic drills and don't show duplicates (#62778)

Williama08cb0df7bdb
diff --git a/e2e/test/scenarios/visualizations-tabular/drillthroughs/chart_drill.cy.spec.js b/e2e/test/scenarios/visualizations-tabular/drillthroughs/chart_drill.cy.spec.js
index 1538c9fef88..52d5acadae3 100644
--- a/e2e/test/scenarios/visualizations-tabular/drillthroughs/chart_drill.cy.spec.js
+++ b/e2e/test/scenarios/visualizations-tabular/drillthroughs/chart_drill.cy.spec.js
@@ -868,7 +868,7 @@ describe("scenarios > visualizations > drillthroughs > chart drill", () => {
cy.findByTestId("click-actions-popover-content-for-Count").within(() => {
cy.findByText("See these People").should("be.visible");
- cy.findByText("Zoom in").should("be.visible");
+ cy.findByText("Zoom in: State").should("be.visible");
cy.findByText("Break out by…").should("be.visible");
cy.findByText("Automatic insights…").should("be.visible");
diff --git a/e2e/test/scenarios/visualizations-tabular/drillthroughs/geographic_drill.cy.spec.ts b/e2e/test/scenarios/visualizations-tabular/drillthroughs/geographic_drill.cy.spec.ts
new file mode 100644
index 00000000000..82d4d8b4504
--- /dev/null
+++ b/e2e/test/scenarios/visualizations-tabular/drillthroughs/geographic_drill.cy.spec.ts
@@ -0,0 +1,142 @@
+const { H } = cy;
+import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
+
+const { ORDERS, ORDERS_ID, PEOPLE, PEOPLE_ID } = SAMPLE_DATABASE;
+
+describe("scenarios > visualizations > drillthroughs > geographic drill", () => {
+ beforeEach(() => {
+ H.restore();
+ cy.signInAsAdmin();
+ });
+
+ it("should display proper drills for city, state, and lat/lon queries", () => {
+ H.createQuestion(
+ {
+ name: "Geographic Drills",
+ query: {
+ "source-table": PEOPLE_ID,
+ aggregation: [["count"]],
+ breakout: [
+ ["field", PEOPLE.STATE, null],
+ ["field", PEOPLE.CITY, null],
+ ["field", PEOPLE.LATITUDE, { binning: { strategy: "default" } }],
+ ["field", PEOPLE.LONGITUDE, { binning: { strategy: "default" } }],
+ ],
+ },
+ display: "table",
+ },
+ { visitQuestion: true },
+ );
+
+ cy.findByTestId("table-body").findAllByText("1").first().click();
+ H.popover().within(() => {
+ cy.findByText("Zoom in: City").should("be.visible");
+ cy.findByText("Zoom in: State").should("be.visible");
+ cy.findByText("Zoom in: Lat/Lon").should("be.visible");
+ cy.findByText("Zoom in").should("not.exist");
+ });
+ });
+
+ it("should display normal binning zoom in when only lat exists", () => {
+ H.createQuestion(
+ {
+ name: "Geographic Drills",
+ query: {
+ "source-table": PEOPLE_ID,
+ aggregation: [["count"]],
+ breakout: [
+ ["field", PEOPLE.STATE, null],
+ ["field", PEOPLE.CITY, null],
+ ["field", PEOPLE.LATITUDE, { binning: { strategy: "default" } }],
+ ],
+ },
+ display: "table",
+ },
+ { visitQuestion: true },
+ );
+
+ cy.findByTestId("table-body").findAllByText("1").first().click();
+ H.popover().within(() => {
+ cy.findByText("Zoom in: City").should("be.visible");
+ cy.findByText("Zoom in: State").should("be.visible");
+ cy.findByText("Zoom in: Lat/Lon").should("not.exist");
+ cy.findByText("Zoom in").should("be.visible");
+ });
+ });
+
+ it("should display normal binning zoom in when only lon exists", () => {
+ H.createQuestion(
+ {
+ name: "Geographic Drills",
+ query: {
+ "source-table": PEOPLE_ID,
+ aggregation: [["count"]],
+ breakout: [
+ ["field", PEOPLE.STATE, null],
+ ["field", PEOPLE.CITY, null],
+ ["field", PEOPLE.LONGITUDE, { binning: { strategy: "default" } }],
+ ],
+ },
+ display: "table",
+ },
+ { visitQuestion: true },
+ );
+
+ cy.findByTestId("table-body").findAllByText("1").first().click();
+ H.popover().within(() => {
+ cy.findByText("Zoom in: City").should("be.visible");
+ cy.findByText("Zoom in: State").should("be.visible");
+ cy.findByText("Zoom in: Lat/Lon").should("not.exist");
+ cy.findByText("Zoom in").should("be.visible");
+ });
+ });
+
+ it("should display both normal and lat/lon zoom in when lat/lon and a binnable column both exist", () => {
+ H.createQuestion(
+ {
+ name: "Geographic Drills",
+ query: {
+ "source-table": PEOPLE_ID,
+ joins: [
+ {
+ "source-table": ORDERS_ID,
+ condition: [
+ "=",
+ ["field", PEOPLE.ID, null],
+ ["field", ORDERS.USER_ID, null],
+ ],
+ alias: "Orders",
+ fields: "all",
+ },
+ ],
+ filter: [
+ "not-null",
+ ["field", ORDERS.SUBTOTAL, { "join-alias": "Orders" }],
+ ],
+ aggregation: [["count"]],
+ breakout: [
+ ["field", PEOPLE.STATE, null],
+ ["field", PEOPLE.CITY, null],
+ ["field", PEOPLE.LATITUDE, { binning: { strategy: "default" } }],
+ ["field", PEOPLE.LONGITUDE, { binning: { strategy: "default" } }],
+ [
+ "field",
+ ORDERS.SUBTOTAL,
+ { binning: { strategy: "default" }, "join-alias": "Orders" },
+ ],
+ ],
+ },
+ display: "table",
+ },
+ { visitQuestion: true },
+ );
+
+ cy.findByTestId("table-body").findAllByText("1").first().click();
+ H.popover().within(() => {
+ cy.findByText("Zoom in: City").should("be.visible");
+ cy.findByText("Zoom in: State").should("be.visible");
+ cy.findByText("Zoom in: Lat/Lon").should("be.visible");
+ cy.findByText("Zoom in").should("be.visible");
+ });
+ });
+});
diff --git a/e2e/test/scenarios/visualizations-tabular/pivot_tables.cy.spec.js b/e2e/test/scenarios/visualizations-tabular/pivot_tables.cy.spec.js
index 3c3e4b4eb37..203af5fbb0f 100644
--- a/e2e/test/scenarios/visualizations-tabular/pivot_tables.cy.spec.js
+++ b/e2e/test/scenarios/visualizations-tabular/pivot_tables.cy.spec.js
@@ -1311,7 +1311,7 @@ describe("scenarios > visualizations > pivot tables", { tags: "@slow" }, () => {
it("correctly filters the query when zooming in on a **row** header (metabase#38265)", () => {
cy.findByTestId("pivot-table").findByText("KS").click();
- H.popover().findByText("Zoom in").click();
+ H.popover().findByText("Zoom in: State").click();
cy.log("Filter pills");
cy.findByTestId("filter-pill").should("have.text", "User → State is KS");
diff --git a/frontend/src/metabase-lib/types.ts b/frontend/src/metabase-lib/types.ts
index 6d1bdd1c8d2..7f514f4054d 100644
--- a/frontend/src/metabase-lib/types.ts
+++ b/frontend/src/metabase-lib/types.ts
@@ -576,6 +576,11 @@ export type ZoomTimeseriesDrillThruInfo =
displayName?: string;
};
+export type ZoomGeographicDrillThruInfo =
+ BaseDrillThruInfo<"drill-thru/zoom-in.geographic"> & {
+ displayName: string;
+ };
+
export type DrillThruDisplayInfo =
| ColumnExtractDrillThruInfo
| CombineColumnsDrillThruInfo
@@ -591,7 +596,8 @@ export type DrillThruDisplayInfo =
| SummarizeColumnByTimeDrillThruInfo
| ColumnFilterDrillThruInfo
| UnderlyingRecordsDrillThruInfo
- | ZoomTimeseriesDrillThruInfo;
+ | ZoomTimeseriesDrillThruInfo
+ | ZoomGeographicDrillThruInfo;
export type FilterDrillDetails = {
query: Query;
diff --git a/frontend/src/metabase/querying/drills/utils/zoom-in-geographic-drill.ts b/frontend/src/metabase/querying/drills/utils/zoom-in-geographic-drill.ts
index dac42f531fa..c3306edbef6 100644
--- a/frontend/src/metabase/querying/drills/utils/zoom-in-geographic-drill.ts
+++ b/frontend/src/metabase/querying/drills/utils/zoom-in-geographic-drill.ts
@@ -1,16 +1,15 @@
-import { t } from "ttag";
-
import type { Drill } from "metabase/visualizations/types";
import type * as Lib from "metabase-lib";
-export const zoomInGeographicDrill: Drill<Lib.ZoomDrillThruInfo> = ({
+export const zoomInGeographicDrill: Drill<Lib.ZoomGeographicDrillThruInfo> = ({
drill,
applyDrill,
+ drillInfo,
}) => {
return [
{
name: "zoom-in.geographic",
- title: t`Zoom in`,
+ title: drillInfo.displayName,
section: "zoom",
icon: "zoom_in",
buttonType: "horizontal",
diff --git a/src/metabase/lib/drill_thru/zoom_in_bins.cljc b/src/metabase/lib/drill_thru/zoom_in_bins.cljc
index cd4cad63749..91c9036fe4c 100644
--- a/src/metabase/lib/drill_thru/zoom_in_bins.cljc
+++ b/src/metabase/lib/drill_thru/zoom_in_bins.cljc
@@ -74,11 +74,13 @@
[metabase.lib.drill-thru.common :as lib.drill-thru.common]
[metabase.lib.equality :as lib.equality]
[metabase.lib.filter :as lib.filter]
+ [metabase.lib.metadata.calculation :as lib.metadata.calculation]
[metabase.lib.remove-replace :as lib.remove-replace]
[metabase.lib.schema :as lib.schema]
[metabase.lib.schema.binning :as lib.schema.binning]
[metabase.lib.schema.drill-thru :as lib.schema.drill-thru]
[metabase.lib.schema.metadata :as lib.schema.metadata]
+ [metabase.lib.types.isa :as lib.types.isa]
[metabase.lib.underlying :as lib.underlying]
[metabase.util.malli :as mu]))
@@ -86,13 +88,24 @@
;;; available-drill-thrus
;;;
+(defn- has-lat-lon? [query stage-number]
+ (->> [(lib.metadata.calculation/returned-columns query stage-number)
+ (lib.metadata.calculation/visible-columns query stage-number)]
+ (some (fn [columns]
+ [(some lib.types.isa/latitude? columns)
+ (some lib.types.isa/longitude? columns)]))
+ (every? identity)))
+
(mu/defn zoom-in-binning-drill :- [:maybe ::lib.schema.drill-thru/drill-thru.zoom-in.binning]
"Return a drill thru that 'zooms in' on a breakout that uses `:binning` if applicable.
See [[metabase.lib.drill-thru.zoom-in-bins]] docstring for more information."
[query :- ::lib.schema/query
- _stage-number :- :int
- {:keys [column value], :as _context} :- ::lib.schema.drill-thru/context]
- (when (and column value (not= value :null))
+ stage-number :- :int
+ {{:keys [semantic-type] :as column} :column, :keys [value], :as _context} :- ::lib.schema.drill-thru/context]
+ (when (and column value (not= value :null)
+ (or (not (or (= semantic-type :type/Latitude)
+ (= semantic-type :type/Longitude)))
+ (not (has-lat-lon? query stage-number))))
(when-let [existing-breakout (first (lib.breakout/existing-breakouts query
(lib.underlying/top-level-stage-number query)
column))]
diff --git a/src/metabase/lib/drill_thru/zoom_in_geographic.cljc b/src/metabase/lib/drill_thru/zoom_in_geographic.cljc
index 4d624471bfc..489a01198c5 100644
--- a/src/metabase/lib/drill_thru/zoom_in_geographic.cljc
+++ b/src/metabase/lib/drill_thru/zoom_in_geographic.cljc
@@ -88,6 +88,7 @@
[metabase.lib.schema.metadata :as lib.schema.metadata]
[metabase.lib.types.isa :as lib.types.isa]
[metabase.lib.underlying :as lib.underlying]
+ [metabase.util.i18n :as i18n]
[metabase.util.malli :as mu]))
(def ^:private ContextWithLatLon
@@ -136,15 +137,20 @@
[{:keys [column value lat-column lon-column], :as _context} :- ContextWithLatLon
lat-lon-bin-width :- ::lib.schema.binning/bin-width]
(when value
- {:lib/type :metabase.lib.drill-thru/drill-thru
- :type :drill-thru/zoom-in.geographic
- :subtype :drill-thru.zoom-in.geographic/country-state-city->binned-lat-lon
- :column column
- :value value
- :latitude {:column lat-column
- :bin-width lat-lon-bin-width}
- :longitude {:column lon-column
- :bin-width lat-lon-bin-width}}))
+ {:lib/type :metabase.lib.drill-thru/drill-thru
+ :type :drill-thru/zoom-in.geographic
+ :subtype :drill-thru.zoom-in.geographic/country-state-city->binned-lat-lon
+ :column column
+ :value value
+ :display-name (case (:semantic-type column)
+ :type/City (i18n/tru "Zoom in: City")
+ :type/State (i18n/tru "Zoom in: State")
+ :type/Country (i18n/tru "Zoom in: Country")
+ (i18n/tru "Zoom in"))
+ :latitude {:column lat-column
+ :bin-width lat-lon-bin-width}
+ :longitude {:column lon-column
+ :bin-width lat-lon-bin-width}}))
(mu/defn- country->binned-lat-lon-drill :- [:maybe ::lib.schema.drill-thru/drill-thru.zoom-in.geographic.country-state-city->binned-lat-lon]
[{:keys [column], :as context} :- ContextWithLatLon]
@@ -163,9 +169,13 @@
(mu/defn- binned-lat-lon->binned-lat-lon-drill :- [:maybe ::lib.schema.drill-thru/drill-thru.zoom-in.geographic.binned-lat-lon->binned-lat-lon]
[metadata-providerable :- ::lib.schema.metadata/metadata-providerable
- {:keys [lat-column lon-column lat-value lon-value], :as _context} :- ContextWithLatLon]
+ {:keys [column lat-column lon-column lat-value lon-value], :as _context} :- ContextWithLatLon]
(when (and lat-value
- lon-value)
+ lon-value
+ ;; Only display this drill for latitude columns. We only display this drill when we have both latitude
+ ;; and longitude columns, so by default, we get this drill twice whenever it shows up. Only displaying
+ ;; it for one column type fixes that.
+ (= (:semantic-type column) :type/Latitude))
(when-let [{lat-bin-width :bin-width} (lib.binning/resolve-bin-width metadata-providerable lat-column lat-value)]
(when-let [{lon-bin-width :bin-width} (lib.binning/resolve-bin-width metadata-providerable lon-column lon-value)]
(let [[new-lat-bin-width new-lon-bin-width] (if (and (>= lat-bin-width 20)
@@ -173,17 +183,18 @@
[10 10]
[(/ lat-bin-width 10.0)
(/ lon-bin-width 10.0)])]
- {:lib/type :metabase.lib.drill-thru/drill-thru
- :type :drill-thru/zoom-in.geographic
- :subtype :drill-thru.zoom-in.geographic/binned-lat-lon->binned-lat-lon
- :latitude {:column lat-column
- :bin-width new-lat-bin-width
- :min lat-value
- :max (+ lat-value lat-bin-width)}
- :longitude {:column lon-column
- :bin-width new-lon-bin-width
- :min lon-value
- :max (+ lon-value lon-bin-width)}})))))
+ {:lib/type :metabase.lib.drill-thru/drill-thru
+ :type :drill-thru/zoom-in.geographic
+ :subtype :drill-thru.zoom-in.geographic/binned-lat-lon->binned-lat-lon
+ :display-name (i18n/tru "Zoom in: Lat/Lon")
+ :latitude {:column lat-column
+ :bin-width new-lat-bin-width
+ :min lat-value
+ :max (+ lat-value lat-bin-width)}
+ :longitude {:column lon-column
+ :bin-width new-lon-bin-width
+ :min lon-value
+ :max (+ lon-value lon-bin-width)}})))))
(mu/defn zoom-in-geographic-drill :- [:maybe ::lib.schema.drill-thru/drill-thru.zoom-in.geographic]
"Return a `:drill-thru/zoom-in.geographic` drill if appropriate. See docstring
diff --git a/test/metabase/lib/drill_thru_test.cljc b/test/metabase/lib/drill_thru_test.cljc
index 1c2632b48d0..265598ba0ec 100644
--- a/test/metabase/lib/drill_thru_test.cljc
+++ b/test/metabase/lib/drill_thru_test.cljc
@@ -8,6 +8,7 @@
[metabase.lib.drill-thru.common :as lib.drill-thru.common]
[metabase.lib.drill-thru.test-util :as lib.drill-thru.tu]
[metabase.lib.field :as-alias lib.field]
+ [metabase.lib.metadata :as lib.metadata]
[metabase.lib.schema :as lib.schema]
[metabase.lib.test-metadata :as meta]
[metabase.lib.test-util :as lib.tu]
@@ -922,6 +923,210 @@
:value (meta/id :products :id)}]
(lib/available-drill-thrus query -1 context))))))
+(deftest ^:parallel geographic-breakout-available-drill-thrus-test
+ (let [metadata-provider (lib.tu/mock-metadata-provider
+ meta/metadata-provider
+ {:fields [{:id 1
+ :table-id (meta/id :people)
+ :name "COUNTRY"
+ :base-type :type/Text
+ :effective-type :type/Text
+ :semantic-type :type/Country}]})
+ query (as-> (lib/query metadata-provider (meta/table-metadata :people)) $
+ (lib/aggregate $ (lib/count))
+ (lib/breakout $ (lib.metadata/field metadata-provider 1))
+ (lib/breakout $ (meta/field-metadata :people :state))
+ (lib/breakout $ (meta/field-metadata :people :city))
+ (lib/breakout $ (let [field (meta/field-metadata :people :latitude)]
+ (->> (lib/available-binning-strategies $ field)
+ first
+ (lib/with-binning field))))
+ (lib/breakout $ (let [field (meta/field-metadata :people :longitude)]
+ (->> (lib/available-binning-strategies $ field)
+ first
+ (lib/with-binning field)))))
+ lat-col (m/find-first #(= (:id %) (meta/id :people :latitude))
+ (lib/returned-columns query))
+ lon-col (m/find-first #(= (:id %) (meta/id :people :longitude))
+ (lib/returned-columns query))]
+ (testing "Drills for country breakout"
+ (let [country-col (m/find-first #(= (:id %) 1)
+ (lib/returned-columns query))]
+ (is (some? country-col))
+ (let [context {:column country-col
+ :column-ref (lib/ref country-col)
+ :value 2
+ :row [{:column lat-col
+ :column-ref (lib/ref lat-col)
+ :value 10}
+ {:column lon-col
+ :column-ref (lib/ref lon-col)
+ :value 10}]}]
+ (is (=? [{:type :drill-thru/quick-filter}
+ {:type :drill-thru/zoom-in.geographic
+ :subtype :drill-thru.zoom-in.geographic/country-state-city->binned-lat-lon
+ :display-name "Zoom in: Country"}]
+ (lib/available-drill-thrus query -1 context)))
+ (test-drill-applications query context))))
+ (testing "Drills for state breakout"
+ (let [state-col (m/find-first #(= (:id %) (meta/id :people :state))
+ (lib/returned-columns query))]
+ (is (some? state-col))
+ (let [context {:column state-col
+ :column-ref (lib/ref state-col)
+ :value 2
+ :row [{:column lat-col
+ :column-ref (lib/ref lat-col)
+ :value 10}
+ {:column lon-col
+ :column-ref (lib/ref lon-col)
+ :value 10}]}]
+ (is (=? [{:type :drill-thru/quick-filter}
+ {:type :drill-thru/zoom-in.geographic
+ :subtype :drill-thru.zoom-in.geographic/country-state-city->binned-lat-lon
+ :display-name "Zoom in: State"}]
+ (lib/available-drill-thrus query -1 context)))
+ (test-drill-applications query context))))
+ (testing "Drills for city breakout"
+ (let [city-col (m/find-first #(= (:id %) (meta/id :people :city))
+ (lib/returned-columns query))]
+ (is (some? city-col))
+ (let [context {:column city-col
+ :column-ref (lib/ref city-col)
+ :value 2
+ :row [{:column lat-col
+ :column-ref (lib/ref lat-col)
+ :value 10}
+ {:column lon-col
+ :column-ref (lib/ref lon-col)
+ :value 10}]}]
+ (is (=? [{:type :drill-thru/quick-filter}
+ {:type :drill-thru/zoom-in.geographic
+ :subtype :drill-thru.zoom-in.geographic/country-state-city->binned-lat-lon
+ :display-name "Zoom in: City"}]
+ (lib/available-drill-thrus query -1 context)))
+ (test-drill-applications query context))))
+ (testing "Drills for latitude breakout"
+ (is (some? lat-col))
+ (let [context {:column lat-col
+ :column-ref (lib/ref lat-col)
+ :value 2
+ :row [{:column lat-col
+ :column-ref (lib/ref lat-col)
+ :value 10}
+ {:column lon-col
+ :column-ref (lib/ref lon-col)
+ :value 10}]}]
+ (is (=? [{:type :drill-thru/quick-filter}
+ {:type :drill-thru/zoom-in.geographic
+ :subtype :drill-thru.zoom-in.geographic/binned-lat-lon->binned-lat-lon
+ :display-name "Zoom in: Lat/Lon"}]
+ (lib/available-drill-thrus query -1 context)))
+ (test-drill-applications query context)))
+ (testing "Drills for longitude breakout"
+ (is (some? lon-col))
+ (let [context {:column lon-col
+ :column-ref (lib/ref lon-col)
+ :value 2
+ :row [{:column lat-col
+ :column-ref (lib/ref lat-col)
+ :value 10}
+ {:column lon-col
+ :column-ref (lib/ref lon-col)
+ :value 10}]}]
+ (is (=? [{:type :drill-thru/quick-filter}]
+ (lib/available-drill-thrus query -1 context)))
+ (test-drill-applications query context)))))
+
+(deftest ^:parallel only-lat-available-drill-thrus-test
+ (let [query (as-> (lib/query meta/metadata-provider (meta/table-metadata :people)) $
+ (lib/aggregate $ (lib/count))
+ (lib/breakout $ (let [field (meta/field-metadata :people :latitude)]
+ (->> (lib/available-binning-strategies $ field)
+ first
+ (lib/with-binning field)))))
+ lat-col (m/find-first #(= (:id %) (meta/id :people :latitude))
+ (lib/returned-columns query))]
+ (testing "Drills for latitude breakout with no longitude"
+ (is (some? lat-col))
+ (let [context {:column lat-col
+ :column-ref (lib/ref lat-col)
+ :value 2
+ :row [{:column lat-col
+ :column-ref (lib/ref lat-col)
+ :value 10}]}]
+ (is (=? [{:type :drill-thru/quick-filter}
+ {:type :drill-thru/zoom-in.binning}]
+ (lib/available-drill-thrus query -1 context)))
+ (test-drill-applications query context)))))
+
+(deftest ^:parallel only-lon-available-drill-thrus-test
+ (let [query (as-> (lib/query meta/metadata-provider (meta/table-metadata :people)) $
+ (lib/aggregate $ (lib/count))
+ (lib/breakout $ (let [field (meta/field-metadata :people :longitude)]
+ (->> (lib/available-binning-strategies $ field)
+ first
+ (lib/with-binning field)))))
+ lon-col (m/find-first #(= (:id %) (meta/id :people :longitude))
+ (lib/returned-columns query))]
+ (testing "Drills for longitude breakout with no latitude"
+ (is (some? lon-col))
+ (let [context {:column lon-col
+ :column-ref (lib/ref lon-col)
+ :value 2
+ :row [{:column lon-col
+ :column-ref (lib/ref lon-col)
+ :value 10}]}]
+ (is (=? [{:type :drill-thru/quick-filter}
+ {:type :drill-thru/zoom-in.binning}]
+ (lib/available-drill-thrus query -1 context)))
+ (test-drill-applications query context)))))
+
+(deftest ^:parallel regular-binning-with-lat-lon-available-drill-thrus-test
+ (let [query (as-> (lib/query meta/metadata-provider (meta/table-metadata :people)) $
+ (lib/join $ (-> (lib/join-clause (meta/table-metadata :orders)
+ [(lib/=
+ (meta/field-metadata :people :id)
+ (-> (meta/field-metadata :orders :user-id)
+ (lib/with-join-alias "Orders")))])
+ (lib/with-join-alias "Orders")
+ (lib/with-join-strategy :left-join)))
+ (lib/aggregate $ (lib/count))
+ (lib/breakout $ (let [field (meta/field-metadata :people :latitude)]
+ (->> (lib/available-binning-strategies $ field)
+ first
+ (lib/with-binning field))))
+ (lib/breakout $ (let [field (meta/field-metadata :people :longitude)]
+ (->> (lib/available-binning-strategies $ field)
+ first
+ (lib/with-binning field))))
+ (lib/breakout $ (let [field (-> (meta/field-metadata :orders :subtotal)
+ (lib/with-join-alias "Orders"))]
+ (->> (lib/available-binning-strategies $ field)
+ first
+ (lib/with-binning field)))))
+ lat-col (m/find-first #(= (:id %) (meta/id :people :latitude))
+ (lib/returned-columns query))
+ lon-col (m/find-first #(= (:id %) (meta/id :people :longitude))
+ (lib/returned-columns query))]
+ (testing "Drills for numeric breakout when lat/lon exist"
+ (let [subtotal-col (m/find-first #(= (:id %) (meta/id :orders :subtotal))
+ (lib/returned-columns query))]
+ (is (some? subtotal-col))
+ (let [context {:column subtotal-col
+ :column-ref (lib/ref subtotal-col)
+ :value 2
+ :row [{:column lat-col
+ :column-ref (lib/ref lat-col)
+ :value 10}
+ {:column lon-col
+ :column-ref (lib/ref lon-col)
+ :value 10}]}]
+ (is (=? [{:type :drill-thru/quick-filter}
+ {:type :drill-thru/zoom-in.binning}]
+ (lib/available-drill-thrus query -1 context)))
+ (test-drill-applications query context))))))
+
(deftest ^:parallel primary-key?-test
(let [orders+products-query (-> (lib/query meta/metadata-provider (meta/table-metadata :orders))
(lib/join (lib/join-clause (meta/table-metadata :products)