Skip to content

WINDOWING - Fix 2 nodes with same digest causing mapping issue#16301

Merged
LakshSingla merged 5 commits intoapache:masterfrom
sreemanamala:window-mapping
Apr 24, 2024
Merged

WINDOWING - Fix 2 nodes with same digest causing mapping issue#16301
LakshSingla merged 5 commits intoapache:masterfrom
sreemanamala:window-mapping

Conversation

@sreemanamala
Copy link
Copy Markdown
Contributor

@sreemanamala sreemanamala commented Apr 17, 2024

Description

The PR aims to fixing the mapping issue in window fxns where 2 nodes get the same reference.

example:
SELECT
(rank() over (order by count(*) desc)),
(rank() over (order by count(*) desc))
FROM table


Key changed/added classes in this PR
  • Windowing.java

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.

public void testWindow()
{
testBuilder()
.sql("SELECT\n" +
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.

A test case in MSQ window functions would also be helpful.

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.

great idea :)
after the separation of test suppliers patch gets in that we'll be even easier to do!

Comment on lines +247 to +254
partialQuery.getWindowProject().getProjects().stream().map(RexNode::toString).collect(Collectors.toSet()).size()
< partialQuery.getWindowProject().getProjects().size()
? Project.getPartialMapping(
partialQuery.getWindowProject().getRowType().getFieldCount(),
partialQuery.getWindowProject().getProjects()
)
: partialQuery.getWindowProject().getMapping(),
"mapping for windowProject[%s]", partialQuery.getWindowProject()
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.

discussed offline; but leave a note here:
I believe we want a real PartialMapping ; you could copy getPartialMapping over and change
INVERSE_FUNCTION to INVERSE_PARTIAL_FUNCTION

that way we will support partial mapping even in case columns are being discarded...

I also think that Project.getPartialMapping might need this change as its apidoc suggersts that a source might have 0, 1 or more targets.

Copy link
Copy Markdown
Contributor Author

@sreemanamala sreemanamala Apr 20, 2024

Choose a reason for hiding this comment

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

didn't had to change the mapping type. both INVERSE_FUNCTION & INVERSE_PARTIAL_FUNCTION are internally using PartialFunctionImpl

made use of source might have 0 targets by providing the field count as 1 + highest index in our window projection

public void testWindow()
{
testBuilder()
.sql("SELECT\n" +
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.

great idea :)
after the separation of test suppliers patch gets in that we'll be even easier to do!

@github-actions github-actions Bot added Area - Batch Ingestion Area - MSQ For multi stage queries - https://github.com/apache/druid/issues/12262 labels Apr 20, 2024

@MethodSource("data")
@ParameterizedTest(name = "{index}:with context {0}")
public void testSimpleWindowWithDuplicateSelectNode(String contextName, Map<String, Object> context)

Check notice

Code scanning / CodeQL

Useless parameter

The parameter 'contextName' is never used.
// as defensive programming.
// We know windowProject is a mapping due to the isMapping() check in DruidRules.
// check anyway as defensive programming.
Preconditions.checkArgument(partialQuery.getWindowProject().isMapping());
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.

possibly extracting partialQuery.getWindowProject() into a local variable may make it more readable

@LakshSingla LakshSingla merged commit 080476f into apache:master Apr 24, 2024
@sreemanamala sreemanamala deleted the window-mapping branch April 24, 2024 11:15
@adarshsanjeev adarshsanjeev added this to the 30.0.0 milestone May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area - Batch Ingestion Area - MSQ For multi stage queries - https://github.com/apache/druid/issues/12262 Area - Querying

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants