Skip to content

Add getRightEquiConditionKeys to JoinConditionAnalysis#9287

Merged
gianm merged 3 commits intoapache:masterfrom
suneet-s:joinable-factory
Jan 30, 2020
Merged

Add getRightEquiConditionKeys to JoinConditionAnalysis#9287
gianm merged 3 commits intoapache:masterfrom
suneet-s:joinable-factory

Conversation

@suneet-s
Copy link
Copy Markdown
Contributor

@suneet-s suneet-s commented Jan 29, 2020

This change allows other implementations of JoinableFactory to ask the analysis
for the right key columns instead of having to calculate it themselves.

This PR has:

  • been self-reviewed.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • 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.
  • added integration tests.
  • been tested in a test Druid cluster.

This change other implementations of JoinableFactory to ask the analysis
for the right key columns instead of having to calculate it themselves.
* Returns the distinct column keys from the RHS required to evaluate the equi conditions.
*/
public List<String> getRightKeyColumns()
{
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.

I'm not sure if it's clear that this method only applies to the equi-conditions. The javadoc explains it but the method name might be misleading? What do you think?

I don't know if I have a good solution, btw. getRightKeyColumnsForEquiConditions is clear but quite a mouthful. Maybe getRightEquiConditionKeys.

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.

Btw, a Set may be more appropriate than a List here.

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 like the suggestion. Done.

ImmutableList.of(),
exprsToStrings(analysis.getNonEquiConditions())
);
Assert.assertThat(analysis.getRightKeyColumns(), CoreMatchers.is(ImmutableList.of("y")));
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.

Is this better than Assert.assertEquals?

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.

assertEquals fails because getRightKeyColumns doesn't return an ImmutableList

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.

How can that be? CoreMatchers.is is calling actual.equals(expected), with extra steps.

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 definitely saw the test fail which is why I had to google how to fix this - and I found CoreMatchers.

hahaha I think I know why now -
Assert.assertEquals checks expected.equals(actual)
CoreMatchers.is checks actual.equals(expected)
That probably means the equals implementation for one (or both?) of those classes isn't correct according to the javadocs

final InlineDataSource inlineDataSource = (InlineDataSource) dataSource;
final List<String> rightKeyColumns =
condition.getEquiConditions().stream().map(Equality::getRightColumn).distinct().collect(Collectors.toList());
final List<String> rightKeyColumns = condition.getRightKeyColumns();
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.

You could probably do a similar simplification in LookupJoinMatcher (there's a part that checks that all the equikeys are the key column).

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.

It's not immediately obvious to me how other implementations would use what LookupJoinMatcher is doing with the equiConditions. If it's ok with you, I'd like to do that refactoring at a later time

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.

Ah, I just meant replacing this:

    } else if (!condition.getEquiConditions()
                         .stream()
                         .allMatch(eq -> eq.getRightColumn().equals(LookupColumnSelectorFactory.KEY_COLUMN))) {

With this:

    } else if (!condition.getRightEquiConditionKeys().equals(Collections.singletonSet(LookupColumnSelectorFactory.KEY_COLUMN)) {

@suneet-s suneet-s changed the title Add getRightColumns to JoinConditionAnalysis Add getRightEquiConditionKeys to JoinConditionAnalysis Jan 30, 2020
Copy link
Copy Markdown
Contributor

@gianm gianm left a comment

Choose a reason for hiding this comment

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

LGTM. I made two further comments but they are cosmetic. If you are doing further work in this area please consider addressing them in a later patch.

ImmutableList.of(),
exprsToStrings(analysis.getNonEquiConditions())
);
Assert.assertEquals(analysis.getRightEquiConditionKeys(), ImmutableSet.of("x"));
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.

These are backwards. (I think putting actual before expected is more natural, but JUnit disagrees and who am I to judge?)

"equiConditions", "nonEquiConditions",
// These fields are calculated from nonEquiConditions
"isAlwaysTrue", "isAlwaysFalse", "canHashJoin")
// These fields are calculated from other other fields in the class
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.

Typo (other other)

@gianm gianm merged commit 6b44d4a into apache:master Jan 30, 2020
@jihoonson jihoonson added this to the 0.18.0 milestone Mar 26, 2020
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