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

DRILL-6431: Unnest operator requires table and a single column alias #1277

Merged
merged 2 commits into from May 22, 2018

Conversation

HanumathRao
Copy link
Contributor

@amansinha100 @parthchandra Please review this PR.

This PR includes following changes.

  1. Throw an error if an alias table and column name is not provided to the unnest operator.
  2. Disambiguate the * and also column names(if they are same ) for a lateral and unnest operator.
  3. Remove the code which destructs the map.
  4. unnest operator produces same column name as the input column name in unnestrecordbatch.
  5. Added test cases with validation of the results to TestLateralPlans. Some tests were also included from chunhui-shi PR.

There are two commits in this PR. One commit (ie DRILL-6419) is about E2E integration test suite which was introduced by @sohami . There are some changes made to this test suite to provide an alias column for unnest operator.

* If not, insert a project renaming them.
*/
public RelNode getCorrelateInput(int offset, RelNode input) {
assert DrillJoinRelBase.uniqueFieldNames(input.getRowType());

Choose a reason for hiding this comment

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

Make this a preconditions check.


List<RelNode> reNamedChildren = Lists.newArrayList();

RelNode left = prel.getCorrelateInput(0, children.get(0));

Choose a reason for hiding this comment

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

Although the general logic for this is similar to that of Joins, didn't we want to make one distinction by only renaming the right side (unnest side) of Correlate ? In the current implementation both left and right would be eligible but will that ever be needed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. We wanted to make renaming only on right side. When I looked at the code it looks like all the time it should modify only the right side, because it first checks the left side and then the right side. Hence I thought same logic should work. Please let me know if I am missing anything here.

Choose a reason for hiding this comment

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

Ok, you might want to add a TODO to indicate that this code could potentially be consolidated with JoinPrelRenameVisitor in the future.

@@ -261,6 +263,11 @@ protected void validateFrom(
}
changeNamesIfTableIsTemporary(tempNode);
}
else if (((SqlCall) node).operand(0).getKind() == SqlKind.UNNEST) {
if (((SqlCall) node).operandCount() < 3) {
throw RESOURCE.validationError("Alias column name is required for UNNEST").ex();

Choose a reason for hiding this comment

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

Alias table and column name ? Also, would be good to add 1 negative unit test that exercises this error.

public void testMultipleBatchesLateral_WithLimitFilterInSubQuery() throws Exception {
String sql = "SELECT customer.c_name, customer.c_address, orders.o_orderkey, orders.o_totalprice " +
"FROM dfs.`lateraljoin/multipleFiles` customer, LATERAL " +
"(SELECT O.o.o_orderkey as o_orderkey, O.o.o_totalprice as o_totalprice FROM UNNEST(customer.c_orders) O(o) WHERE O.o.o_totalprice > 100000 LIMIT 2) " +

Choose a reason for hiding this comment

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

Minor nit: could you pls use different letter for the table name and column name in the alias (the upper and lower case 'o' is easy to get mixed up).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. will do it.

Copy link
Contributor

@parthchandra parthchandra left a comment

Choose a reason for hiding this comment

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

Changes to Unnest and related tests look good.

@HanumathRao HanumathRao changed the title Drill 6431 DRILL-6431: Unnest operator requires table and a single column alias May 21, 2018
@HanumathRao
Copy link
Contributor Author

@amansinha100 @parthchandra Thank you for the review.
I have made the changes. Please let me know if any other changes are required.

import static junit.framework.TestCase.fail;

public class TestE2EUnnestAndLateral extends BaseTestQuery {
//private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestE2EUnnestAndLateral.class);

Choose a reason for hiding this comment

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

Remove this line


List<RelNode> reNamedChildren = Lists.newArrayList();

RelNode left = prel.getCorrelateInput(0, children.get(0));

Choose a reason for hiding this comment

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

Ok, you might want to add a TODO to indicate that this code could potentially be consolidated with JoinPrelRenameVisitor in the future.

@amansinha100
Copy link

+1 (see couple of minor comments above).

…to be specified.

Fixing the issues related to star column renaming, same field name renaming
and also enforcing that an alias column is required for the unnest operator.
@HanumathRao
Copy link
Contributor Author

@amansinha100 Thank you for the review. Done the changes.

@sohami I have done the required refactoring of the code. Please do let me know if it is fine.

@sohami
Copy link
Contributor

sohami commented May 22, 2018

+1 LGTM as well.

@parthchandra parthchandra merged commit 3af718f into apache:master May 22, 2018
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.

None yet

4 participants