Skip to content

Catalog granularity accepts query format#16680

Merged
zachjsh merged 8 commits intoapache:masterfrom
zachjsh:catalog-granularity-accepts-query-format
Jul 2, 2024
Merged

Catalog granularity accepts query format#16680
zachjsh merged 8 commits intoapache:masterfrom
zachjsh:catalog-granularity-accepts-query-format

Conversation

@zachjsh
Copy link
Copy Markdown
Contributor

@zachjsh zachjsh commented Jul 1, 2024

Description

Previously, the segment granularity for tables in the catalog had to be defined in period format, ie 'PT1H' , 'P1D', etc. This disallows a user from defining segment granularity of 'ALL' for a table in the catalog, which may be a valid use case. This change makes it so that a user may define the segment granularity of a table in the catalog, as any string that results in a valid granularity using either the Granularity.fromString(str) method, or new PeriodGranularity(new Period(value), null, null), and that granularity maps to a standard supported granularity, where GranularityType.isStandard(granularity) returns true. As a result a user may who wants to assign a catalog table's segment granularity to be hourly, may assign the segment granularity property of the table to be either PT1H, or HOUR. These are the same formats accepted at query time.

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

granularity = new PeriodGranularity(new Period(value), null, null);
}
catch (IllegalArgumentException e2) {
throw new IAE(StringUtils.format("[%s] is an invalid granularity string", value));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

DruidException instead of IAE:

Suggested change
throw new IAE(StringUtils.format("[%s] is an invalid granularity string", value));
throw InvalidInput.exception("[%s] is an invalid granularity string.", value);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This caused a test failure. i see that there are catch blocks in places expecting IAE, dont want to fuss with that at the moment. I think we can change all of these throws in a different pr. ok with you?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yep, sounds good to me. I noticed that we throw IAE in a bunch of places in CatalogUtils which can be addressed in a separate PR.

@@ -68,12 +68,20 @@ public static Granularity asDruidGranularity(String value)
if (Strings.isNullOrEmpty(value) || value.equalsIgnoreCase(DatasourceDefn.ALL_GRANULARITY)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are there tests for this static utility or perhaps something more end-to-end? If so, it'd be nice if we could add some tests with granularity strings like HOUR and DAY for the enhancement

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated existing integration tests to test all formats P1D, DAY, ALL

Copy link
Copy Markdown
Contributor

@abhishekrb19 abhishekrb19 left a comment

Choose a reason for hiding this comment

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

LGTM! It seems that the UT/ITs haven't run on this PR, and the catalog integration tests haven't run either?
(Edit: Never mind, it seems that the UT/IT checks are still pending: https://github.com/apache/druid/actions/runs/9753473200. I got tripped up by the blue check with only 12 successful checks, all the checks should eventually appear)

@zachjsh zachjsh merged commit 5e05858 into apache:master Jul 2, 2024
@zachjsh zachjsh deleted the catalog-granularity-accepts-query-format branch July 2, 2024 16:14
@kfaraz kfaraz added this to the 31.0.0 milestone Oct 4, 2024
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.

3 participants