Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distribution on cached models that were originally JSONB does not work #35636

Closed
paoliniluis opened this issue Nov 12, 2023 · 1 comment · Fixed by #39446
Closed

Distribution on cached models that were originally JSONB does not work #35636

paoliniluis opened this issue Nov 12, 2023 · 1 comment · Fixed by #39446
Labels

Comments

@paoliniluis
Copy link
Contributor

Describe the bug

An interesting turnaround of events that lead to the query processor making wrong choices in which the distribution functionality will generate wrong SQL

To Reproduce

  1. get a postgres
  2. run
-- Creating the table
CREATE TABLE sample_table (
    id SERIAL PRIMARY KEY,
    json_data JSONB
);

-- Inserting 10 sample values
INSERT INTO sample_table (json_data) VALUES
  ('{"name": "John Doe", "age": 25, "address": {"city": "New York", "zipcode": "10001"}}'),
  ('{"name": "Alice Smith", "age": 30, "address": {"city": "Los Angeles", "zipcode": "90001"}}'),
  ('{"name": "Bob Johnson", "age": 28, "address": {"city": "Chicago", "zipcode": "60601"}}'),
  ('{"name": "Eva Brown", "age": 35, "address": {"city": "San Francisco", "zipcode": "94105"}}'),
  ('{"name": "Chris White", "age": 22, "address": {"city": "Seattle", "zipcode": "98101"}}'),
  ('{"name": "Olivia Davis", "age": 27, "address": {"city": "Miami", "zipcode": "33101"}}'),
  ('{"name": "Daniel Lee", "age": 32, "address": {"city": "Dallas", "zipcode": "75201"}}'),
  ('{"name": "Sophia Garcia", "age": 29, "address": {"city": "Denver", "zipcode": "80202"}}'),
  ('{"name": "Matthew Taylor", "age": 26, "address": {"city": "Boston", "zipcode": "02108"}}'),
  ('{"name": "Emma Martinez", "age": 31, "address": {"city": "Phoenix", "zipcode": "85001"}}');
  1. enable model caching
  2. go to the sample_table table and make a question out of it
  3. then save it as a model
  4. enable model caching (cron expression to make it run every minute)
  5. then do a distribution on the age column, see the error

ERROR: column "source.json_data" must appear in the GROUP BY clause or be used in an aggregate function
Position: 125

Expected behavior

No response

Logs

SELECT ("source"."json_data"#>> array[$1]::text[])::bigint AS "json_data → age", COUNT(*) AS "count" FROM (select * from "metabase_cache_f3484_2"."model_6_sample_tab") AS "source" GROUP BY "json_data → age" ORDER BY "json_data → age" ASC

Information about your Metabase installation

v47.x

Severity

P2

Additional context

Way out: disable model caching

@bshepherdson
Copy link
Contributor

This is a duplicate of #34930 .

bshepherdson added a commit that referenced this issue Mar 1, 2024
In the legacy QP the `:fields` of the outer query has the ID,
`[:field 100 {}]` so the JSON unfolding is written out again.

With this change, the `source-alias` is used for columns coming from
previous stages.

Fixes #34930. Fixes #35636.
bshepherdson added a commit that referenced this issue Mar 1, 2024
In the legacy QP the `:fields` of the outer query has the ID,
`[:field 100 {}]` so the JSON unfolding is written out again.

With this change, the `source-alias` is used for columns coming from
previous stages.

Fixes #34930. Fixes #35636.
bshepherdson added a commit that referenced this issue Mar 4, 2024
In the legacy QP the `:fields` of the outer query has the ID,
`[:field 100 {}]` so the JSON unfolding is written out again.

With this change, the `source-alias` is used for columns coming from
previous stages.

Fixes #34930. Fixes #35636.
bshepherdson added a commit that referenced this issue Mar 4, 2024
…9446)

In the legacy QP the `:fields` of the outer query has the ID,
`[:field 100 {}]` so the JSON unfolding is written out again.

With this change, the `source-alias` is used for columns coming from
previous stages.

Fixes #34930. Fixes #35636.
github-actions bot pushed a commit that referenced this issue Mar 4, 2024
…9446)

In the legacy QP the `:fields` of the outer query has the ID,
`[:field 100 {}]` so the JSON unfolding is written out again.

With this change, the `source-alias` is used for columns coming from
previous stages.

Fixes #34930. Fixes #35636.
bshepherdson added a commit that referenced this issue Mar 4, 2024
…9446)

In the legacy QP the `:fields` of the outer query has the ID,
`[:field 100 {}]` so the JSON unfolding is written out again.

With this change, the `source-alias` is used for columns coming from
previous stages.

Fixes #34930. Fixes #35636.
metabase-bot bot added a commit that referenced this issue Mar 4, 2024
…9446) (#39536)

In the legacy QP the `:fields` of the outer query has the ID,
`[:field 100 {}]` so the JSON unfolding is written out again.

With this change, the `source-alias` is used for columns coming from
previous stages.

Fixes #34930. Fixes #35636.

Co-authored-by: Braden Shepherdson <braden@metabase.com>
bshepherdson added a commit that referenced this issue Mar 5, 2024
…9446)

In the legacy QP the `:fields` of the outer query has the ID,
`[:field 100 {}]` so the JSON unfolding is written out again.

With this change, the `source-alias` is used for columns coming from
previous stages.

Fixes #34930. Fixes #35636.
bshepherdson added a commit that referenced this issue Mar 5, 2024
…stages (#39446)" (#39642)

In the legacy QP the `:fields` of the outer query has the ID,
`[:field 100 {}]` so the JSON unfolding is written out again.

With this change, the `source-alias` is used for columns coming from
previous stages.

Fixes #34930. Fixes #35636.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants