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

Port query description logic to MLv2 #29200

Merged
merged 42 commits into from Mar 21, 2023
Merged

Port query description logic to MLv2 #29200

merged 42 commits into from Mar 21, 2023

Conversation

camsaul
Copy link
Member

@camsaul camsaul commented Mar 14, 2023

Implements #28882

Replaces a solid 300 Loc from JS metabase lib with Cljs versions. That's a little over 1% of metabase-lib, so if we just open 99 more PRs like this we'll be done. Nice

This ports the version of generateQueryDescription in Question.ts, rather than the version in queries/utils/description.js which is pretty much an exact copy, but somewhat harder to port since it's used without a full query. The version in Question.ts is used more extensively anyway. I'll try to port that over as well as a follow-on.

This PR seems bigger than it is, but that's because I shuffled around a lot of multimethods used for metadata calculation and moved their implementations to live with the other functions related to them e.g. the display-name method for aggregations lives in metabase.lib.aggregations now instead of in metabase.lib.metadata.calculate.names. So like 90% of this PR is just moving stuff around so it's easier to deal with going forward.

I'm also working on porting over a ton of other stuff, e.g. Aggregation.displayName(), but I'll open a follow-on PR for that.

@camsaul camsaul changed the title M lv2 query descriptions Port query description logic to MLv2 Mar 14, 2023
@camsaul camsaul marked this pull request as ready for review March 14, 2023 23:27
@codecov
Copy link

codecov bot commented Mar 15, 2023

Codecov Report

Patch coverage: 80.45% and project coverage change: +0.04 🎉

Comparison is base (b424ddb) 68.46% compared to head (5deaa35) 68.51%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #29200      +/-   ##
==========================================
+ Coverage   68.46%   68.51%   +0.04%     
==========================================
  Files        2788     2790       +2     
  Lines       96474    96579     +105     
  Branches    12297    12316      +19     
==========================================
+ Hits        66054    66167     +113     
+ Misses      25233    25205      -28     
- Partials     5187     5207      +20     
Flag Coverage Δ
front-end 50.43% <95.83%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...tend/src/metabase-lib/queries/utils/description.js 0.00% <ø> (-14.90%) ⬇️
src/metabase/lib/core.cljc 100.00% <ø> (ø)
src/metabase/lib/metadata/protocols.cljc 72.72% <33.33%> (-1.70%) ⬇️
src/metabase/lib/schema/expression/arithmetic.cljc 85.07% <62.50%> (-6.00%) ⬇️
src/metabase/lib/metric.cljc 71.42% <71.42%> (ø)
src/metabase/lib/table.cljc 69.23% <72.22%> (-0.77%) ⬇️
src/metabase/lib/expression.cljc 83.20% <72.41%> (-3.98%) ⬇️
src/metabase/lib/schema/expression/temporal.cljc 76.47% <75.75%> (-23.53%) ⬇️
src/metabase/lib/schema/expression/string.cljc 84.21% <84.21%> (ø)
frontend/src/metabase-lib/Question.ts 64.26% <95.23%> (+4.26%) ⬆️
... and 8 more

... and 5 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@deploysentinel
Copy link

deploysentinel bot commented Mar 15, 2023

No failed tests 🎉

.clj-kondo/config.edn Outdated Show resolved Hide resolved
Comment on lines +1331 to +1338
let metadata =
tableMetadata?.id != null
? assocIn(
this._metadata,
["tables", String(tableMetadata.id)],
tableMetadata,
)
: this._metadata;
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why we need to modify the metadata here and below now?

Copy link
Member Author

Choose a reason for hiding this comment

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

MLv2 currently wants queries to be initialized with complete metadata like this._metadata, not just metadata for a single table. So I'm just merging the metadata for the individual table into this._metadata.

I suppose we could rework things so we can initialize a query with just the metadata for a single table but it seems like query descriptions would break if you happened to be filtering on a field from a different table, so it didn't make a ton of sense to relax that rule honestly

Copy link
Member

@kulyk kulyk Mar 15, 2023

Choose a reason for hiding this comment

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

@camsaul I see, thank you. What if we rework the caller so it actually provides the full Metadata instance instead?

I can open a PR doing this against your branch or make another PR once this one is merged

Comment on lines 1326 to 1328
_getMLv2Query(metadata = this._metadata) {
return MLv2.query(this.databaseId(), metadata, this.datasetQuery());
}
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to make the method private?

@camsaul camsaul changed the base branch from master to MLv2-more-shuffling March 15, 2023 18:27
@@ -1605,47 +1605,6 @@ describe("Question", () => {
);
});
});

describe("Question._getOrderByDescription", () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

these test a specific part of getQueryDescription, tests are in cljs now

Base automatically changed from MLv2-more-shuffling to master March 20, 2023 16:47
@camsaul camsaul enabled auto-merge (squash) March 21, 2023 06:47
@camsaul camsaul merged commit 8f55452 into master Mar 21, 2023
89 checks passed
@camsaul camsaul deleted the MLv2-query-descriptions branch March 21, 2023 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants