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

Fix behavior of INNER and LEFT_OUTER joins with empty left table #783

Merged
merged 2 commits into from
Apr 5, 2020

Conversation

vanderzee-anl-gov
Copy link
Contributor

Thanks for contributing.

Description

Current behavior of tablesaw behaves like a right outer join or full outer join should behave if the left table is empty. Based on review of the source code, this appears to be the case because the normal termination for left outer join and inner join is within a loop over the rows of the first table. This commit handles the special case of an empty left table for left outer join and inner join, correctly returning an empty table with the appropriate columns.

Testing

Although it should be fairly simple to test this, I did not take the time to understand your testing framework and add a unit test.

@benmccann
Copy link
Collaborator

Although it should be fairly simple to test this, I did not take the time to understand your testing framework and add a unit test.

Like you said, I think it should be pretty easy. You can add a test to DataFrameJoinerTest and then you can run the tests for just that class with cd core and then mvn -Dtest=DataFrameJoinerTest test. Let me know if you have any particular questions

Before the fix, the number of rows was correctly zero in the result
table, but the columns were not all size zero.
@vanderzee-anl-gov
Copy link
Contributor Author

I haven't used maven much before, but I have now added tests that illustrate the difference in behavior with and without my suggested block of code. They fail without my code and pass when it is included.

Copy link
Collaborator

@benmccann benmccann left a comment

Choose a reason for hiding this comment

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

thanks for adding a test!


@Test
public void innerJoinEmptyLeftTable() {
StringColumn animalColumn = StringColumn.create("Animal");
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could condense the first four lines into two:

    Table leftTable = Table.create(StringColumn.create("Animal"));
    Table joined = leftTable.joinOn("Animal").inner(ANIMAL_NAMES);

@benmccann benmccann merged commit 35617de into jtablesaw:master Apr 5, 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.

2 participants