forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SortMerge join support for IS NOT DISTINCT FROM. (apache#16003)
* SortMerge join support for IS NOT DISTINCT FROM. The patch adds a "requiredNonNullKeyParts" field to the sortMerge processor, which has the list of key parts that must be nonnull for an equijoin condition to match. Conditions with SQL "=" are present in the list; conditions with SQL "IS NOT DISTINCT FROM" are absent from the list. * Fix test. * Update javadoc.
- Loading branch information
Showing
10 changed files
with
576 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
241 changes: 241 additions & 0 deletions
241
...est/java/org/apache/druid/msq/querykit/common/SortMergeJoinFrameProcessorFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.msq.querykit.common; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import org.apache.druid.frame.key.KeyColumn; | ||
import org.apache.druid.frame.key.KeyOrder; | ||
import org.apache.druid.math.expr.ExprMacroTable; | ||
import org.apache.druid.segment.join.JoinConditionAnalysis; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class SortMergeJoinFrameProcessorFactoryTest | ||
{ | ||
@Test | ||
public void test_validateCondition() | ||
{ | ||
Assert.assertNotNull( | ||
SortMergeJoinFrameProcessorFactory.validateCondition( | ||
JoinConditionAnalysis.forExpression("1", "j.", ExprMacroTable.nil()) | ||
) | ||
); | ||
|
||
Assert.assertNotNull( | ||
SortMergeJoinFrameProcessorFactory.validateCondition( | ||
JoinConditionAnalysis.forExpression("x == \"j.y\"", "j.", ExprMacroTable.nil()) | ||
) | ||
); | ||
|
||
Assert.assertNotNull( | ||
SortMergeJoinFrameProcessorFactory.validateCondition( | ||
JoinConditionAnalysis.forExpression("1", "j.", ExprMacroTable.nil()) | ||
) | ||
); | ||
|
||
Assert.assertNotNull( | ||
SortMergeJoinFrameProcessorFactory.validateCondition( | ||
JoinConditionAnalysis.forExpression("x == \"j.y\" && a == \"j.b\"", "j.", ExprMacroTable.nil()) | ||
) | ||
); | ||
|
||
Assert.assertNotNull( | ||
SortMergeJoinFrameProcessorFactory.validateCondition( | ||
JoinConditionAnalysis.forExpression( | ||
"notdistinctfrom(x, \"j.y\") && a == \"j.b\"", | ||
"j.", | ||
ExprMacroTable.nil() | ||
) | ||
) | ||
); | ||
|
||
Assert.assertThrows( | ||
IllegalArgumentException.class, | ||
() -> SortMergeJoinFrameProcessorFactory.validateCondition( | ||
JoinConditionAnalysis.forExpression("x == y", "j.", ExprMacroTable.nil()) | ||
) | ||
); | ||
|
||
Assert.assertThrows( | ||
IllegalArgumentException.class, | ||
() -> SortMergeJoinFrameProcessorFactory.validateCondition( | ||
JoinConditionAnalysis.forExpression("x + 1 == \"j.y\"", "j.", ExprMacroTable.nil()) | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
public void test_toKeyColumns() | ||
{ | ||
Assert.assertEquals( | ||
ImmutableList.of( | ||
ImmutableList.of(new KeyColumn("x", KeyOrder.ASCENDING)), | ||
ImmutableList.of(new KeyColumn("y", KeyOrder.ASCENDING)) | ||
), | ||
SortMergeJoinFrameProcessorFactory.toKeyColumns( | ||
JoinConditionAnalysis.forExpression( | ||
"x == \"j.y\"", | ||
"j.", | ||
ExprMacroTable.nil() | ||
) | ||
) | ||
); | ||
|
||
Assert.assertEquals( | ||
ImmutableList.of( | ||
ImmutableList.of(), | ||
ImmutableList.of() | ||
), | ||
SortMergeJoinFrameProcessorFactory.toKeyColumns( | ||
JoinConditionAnalysis.forExpression( | ||
"1", | ||
"j.", | ||
ExprMacroTable.nil() | ||
) | ||
) | ||
); | ||
|
||
Assert.assertEquals( | ||
ImmutableList.of( | ||
ImmutableList.of(new KeyColumn("x", KeyOrder.ASCENDING), new KeyColumn("a", KeyOrder.ASCENDING)), | ||
ImmutableList.of(new KeyColumn("y", KeyOrder.ASCENDING), new KeyColumn("b", KeyOrder.ASCENDING)) | ||
), | ||
SortMergeJoinFrameProcessorFactory.toKeyColumns( | ||
JoinConditionAnalysis.forExpression( | ||
"x == \"j.y\" && a == \"j.b\"", | ||
"j.", | ||
ExprMacroTable.nil() | ||
) | ||
) | ||
); | ||
|
||
Assert.assertEquals( | ||
ImmutableList.of( | ||
ImmutableList.of(new KeyColumn("x", KeyOrder.ASCENDING), new KeyColumn("a", KeyOrder.ASCENDING)), | ||
ImmutableList.of(new KeyColumn("y", KeyOrder.ASCENDING), new KeyColumn("b", KeyOrder.ASCENDING)) | ||
), | ||
SortMergeJoinFrameProcessorFactory.toKeyColumns( | ||
JoinConditionAnalysis.forExpression( | ||
"x == \"j.y\" && notdistinctfrom(a, \"j.b\")", | ||
"j.", | ||
ExprMacroTable.nil() | ||
) | ||
) | ||
); | ||
|
||
Assert.assertEquals( | ||
ImmutableList.of( | ||
ImmutableList.of(new KeyColumn("x", KeyOrder.ASCENDING), new KeyColumn("a", KeyOrder.ASCENDING)), | ||
ImmutableList.of(new KeyColumn("y", KeyOrder.ASCENDING), new KeyColumn("b", KeyOrder.ASCENDING)) | ||
), | ||
SortMergeJoinFrameProcessorFactory.toKeyColumns( | ||
JoinConditionAnalysis.forExpression( | ||
"notdistinctfrom(x, \"j.y\") && a == \"j.b\"", | ||
"j.", | ||
ExprMacroTable.nil() | ||
) | ||
) | ||
); | ||
|
||
Assert.assertEquals( | ||
ImmutableList.of( | ||
ImmutableList.of(new KeyColumn("x", KeyOrder.ASCENDING), new KeyColumn("a", KeyOrder.ASCENDING)), | ||
ImmutableList.of(new KeyColumn("y", KeyOrder.ASCENDING), new KeyColumn("b", KeyOrder.ASCENDING)) | ||
), | ||
SortMergeJoinFrameProcessorFactory.toKeyColumns( | ||
JoinConditionAnalysis.forExpression( | ||
"notdistinctfrom(x, \"j.y\") && notdistinctfrom(a, \"j.b\")", | ||
"j.", | ||
ExprMacroTable.nil() | ||
) | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
public void test_toRequiredNonNullKeyParts() | ||
{ | ||
Assert.assertArrayEquals( | ||
new int[0], | ||
SortMergeJoinFrameProcessorFactory.toRequiredNonNullKeyParts( | ||
JoinConditionAnalysis.forExpression( | ||
"1", | ||
"j.", | ||
ExprMacroTable.nil() | ||
) | ||
) | ||
); | ||
|
||
Assert.assertArrayEquals( | ||
new int[]{0}, | ||
SortMergeJoinFrameProcessorFactory.toRequiredNonNullKeyParts( | ||
JoinConditionAnalysis.forExpression( | ||
"x == \"j.y\"", | ||
"j.", | ||
ExprMacroTable.nil() | ||
) | ||
) | ||
); | ||
|
||
Assert.assertArrayEquals( | ||
new int[]{0, 1}, | ||
SortMergeJoinFrameProcessorFactory.toRequiredNonNullKeyParts( | ||
JoinConditionAnalysis.forExpression( | ||
"x == \"j.y\" && a == \"j.b\"", | ||
"j.", | ||
ExprMacroTable.nil() | ||
) | ||
) | ||
); | ||
|
||
Assert.assertArrayEquals( | ||
new int[]{0}, | ||
SortMergeJoinFrameProcessorFactory.toRequiredNonNullKeyParts( | ||
JoinConditionAnalysis.forExpression( | ||
"x == \"j.y\" && notdistinctfrom(a, \"j.b\")", | ||
"j.", | ||
ExprMacroTable.nil() | ||
) | ||
) | ||
); | ||
|
||
Assert.assertArrayEquals( | ||
new int[]{1}, | ||
SortMergeJoinFrameProcessorFactory.toRequiredNonNullKeyParts( | ||
JoinConditionAnalysis.forExpression( | ||
"notdistinctfrom(x, \"j.y\") && a == \"j.b\"", | ||
"j.", | ||
ExprMacroTable.nil() | ||
) | ||
) | ||
); | ||
|
||
Assert.assertArrayEquals( | ||
new int[0], | ||
SortMergeJoinFrameProcessorFactory.toRequiredNonNullKeyParts( | ||
JoinConditionAnalysis.forExpression( | ||
"notdistinctfrom(x, \"j.y\") && notdistinctfrom(a, \"j.b\")", | ||
"j.", | ||
ExprMacroTable.nil() | ||
) | ||
) | ||
); | ||
} | ||
} |
Oops, something went wrong.