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

Add DatePart Support to ValidLinkableSpecResolver #911

Merged
merged 2 commits into from
Dec 15, 2023

Conversation

plypaul
Copy link
Contributor

@plypaul plypaul commented Nov 29, 2023

Description

ValidLinkableSpecResolver is used to list specs that are available for querying metrics. Since we added date_part to TimeDimensionSpecs, this PR updates ValidLinkableSpecResolver to include them as well.

@cla-bot cla-bot bot added the cla:yes label Nov 29, 2023
Copy link

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

@plypaul plypaul marked this pull request as ready for review November 30, 2023 06:52
@plypaul plypaul force-pushed the plypaul--58.10--resolution-dag branch from 9ade7e7 to affb229 Compare December 1, 2023 00:08
@plypaul plypaul force-pushed the plypaul--58.11--add-date-part-to-resolver branch from ad2df4e to a2771ac Compare December 1, 2023 00:08
Copy link
Contributor

@tlento tlento left a comment

Choose a reason for hiding this comment

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

Seems reasonable! Minor suggestions inline.

Comment on lines +508 to +509
# If no metrics are specified, the query interface supports distinct dimension values from a single semantic
# model.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this true? Because build_plan_for_distinct_values doesn't behave as if this is true. For that matter, neither does this code. Maybe we just remove this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well dang, looks like I misread the method. I'll have to update this and a few other parts in the stakc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, it does:

def test_distinct_values( # noqa: D

# No date part, just the metric time at a different grain.
(None,)
# date part of a metric time at a different grain.
+ tuple(date_part for date_part in DatePart if time_granularity.to_int() <= date_part.to_int())
Copy link
Contributor

Choose a reason for hiding this comment

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

I see this granularity/date_part comparison all over the place and it's confusing every time. Maybe we should add a method to DatePart that does this and document the mechanics of the comparison there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that we should. The reason why this was in place was that there was a bug in DSI (dbt-labs/dbt-semantic-interfaces#212), so I did this while that was getting pulled in to MF. I'll handle this as a follow up.

Comment on lines +675 to +680
possible_date_parts: Sequence[Optional[DatePart]] = (
# No date part, just the metric time at a different grain.
(None,)
# date part of a metric time at a different grain.
+ tuple(date_part for date_part in DatePart if time_granularity.to_int() <= date_part.to_int())
)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I find this hard to read because it looks like a tuple of tuples and that leading + gets elided a bit by the commentary. Maybe it's a "Tom, you need reading glasses" problem, but there it is. There are lots of ways to restructure this so it's easier to see. Here's one:

# No date part (i.e., just metric time) plus all date parts for metric time at a different grain
possible_date_parts = (None,) + tuple([date_part for date_part....])

In theory the typechecker should infer that correctly but if it doesn't it's more contained and easier to reorient. Note you can also keep the multi-line commentary by using locals and just doing the assignment at the end, whatever works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will update before merging.

@plypaul plypaul force-pushed the plypaul--58.10--resolution-dag branch 2 times, most recently from a5e0bef to 8bb8e87 Compare December 7, 2023 19:25
Base automatically changed from plypaul--58.10--resolution-dag to main December 7, 2023 19:33
Adds time dimension specs with the date_part in returned results so that
spec patterns can be used to resolve ambiguous group-by-items.
@plypaul plypaul force-pushed the plypaul--58.11--add-date-part-to-resolver branch from a2771ac to 0d5afea Compare December 15, 2023 23:00
@plypaul plypaul merged commit 68e54f5 into main Dec 15, 2023
9 checks passed
@plypaul plypaul deleted the plypaul--58.11--add-date-part-to-resolver branch December 15, 2023 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants