Skip to content

Add projection data to SegmentAnalysis#18119

Merged
cecemei merged 9 commits intoapache:masterfrom
cecemei:projection
Jun 17, 2025
Merged

Add projection data to SegmentAnalysis#18119
cecemei merged 9 commits intoapache:masterfrom
cecemei:projection

Conversation

@cecemei
Copy link
Copy Markdown
Contributor

@cecemei cecemei commented Jun 11, 2025

Description

New Feature

SegmentAnalysis should return AggregateProjectionMetadata in the segment if AnalysisType.PROJECTIONS is included in SegmentMetadataQuery. If schema doesn't match for the same projection, the specific schema won't be included in the result.

Testing & Refactor

  • Added SegmentAnalysisBuilder class.
  • Use parameterized tests in JUnit 5 to simplify tests in SegmentMetadataQueryQueryToolChestTest.
  • In IndexMergerV9, move sortOrder must include time column check in projections out of makeIndexFiles, to its call site. Also, Metadata.merge(metadataList, combiningMetricAggs) would never take null inputs, this refactor makes it more obvious.
  • In SegmentMetadataQueryQueryToolChest.mergeAnalyses, throw defensive exception if no data source in the query.

Key changed/added classes in this PR
  • SegmentMetadataQuery
  • SegmentAnalysis
  • SegmentMetadataQueryQueryToolChestTest
    • majority is refactoring tests via using the builder class and parameterized tests
  • IndexMergerV9

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.

@cecemei cecemei marked this pull request as ready for review June 13, 2025 01:42
* @param projections2 second map of projections to merge
* @return merged map of projections
*/
public static Map<String, AggregateProjectionMetadata> merge(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this logic should be part of the segment metadata query stuff instead of living here since it is specific to that query, so it isn't unintentionally used for other purposes. Similarly, the Metadata class has its own logic that it uses when combining the Metadata during segment creation, though with different logic that is validating the projections are all the same: https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/segment/Metadata.java#L344

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.

moved it out to SegmentMetadataQueryQueryToolChest.

QUERYGRANULARITY,
ROLLUP;
ROLLUP,
PROJECTIONS;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

will need to update the docs to include this new analysis type too at some point, https://github.com/apache/druid/blob/master/docs/querying/segmentmetadataquery.md#analysistypes, and also include the fact that when merging results that any mismatched projections will be omitted. It would be fine to do this as a follow-up or part of this PR is fine too

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 the doc

Comment thread processing/src/main/java/org/apache/druid/segment/IndexMergerV9.java Outdated
/**
* Helper class to build {@link SegmentAnalysis} objects for testing purposes.
*/
public class SegmentAnalysisBuilder
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: we commonly put builders inside of the class they build as an internal class just named like Builder, which i think helps with visibility, so people already looking at a class know it has a builder, and just have a static method like SegmentAnalysis.builder().addFoo(..).build()

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.

I moved it to SegmentAnalysis. I put it in test folder initially because it looks like it's mostly needed in tests, not in production code, but i guess it's no harm to put it as internal static class as well. It might also help to unify when we use null, v.s. empty collections.

Copy link
Copy Markdown
Member

@clintropolis clintropolis left a comment

Choose a reason for hiding this comment

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

🤘

@cecemei cecemei merged commit 658f801 into apache:master Jun 17, 2025
137 of 139 checks passed
@capistrant capistrant added this to the 34.0.0 milestone Jul 22, 2025
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.

4 participants