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

Allow custom granularity names in string name to struct conversion #1387

Conversation

tlento
Copy link
Contributor

@tlento tlento commented Aug 29, 2024

MetricFlow relies on a class called StructuredLinkableSpecName to manage
conversion between structured names and their string representations,
e.g., listing__is_lux or listing__created_at__month.

Up until now the time granularity component of this naming struct
required an enumeration value, which would then be converted to its
string representation at serialization time. With custom granularities
we need to explicitly allow for a string name for the input time
granularity. This implements that change, along with some added
enforcement to ensure consistency in how we conver to/from the string
representations of these names.

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.

@tlento tlento force-pushed the allow-arbitrary-granularity-names-in-structured-linkable-spect-name branch from ea0ee4f to c8ca0af Compare August 29, 2024 18:38
@tlento tlento requested a review from courtneyholcomb August 29, 2024 18:38

This implies that all values in the TimeGranularity enumeration must be lower-case.
"""
assert self.element_name.lower() == self.element_name, (
Copy link
Contributor

Choose a reason for hiding this comment

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

This means that custom granularities will be required to be lowercase. Is that a necessary restriction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my opinion, yes. We do not want Fortnight and fortnight to mean different things in the same model. But also this this the standard we've used for ages.

"parse time!"
)
assert all([link_name.lower() == link_name for link_name in self.entity_link_names]), (
f"Found entity link name that includes upper-case letters. Entity link names: {self.entity_link_names}. "
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 enforced already? That entity names must be lowercase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In theory, yes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Excellent! And a helpful link pointing me to how to add this validation for custom granularities too 🙃

@tlento tlento force-pushed the allow-arbitrary-granularity-names-in-structured-linkable-spect-name branch from c8ca0af to dafccd5 Compare September 3, 2024 20:51
Copy link
Contributor Author

tlento commented Sep 3, 2024

Merge activity

  • Sep 3, 3:08 PM PDT: @tlento started a stack merge that includes this pull request via Graphite.
  • Sep 3, 3:15 PM PDT: Graphite rebased this pull request as part of a merge.
  • Sep 3, 3:18 PM PDT: @tlento merged this pull request with Graphite.

@tlento tlento changed the base branch from remove-from-name-spec-methods to graphite-base/1387 September 3, 2024 22:09
@tlento tlento changed the base branch from graphite-base/1387 to main September 3, 2024 22:13
MetricFlow relies on a class called StructuredLinkableSpecName to manage
conversion between structured names and their string representations,
e.g., `listing__is_lux` or `listing__created_at__month`.

Up until now the time granularity component of this naming struct
required an enumeration value, which would then be converted to its
string representation at serialization time. With custom granularities
we need to explicitly allow for a string name for the input time
granularity. This implements that change, along with some added
enforcement to ensure consistency in how we conver to/from the string
representations of these names.
@tlento tlento force-pushed the allow-arbitrary-granularity-names-in-structured-linkable-spect-name branch from dafccd5 to 1b2bbeb Compare September 3, 2024 22:14
@tlento tlento merged commit ad8b50b into main Sep 3, 2024
16 checks passed
@tlento tlento deleted the allow-arbitrary-granularity-names-in-structured-linkable-spect-name branch September 3, 2024 22:18
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