The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Match test query spec columns exactly by field id or name (#83973)
Alexander Polyankin85af4fc721a2
diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding/guest-token-refresh.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding/guest-token-refresh.cy.spec.tsindex f12ae9319f0..34db5ea5c5e 100644--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding/guest-token-refresh.cy.spec.ts+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding/guest-token-refresh.cy.spec.ts@@ -78,9 +78,9 @@ describe("scenarios > embedding > sdk iframe embedding > guest token refresh", ({source: { type: "table", id: PRODUCTS_ID },fields: [- { type: "column", name: "ID", sourceName: "PRODUCTS" },- { type: "column", name: "TITLE", sourceName: "PRODUCTS" },- { type: "column", name: "PRICE", sourceName: "PRODUCTS" },+ { type: "column", name: "ID" },+ { type: "column", name: "TITLE" },+ { type: "column", name: "PRICE" },],limit: 10,},@@ -130,9 +130,9 @@ describe("scenarios > embedding > sdk iframe embedding > guest token refresh", ({source: { type: "table", id: PRODUCTS_ID },fields: [- { type: "column", name: "ID", sourceName: "PRODUCTS" },- { type: "column", name: "TITLE", sourceName: "PRODUCTS" },- { type: "column", name: "CATEGORY", sourceName: "PRODUCTS" },+ { type: "column", name: "ID" },+ { type: "column", name: "TITLE" },+ { type: "column", name: "CATEGORY" },],limit: 10,},diff --git a/e2e/test/scenarios/question/summarization.cy.spec.js b/e2e/test/scenarios/question/summarization.cy.spec.jsindex 81de6823869..4710068ebc4 100644--- a/e2e/test/scenarios/question/summarization.cy.spec.js+++ b/e2e/test/scenarios/question/summarization.cy.spec.js@@ -179,6 +179,7 @@ describe("scenarios > question > summarize", () => {{type: "operator",operator: "sum",+ name: "sum_2",args: [{ type: "column", name: "TOTAL" }],},],@@ -186,7 +187,6 @@ describe("scenarios > question > summarize", () => {{type: "column",name: "CREATED_AT",- sourceName: "ORDERS",unit: "year",},],@@ -195,7 +195,6 @@ describe("scenarios > question > summarize", () => {direction: "desc",type: "column",name: "sum",- displayName: "Sum of Subtotal",},],},diff --git a/enterprise/backend/src/metabase_enterprise/data_apps/query_definition.clj b/enterprise/backend/src/metabase_enterprise/data_apps/query_definition.cljindex 6889e71757e..e0b19062aa6 100644--- a/enterprise/backend/src/metabase_enterprise/data_apps/query_definition.clj+++ b/enterprise/backend/src/metabase_enterprise/data_apps/query_definition.clj@@ -28,14 +28,12 @@(mr/def ::column[:map {:closed true :decode/normalize {:compile query-map-decoder}- ::sdk-metadata [:description :js-type :field-id :base-type :effective-type :default-temporal-bucket :id :metric-id]}+ ::sdk-metadata [:description :display-name :js-type :table-id :source-name :base-type :effective-type+ :default-temporal-bucket :id :metric-id]}[:type [:= {:decode/normalize lib.schema.common/normalize-keyword} :column]][:name string?]- [:table-id {:optional true} [:maybe ::lib.schema.id/table]]- [:source-name {:optional true} [:maybe string?]]- [:source-field-id {:optional true} [:maybe ::lib.schema.id/field]]- [:display-name {:optional true} [:maybe string?]]- [:index {:optional true} [:maybe pos-int?]]])+ [:field-id {:optional true} [:maybe ::lib.schema.id/field]]+ [:source-field-id {:optional true} [:maybe ::lib.schema.id/field]]])(mr/def ::temporal-bucket[:map {:closed true :decode/normalize {:compile query-map-decoder}}diff --git a/enterprise/frontend/src/embedding-sdk-package/hooks/public/use-metabase-query/tests/resolve-dataset-query.unit.spec.tsx b/enterprise/frontend/src/embedding-sdk-package/hooks/public/use-metabase-query/tests/resolve-dataset-query.unit.spec.tsxindex 5e32b702c1d..c6596d45966 100644--- a/enterprise/frontend/src/embedding-sdk-package/hooks/public/use-metabase-query/tests/resolve-dataset-query.unit.spec.tsx+++ b/enterprise/frontend/src/embedding-sdk-package/hooks/public/use-metabase-query/tests/resolve-dataset-query.unit.spec.tsx@@ -269,6 +269,28 @@ describe("resolveDatasetQuery", () => {});});+ it("filters the dynamic stage on an FK-joined dimension of the static query", async () => {+ const product = TEST_SCHEMA.metrics.revenue.dimensions.orders.product;++ const datasetQuery = await resolveDatasetQueryInBundle(createMockStore())(+ {+ source: TEST_SCHEMA.tables.orders,+ aggregations: [TEST_SCHEMA.metrics.revenue],+ breakouts: [breakout(product)],+ },+ { filters: [filter(product, "=", "Widget")] },+ );++ expect(stagesOf(datasetQuery)[1].filters).toEqual([+ [+ "=",+ expect.anything(),+ ["field", expect.anything(), expect.stringContaining("NAME")],+ "Widget",+ ],+ ]);+ });+it("passes generated metric dimension orderBys through Lib.createTestQuery", async () => {const datasetQuery = await resolveDatasetQueryInBundle(createMockStore())({source: TEST_SCHEMA.tables.orders,diff --git a/frontend/src/embedding-sdk-bundle/lib/create-metabase-query/index.ts b/frontend/src/embedding-sdk-bundle/lib/create-metabase-query/index.tsindex 6df55775f52..a7d315d9b11 100644--- a/frontend/src/embedding-sdk-bundle/lib/create-metabase-query/index.ts+++ b/frontend/src/embedding-sdk-bundle/lib/create-metabase-query/index.ts@@ -187,15 +187,14 @@ function toResultColumnStageSpec({};}-// A card stage exposes the saved question's result columns, so they are looked-// up by name. `sourceName` and `displayName` describe the table field rather-// than the result column and stop it matching, so they are dropped. `tableId`-// and `sourceFieldId` stay: a result column keeps both, and they tell it apart-// from a same-named column reachable through an FK.+// A card stage exposes the saved question's result columns, which are no+// longer joined, so the join and foreign key keys are dropped; the field ID or+// the name still finds the column.function toResultColumnSpec<TSpec extends TestColumnSpec>(spec: TSpec) {const {- sourceName: _sourceName,- displayName: _displayName,+ joinAlias: _joinAlias,+ sourceFieldId: _sourceFieldId,+ sourceFieldJoinAlias: _sourceFieldJoinAlias,...resultColumn} = spec;diff --git a/frontend/src/metabase-lib/query/comparison.unit.spec.ts b/frontend/src/metabase-lib/query/comparison.unit.spec.tsindex 7dc1331af83..9f0ed0861a8 100644--- a/frontend/src/metabase-lib/query/comparison.unit.spec.ts+++ b/frontend/src/metabase-lib/query/comparison.unit.spec.ts@@ -17,13 +17,11 @@ describe("findColumnIndexesFromLegacyRefs", () => {breakouts: [{type: "column",- sourceName: "ORDERS",name: "CREATED_AT",unit: "year",},{type: "column",- sourceName: "ORDERS",name: "CREATED_AT",unit: "month",},@@ -52,13 +50,11 @@ describe("findColumnIndexesFromLegacyRefs", () => {breakouts: [{type: "column",- sourceName: "ORDERS",name: "TOTAL",binning: { strategy: "num-bins", numBins: 10 },},{type: "column",- sourceName: "ORDERS",name: "TOTAL",binning: { strategy: "num-bins", numBins: 50 },},diff --git a/frontend/src/metabase-lib/query/display.unit.spec.ts b/frontend/src/metabase-lib/query/display.unit.spec.tsindex 4bfd6bda144..4b28376aae9 100644--- a/frontend/src/metabase-lib/query/display.unit.spec.ts+++ b/frontend/src/metabase-lib/query/display.unit.spec.ts@@ -7,6 +7,7 @@ import {createMockTable,} from "metabase-types/api/mocks";import {+ ORDERS,ORDERS_ID,createSampleDatabase,} from "metabase-types/api/mocks/presets";@@ -89,7 +90,9 @@ describe("defaultDisplay", () => {{source: { type: "table", id: ORDERS_ID },aggregations: [{ type: "operator", operator: "count", args: [] }],- breakouts: [{ type: "column", name: "STATE", sourceName: "PEOPLE" }],+ breakouts: [+ { type: "column", name: "STATE", sourceFieldId: ORDERS.USER_ID },+ ],},],});@@ -112,9 +115,7 @@ describe("defaultDisplay", () => {id: ACCOUNTS_ID,},aggregations: [{ type: "operator", operator: "count", args: [] }],- breakouts: [- { type: "column", name: "COUNTRY", sourceName: "ACCOUNTS" },- ],+ breakouts: [{ type: "column", name: "COUNTRY" }],},],});@@ -141,7 +142,6 @@ describe("defaultDisplay", () => {{type: "column",name: "CREATED_AT",- sourceName: "ORDERS",unit: "day-of-month",},],@@ -158,9 +158,7 @@ describe("defaultDisplay", () => {{source: { type: "table", id: ORDERS_ID },aggregations: [{ type: "operator", operator: "count", args: [] }],- breakouts: [- { type: "column", name: "CREATED_AT", sourceName: "ORDERS" },- ],+ breakouts: [{ type: "column", name: "CREATED_AT" }],},],});@@ -174,9 +172,7 @@ describe("defaultDisplay", () => {{source: { type: "table", id: ORDERS_ID },aggregations: [{ type: "operator", operator: "count", args: [] }],- breakouts: [- { type: "column", name: "CREATED_AT", sourceName: "ORDERS" },- ],+ breakouts: [{ type: "column", name: "CREATED_AT" }],},],});@@ -202,7 +198,6 @@ describe("defaultDisplay", () => {{type: "column",name: "TOTAL",- sourceName: "ORDERS",binning: { strategy: "num-bins", numBins: 10 },},],@@ -219,7 +214,7 @@ describe("defaultDisplay", () => {{source: { type: "table", id: ORDERS_ID },aggregations: [{ type: "operator", operator: "count", args: [] }],- breakouts: [{ type: "column", name: "TOTAL", sourceName: "ORDERS" }],+ breakouts: [{ type: "column", name: "TOTAL" }],},],});@@ -234,7 +229,11 @@ describe("defaultDisplay", () => {source: { type: "table", id: ORDERS_ID },aggregations: [{ type: "operator", operator: "count", args: [] }],breakouts: [- { type: "column", name: "CATEGORY", sourceName: "PRODUCTS" },+ {+ type: "column",+ name: "CATEGORY",+ sourceFieldId: ORDERS.PRODUCT_ID,+ },],},],@@ -250,8 +249,8 @@ describe("defaultDisplay", () => {source: { type: "table", id: ORDERS_ID },aggregations: [{ type: "operator", operator: "count", args: [] }],breakouts: [- { type: "column", name: "CREATED_AT", sourceName: "ORDERS" },- { type: "column", name: "TOTAL", sourceName: "ORDERS" },+ { type: "column", name: "CREATED_AT" },+ { type: "column", name: "TOTAL" },],},],@@ -270,13 +269,13 @@ describe("defaultDisplay", () => {{type: "column",name: "LATITUDE",- sourceName: "PEOPLE",+ sourceFieldId: ORDERS.USER_ID,binning: { strategy: "default" },},{type: "column",name: "LONGITUDE",- sourceName: "PEOPLE",+ sourceFieldId: ORDERS.USER_ID,binning: { strategy: "default" },},],@@ -299,8 +298,12 @@ describe("defaultDisplay", () => {source: { type: "table", id: ORDERS_ID },aggregations: [{ type: "operator", operator: "count", args: [] }],breakouts: [- { type: "column", name: "LATITUDE", sourceName: "PEOPLE" },- { type: "column", name: "LONGITUDE", sourceName: "PEOPLE" },+ { type: "column", name: "LATITUDE", sourceFieldId: ORDERS.USER_ID },+ {+ type: "column",+ name: "LONGITUDE",+ sourceFieldId: ORDERS.USER_ID,+ },],},],@@ -324,10 +327,14 @@ describe("defaultDisplay", () => {{type: "column",name: "LATITUDE",- sourceName: "PEOPLE",+ sourceFieldId: ORDERS.USER_ID,// binning: { strategy: "default" },},- { type: "column", name: "LONGITUDE", sourceName: "PEOPLE" },+ {+ type: "column",+ name: "LONGITUDE",+ sourceFieldId: ORDERS.USER_ID,+ },],},],@@ -348,8 +355,16 @@ describe("defaultDisplay", () => {source: { type: "table", id: ORDERS_ID },aggregations: [{ type: "operator", operator: "count", args: [] }],breakouts: [- { type: "column", name: "CATEGORY", sourceName: "PRODUCTS" },- { type: "column", name: "VENDOR", sourceName: "PRODUCTS" },+ {+ type: "column",+ name: "CATEGORY",+ sourceFieldId: ORDERS.PRODUCT_ID,+ },+ {+ type: "column",+ name: "VENDOR",+ sourceFieldId: ORDERS.PRODUCT_ID,+ },],},],@@ -368,8 +383,12 @@ describe("defaultDisplay", () => {{ type: "operator", operator: "cum-count", args: [] },],breakouts: [- { type: "column", name: "LATITUDE", sourceName: "PEOPLE" },- { type: "column", name: "LONGITUDE", sourceName: "PEOPLE" },+ { type: "column", name: "LATITUDE", sourceFieldId: ORDERS.USER_ID },+ {+ type: "column",+ name: "LONGITUDE",+ sourceFieldId: ORDERS.USER_ID,+ },],},],diff --git a/frontend/src/metabase-lib/query/query.unit.spec.ts b/frontend/src/metabase-lib/query/query.unit.spec.tsindex 78001cc4cd0..8561e1a7137 100644--- a/frontend/src/metabase-lib/query/query.unit.spec.ts+++ b/frontend/src/metabase-lib/query/query.unit.spec.ts@@ -330,7 +330,6 @@ describe("createTestQuery", () => {{type: "column",name: "LATITUDE",- sourceName: "PEOPLE",binning: { strategy: "bin-width", binWidth: 10 },},],diff --git a/frontend/src/metabase-lib/v1/parameters/utils/targets.unit.spec.ts b/frontend/src/metabase-lib/v1/parameters/utils/targets.unit.spec.tsindex 8c245282599..5fd71d85f5f 100644--- a/frontend/src/metabase-lib/v1/parameters/utils/targets.unit.spec.ts+++ b/frontend/src/metabase-lib/v1/parameters/utils/targets.unit.spec.ts@@ -31,6 +31,7 @@ import {createMockTemplateTag,} from "metabase-types/api/mocks";import {+ ORDERS,ORDERS_ID,PRODUCTS,PRODUCTS_ID,@@ -73,7 +74,6 @@ const queryNonDateBreakout = Lib.createTestQuery(provider, {{type: "column",name: "QUANTITY",- sourceName: "ORDERS",},],},@@ -89,7 +89,6 @@ const query1DateBreakout = Lib.createTestQuery(SAMPLE_PROVIDER, {{type: "column",name: "CREATED_AT",- sourceName: "ORDERS",unit: "month",},],@@ -106,13 +105,12 @@ const query2DateBreakouts = Lib.createTestQuery(SAMPLE_PROVIDER, {{type: "column",name: "CREATED_AT",- sourceName: "ORDERS",unit: "month",},{type: "column",name: "CREATED_AT",- sourceName: "PRODUCTS",+ sourceFieldId: ORDERS.PRODUCT_ID,unit: "month",},],@@ -129,7 +127,6 @@ const queryDateBreakoutsMultiStage = Lib.createTestQuery(SAMPLE_PROVIDER, {{type: "column",name: "CREATED_AT",- sourceName: "ORDERS",unit: "month",},],@@ -139,7 +136,6 @@ const queryDateBreakoutsMultiStage = Lib.createTestQuery(SAMPLE_PROVIDER, {breakouts: [{type: "column",- sourceName: "ORDERS",name: "CREATED_AT",unit: "year",},@@ -618,6 +614,7 @@ function createComplex1StageQuery() {joins: [{source: { type: "table", id: REVIEWS_ID },+ alias: "Reviews - Product",strategy: "left-join",conditions: [{@@ -625,12 +622,10 @@ function createComplex1StageQuery() {left: {type: "column",name: "PRODUCT_ID",- sourceName: "ORDERS",},right: {type: "column",name: "PRODUCT_ID",- sourceName: "REVIEWS",},},],@@ -643,7 +638,11 @@ function createComplex1StageQuery() {type: "operator",operator: "datetime-add",args: [- { type: "column", name: "BIRTH_DATE", sourceName: "PEOPLE" },+ {+ type: "column",+ name: "BIRTH_DATE",+ sourceFieldId: ORDERS.USER_ID,+ },{ type: "literal", value: 18 },{ type: "literal", value: "year" },],@@ -655,27 +654,25 @@ function createComplex1StageQuery() {{type: "operator",operator: "sum",- args: [{ type: "column", name: "TOTAL", sourceName: "ORDERS" }],+ args: [{ type: "column", name: "TOTAL" }],},],breakouts: [{type: "column",name: "CREATED_AT",- sourceName: "ORDERS",unit: "month",},{type: "column",name: "CREATED_AT",- sourceName: "PRODUCTS",+ sourceFieldId: ORDERS.PRODUCT_ID,unit: "year",- index: 0,},{type: "column",name: "CREATED_AT",- sourceName: "REVIEWS",+ joinAlias: "Reviews - Product",unit: "quarter",},{@@ -696,6 +693,7 @@ function createComplex2StageQuery() {joins: [{source: { type: "table", id: REVIEWS_ID },+ alias: "Reviews - Product",strategy: "left-join",conditions: [{@@ -703,12 +701,10 @@ function createComplex2StageQuery() {left: {type: "column",name: "PRODUCT_ID",- sourceName: "ORDERS",},right: {type: "column",name: "PRODUCT_ID",- sourceName: "REVIEWS",},},],@@ -721,7 +717,11 @@ function createComplex2StageQuery() {type: "operator",operator: "datetime-add",args: [- { type: "column", name: "BIRTH_DATE", sourceName: "PEOPLE" },+ {+ type: "column",+ name: "BIRTH_DATE",+ sourceFieldId: ORDERS.USER_ID,+ },{ type: "literal", value: 18 },{ type: "literal", value: "year" },],@@ -737,7 +737,6 @@ function createComplex2StageQuery() {{type: "column",name: "TOTAL",- sourceName: "ORDERS",},],},@@ -746,19 +745,17 @@ function createComplex2StageQuery() {{type: "column",name: "CREATED_AT",- sourceName: "ORDERS",unit: "month",},{type: "column",name: "CREATED_AT",- sourceName: "ORDERS",unit: "year",},{type: "column",name: "CREATED_AT",- sourceName: "REVIEWS",+ joinAlias: "Reviews - Product",unit: "quarter",},{@@ -771,6 +768,7 @@ function createComplex2StageQuery() {joins: [{source: { type: "table", id: REVIEWS_ID },+ alias: "Reviews - Product",strategy: "left-join",conditions: [{@@ -778,13 +776,10 @@ function createComplex2StageQuery() {left: {type: "column",name: "CREATED_AT",- sourceName: "ORDERS",- index: 0,},right: {type: "column",name: "CREATED_AT",- sourceName: "REVIEWS",},},],diff --git a/frontend/src/metabase-types/api/query.ts b/frontend/src/metabase-types/api/query.tsindex e52765cf324..831ce8ce61d 100644--- a/frontend/src/metabase-types/api/query.ts+++ b/frontend/src/metabase-types/api/query.ts@@ -467,15 +467,11 @@ export type TestSourceSpec = TestTableSourceSpec | TestCardSourceSpec;export type TestColumnSpec = {type: "column";- name: string;- tableId?: TableId;- sourceName?: string;+ name?: string;+ fieldId?: FieldId;+ joinAlias?: string;sourceFieldId?: FieldId;- displayName?: string;-- // When the columns cannot be disambiguated with name, sourceName and displayName- // use this index to pick one.- index?: number;+ sourceFieldJoinAlias?: string;};export type TestExpressionSpec =@@ -560,6 +556,7 @@ export type TestBreakoutSpec = TestColumnWithBinningSpec;export type TestJoinSpec = {source: TestSourceSpec;strategy: JoinStrategy;+ alias?: string;// If not set we will use the suggested join conditionsconditions?: TestJoinConditionSpec[];diff --git a/frontend/src/metabase/common/utils/card.unit.spec.ts b/frontend/src/metabase/common/utils/card.unit.spec.tsindex f9f773c3f87..6785d91f2dd 100644--- a/frontend/src/metabase/common/utils/card.unit.spec.ts+++ b/frontend/src/metabase/common/utils/card.unit.spec.ts@@ -50,7 +50,6 @@ describe("getMetricSeriesWithDefaultDisplay", () => {{type: "column",name: "TOTAL",- sourceName: "ORDERS",binning: { strategy: "num-bins", numBins: 10 },},],@@ -72,9 +71,7 @@ describe("getMetricSeriesWithDefaultDisplay", () => {{source: { type: "table", id: ORDERS_ID },aggregations: [{ type: "operator", operator: "count", args: [] }],- breakouts: [- { type: "column", name: "CREATED_AT", sourceName: "ORDERS" },- ],+ breakouts: [{ type: "column", name: "CREATED_AT" }],},],});diff --git a/frontend/src/metabase/embedding/mcp/McpQuestionTitle.unit.spec.ts b/frontend/src/metabase/embedding/mcp/McpQuestionTitle.unit.spec.tsindex 85fa0aeae0e..c47d45fe95b 100644--- a/frontend/src/metabase/embedding/mcp/McpQuestionTitle.unit.spec.ts+++ b/frontend/src/metabase/embedding/mcp/McpQuestionTitle.unit.spec.ts@@ -14,7 +14,6 @@ const query = Lib.createTestQuery(SAMPLE_PROVIDER, {{type: "column",name: "CREATED_AT",- sourceName: "ORDERS",unit: "month",},],diff --git a/frontend/src/metabase/metrics-viewer/utils/__tests__/test-helpers.ts b/frontend/src/metabase/metrics-viewer/utils/__tests__/test-helpers.tsindex fd751a55635..a2bf941e170 100644--- a/frontend/src/metabase/metrics-viewer/utils/__tests__/test-helpers.ts+++ b/frontend/src/metabase/metrics-viewer/utils/__tests__/test-helpers.ts@@ -161,7 +161,6 @@ export const TOTAL_MEASURE = createMockMeasure({{type: "column",name: "TOTAL",- sourceName: "ORDERS",},],},diff --git a/frontend/src/metabase/parameters/utils/mapping-options.unit.spec.tsx b/frontend/src/metabase/parameters/utils/mapping-options.unit.spec.tsxindex 0bca50eb561..6a7681e1271 100644--- a/frontend/src/metabase/parameters/utils/mapping-options.unit.spec.tsx+++ b/frontend/src/metabase/parameters/utils/mapping-options.unit.spec.tsx@@ -200,12 +200,10 @@ describe("parameters/utils/mapping-options", () => {operator: "=",left: {type: "column",- sourceName: "ORDERS",name: "PRODUCT_ID",},right: {type: "column",- sourceName: "PRODUCTS",name: "ID",},},@@ -807,7 +805,6 @@ describe("getMappingOptionByTarget", () => {breakouts: [{type: "column",- sourceName: "ORDERS",name: "CREATED_AT",unit: "month",},diff --git a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/AdHocQuestionDescription/AdHocQuestionDescription.unit.spec.ts b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/AdHocQuestionDescription/AdHocQuestionDescription.unit.spec.tsindex db9470f233a..94b712ee60c 100644--- a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/AdHocQuestionDescription/AdHocQuestionDescription.unit.spec.ts+++ b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/AdHocQuestionDescription/AdHocQuestionDescription.unit.spec.ts@@ -15,7 +15,6 @@ describe("describeQueryStage", () => {{type: "column",name: "CREATED_AT",- sourceName: "ORDERS",unit: "month",},],@@ -42,7 +41,6 @@ describe("describeQueryStage", () => {{type: "column",name: "RATING",- sourceName: "PRODUCTS",binning: { strategy: "num-bins", numBins: 10 },},],diff --git a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionFiltersHeader/QuestionFiltersHeader.unit.spec.tsx b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionFiltersHeader/QuestionFiltersHeader.unit.spec.tsxindex 418596006ca..7d6c9e8ffc2 100644--- a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionFiltersHeader/QuestionFiltersHeader.unit.spec.tsx+++ b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionFiltersHeader/QuestionFiltersHeader.unit.spec.tsx@@ -13,6 +13,7 @@ import { SAMPLE_PROVIDER } from "metabase-lib/test-helpers";import Question from "metabase-lib/v1/Question";import type { GetFieldValuesResponse } from "metabase-types/api";import {+ ORDERS,ORDERS_ID,PEOPLE_SOURCE_VALUES,createSampleDatabase,@@ -221,12 +222,14 @@ const TEST_MULTISTAGE_QUERY = Lib.createTestQuery(SAMPLE_PROVIDER, {type: "operator",operator: ">",args: [- { type: "column", sourceName: "ORDERS", name: "QUANTITY" },+ { type: "column", name: "QUANTITY" },{ type: "literal", value: 4 },],},],- breakouts: [{ type: "column", sourceName: "PEOPLE", name: "SOURCE" }],+ breakouts: [+ { type: "column", sourceFieldId: ORDERS.USER_ID, name: "SOURCE" },+ ],},{breakouts: [{ type: "column", name: "SOURCE" }],diff --git a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/SavedQuestionLeftSide/ViewOnly.unit.spec.tsx b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/SavedQuestionLeftSide/ViewOnly.unit.spec.tsxindex 6613a5fcb8e..cd26bfb0f4f 100644--- a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/SavedQuestionLeftSide/ViewOnly.unit.spec.tsx+++ b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/SavedQuestionLeftSide/ViewOnly.unit.spec.tsx@@ -101,8 +101,8 @@ const ORDERS_JOIN_PRODUCTS_QUERY = Lib.createTestQuery(SAMPLE_PROVIDER, {conditions: [{operator: "=",- left: { type: "column", name: "ID", sourceName: "ORDERS" },- right: { type: "column", name: "ID", sourceName: "PRODUCTS" },+ left: { type: "column", name: "ID" },+ right: { type: "column", name: "ID" },},],},diff --git a/frontend/src/metabase/query_builder/components/view/sidebars/QuestionInfoSidebar/tests/common.unit.spec.tsx b/frontend/src/metabase/query_builder/components/view/sidebars/QuestionInfoSidebar/tests/common.unit.spec.tsxindex 12cb5cbf6a8..313ae3f0b0c 100644--- a/frontend/src/metabase/query_builder/components/view/sidebars/QuestionInfoSidebar/tests/common.unit.spec.tsx+++ b/frontend/src/metabase/query_builder/components/view/sidebars/QuestionInfoSidebar/tests/common.unit.spec.tsx@@ -300,10 +300,9 @@ function getJoinedQuery() {operator: "=",left: {type: "column",- sourceName: "ORDERS",name: "PRODUCT_ID",},- right: { type: "column", sourceName: "PRODUCTS", name: "ID" },+ right: { type: "column", name: "ID" },},],},diff --git a/frontend/src/metabase/query_builder/components/view/sidebars/SummarizeSidebar/SummarizeSidebar.unit.spec.tsx b/frontend/src/metabase/query_builder/components/view/sidebars/SummarizeSidebar/SummarizeSidebar.unit.spec.tsxindex a9810b6e2a7..5ac8ca99e95 100644--- a/frontend/src/metabase/query_builder/components/view/sidebars/SummarizeSidebar/SummarizeSidebar.unit.spec.tsx+++ b/frontend/src/metabase/query_builder/components/view/sidebars/SummarizeSidebar/SummarizeSidebar.unit.spec.tsx@@ -11,6 +11,7 @@ import * as Lib from "metabase-lib";import { DEFAULT_TEST_QUERY, SAMPLE_PROVIDER } from "metabase-lib/test-helpers";import { createMockCard } from "metabase-types/api/mocks";import {+ ORDERS,ORDERS_ID,createSampleDatabase,} from "metabase-types/api/mocks/presets";@@ -37,13 +38,12 @@ function createSummarizedQuery() {breakouts: [{type: "column",- sourceName: "ORDERS",name: "CREATED_AT",unit: "month",},{type: "column",- sourceName: "PRODUCTS",+ sourceFieldId: ORDERS.PRODUCT_ID,name: "CATEGORY",},],@@ -61,13 +61,11 @@ function createQueryWithBreakoutsForSameColumn() {breakouts: [{type: "column",- sourceName: "ORDERS",name: "CREATED_AT",unit: "year",},{type: "column",- sourceName: "ORDERS",name: "CREATED_AT",unit: "quarter",},diff --git a/frontend/src/metabase/querying/common/components/AggregationPicker/AggregationPicker.unit.spec.tsx b/frontend/src/metabase/querying/common/components/AggregationPicker/AggregationPicker.unit.spec.tsxindex 1c98191dae4..5892bc041f9 100644--- a/frontend/src/metabase/querying/common/components/AggregationPicker/AggregationPicker.unit.spec.tsx+++ b/frontend/src/metabase/querying/common/components/AggregationPicker/AggregationPicker.unit.spec.tsx@@ -78,9 +78,7 @@ function createQueryWithInlineExpression() {value: {type: "operator",operator: "avg",- args: [- { type: "column", name: "QUANTITY", sourceName: "ORDERS" },- ],+ args: [{ type: "column", name: "QUANTITY" }],},},],diff --git a/frontend/src/metabase/querying/common/components/QueryColumnPicker/QueryColumnPicker.unit.spec.tsx b/frontend/src/metabase/querying/common/components/QueryColumnPicker/QueryColumnPicker.unit.spec.tsxindex 26caf0666fb..c54e01b0d8b 100644--- a/frontend/src/metabase/querying/common/components/QueryColumnPicker/QueryColumnPicker.unit.spec.tsx+++ b/frontend/src/metabase/querying/common/components/QueryColumnPicker/QueryColumnPicker.unit.spec.tsx@@ -30,7 +30,6 @@ function createQueryWithBreakout() {{type: "column",name: "CREATED_AT",- sourceName: "ORDERS",},],},diff --git a/frontend/src/metabase/querying/expressions/suggestions/fields.unit.spec.ts b/frontend/src/metabase/querying/expressions/suggestions/fields.unit.spec.tsindex 927a6f4793d..a24c9915d12 100644--- a/frontend/src/metabase/querying/expressions/suggestions/fields.unit.spec.ts+++ b/frontend/src/metabase/querying/expressions/suggestions/fields.unit.spec.ts@@ -327,12 +327,10 @@ describe("suggestFields", () => {operator: "=",left: {type: "column",- sourceName: "ORDERS",name: "PRODUCT_ID",},right: {type: "column",- sourceName: "REVIEWS",name: "PRODUCT_ID",},},@@ -399,7 +397,6 @@ describe("suggestFields", () => {breakouts: [{type: "column",- sourceName: "ORDERS",name: "TOTAL",},],diff --git a/frontend/src/metabase/querying/expressions/suggestions/measures.unit.spec.ts b/frontend/src/metabase/querying/expressions/suggestions/measures.unit.spec.tsindex 7a054e8082a..a6b481f35d9 100644--- a/frontend/src/metabase/querying/expressions/suggestions/measures.unit.spec.ts+++ b/frontend/src/metabase/querying/expressions/suggestions/measures.unit.spec.ts@@ -82,7 +82,7 @@ describe("suggestMeasures", () => {{type: "operator",operator: "sum",- args: [{ type: "column", name: "sum", displayName: "Sum" }],+ args: [{ type: "column", name: "sum" }],},],},diff --git a/frontend/src/metabase/querying/expressions/test/shared.ts b/frontend/src/metabase/querying/expressions/test/shared.tsindex 4e85e00ba51..27b51c4320c 100644--- a/frontend/src/metabase/querying/expressions/test/shared.ts+++ b/frontend/src/metabase/querying/expressions/test/shared.ts@@ -93,7 +93,6 @@ metadata = createMockMetadata({{type: "column",name: "TOTAL",- sourceName: "ORDERS",},],},diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/MultiStageFilterPicker/MultiStageFilterPicker.unit.spec.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/MultiStageFilterPicker/MultiStageFilterPicker.unit.spec.tsxindex cd2efb45dab..89cde42d38f 100644--- a/frontend/src/metabase/querying/filters/components/FilterPicker/MultiStageFilterPicker/MultiStageFilterPicker.unit.spec.tsx+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/MultiStageFilterPicker/MultiStageFilterPicker.unit.spec.tsx@@ -3,7 +3,7 @@ import userEvent from "@testing-library/user-event";import { renderWithProviders, screen } from "__support__/ui";import * as Lib from "metabase-lib";import { SAMPLE_PROVIDER } from "metabase-lib/test-helpers";-import { ORDERS_ID } from "metabase-types/api/mocks/presets";+import { ORDERS, ORDERS_ID } from "metabase-types/api/mocks/presets";import { MultiStageFilterPicker } from "./MultiStageFilterPicker";@@ -40,7 +40,13 @@ describe("MultiStageFilterPicker", () => {{source: { type: "table", id: ORDERS_ID },aggregations: [{ type: "operator", operator: "count", args: [] }],- breakouts: [{ type: "column", name: "CATEGORY" }],+ breakouts: [+ {+ type: "column",+ name: "CATEGORY",+ sourceFieldId: ORDERS.PRODUCT_ID,+ },+ ],},],}),@@ -63,7 +69,13 @@ describe("MultiStageFilterPicker", () => {{source: { type: "table", id: ORDERS_ID },aggregations: [{ type: "operator", operator: "count", args: [] }],- breakouts: [{ type: "column", name: "CATEGORY" }],+ breakouts: [+ {+ type: "column",+ name: "CATEGORY",+ sourceFieldId: ORDERS.PRODUCT_ID,+ },+ ],},],}),diff --git a/frontend/src/metabase/querying/filters/components/TimeseriesChrome/TimeseriesBucketPicker/TimeseriesBucketPicker.unit.spec.tsx b/frontend/src/metabase/querying/filters/components/TimeseriesChrome/TimeseriesBucketPicker/TimeseriesBucketPicker.unit.spec.tsxindex 6ea905e0dc8..4c39ff9fbcd 100644--- a/frontend/src/metabase/querying/filters/components/TimeseriesChrome/TimeseriesBucketPicker/TimeseriesBucketPicker.unit.spec.tsx+++ b/frontend/src/metabase/querying/filters/components/TimeseriesChrome/TimeseriesBucketPicker/TimeseriesBucketPicker.unit.spec.tsx@@ -19,7 +19,6 @@ interface QueryWithBreakoutOpts {function createQueryWithBreakout({column = {type: "column",- sourceName: "ORDERS",name: "CREATED_AT",},bucket = "month",@@ -127,7 +126,7 @@ describe("TimeseriesBucketPicker", () => {it("should show all options when the current bucket is below the More button", async () => {const { query, breakout, column } = createQueryWithBreakout({- column: { type: "column", sourceName: "ORDERS", name: "CREATED_AT" },+ column: { type: "column", name: "CREATED_AT" },bucket: "quarter-of-year",});diff --git a/frontend/src/metabase/querying/filters/components/TimeseriesChrome/TimeseriesChrome.unit.spec.tsx b/frontend/src/metabase/querying/filters/components/TimeseriesChrome/TimeseriesChrome.unit.spec.tsxindex 2df1ff792bd..fe9c74509fe 100644--- a/frontend/src/metabase/querying/filters/components/TimeseriesChrome/TimeseriesChrome.unit.spec.tsx+++ b/frontend/src/metabase/querying/filters/components/TimeseriesChrome/TimeseriesChrome.unit.spec.tsx@@ -9,7 +9,7 @@ import {} from "metabase-lib/test-helpers";import Question from "metabase-lib/v1/Question";import { createMockCard } from "metabase-types/api/mocks";-import { ORDERS_ID } from "metabase-types/api/mocks/presets";+import { ORDERS, ORDERS_ID } from "metabase-types/api/mocks/presets";import { TimeseriesChrome } from "./TimeseriesChrome";@@ -55,7 +55,13 @@ describe("TimeseriesChrome", () => {type: "table",id: ORDERS_ID,},- breakouts: [{ type: "column", name: "CATEGORY" }],+ breakouts: [+ {+ type: "column",+ name: "CATEGORY",+ sourceFieldId: ORDERS.PRODUCT_ID,+ },+ ],},],});@@ -74,7 +80,6 @@ describe("TimeseriesChrome", () => {breakouts: [{type: "column",- sourceName: "ORDERS",name: "CREATED_AT",unit: "month",},@@ -103,13 +108,11 @@ describe("TimeseriesChrome", () => {breakouts: [{type: "column",- sourceName: "ORDERS",name: "CREATED_AT",unit: "month",},{type: "column",- sourceName: "ORDERS",name: "CREATED_AT",unit: "year",},diff --git a/frontend/src/metabase/querying/notebook/components/AggregateStep/AggregateStep.unit.spec.tsx b/frontend/src/metabase/querying/notebook/components/AggregateStep/AggregateStep.unit.spec.tsxindex 5b5c460a828..d3f69ef80d0 100644--- a/frontend/src/metabase/querying/notebook/components/AggregateStep/AggregateStep.unit.spec.tsx+++ b/frontend/src/metabase/querying/notebook/components/AggregateStep/AggregateStep.unit.spec.tsx@@ -61,7 +61,6 @@ function createMetricAggregatedQuery() {breakouts: [{type: "column",- sourceName: "ORDERS",name: "CREATED_AT",unit: "month",},@@ -83,7 +82,7 @@ function createAggregatedQuery() {{type: "operator",operator: "avg",- args: [{ type: "column", sourceName: "ORDERS", name: "QUANTITY" }],+ args: [{ type: "column", name: "QUANTITY" }],},],},@@ -166,6 +165,7 @@ describe("AggregateStep", () => {{type: "column",name: "RATING",+ sourceFieldId: ORDERS.PRODUCT_ID,},],},diff --git a/frontend/src/metabase/querying/notebook/components/BreakoutStep/BreakoutStep.unit.spec.tsx b/frontend/src/metabase/querying/notebook/components/BreakoutStep/BreakoutStep.unit.spec.tsxindex 1cffb95751b..0d276d75989 100644--- a/frontend/src/metabase/querying/notebook/components/BreakoutStep/BreakoutStep.unit.spec.tsx+++ b/frontend/src/metabase/querying/notebook/components/BreakoutStep/BreakoutStep.unit.spec.tsx@@ -41,7 +41,6 @@ function createQueryWithBreakout() {breakouts: [{type: "column",- sourceName: "ORDERS",name: "TAX",},],@@ -63,7 +62,6 @@ function createQueryWithBreakoutAndBinningCount(breakouts: [{type: "column",- sourceName: "ORDERS",name: "TAX",binning:binningCount != null@@ -87,13 +85,11 @@ function createQueryWithMultipleBreakoutsAndBinningStrategy() {breakouts: [{type: "column",- sourceName: "ORDERS",name: "TAX",binning: { strategy: "num-bins", numBins: 10 },},{type: "column",- sourceName: "ORDERS",name: "TAX",binning: { strategy: "num-bins", numBins: 50 },},@@ -116,7 +112,6 @@ function createQueryWithBreakoutAndTemporalBucket(breakouts: [{type: "column",- sourceName: "ORDERS",name: "CREATED_AT",unit: temporalBucketName,},@@ -137,13 +132,11 @@ function createQueryWithMultipleBreakoutsAndTemporalBucket() {breakouts: [{type: "column",- sourceName: "ORDERS",name: "CREATED_AT",unit: "year",},{type: "column",- sourceName: "ORDERS",name: "CREATED_AT",unit: "month",},@@ -621,9 +614,7 @@ describe("BreakoutStep", () => {type: "table",id: ORDERS_ID,},- breakouts: [- { type: "column", sourceName: "ORDERS", name: "CREATED_AT" },- ],+ breakouts: [{ type: "column", name: "CREATED_AT" }],},],});diff --git a/frontend/src/metabase/querying/notebook/components/FilterStep/FilterStep.unit.spec.tsx b/frontend/src/metabase/querying/notebook/components/FilterStep/FilterStep.unit.spec.tsxindex ce31dc8c94c..a17e679b1a4 100644--- a/frontend/src/metabase/querying/notebook/components/FilterStep/FilterStep.unit.spec.tsx+++ b/frontend/src/metabase/querying/notebook/components/FilterStep/FilterStep.unit.spec.tsx@@ -17,7 +17,7 @@ function createQueryWithFilter() {type: "operator",operator: ">",args: [- { type: "column", sourceName: "ORDERS", name: "TOTAL" },+ { type: "column", name: "TOTAL" },{ type: "literal", value: 20 },],},diff --git a/frontend/src/metabase/querying/notebook/components/JoinStep/JoinStep.unit.spec.tsx b/frontend/src/metabase/querying/notebook/components/JoinStep/JoinStep.unit.spec.tsxindex 438c6ddef17..86eb4c7f84e 100644--- a/frontend/src/metabase/querying/notebook/components/JoinStep/JoinStep.unit.spec.tsx+++ b/frontend/src/metabase/querying/notebook/components/JoinStep/JoinStep.unit.spec.tsx@@ -99,10 +99,9 @@ function getJoinedQuery() {operator: "=",left: {type: "column",- sourceName: "ORDERS",name: "PRODUCT_ID",},- right: { type: "column", sourceName: "PRODUCTS", name: "ID" },+ right: { type: "column", name: "ID" },},],},@@ -152,21 +151,18 @@ function getJoinedQueryWithMultipleConditions() {operator: "=",left: {type: "column",- sourceName: "ORDERS",name: "PRODUCT_ID",},- right: { type: "column", sourceName: "PRODUCTS", name: "ID" },+ right: { type: "column", name: "ID" },},{operator: "=",left: {type: "column",- sourceName: "ORDERS",name: "CREATED_AT",},right: {type: "column",- sourceName: "PRODUCTS",name: "CREATED_AT",},},@@ -995,10 +991,9 @@ describe("Notebook Editor > Join Step", () => {operator: "=",left: {type: "column",- sourceName: "ORDERS",name: "USER_ID",},- right: { type: "column", sourceName: "PEOPLE", name: "ID" },+ right: { type: "column", name: "ID" },},],},@@ -1442,7 +1437,6 @@ describe("Notebook Editor > Join Step", () => {},{type: "column",- sourceName: "PRODUCTS",name: "ID",},),@@ -1458,7 +1452,7 @@ describe("Notebook Editor > Join Step", () => {setup({step: createMockNotebookStep({query: getJoinedQueryWithCustomExpressions(- { type: "column", sourceName: "ORDERS", name: "PRODUCT_ID" },+ { type: "column", name: "PRODUCT_ID" },{ type: "literal", value: "abc" },),}),@@ -1477,11 +1471,11 @@ describe("Notebook Editor > Join Step", () => {type: "operator",operator: "+",args: [- { type: "column", sourceName: "ORDERS", name: "PRODUCT_ID" },+ { type: "column", name: "PRODUCT_ID" },{ type: "literal", value: 1 },],},- { type: "column", sourceName: "PRODUCTS", name: "ID" },+ { type: "column", name: "ID" },),}),});@@ -1497,14 +1491,13 @@ describe("Notebook Editor > Join Step", () => {query: getJoinedQueryWithCustomExpressions({type: "column",- sourceName: "ORDERS",name: "PRODUCT_ID",},{type: "operator",operator: "+",args: [- { type: "column", sourceName: "PRODUCTS", name: "ID" },+ { type: "column", name: "ID" },{ type: "literal", value: 1 },],},diff --git a/frontend/src/metabase/querying/notebook/components/SortStep/SortStep.unit.spec.tsx b/frontend/src/metabase/querying/notebook/components/SortStep/SortStep.unit.spec.tsxindex 320f1b5f56b..3d243517a31 100644--- a/frontend/src/metabase/querying/notebook/components/SortStep/SortStep.unit.spec.tsx+++ b/frontend/src/metabase/querying/notebook/components/SortStep/SortStep.unit.spec.tsx@@ -22,7 +22,6 @@ function createQueryWithOrderBy(direction: Lib.OrderByDirection = "asc") {orderBys: [{type: "column",- sourceName: "ORDERS",name: "CREATED_AT",direction,},diff --git a/frontend/src/metabase/querying/parameters/utils/query.unit.spec.ts b/frontend/src/metabase/querying/parameters/utils/query.unit.spec.tsindex 8599e8fe298..2ed09f866c1 100644--- a/frontend/src/metabase/querying/parameters/utils/query.unit.spec.ts+++ b/frontend/src/metabase/querying/parameters/utils/query.unit.spec.ts@@ -410,7 +410,6 @@ describe("applyParameter", () => {{type: "column",name: "CREATED_AT",- sourceName: "ORDERS",unit: "month",},],diff --git a/frontend/src/metabase/querying/viz-settings/utils/sync-viz-settings.unit.spec.tsx b/frontend/src/metabase/querying/viz-settings/utils/sync-viz-settings.unit.spec.tsxindex 457e7b46e9a..1b90c817a9b 100644--- a/frontend/src/metabase/querying/viz-settings/utils/sync-viz-settings.unit.spec.tsx+++ b/frontend/src/metabase/querying/viz-settings/utils/sync-viz-settings.unit.spec.tsx@@ -8,7 +8,11 @@ import {createMockTableColumnOrderSetting,createMockVisualizationSettings,} from "metabase-types/api/mocks";-import { ORDERS_ID, SAMPLE_DB_ID } from "metabase-types/api/mocks/presets";+import {+ ORDERS,+ ORDERS_ID,+ SAMPLE_DB_ID,+} from "metabase-types/api/mocks/presets";import {type ColumnInfo,@@ -554,8 +558,8 @@ describe("syncVizSettingsWithQuery", () => {{source: { type: "table", id: ORDERS_ID },fields: [- { type: "column", name: "ID", sourceName: "ORDERS" },- { type: "column", name: "ID", sourceName: "PEOPLE" },+ { type: "column", name: "ID" },+ { type: "column", name: "ID", sourceFieldId: ORDERS.USER_ID },],},],@@ -566,9 +570,9 @@ describe("syncVizSettingsWithQuery", () => {{source: { type: "table", id: ORDERS_ID },fields: [- { type: "column", name: "ID", sourceName: "ORDERS" },- { type: "column", name: "ID", sourceName: "PRODUCTS" },- { type: "column", name: "ID", sourceName: "PEOPLE" },+ { type: "column", name: "ID" },+ { type: "column", name: "ID", sourceFieldId: ORDERS.PRODUCT_ID },+ { type: "column", name: "ID", sourceFieldId: ORDERS.USER_ID },],},],@@ -612,12 +616,10 @@ describe("syncVizSettingsWithQuery", () => {{type: "operator",operator: "sum",- args: [{ type: "column", name: "TOTAL", sourceName: "ORDERS" }],+ args: [{ type: "column", name: "TOTAL" }],},],- breakouts: [- { type: "column", name: "CREATED_AT", sourceName: "ORDERS" },- ],+ breakouts: [{ type: "column", name: "CREATED_AT" }],},],});@@ -629,19 +631,15 @@ describe("syncVizSettingsWithQuery", () => {{type: "operator",operator: "sum",- args: [{ type: "column", name: "TOTAL", sourceName: "ORDERS" }],+ args: [{ type: "column", name: "TOTAL" }],},{type: "operator",operator: "sum",- args: [- { type: "column", name: "SUBTOTAL", sourceName: "ORDERS" },- ],+ args: [{ type: "column", name: "SUBTOTAL" }],},],- breakouts: [- { type: "column", name: "CREATED_AT", sourceName: "ORDERS" },- ],+ breakouts: [{ type: "column", name: "CREATED_AT" }],},],});diff --git a/frontend/src/metabase/visualizations/components/settings/ChartSettingTableColumns/FieldPanel/FieldPanel.unit.spec.tsx b/frontend/src/metabase/visualizations/components/settings/ChartSettingTableColumns/FieldPanel/FieldPanel.unit.spec.tsxindex 50137144bfc..70d2b9b189d 100644--- a/frontend/src/metabase/visualizations/components/settings/ChartSettingTableColumns/FieldPanel/FieldPanel.unit.spec.tsx+++ b/frontend/src/metabase/visualizations/components/settings/ChartSettingTableColumns/FieldPanel/FieldPanel.unit.spec.tsx@@ -4,7 +4,11 @@ import { useState } from "react";import { renderWithProviders, screen } from "__support__/ui";import * as Lib from "metabase-lib";import { DEFAULT_TEST_QUERY, SAMPLE_PROVIDER } from "metabase-lib/test-helpers";-import { ORDERS_ID, PRODUCTS_ID } from "metabase-types/api/mocks/presets";+import {+ ORDERS,+ ORDERS_ID,+ PRODUCTS_ID,+} from "metabase-types/api/mocks/presets";import { FieldPanel } from "./FieldPanel";@@ -166,7 +170,7 @@ describe("QueryColumnPicker", () => {{type: "column",name: "PRICE",- sourceName: "PRODUCTS",+ sourceFieldId: ORDERS.PRODUCT_ID,},],},@@ -198,7 +202,7 @@ describe("QueryColumnPicker", () => {{type: "column",name: "PRICE",- sourceName: "PRODUCTS",+ sourceFieldId: ORDERS.PRODUCT_ID,},],},@@ -228,7 +232,7 @@ describe("QueryColumnPicker", () => {{type: "column",name: "PRICE",- sourceName: "PRODUCTS",+ sourceFieldId: ORDERS.PRODUCT_ID,},],},@@ -274,12 +278,12 @@ describe("QueryColumnPicker", () => {{type: "column",name: "PRICE",- sourceName: "PRODUCTS",+ sourceFieldId: ORDERS.PRODUCT_ID,},{type: "column",name: "CREATED_AT",- sourceName: "PRODUCTS",+ sourceFieldId: ORDERS.PRODUCT_ID,},],},@@ -414,7 +418,7 @@ describe("QueryColumnPicker", () => {{type: "column",name: "PRICE",- sourceName: "PRODUCTS",+ sourceFieldId: ORDERS.PRODUCT_ID,},],},diff --git a/src/metabase/lib/query/test_spec.cljc b/src/metabase/lib/query/test_spec.cljcindex 522ef2b8bb8..55f6486fa24 100644--- a/src/metabase/lib/query/test_spec.cljc+++ b/src/metabase/lib/query/test_spec.cljc@@ -1,5 +1,5 @@(ns metabase.lib.query.test-spec- (:refer-clojure :exclude [mapv name not-empty])+ (:refer-clojure :exclude [mapv name])(:require[malli.core :as mc][malli.transform :as mtx]@@ -12,6 +12,7 @@[metabase.lib.field :as lib.field][metabase.lib.filter :as lib.filter][metabase.lib.join :as lib.join]+ [metabase.lib.join.util :as lib.join.util][metabase.lib.limit :as lib.limit][metabase.lib.metadata :as lib.metadata][metabase.lib.metadata.calculation :as lib.metadata.calculation]@@ -34,7 +35,7 @@[metabase.util :as u][metabase.util.malli :as mu][metabase.util.malli.registry :as mr]- [metabase.util.performance :refer [mapv not-empty]]))+ [metabase.util.performance :refer [mapv]]))(mu/defn- find-source :- [:or ::lib.schema.metadata/table ::lib.schema.metadata/card][metadata-providerable :- ::lib.schema.metadata/metadata-providerable@@ -44,34 +45,42 @@:card (lib.metadata/card metadata-providerable spec-id)))(mu/defn- matches-column? :- :boolean- [query :- ::lib.schema/query- _stage-number :- :int- name-key :- :keyword- {:keys [name table-id source-name source-field-id display-name]} :- ::lib.schema.test-spec/test-order-by-spec- column :- ::lib.schema.metadata/column]- (cond-> (= name (name-key column))- (some? table-id) (and (= table-id (:table-id column)))- (some? source-name) (and (= source-name (some->> column :table-id (lib.metadata/table query) :name)))- (some? source-field-id) (and (= source-field-id ((some-fn :fk-field-id :lib/original-fk-field-id) column)))- (some? display-name) (and (= display-name (:display-name column)))))+ [{:keys [name field-id join-alias source-field-id source-field-join-alias]}+ :- ::lib.schema.test-spec/test-order-by-spec+ column :- ::lib.schema.metadata/column]+ (and (if field-id+ (= field-id (:id column))+ (= name ((some-fn :lib/deduplicated-name :name) column)))+ (= join-alias (lib.join.util/current-join-alias column))+ (= source-field-id (:fk-field-id column))+ (= source-field-join-alias (:fk-join-alias column))))++(mu/defn- matches-bucketing? :- :boolean+ [{:keys [unit binning]} :- ::lib.schema.test-spec/test-order-by-spec+ column :- ::lib.schema.metadata/column]+ (let [{:keys [strategy] :as column-binning} (lib.binning/binning column)]+ (and (= unit (lib.temporal-bucket/raw-temporal-bucket column))+ (= (:strategy binning) strategy)+ (or (nil? binning)+ (= strategy :default)+ (== (strategy binning) (strategy column-binning))))))(mu/defn- find-column :- ::lib.schema.metadata/column- [query :- ::lib.schema/query- stage-number :- :int+ "Finds the column a spec names. A column already bucketed more than one way, like a breakout by month and by year,+ is told apart by the spec's `:unit` or `:binning`."+ [_query :- ::lib.schema/query+ _stage-number :- :intavailable-columns :- [:sequential ::lib.schema.metadata/column]column-spec :- ::lib.schema.test-spec/test-order-by-spec]- (let [matching (fn [name-key]- (filterv (partial matches-column? query stage-number name-key column-spec) available-columns))- ;; A saved card stores repeated names deduplicated (`ID`, `ID_2`), so a spec naming the column as its table- ;; does matches nothing; the name it had before deduplication still finds it.- columns (or (not-empty (matching :name))- (matching :lib/original-name))]+ (let [matching (filterv (partial matches-column? column-spec) available-columns)+ columns (if (and (> (count matching) 1)+ ((some-fn :unit :binning) column-spec))+ (filterv (partial matches-bucketing? column-spec) matching)+ matching)](case (count columns)0 (throw (ex-info "No column found" {:columns available-columns, :column-spec column-spec}))1 (first columns)- (if (:index column-spec)- (get columns (:index column-spec))- (throw (ex-info "Multiple columns found" {:columns columns, :column-spec column-spec}))))))+ (throw (ex-info "Multiple columns found" {:columns columns, :column-spec column-spec})))))(mu/defn- append-fields :- ::lib.schema/query[query :- ::lib.schema/query@@ -247,13 +256,14 @@(mu/defn- append-join :- ::lib.schema/query[query :- ::lib.schema/querystage-number :- :int- {:keys [source strategy conditions]} :- ::lib.schema.test-spec/test-join-spec]+ {:keys [source strategy conditions], join-alias :alias} :- ::lib.schema.test-spec/test-join-spec](let [join-target (find-source query source)join-strategy (find-join-strategy query stage-number strategy)join-conditions (if conditions(mapv (partial join-condition-spec->join-condition query stage-number join-target) conditions)(lib.join/suggested-join-conditions query stage-number join-target))- join-clause (lib.join/join-clause join-target join-conditions join-strategy)]+ join-clause (cond-> (lib.join/join-clause join-target join-conditions join-strategy)+ join-alias (lib.join/with-join-alias join-alias))](lib.join/join query stage-number join-clause)))(mu/defn- append-joins :- ::lib.schema/querydiff --git a/src/metabase/lib/schema/test_spec.cljc b/src/metabase/lib/schema/test_spec.cljcindex 38694abb8c3..fb2dbb5ec2c 100644--- a/src/metabase/lib/schema/test_spec.cljc+++ b/src/metabase/lib/schema/test_spec.cljc@@ -29,14 +29,16 @@[:card ::test-card-source-spec]])(mr/def ::test-column-spec+ "A column of the stage: a field by `:field-id`, or else a column by its `:name`. Every other key is matched exactly:+ a missing `:join-alias` means the column does not come from a join, a missing `:source-field-id` means it is not+ implicitly joined."[:map {:closed true}[:type [:= {:decode/normalize lib.schema.common/normalize-keyword} :column]]- [:name string?]- [:table-id {:optional true} [:maybe ::lib.schema.id/table]]- [:source-name {:optional true} [:maybe string?]]+ [:name {:optional true} [:maybe string?]]+ [:field-id {:optional true} [:maybe ::lib.schema.id/field]]+ [:join-alias {:optional true} [:maybe ::lib.schema.join/alias]][:source-field-id {:optional true} [:maybe ::lib.schema.id/field]]- [:display-name {:optional true} [:maybe string?]]- [:index {:optional true} [:maybe pos-int?]]])+ [:source-field-join-alias {:optional true} [:maybe ::lib.schema.join/alias]]])(mr/def ::test-temporal-bucket-spec[:map@@ -121,6 +123,7 @@[:map {:closed true}[:source [:ref ::test-source-spec]][:strategy ::lib.schema.join/strategy]+ [:alias {:optional true} [:maybe ::lib.schema.join/alias]][:conditions {:optional true} [:maybe [:sequential ::test-join-condition-spec]]]])(mr/def ::test-join-source-specdiff --git a/test/metabase/lib/query/test_spec_test.cljc b/test/metabase/lib/query/test_spec_test.cljcindex d226f9410b4..ec16a1a9a31 100644--- a/test/metabase/lib/query/test_spec_test.cljc+++ b/test/metabase/lib/query/test_spec_test.cljc@@ -43,15 +43,13 @@{:stages [{:source {:type :table:id (meta/id :orders)}:fields [{:type :column- :name "ID"- :source-name "ORDERS"}- ;; column without source-name can be found if it is unambiguous+ :name "ID"}{:type :column:name "TOTAL"};; implicitly joined column{:type :column:name "NAME"- :source-name "PEOPLE"}]}]})]+ :source-field-id (meta/id :orders :user-id)}]}]})](is (=? [[:field {} (meta/id :orders :id)][:field {} (meta/id :orders :total)][:field {} (meta/id :people :name)]]@@ -273,11 +271,9 @@:conditions [{:operator :=:left {:type :column:name "LAST_LOGIN"- :source-name "USERS":unit :month}:right {:type :column:name "DATE"- :source-name "CHECKINS":unit :month}}]}]}]})](is (=? [{:strategy :left-join:conditions [[:= {}@@ -365,20 +361,16 @@(deftest ^:parallel test-query-error-multiple-columns-found-test(testing "test-query throws when multiple columns match"- ;; This test would need a scenario where the same column name appears multiple times- ;; For example, after a join. Let's test this with a join scenario(is (thrown-with-msg?#?(:clj Exception :cljs js/Error)#"Multiple columns found"(lib.query.test-spec/test-querymeta/metadata-provider- {:stages [{:source {:type :table- :id (meta/id :venues)}- :joins [{:source {:type :table- :id (meta/id :categories)}- :strategy :left-join}]- :fields [{:type :column- :name "ID"}]}]})))))+ {:stages [{:source {:type :table+ :id (meta/id :checkins)}+ :breakouts [{:type :column :name "DATE" :unit :month}+ {:type :column :name "DATE" :unit :year}]+ :order-bys [{:type :column :name "DATE"}]}]})))))(deftest ^:parallel test-query-aggregation-with-args-test(testing "test-query handles aggregations with column arguments"@@ -494,7 +486,7 @@:unit :year}]:order-bys [{:type :column:name "DATE"- :display-name "Date: Month"+ :unit :month:direction :desc}]}]})](is (=? [[:desc {}[:field {:temporal-unit :month} (meta/id :checkins :date)]]]@@ -512,7 +504,7 @@:unit :year}]:order-bys [{:type :column:name "DATE"- :display-name "Date: Year"+ :unit :year:direction :desc}]}]})](is (=? [[:desc {}[:field {:temporal-unit :year} (meta/id :checkins :date)]]]@@ -610,7 +602,7 @@:conditions [{:operator :=:left {:type :column:name "ID"- :source-name "PRODUCTS"}+ :join-alias "Products"}:right {:type :column:name "PRODUCT_ID"}}]}]}]})](is (=? [{:strategy :left-join@@ -633,16 +625,16 @@:args [{:type :literal:value "Gadget"}{:type :column- :source-name "PRODUCTS"+ :source-field-id (meta/id :orders :product-id):name "CATEGORY"}]}]:aggregations [{:type :operator:operator :sum:args [{:type :column- :source-name "PRODUCTS"+ :source-field-id (meta/id :orders :product-id):name "PRICE"}]}]:breakouts [{:type :column- :source-name "PRODUCTS"+ :source-field-id (meta/id :orders :product-id):name "CREATED_AT"}]:expressions [{:name "Custom"@@ -651,7 +643,8 @@:args [{:type :literal:value 42}{:type :column- :name "PRICE"}]}}]}]})]+ :name "PRICE"+ :source-field-id (meta/id :orders :product-id)}]}}]}]})](is (=? [[:={} "Gadget"[:field@@ -690,7 +683,8 @@{:stages [{:source {:type :table:id (meta/id :orders)}:order-bys [{:type :column- :name "PRICE"}]}]})]+ :name "PRICE"+ :source-field-id (meta/id :orders :product-id)}]}]})](is (=? [[:asc {} [:field{:source-field (meta/id :orders :product-id)}(meta/id :products :price)]]]@@ -747,7 +741,7 @@:operator :*:args [{:type :column:name "PRICE"- :source-name "PRODUCTS"}+ :join-alias "Products"}{:type :literal:value 0.9}]}}{:name "double-discount"@@ -772,7 +766,7 @@:operator :=:args [{:type :column:name "CATEGORY"- :source-name "PRODUCTS"}+ :join-alias "Products"}{:type :literal:value "Widget"}]}{:type :operator@@ -795,11 +789,10 @@:operator :avg:args [{:type :column:name "PRICE"- :source-name "PRODUCTS"}]}]+ :join-alias "Products"}]}]:breakouts [{:type :column:name "CREATED_AT"- :source-name "ORDERS":unit :month}{:type :column:name "QUANTITY"@@ -807,7 +800,6 @@:order-bys [{:type :column:name "CREATED_AT"- :source-name "ORDERS":direction :desc}]};; Stage 1{:expressions [{:name "doubled-count"@@ -904,7 +896,7 @@:operator :*:args [{:type :column:name "PRICE"- :source-name "PRODUCTS"}+ :join-alias "Products"}{:type :literal:value 0.9}]}}{:name "double-discount"@@ -929,7 +921,7 @@:operator :=:args [{:type :column:name "CATEGORY"- :source-name "PRODUCTS"}+ :join-alias "Products"}{:type :literal:value "Widget"}]}{:type :operator@@ -941,14 +933,13 @@:order-bys [{:type :column:name "CREATED_AT"- :source-name "ORDERS":direction :desc}]:fields [{:type :column:name "TOTAL"}{:type :column:name "CATEGORY"- :source-name "PRODUCTS"}+ :join-alias "Products"}{:type :column:name "double-discount"}]};; Stage 1@@ -1277,7 +1268,7 @@(defn- orders-column[column-name]- {:type :column :name column-name :table-id (meta/id :orders)})+ {:type :column :name column-name})(defn- orders-then[first-stage second-stage]@@ -1329,7 +1320,7 @@(lib/order-bys query 1))))))(deftest ^:parallel test-query-later-stage-tells-joined-result-columns-apart-by-fk-test- (testing "PRODUCTS.ID and PEOPLE.ID are both named ID; the FK they were reached through picks one"+ (testing "PRODUCTS.ID and PEOPLE.ID are both named ID; a later stage picks one by its field id"(is (=? [[:< {} [:field {} "PEOPLE__via__USER_ID__ID"] 10]](lib/filters(orders-then {:aggregations [{:type :operator :operator :count :args []}]@@ -1337,12 +1328,12 @@{:type :column :name "ID" :source-field-id (meta/id :orders :user-id)}]}{:filters [{:type :operator:operator :<- :args [{:type :column :name "ID" :source-field-id (meta/id :orders :user-id)}+ :args [{:type :column :field-id (meta/id :people :id)}{:type :literal :value 10}]}]})1)))))(deftest ^:parallel test-query-joined-result-column-through-card-test- (testing "a saved card stores the second joined ID as ID_2; its original name and FK still pick it"+ (testing "a saved card stores the second joined ID as ID_2, and that name picks it"(let [card-query (lib.query.test-spec/test-querymeta/metadata-provider{:stages [{:source {:type :table :id (meta/id :orders)}@@ -1359,7 +1350,100 @@{:stages [{:source {:type :card :id 1}}{:filters [{:type :operator:operator :<- :args [{:type :column :name "ID" :source-field-id (meta/id :orders :user-id)}+ :args [{:type :column :name "ID_2"}{:type :literal :value 10}]}]}]})](is (=? [[:< {} [:field {} "PEOPLE__via__USER_ID__ID"] 10]](lib/filters query 1))))))++(def ^:private two-fks-to-products-provider+ "ORDERS with USER_ID as a second FK into PRODUCTS."+ (lib.tu/merged-mock-metadata-provider+ meta/metadata-provider+ {:fields [{:id (meta/id :orders :user-id) :semantic-type :type/FK :fk-target-field-id (meta/id :products :id)}]}))++(deftest ^:parallel test-query-implicit-joins-through-several-fks-test+ (testing "the FK field picks between implicit joins into the same table"+ (is (=? [[:field {:source-field (meta/id :orders :product-id)} (meta/id :products :title)]+ [:field {:source-field (meta/id :orders :user-id)} (meta/id :products :title)]]+ (lib/breakouts+ (lib.query.test-spec/test-query+ two-fks-to-products-provider+ {:stages [{:source {:type :table :id (meta/id :orders)}+ :aggregations [{:type :operator :operator :count}]+ :breakouts [{:type :column :field-id (meta/id :products :title)+ :source-field-id (meta/id :orders :product-id)}+ {:type :column :name "TITLE" :source-field-id (meta/id :orders :user-id)}]}]})))))+ (testing "a column without a source field is never an implicitly joined one"+ (is (thrown-with-msg?+ #?(:clj Exception :cljs js/Error)+ #"No column found"+ (lib.query.test-spec/test-query+ two-fks-to-products-provider+ {:stages [{:source {:type :table :id (meta/id :orders)}+ :breakouts [{:type :column :name "TITLE"}]}]})))))++(deftest ^:parallel test-query-implicit-join-through-joined-fk-test+ (testing "the join alias of the FK picks between the base table's FK and a joined copy of it"+ (is (=? [[:field {:join-alias "O1"} (meta/id :orders :id)]+ [:field {:source-field (meta/id :orders :product-id) :source-field-join-alias missing-value}+ (meta/id :products :title)]+ [:field {:source-field (meta/id :orders :product-id) :source-field-join-alias "O1"}+ (meta/id :products :title)]]+ (lib/breakouts+ (lib.query.test-spec/test-query+ meta/metadata-provider+ {:stages [{:source {:type :table :id (meta/id :orders)}+ :joins [{:source {:type :table :id (meta/id :orders)}+ :strategy :left-join+ :alias "O1"+ :conditions [{:operator := :left {:type :column :name "ID"} :right {:type :column :name "ID"}}]}]+ :aggregations [{:type :operator :operator :count}]+ :breakouts [{:type :column :field-id (meta/id :orders :id) :join-alias "O1"}+ {:type :column :name "TITLE" :source-field-id (meta/id :orders :product-id)}+ {:type :column+ :name "TITLE"+ :source-field-id (meta/id :orders :product-id)+ :source-field-join-alias "O1"}]}]}))))))++(deftest ^:parallel test-query-joined-card-columns-by-name-test+ (testing "a joined card's columns are named with the join's alias; the condition's right side is not yet joined"+ (let [card-query (lib/aggregate (lib/breakout (lib/query meta/metadata-provider (meta/table-metadata :orders))+ (meta/field-metadata :orders :product-id))+ (lib/count))+ query (lib.query.test-spec/test-query+ (lib.tu/metadata-provider-with-card-from-query 1 card-query)+ {:stages [{:source {:type :table :id (meta/id :products)}+ :joins [{:source {:type :card :id 1}+ :strategy :left-join+ :alias "C"+ :conditions [{:operator := :left {:type :column :name "ID"}+ :right {:type :column :name "PRODUCT_ID"}}]}]+ :order-bys [{:type :column :name "count" :join-alias "C" :direction :desc}]}]})]+ (is (=? [[:desc {} [:field {:join-alias "C"} "count"]]]+ (lib/order-bys query))))))++(deftest ^:parallel test-query-camel-case-column-keys-test+ (testing "test-query reads camelCase column keys"+ (is (=? [[:field {:source-field (meta/id :orders :product-id)} (meta/id :products :category)]]+ (lib/breakouts+ (lib.query.test-spec/test-query+ meta/metadata-provider+ {"stages" [{"source" {"type" "table" "id" (meta/id :orders)}+ "aggregations" [{"type" "operator" "operator" "count"}]+ "breakouts" [{"type" "column"+ "fieldId" (meta/id :products :category)+ "sourceFieldId" (meta/id :orders :product-id)}]}]}))))))++(deftest ^:parallel test-query-expression-named-like-a-field-test+ (testing "an expression named like a field of the stage is ambiguous"+ (is (thrown-with-msg?+ #?(:clj Exception :cljs js/Error)+ #"Multiple columns found"+ (lib.query.test-spec/test-query+ meta/metadata-provider+ {:stages [{:source {:type :table :id (meta/id :orders)}+ :expressions [{:name "TOTAL"+ :value {:type :operator :operator :++ :args [{:type :column :name "TOTAL"} {:type :literal :value 1}]}}]+ :aggregations [{:type :operator :operator :count}]+ :breakouts [{:type :column :name "TOTAL"}]}]})))))