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

[MBQL lib] Add preview-query to truncate a query for Notebook preview #42836

Merged
merged 8 commits into from
May 29, 2024

Conversation

bshepherdson
Copy link
Contributor

Fixes #42831.

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @bshepherdson and the rest of your teammates on Graphite Graphite

@metabase-bot metabase-bot bot added the .Team/QueryProcessor :hammer_and_wrench: label May 17, 2024
@bshepherdson bshepherdson marked this pull request as ready for review May 17, 2024 20:07
@bshepherdson bshepherdson added the backport Automatically create PR on current release branch on merge label May 17, 2024
@bshepherdson bshepherdson requested review from metamben, ranquild and snoe and removed request for camsaul May 17, 2024 20:07
Copy link

replay-io bot commented May 17, 2024

Status Complete ↗︎
Commit 0a3573b
Results
2575 Passed

Copy link
Contributor

@metamben metamben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have only minor suggestions and questions.

src/metabase/lib/js.cljs Outdated Show resolved Hide resolved
src/metabase/lib/js.cljs Show resolved Hide resolved
Comment on lines +2202 to +2254
- `:data` - just the source data for the stage
- `:joins`
- `:expressions`
- `:filters`
- `:aggregation`
- `:breakout`
- `:order-by`
- `:limit`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look like keywords, but at this point we get strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do this everywhere else in the API as well. The intuition is that these are not "data" strings, they're "enum" strings. That's reinforced by the types like type ClauseType = "data" | ...;.

@@ -253,3 +253,43 @@
[a-query :- ::lib.schema/query
metric-id :- [:or ::lib.schema.id/legacy-metric :string]]
(occurs-in-stage-clause? a-query :aggregation #(occurs-in-expression? % :metric metric-id)))

(def ^:private clause-types-order
;; Note that :breakout is never actually sent, but when we get :aggregation we want to drop :breakout too.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would using :summary be cleaner then? The precedence between :aggregation and :breakout is somewhat arbitrary (and it's right to left, and reverse lexicographic)).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:summary would be more transparent, I agree. However, this is effectively a list of keys on a stage, in a specific order. The order of :aggregation and :breakout is not arbitrary.

When previewing some part :x we want to remove a prefix of the keys in this list, up to but excluding the specified clause :x.

  • So if you preview :aggregation we remove :limit and :order-by
  • If you preview :filters we remove :limit, :order-by, :aggregation and :breakout.

This is the only order of :aggregation and :breakout that gives those properties.

I've added an expanded comment to explain that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the order arbitrary in the sense that I could choose to use :breakout instead of :aggregation to signify that the summary has to be removed and swap them in the vector? (I'm assuming we can change the callers.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that's true. The important property is that whichever of :aggregation and :breakout is sent by the FE when previewing the Summary step is first in this list.

(test-preview 0 :expressions nil
{:stages [{:source-table (meta/id :orders)
:joins [{} {}]
:expressions [vector?]}]}))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:expressions [vector?]}]}))))
:expressions [vector?]}]}))))

@bshepherdson bshepherdson merged commit a672996 into master May 29, 2024
111 checks passed
@bshepherdson bshepherdson deleted the mblib-preview-query branch May 29, 2024 19:24
Copy link

@bshepherdson Did you forget to add a milestone to the issue for this PR? When and where should I add a milestone?

bshepherdson added a commit that referenced this pull request May 29, 2024
…ew (#42836)

Fixes #42831.

Co-authored-by: Alexander Polyankin <alexander.polyankin@metabase.com>
bshepherdson added a commit that referenced this pull request May 30, 2024
…ew (#42836) (#43327)

Fixes #42831.

Co-authored-by: Braden Shepherdson <braden@metabase.com>
Co-authored-by: Alexander Polyankin <alexander.polyankin@metabase.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Automatically create PR on current release branch on merge .Team/QueryProcessor :hammer_and_wrench:
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize creating preview queries on the FE
3 participants