-
- Downloads
Handle models with joins (#29014) (#29125)
* Handle models with joins
We had been using the metadata from the query to get column names, and
then `select (column-names) from persisted-table`.
But joins affect how columns are emitted.
For this tests, using orders join to products, selecting order.total and
product.category. And the metadata from running this query uses the
normal names `:name "total"`, and `:name "category"`. _BUT_ the emitted
sql does not use these names:
```sql
SELECT "public"."orders"."total" AS "total",
"products"."category" AS "products__category" -- <--------
FROM "public"."orders"
LEFT JOIN "public"."products" AS "products"
ON "public"."orders"."product_id" = "products"."id"
```
When we persist, we do `create table as <(qp/compile query)> so we were
creating a column named `products__category` _NOT_ "category". But later
on we would select "category" and this would blow up.
```sql
select "total", "category" -- <- category doesn't exist in this table
from "metabase_cache_424a9_8"."model_1105_txbhmkrnoy"
```
Now a query of `{:source-table "card__<model-id>"}' emits the following
query when the persisted cache is substituted:
```sql
SELECT "source"."total" AS "total",
"source"."products__category" AS "products__category"
FROM (select * from "metabase_cache_424a9_8"."model_1152_lecqfzcjke") AS
"source"
LIMIT 1048575
```
* Test and lint fixes
Co-authored-by:
dpsutton <dan@dpsutton.com>
Showing
- src/metabase/models/persisted_info.clj 1 addition, 1 deletionsrc/metabase/models/persisted_info.clj
- src/metabase/query_processor/util/persisted_cache.clj 6 additions, 12 deletionssrc/metabase/query_processor/util/persisted_cache.clj
- test/metabase/driver/common/parameters/values_test.clj 1 addition, 1 deletiontest/metabase/driver/common/parameters/values_test.clj
- test/metabase/query_processor/persistence_test.clj 36 additions, 1 deletiontest/metabase/query_processor/persistence_test.clj
Please register or sign in to comment