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

test: don't allow FK-outer joins and add QTT cases for FK-join with flipped join condition #7526

Merged
merged 3 commits into from
May 18, 2021
Merged

Conversation

mjsax
Copy link
Member

@mjsax mjsax commented May 14, 2021

Description

Add a check to disallow OUTER join for FK-joins.

Add new tests for FK-joins with "flipped" join condition. Luckily JoinTree.build() take care of the order by calling join.flip() if necessary, and thus we don't need to write additional code for FK-joins for this case. However, we should have the corresponding tests.

Testing done

Only added tests for binary joins. Not sure if we should add tests for n-way joins at this point, as don't plan to support n-way joins yet.

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@mjsax mjsax requested a review from a team as a code owner May 14, 2021 07:02
@mjsax mjsax mentioned this pull request May 14, 2021
Copy link
Contributor

@vcrfxia vcrfxia left a comment

Choose a reason for hiding this comment

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

Thanks @mjsax . Comments inline.

@@ -12,6 +12,18 @@
"message": "Invalid join condition: table-table joins require to join on the primary key of the right input table. Got LEFT_TABLE.ID1 = RIGHT_TABLE.F2."
}
},
{
"name": "Should fail on right non-key attribute for inner-join -- revers join condition order",
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need copies of these tests with the feature flag disabled. If the purpose of the test is to check that table-table joins are only allowed on primary keys, then tests for that already exist. If the purpose is to check that the behavior does not change if the join condition is flipped, then that belongs in the regular joins.json file since it's not related to foreign key joins.

I think adding duplicates of all the new FK join tests will unnecessarily blow up this file and create more busywork for us (harder reviews, more work when we ungate the feature flag) than it's worth.

Copy link
Member Author

Choose a reason for hiding this comment

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

What is your concrete proposal? I think we should have some of those tests, to make sure that the condition is correctly identified even if the join condition is flipped. And yes, we should have corresponding tests in joins.json in addition.

Copy link
Contributor

Choose a reason for hiding this comment

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

My concrete proposal is:

  • delete all the new tests in this PR that do not have the feature flag enabled
  • remove the comments from the copies of the tests with the feature flag enabled about deleting the test when ungating from the feature flag
  • remove - feature flag enabled from the names of the copies of the tests that have the feature flag enabled

If we're planning to support flipped join conditions out of the box (which it sounds like we are), then we should add positive test coverage to ensure this is properly supported. I will add that into #7528.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about this a little bit. I agree that those this test (and it's "siblings") should not be part of fk-join test. However, joins.json is very long and hard to keep an overview what we test and what not. Will add table-table-join.json and move these 10 test over. Want to keep the reverse order as I think we should test that the condition is detected for both cases (and also that we "flip" left/right condition in the error message).

I would hope we can cleanup join.json eventually, but it's a little tricky to "move" test as we also need to migrate old plans accordingly. Plan tp can dig into this as a follow up.

"properties": {
"ksql.joins.foreign.key.enable": true
},
"comments": [
Copy link
Contributor

Choose a reason for hiding this comment

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

If you go with my suggestion above to remove the copies of these tests without the feature flag enabled, then we can also remove these comments. When we ungate the feature flag, we'll simply remove the properties block rather than deleting the test. You can also update the test name to remove the - feature flag enabled portion now so we don't have to update the test name later when ungating the feature flag.

],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "Invalid join condition: table-table joins require to join on the primary key of the right input table. Got LEFT_TABLE.ID1 = RIGHT_TABLE.F2."
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it'd be marginally better if the error message showed the join expressions in the same order as in the user's query but given the structure of the code right now this is somewhat difficult to achieve so I think this is fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

I had a similar though... But I think we could fix it: JoinTree could set a flag "flipped" that we preserve that allows us to flip back in the error message. Let me add this.

@@ -193,6 +327,25 @@
"message": "Invalid join condition: table-table joins require to join on the primary key of the right input table. Got LEFT_TABLE.ID1 = RIGHT_TABLE.F2."
}
},
{
"name": "Should fail on right non-key attribute for outer-join (reverse join condition order) - feature flag enabled",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this test? FK joins aren't supported for outer joins at all.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah. Good catch. Seems I did to much "blind" c&p :)

@mjsax mjsax changed the title test: add QTT cases for FK-join with flipped join condition test: don't allow FK-outer joins and add QTT cases for FK-join with flipped join condition May 18, 2021
@@ -1,99 +1,105 @@
{
"tests": [
{
"name": "Should fail on right non-key attribute for inner-join",
Copy link
Member Author

@mjsax mjsax May 18, 2021

Choose a reason for hiding this comment

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

This diff is confusion... This test (and the next 3 tests) got moved to table-table-join.json

}
},
{
"name": "Should fail on right non-key attribute for inner-join with qualifiers",
"name": "Should fail on outer-join",
Copy link
Member Author

Choose a reason for hiding this comment

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

new test

@@ -1,99 +1,105 @@
{
"tests": [
{
"name": "Should fail on right non-key attribute for inner-join",
"name": "Should fail on left non-key attribute for inner-join",
Copy link
Member Author

Choose a reason for hiding this comment

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

existing test, just bad diff

}
},
{
"name": "Should fail on right non-key attribute for left-join",
"name": "Should fail on left non-key attribute for inner-join -- revers join condition order",
Copy link
Member Author

Choose a reason for hiding this comment

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

new test: duplicates the above existing test.

}
},
{
"name": "Should fail on left non-key attribute for inner-join",
"name": "Should fail on left non-key attribute for left-join -- revers join condition order",
Copy link
Member Author

Choose a reason for hiding this comment

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

new test: duplicates the above existing test.

],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlStatementException",
"message": "Invalid join condition: foreign-key table-table joins are not supported. Got LEFT_TABLE.F1 = RIGHT_TABLE.ID2."
}
},
{
"name": "Should fail on left non-key attribute for outer-join",
"name": "Should fail on left non-key attribute for outer-join -- revers join condition order",
Copy link
Member Author

Choose a reason for hiding this comment

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

new test: duplicates the above existing test.

}
},
{
"name": "Should fail on right non-key attribute for inner-join with qualifiers",
Copy link
Member Author

Choose a reason for hiding this comment

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

This test (and the next tests) got moved to table-table-join.json

}
},
{
"name": "Should fail on right non-key attribute for inner-join with alias",
"name": "Should fail on outer-join -- reverse join condition",
Copy link
Member Author

Choose a reason for hiding this comment

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

new test (duplicate of the previous new test)

{
"tests": [
{
"name": "Should fail on right non-key attribute for inner-join",
Copy link
Member Author

Choose a reason for hiding this comment

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

moved from fk-join.json

}
},
{
"name": "Should fail on right non-key attribute for inner-join -- revers join condition order",
Copy link
Member Author

Choose a reason for hiding this comment

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

duplicate the test (similar pattern below)

Copy link
Contributor

@vcrfxia vcrfxia left a comment

Choose a reason for hiding this comment

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

I forgot this PR was still open... we're going to have a lot of merge conflicts with #7528 and #7537

Didn't look at the latest changes too carefully but LGTM based on the comments that the latest revision claims to have addressed.

@vcrfxia vcrfxia merged commit b073bbc into confluentinc:master May 18, 2021
@mjsax mjsax deleted the fk-join-relax-order branch June 10, 2021 05:53
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