From 433bcb67eb4cc3b0d27174364f10785a7530aa53 Mon Sep 17 00:00:00 2001 From: Nemanja Glumac <31325167+nemanjaglumac@users.noreply.github.com> Date: Fri, 16 Feb 2024 13:59:35 +0100 Subject: [PATCH] [MLv2] Further StructuredQuery cleanup (#38831) * Remove unused `StructuredQuery.prototype.topLevelQuery` * Remove unused `StructuredQuery.prototype.lastSummarizedQuery` * Remove unused `StructuredQuery.prototype._keyForFK` * Remove unused `isSegmentOption` helper --- .../metabase-lib/queries/StructuredQuery.ts | 37 ------------------- .../StructuredQuery-nesting.unit.spec.js | 33 ----------------- 2 files changed, 70 deletions(-) diff --git a/frontend/src/metabase-lib/queries/StructuredQuery.ts b/frontend/src/metabase-lib/queries/StructuredQuery.ts index 613ce905b71..4bc28e050e0 100644 --- a/frontend/src/metabase-lib/queries/StructuredQuery.ts +++ b/frontend/src/metabase-lib/queries/StructuredQuery.ts @@ -27,7 +27,6 @@ import { isCompatibleAggregationOperatorForField, } from "metabase-lib/operators/utils"; import { TYPE } from "metabase-lib/types/constants"; -import { isSegment } from "metabase-lib/queries/utils/filter"; import { getUniqueExpressionName } from "metabase-lib/queries/utils/expression"; import * as Q from "metabase-lib/queries/utils/query"; import { createLookupByProperty } from "metabase-lib/utils"; @@ -73,10 +72,6 @@ export interface DimensionOption { dimension: Dimension; } -// type guards for determining data types -export const isSegmentOption = (content: any): content is SegmentOption => - content?.filter && isSegment(content.filter); - export interface SegmentOption { name: string; filter: ["segment", number]; @@ -636,14 +631,6 @@ class StructuredQuery extends AtomicQuery { } // DIMENSION OPTIONS - _keyForFK(source, destination) { - if (source && destination) { - return `${source.id},${destination.id}`; - } - - return null; - } - dimensionOptions( dimensionFilter: DimensionFilterFn = _dimension => true, ): DimensionOptions { @@ -849,30 +836,6 @@ class StructuredQuery extends AtomicQuery { return this; } - /** - * Returns the "last" nested query that is already summarized, or `null` if none are - * */ - lastSummarizedQuery = _.once((): StructuredQuery | null | undefined => { - if (this.hasAggregations() || !this.canNest()) { - return this; - } else { - const sourceQuery = this.sourceQuery(); - return sourceQuery ? sourceQuery.lastSummarizedQuery() : null; - } - }); - - /** - * Returns the "last" nested query that is already summarized, or the query itself. - * Used in "view mode" to effectively ignore post-aggregation filter stages - */ - topLevelQuery = _.once((): StructuredQuery => { - if (!this.canNest()) { - return this; - } else { - return this.lastSummarizedQuery() || this; - } - }); - /** * returns the corresponding {Dimension} in the sourceQuery, if any */ diff --git a/frontend/test/metabase-lib/lib/queries/StructuredQuery-nesting.unit.spec.js b/frontend/test/metabase-lib/lib/queries/StructuredQuery-nesting.unit.spec.js index ed652d671ab..e0596b32f03 100644 --- a/frontend/test/metabase-lib/lib/queries/StructuredQuery-nesting.unit.spec.js +++ b/frontend/test/metabase-lib/lib/queries/StructuredQuery-nesting.unit.spec.js @@ -69,39 +69,6 @@ describe("StructuredQuery nesting", () => { }); }); - describe("topLevelQuery", () => { - it("should return the query if it's summarized", () => { - const { ordersTable } = setup(); - const q = ordersTable.legacyQuery(); - expect(q.topLevelQuery().legacyQuery()).toEqual({ - "source-table": ORDERS_ID, - }); - }); - it("should return the query if it's not summarized", () => { - const { ordersTable } = setup(); - const q = ordersTable.legacyQuery().aggregate(["count"]); - expect(q.topLevelQuery().legacyQuery()).toEqual({ - "source-table": ORDERS_ID, - aggregation: [["count"]], - }); - }); - it("should return last stage if none are summarized", () => { - const { ordersTable } = setup(); - const q = ordersTable.legacyQuery().nest(); - expect(q.topLevelQuery().legacyQuery()).toEqual({ - "source-query": { "source-table": ORDERS_ID }, - }); - }); - it("should return last summarized stage if any is summarized", () => { - const { ordersTable } = setup(); - const q = ordersTable.legacyQuery().aggregate(["count"]).nest(); - expect(q.topLevelQuery().legacyQuery()).toEqual({ - "source-table": ORDERS_ID, - aggregation: [["count"]], - }); - }); - }); - describe("model question", () => { it("should not include implicit join dimensions when the underyling question has an explicit join", () => { const fields = [ -- GitLab