[feature](Nereids): Eliminate redundant filter and limit. (#12511)
This commit is contained in:
@ -23,8 +23,9 @@ import org.apache.doris.nereids.rules.expression.rewrite.ExpressionNormalization
|
||||
import org.apache.doris.nereids.rules.mv.SelectRollup;
|
||||
import org.apache.doris.nereids.rules.rewrite.AggregateDisassemble;
|
||||
import org.apache.doris.nereids.rules.rewrite.logical.ColumnPruning;
|
||||
import org.apache.doris.nereids.rules.rewrite.logical.EliminateFilter;
|
||||
import org.apache.doris.nereids.rules.rewrite.logical.EliminateLimit;
|
||||
import org.apache.doris.nereids.rules.rewrite.logical.FindHashConditionForJoin;
|
||||
import org.apache.doris.nereids.rules.rewrite.logical.LogicalLimitZeroToLogicalEmptyRelation;
|
||||
import org.apache.doris.nereids.rules.rewrite.logical.MergeConsecutiveFilters;
|
||||
import org.apache.doris.nereids.rules.rewrite.logical.MergeConsecutiveLimits;
|
||||
import org.apache.doris.nereids.rules.rewrite.logical.MergeConsecutiveProjects;
|
||||
@ -72,7 +73,8 @@ public class RewriteJob extends BatchRulesJob {
|
||||
.add(bottomUpBatch(ImmutableList.of(new MergeConsecutiveProjects())))
|
||||
.add(topDownBatch(ImmutableList.of(new MergeConsecutiveFilters())))
|
||||
.add(bottomUpBatch(ImmutableList.of(new MergeConsecutiveLimits())))
|
||||
.add(bottomUpBatch(ImmutableList.of(new LogicalLimitZeroToLogicalEmptyRelation())))
|
||||
.add(topDownBatch(ImmutableList.of(new EliminateLimit())))
|
||||
.add(topDownBatch(ImmutableList.of(new EliminateFilter())))
|
||||
.add(topDownBatch(ImmutableList.of(new PruneOlapScanPartition())))
|
||||
.add(topDownBatch(ImmutableList.of(new SelectRollup())))
|
||||
.build();
|
||||
|
||||
@ -587,7 +587,7 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
|
||||
@Override
|
||||
public Literal visitBooleanLiteral(BooleanLiteralContext ctx) {
|
||||
Boolean b = Boolean.valueOf(ctx.getText());
|
||||
return new BooleanLiteral(b);
|
||||
return BooleanLiteral.of(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -67,9 +67,9 @@ public enum RuleType {
|
||||
JOIN_RIGHT_CHILD_ELIMINATE_ALIAS_NODE(RuleTypeClass.REWRITE),
|
||||
AGGREGATE_ELIMINATE_ALIAS_NODE(RuleTypeClass.REWRITE),
|
||||
|
||||
//subquery analyze
|
||||
// subquery analyze
|
||||
ANALYZE_FILTER_SUBQUERY(RuleTypeClass.REWRITE),
|
||||
//subquery rewrite rule
|
||||
// subquery rewrite rule
|
||||
PUSH_APPLY_UNDER_PROJECT(RuleTypeClass.REWRITE),
|
||||
PUSH_APPLY_UNDER_FILTER(RuleTypeClass.REWRITE),
|
||||
APPLY_PULL_FILTER_ON_AGG(RuleTypeClass.REWRITE),
|
||||
@ -92,20 +92,25 @@ public enum RuleType {
|
||||
REWRITE_FILTER_EXPRESSION(RuleTypeClass.REWRITE),
|
||||
REWRITE_JOIN_EXPRESSION(RuleTypeClass.REWRITE),
|
||||
REORDER_JOIN(RuleTypeClass.REWRITE),
|
||||
// Merge Consecutive plan
|
||||
MERGE_CONSECUTIVE_FILTERS(RuleTypeClass.REWRITE),
|
||||
MERGE_CONSECUTIVE_PROJECTS(RuleTypeClass.REWRITE),
|
||||
MERGE_CONSECUTIVE_LIMITS(RuleTypeClass.REWRITE),
|
||||
// Eliminate plan
|
||||
ELIMINATE_LIMIT(RuleTypeClass.REWRITE),
|
||||
ELIMINATE_FILTER(RuleTypeClass.REWRITE),
|
||||
|
||||
FIND_HASH_CONDITION_FOR_JOIN(RuleTypeClass.REWRITE),
|
||||
ROLLUP_AGG_SCAN(RuleTypeClass.REWRITE),
|
||||
ROLLUP_AGG_FILTER_SCAN(RuleTypeClass.REWRITE),
|
||||
ROLLUP_AGG_PROJECT_SCAN(RuleTypeClass.REWRITE),
|
||||
ROLLUP_AGG_PROJECT_FILTER_SCAN(RuleTypeClass.REWRITE),
|
||||
ROLLUP_AGG_FILTER_PROJECT_SCAN(RuleTypeClass.REWRITE),
|
||||
REWRITE_SENTINEL(RuleTypeClass.REWRITE),
|
||||
OLAP_SCAN_PARTITION_PRUNE(RuleTypeClass.REWRITE),
|
||||
// Swap plan
|
||||
SWAP_FILTER_AND_PROJECT(RuleTypeClass.REWRITE),
|
||||
LOGICAL_LIMIT_TO_LOGICAL_EMPTY_RELATION_RULE(RuleTypeClass.REWRITE),
|
||||
SWAP_LIMIT_PROJECT(RuleTypeClass.REWRITE),
|
||||
REWRITE_SENTINEL(RuleTypeClass.REWRITE),
|
||||
|
||||
// exploration rules
|
||||
TEST_EXPLORATION(RuleTypeClass.EXPLORATION),
|
||||
@ -147,8 +152,8 @@ public enum RuleType {
|
||||
return ruleTypeClass;
|
||||
}
|
||||
|
||||
public <INPUT_TYPE extends Plan, OUTPUT_TYPE extends Plan>
|
||||
Rule build(PatternMatcher<INPUT_TYPE, OUTPUT_TYPE> patternMatcher) {
|
||||
public <INPUT_TYPE extends Plan, OUTPUT_TYPE extends Plan> Rule build(
|
||||
PatternMatcher<INPUT_TYPE, OUTPUT_TYPE> patternMatcher) {
|
||||
return patternMatcher.toRule(this);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
// 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.doris.nereids.rules.rewrite.logical;
|
||||
|
||||
import org.apache.doris.nereids.rules.Rule;
|
||||
import org.apache.doris.nereids.rules.RuleType;
|
||||
import org.apache.doris.nereids.rules.rewrite.OneRewriteRuleFactory;
|
||||
import org.apache.doris.nereids.trees.expressions.literal.BooleanLiteral;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalEmptyRelation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Eliminate filter false.
|
||||
*/
|
||||
public class EliminateFilter extends OneRewriteRuleFactory {
|
||||
@Override
|
||||
public Rule build() {
|
||||
return logicalFilter()
|
||||
.when(filter -> filter.getPredicates() == BooleanLiteral.FALSE)
|
||||
.then(filter -> new LogicalEmptyRelation((List) filter.getOutput()))
|
||||
.toRule(RuleType.ELIMINATE_FILTER);
|
||||
}
|
||||
}
|
||||
@ -25,15 +25,14 @@ import org.apache.doris.nereids.trees.plans.logical.LogicalEmptyRelation;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* e.g.
|
||||
* LogicalLimit(limit=0) => LogicalEmptyRelation(projects=[limit.output()])
|
||||
* Eliminate limit = 0.
|
||||
*/
|
||||
public class LogicalLimitZeroToLogicalEmptyRelation extends OneRewriteRuleFactory {
|
||||
public class EliminateLimit extends OneRewriteRuleFactory {
|
||||
@Override
|
||||
public Rule build() {
|
||||
return logicalLimit()
|
||||
.when(limit -> limit.getLimit() == 0)
|
||||
.then(limit -> new LogicalEmptyRelation((List) limit.getOutput()))
|
||||
.toRule(RuleType.LOGICAL_LIMIT_TO_LOGICAL_EMPTY_RELATION_RULE);
|
||||
.toRule(RuleType.ELIMINATE_LIMIT);
|
||||
}
|
||||
}
|
||||
@ -32,11 +32,23 @@ public class BooleanLiteral extends Literal {
|
||||
|
||||
private final boolean value;
|
||||
|
||||
public BooleanLiteral(boolean value) {
|
||||
private BooleanLiteral(boolean value) {
|
||||
super(BooleanType.INSTANCE);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static BooleanLiteral of(boolean value) {
|
||||
if (value) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
public static BooleanLiteral of(Boolean value) {
|
||||
return of(value.booleanValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getValue() {
|
||||
return value;
|
||||
|
||||
@ -61,7 +61,7 @@ public abstract class Literal extends Expression implements LeafExpression {
|
||||
} else if (value instanceof BigInteger) {
|
||||
return new LargeIntLiteral((BigInteger) value);
|
||||
} else if (value instanceof Boolean) {
|
||||
return new BooleanLiteral((Boolean) value);
|
||||
return BooleanLiteral.of((Boolean) value);
|
||||
} else if (value instanceof String) {
|
||||
return new StringLiteral((String) value);
|
||||
} else {
|
||||
|
||||
@ -137,7 +137,7 @@ public class ExpressionUtils {
|
||||
|
||||
return distinctExpressions.stream()
|
||||
.reduce(type == And.class ? And::new : Or::new)
|
||||
.orElse(new BooleanLiteral(type == And.class));
|
||||
.orElse(BooleanLiteral.of(type == And.class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -37,7 +37,7 @@ public class CheckAnalysisTest {
|
||||
|
||||
@Test
|
||||
public void testCheckExpressionInputTypes() {
|
||||
Plan plan = new LogicalFilter<>(new And(new IntegerLiteral(1), new BooleanLiteral(true)), groupPlan);
|
||||
Plan plan = new LogicalFilter<>(new And(new IntegerLiteral(1), BooleanLiteral.TRUE), groupPlan);
|
||||
CheckAnalysis checkAnalysis = new CheckAnalysis();
|
||||
Assertions.assertThrows(RuntimeException.class, () -> checkAnalysis.build().transform(plan, cascadesContext));
|
||||
}
|
||||
|
||||
@ -140,15 +140,15 @@ public class TypeCoercionTest {
|
||||
|
||||
@Test
|
||||
public void testCaseWhenTypeCoercion() {
|
||||
WhenClause actualWhenClause1 = new WhenClause(new BooleanLiteral(true), new SmallIntLiteral((short) 1));
|
||||
WhenClause actualWhenClause2 = new WhenClause(new BooleanLiteral(true), new DoubleLiteral(1.5));
|
||||
WhenClause actualWhenClause1 = new WhenClause(BooleanLiteral.TRUE, new SmallIntLiteral((short) 1));
|
||||
WhenClause actualWhenClause2 = new WhenClause(BooleanLiteral.TRUE, new DoubleLiteral(1.5));
|
||||
List<WhenClause> actualWhenClauses = Lists.newArrayList(actualWhenClause1, actualWhenClause2);
|
||||
Expression actualDefaultValue = new IntegerLiteral(1);
|
||||
Expression actual = new CaseWhen(actualWhenClauses, actualDefaultValue);
|
||||
|
||||
WhenClause expectedWhenClause1 = new WhenClause(new BooleanLiteral(true),
|
||||
WhenClause expectedWhenClause1 = new WhenClause(BooleanLiteral.TRUE,
|
||||
new Cast(new SmallIntLiteral((short) 1), DoubleType.INSTANCE));
|
||||
WhenClause expectedWhenClause2 = new WhenClause(new BooleanLiteral(true),
|
||||
WhenClause expectedWhenClause2 = new WhenClause(BooleanLiteral.TRUE,
|
||||
new DoubleLiteral(1.5));
|
||||
List<WhenClause> expectedWhenClauses = Lists.newArrayList(expectedWhenClause1, expectedWhenClause2);
|
||||
Expression expectedDefaultValue = new Cast(new IntegerLiteral(1), DoubleType.INSTANCE);
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
// 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.doris.nereids.rules.rewrite.logical;
|
||||
|
||||
import org.apache.doris.nereids.CascadesContext;
|
||||
import org.apache.doris.nereids.rules.Rule;
|
||||
import org.apache.doris.nereids.trees.expressions.literal.BooleanLiteral;
|
||||
import org.apache.doris.nereids.trees.plans.Plan;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalEmptyRelation;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
|
||||
import org.apache.doris.nereids.util.MemoTestUtils;
|
||||
import org.apache.doris.nereids.util.PlanConstructor;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* MergeConsecutiveFilter ut
|
||||
*/
|
||||
public class EliminateFilterTest {
|
||||
@Test
|
||||
public void testEliminateFilter() {
|
||||
LogicalOlapScan scan = PlanConstructor.newLogicalOlapScan(0, "t1", 0);
|
||||
LogicalFilter<LogicalOlapScan> filter = new LogicalFilter<>(BooleanLiteral.FALSE, scan);
|
||||
|
||||
CascadesContext cascadesContext = MemoTestUtils.createCascadesContext(filter);
|
||||
List<Rule> rules = Lists.newArrayList(new EliminateFilter().build());
|
||||
cascadesContext.topDownRewrite(rules);
|
||||
|
||||
Plan actual = cascadesContext.getMemo().copyOut();
|
||||
Assertions.assertTrue(actual instanceof LogicalEmptyRelation);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
// 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.doris.nereids.rules.rewrite.logical;
|
||||
|
||||
import org.apache.doris.nereids.CascadesContext;
|
||||
import org.apache.doris.nereids.rules.Rule;
|
||||
import org.apache.doris.nereids.trees.plans.Plan;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalEmptyRelation;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalLimit;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
|
||||
import org.apache.doris.nereids.util.MemoTestUtils;
|
||||
import org.apache.doris.nereids.util.PlanConstructor;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* MergeConsecutiveFilter ut
|
||||
*/
|
||||
public class EliminateLimitTest {
|
||||
@Test
|
||||
public void testEliminateLimit() {
|
||||
LogicalOlapScan scan = PlanConstructor.newLogicalOlapScan(0, "t1", 0);
|
||||
LogicalLimit<LogicalOlapScan> limit = new LogicalLimit<>(0, 0, scan);
|
||||
|
||||
CascadesContext cascadesContext = MemoTestUtils.createCascadesContext(limit);
|
||||
List<Rule> rules = Lists.newArrayList(new EliminateLimit().build());
|
||||
cascadesContext.topDownRewrite(rules);
|
||||
|
||||
Plan actual = cascadesContext.getMemo().copyOut();
|
||||
Assertions.assertTrue(actual instanceof LogicalEmptyRelation);
|
||||
}
|
||||
}
|
||||
@ -39,7 +39,7 @@ public class JoinReorderTest implements PatternMatchSupported {
|
||||
UnboundRelation relation1 = new UnboundRelation(Lists.newArrayList("db", "table1"));
|
||||
UnboundRelation relation2 = new UnboundRelation(Lists.newArrayList("db", "table2"));
|
||||
LogicalJoin outerJoin = new LogicalJoin<>(JoinType.LEFT_OUTER_JOIN, relation1, relation2);
|
||||
LogicalFilter logicalFilter = new LogicalFilter<>(new BooleanLiteral(false), outerJoin);
|
||||
LogicalFilter logicalFilter = new LogicalFilter<>(BooleanLiteral.FALSE, outerJoin);
|
||||
|
||||
PlanChecker.from(MemoTestUtils.createConnectContext(), logicalFilter)
|
||||
.applyBottomUp(new ReorderJoin())
|
||||
|
||||
@ -41,11 +41,11 @@ public class MergeConsecutiveFilterTest {
|
||||
public void testMergeConsecutiveFilters() {
|
||||
UnboundRelation relation = new UnboundRelation(Lists.newArrayList("db", "table"));
|
||||
Expression expression1 = new IntegerLiteral(1);
|
||||
LogicalFilter filter1 = new LogicalFilter(expression1, relation);
|
||||
LogicalFilter filter1 = new LogicalFilter<>(expression1, relation);
|
||||
Expression expression2 = new IntegerLiteral(2);
|
||||
LogicalFilter filter2 = new LogicalFilter(expression2, filter1);
|
||||
LogicalFilter filter2 = new LogicalFilter<>(expression2, filter1);
|
||||
Expression expression3 = new IntegerLiteral(3);
|
||||
LogicalFilter filter3 = new LogicalFilter(expression3, filter2);
|
||||
LogicalFilter filter3 = new LogicalFilter<>(expression3, filter2);
|
||||
|
||||
CascadesContext cascadesContext = MemoTestUtils.createCascadesContext(filter3);
|
||||
List<Rule> rules = Lists.newArrayList(new MergeConsecutiveFilters().build());
|
||||
@ -56,7 +56,7 @@ public class MergeConsecutiveFilterTest {
|
||||
Assertions.assertTrue(resultPlan instanceof LogicalFilter);
|
||||
Expression allPredicates = ExpressionUtils.and(expression3,
|
||||
ExpressionUtils.and(expression2, expression1));
|
||||
Assertions.assertTrue(((LogicalFilter<?>) resultPlan).getPredicates().equals(allPredicates));
|
||||
Assertions.assertEquals(((LogicalFilter<?>) resultPlan).getPredicates(), allPredicates);
|
||||
Assertions.assertTrue(resultPlan.child(0) instanceof UnboundRelation);
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,9 +32,9 @@ import java.util.List;
|
||||
public class MergeConsecutiveLimitsTest {
|
||||
@Test
|
||||
public void testMergeConsecutiveLimits() {
|
||||
LogicalLimit limit3 = new LogicalLimit(3, 5, new UnboundRelation(Lists.newArrayList("db", "t")));
|
||||
LogicalLimit limit2 = new LogicalLimit(2, 0, limit3);
|
||||
LogicalLimit limit1 = new LogicalLimit(10, 2, limit2);
|
||||
LogicalLimit limit3 = new LogicalLimit<>(3, 5, new UnboundRelation(Lists.newArrayList("db", "t")));
|
||||
LogicalLimit limit2 = new LogicalLimit<>(2, 0, limit3);
|
||||
LogicalLimit limit1 = new LogicalLimit<>(10, 2, limit2);
|
||||
|
||||
CascadesContext context = MemoTestUtils.createCascadesContext(limit1);
|
||||
List<Rule> rules = Lists.newArrayList(new MergeConsecutiveLimits().build());
|
||||
|
||||
@ -47,9 +47,9 @@ public class MergeConsecutiveProjectsTest {
|
||||
NamedExpression colA = new SlotReference("a", IntegerType.INSTANCE, true, Lists.newArrayList("a"));
|
||||
NamedExpression colB = new SlotReference("b", IntegerType.INSTANCE, true, Lists.newArrayList("b"));
|
||||
NamedExpression colC = new SlotReference("c", IntegerType.INSTANCE, true, Lists.newArrayList("c"));
|
||||
LogicalProject project1 = new LogicalProject(Lists.newArrayList(colA, colB, colC), relation);
|
||||
LogicalProject project2 = new LogicalProject(Lists.newArrayList(colA, colB), project1);
|
||||
LogicalProject project3 = new LogicalProject(Lists.newArrayList(colA), project2);
|
||||
LogicalProject project1 = new LogicalProject<>(Lists.newArrayList(colA, colB, colC), relation);
|
||||
LogicalProject project2 = new LogicalProject<>(Lists.newArrayList(colA, colB), project1);
|
||||
LogicalProject project3 = new LogicalProject<>(Lists.newArrayList(colA), project2);
|
||||
|
||||
CascadesContext cascadesContext = MemoTestUtils.createCascadesContext(project3);
|
||||
List<Rule> rules = Lists.newArrayList(new MergeConsecutiveProjects().build());
|
||||
@ -57,7 +57,7 @@ public class MergeConsecutiveProjectsTest {
|
||||
Plan plan = cascadesContext.getMemo().copyOut();
|
||||
System.out.println(plan.treeString());
|
||||
Assertions.assertTrue(plan instanceof LogicalProject);
|
||||
Assertions.assertTrue(((LogicalProject<?>) plan).getProjects().equals(Lists.newArrayList(colA)));
|
||||
Assertions.assertEquals(((LogicalProject<?>) plan).getProjects(), Lists.newArrayList(colA));
|
||||
Assertions.assertTrue(plan.child(0) instanceof UnboundRelation);
|
||||
}
|
||||
|
||||
@ -81,13 +81,13 @@ public class MergeConsecutiveProjectsTest {
|
||||
Alias alias = new Alias(new Add(colA, new IntegerLiteral(1)), "X");
|
||||
Slot aliasRef = alias.toSlot();
|
||||
|
||||
LogicalProject project1 = new LogicalProject(
|
||||
LogicalProject project1 = new LogicalProject<>(
|
||||
Lists.newArrayList(
|
||||
colB,
|
||||
colC,
|
||||
alias),
|
||||
relation);
|
||||
LogicalProject project2 = new LogicalProject(
|
||||
LogicalProject project2 = new LogicalProject<>(
|
||||
Lists.newArrayList(
|
||||
new Alias(new Add(aliasRef, new IntegerLiteral(2)), "Y")
|
||||
),
|
||||
@ -105,6 +105,6 @@ public class MergeConsecutiveProjectsTest {
|
||||
new IntegerLiteral(2)
|
||||
);
|
||||
Assertions.assertEquals(1, finalProject.getProjects().size());
|
||||
Assertions.assertTrue(((Alias) finalProject.getProjects().get(0)).child().equals(finalExpression));
|
||||
Assertions.assertEquals(((Alias) finalProject.getProjects().get(0)).child(), finalExpression);
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,15 +43,15 @@ public class ExpectedInputTypesTest {
|
||||
public void testAnd() {
|
||||
TypeCheckResult typeCheckResult;
|
||||
|
||||
And secondInputIsNotBoolean = new And(new IntegerLiteral(1), new BooleanLiteral(true));
|
||||
And secondInputIsNotBoolean = new And(new IntegerLiteral(1), BooleanLiteral.TRUE);
|
||||
typeCheckResult = secondInputIsNotBoolean.checkInputDataTypes();
|
||||
Assertions.assertTrue(typeCheckResult.failed());
|
||||
|
||||
And firstInputIsNotBoolean = new And(new BooleanLiteral(true), new IntegerLiteral(1));
|
||||
And firstInputIsNotBoolean = new And(BooleanLiteral.TRUE, new IntegerLiteral(1));
|
||||
typeCheckResult = firstInputIsNotBoolean.checkInputDataTypes();
|
||||
Assertions.assertTrue(typeCheckResult.failed());
|
||||
|
||||
And bothInputAreBoolean = new And(new BooleanLiteral(true), new BooleanLiteral(false));
|
||||
And bothInputAreBoolean = new And(BooleanLiteral.TRUE, BooleanLiteral.FALSE);
|
||||
typeCheckResult = bothInputAreBoolean.checkInputDataTypes();
|
||||
Assertions.assertTrue(typeCheckResult.success());
|
||||
}
|
||||
@ -60,15 +60,15 @@ public class ExpectedInputTypesTest {
|
||||
public void testOr() {
|
||||
TypeCheckResult typeCheckResult;
|
||||
|
||||
Or secondInputIsNotBoolean = new Or(new IntegerLiteral(1), new BooleanLiteral(true));
|
||||
Or secondInputIsNotBoolean = new Or(new IntegerLiteral(1), BooleanLiteral.TRUE);
|
||||
typeCheckResult = secondInputIsNotBoolean.checkInputDataTypes();
|
||||
Assertions.assertTrue(typeCheckResult.failed());
|
||||
|
||||
Or firstInputIsNotBoolean = new Or(new BooleanLiteral(true), new IntegerLiteral(1));
|
||||
Or firstInputIsNotBoolean = new Or(BooleanLiteral.TRUE, new IntegerLiteral(1));
|
||||
typeCheckResult = firstInputIsNotBoolean.checkInputDataTypes();
|
||||
Assertions.assertTrue(typeCheckResult.failed());
|
||||
|
||||
Or bothInputAreBoolean = new Or(new BooleanLiteral(true), new BooleanLiteral(false));
|
||||
Or bothInputAreBoolean = new Or(BooleanLiteral.TRUE, BooleanLiteral.FALSE);
|
||||
typeCheckResult = bothInputAreBoolean.checkInputDataTypes();
|
||||
Assertions.assertTrue(typeCheckResult.success());
|
||||
}
|
||||
@ -129,7 +129,7 @@ public class ExpectedInputTypesTest {
|
||||
// this means has two type check error
|
||||
Assertions.assertEquals(4, typeCheckResult.getMessage().split(",").length);
|
||||
|
||||
Divide bool = new Divide(new BooleanLiteral(false), new BooleanLiteral(true));
|
||||
Divide bool = new Divide(BooleanLiteral.FALSE, BooleanLiteral.TRUE);
|
||||
typeCheckResult = bool.checkInputDataTypes();
|
||||
Assertions.assertTrue(typeCheckResult.failed());
|
||||
// this means has two type check error
|
||||
@ -192,7 +192,7 @@ public class ExpectedInputTypesTest {
|
||||
typeCheckResult = string.checkInputDataTypes();
|
||||
Assertions.assertTrue(typeCheckResult.success());
|
||||
|
||||
LessThan bool = new LessThan(new BooleanLiteral(false), new BooleanLiteral(true));
|
||||
LessThan bool = new LessThan(BooleanLiteral.FALSE, BooleanLiteral.TRUE);
|
||||
typeCheckResult = bool.checkInputDataTypes();
|
||||
Assertions.assertTrue(typeCheckResult.success());
|
||||
|
||||
@ -257,7 +257,7 @@ public class ExpectedInputTypesTest {
|
||||
// this means has two type check error
|
||||
Assertions.assertEquals(4, typeCheckResult.getMessage().split(",").length);
|
||||
|
||||
Multiply bool = new Multiply(new BooleanLiteral(false), new BooleanLiteral(true));
|
||||
Multiply bool = new Multiply(BooleanLiteral.FALSE, BooleanLiteral.TRUE);
|
||||
typeCheckResult = bool.checkInputDataTypes();
|
||||
Assertions.assertTrue(typeCheckResult.failed());
|
||||
// this means has two type check error
|
||||
@ -326,7 +326,7 @@ public class ExpectedInputTypesTest {
|
||||
// this means has two type check error
|
||||
Assertions.assertEquals(4, typeCheckResult.getMessage().split(",").length);
|
||||
|
||||
Subtract bool = new Subtract(new BooleanLiteral(false), new BooleanLiteral(true));
|
||||
Subtract bool = new Subtract(BooleanLiteral.FALSE, BooleanLiteral.TRUE);
|
||||
typeCheckResult = bool.checkInputDataTypes();
|
||||
Assertions.assertTrue(typeCheckResult.failed());
|
||||
// this means has two type check error
|
||||
@ -395,7 +395,7 @@ public class ExpectedInputTypesTest {
|
||||
// this means has two type check error
|
||||
Assertions.assertEquals(4, typeCheckResult.getMessage().split(",").length);
|
||||
|
||||
Mod bool = new Mod(new BooleanLiteral(false), new BooleanLiteral(true));
|
||||
Mod bool = new Mod(BooleanLiteral.FALSE, BooleanLiteral.TRUE);
|
||||
typeCheckResult = bool.checkInputDataTypes();
|
||||
Assertions.assertTrue(typeCheckResult.failed());
|
||||
// this means has two type check error
|
||||
@ -464,7 +464,7 @@ public class ExpectedInputTypesTest {
|
||||
// this means has two type check error
|
||||
Assertions.assertEquals(4, typeCheckResult.getMessage().split(",").length);
|
||||
|
||||
Add bool = new Add(new BooleanLiteral(false), new BooleanLiteral(true));
|
||||
Add bool = new Add(BooleanLiteral.FALSE, BooleanLiteral.TRUE);
|
||||
typeCheckResult = bool.checkInputDataTypes();
|
||||
Assertions.assertTrue(typeCheckResult.failed());
|
||||
// this means has two type check error
|
||||
@ -485,7 +485,7 @@ public class ExpectedInputTypesTest {
|
||||
typeCheckResult = childIsNotBoolean.checkInputDataTypes();
|
||||
Assertions.assertTrue(typeCheckResult.failed());
|
||||
|
||||
Not childIsBoolean = new Not(new BooleanLiteral(true));
|
||||
Not childIsBoolean = new Not(BooleanLiteral.TRUE);
|
||||
typeCheckResult = childIsBoolean.checkInputDataTypes();
|
||||
Assertions.assertTrue(typeCheckResult.success());
|
||||
}
|
||||
@ -494,11 +494,11 @@ public class ExpectedInputTypesTest {
|
||||
public void testWhenClause() {
|
||||
TypeCheckResult typeCheckResult;
|
||||
|
||||
WhenClause firstInputIsNotBoolean = new WhenClause(new IntegerLiteral(1), new BooleanLiteral(true));
|
||||
WhenClause firstInputIsNotBoolean = new WhenClause(new IntegerLiteral(1), BooleanLiteral.TRUE);
|
||||
typeCheckResult = firstInputIsNotBoolean.checkInputDataTypes();
|
||||
Assertions.assertTrue(typeCheckResult.failed());
|
||||
|
||||
WhenClause firstInputIsBoolean = new WhenClause(new BooleanLiteral(true), new BooleanLiteral(true));
|
||||
WhenClause firstInputIsBoolean = new WhenClause(BooleanLiteral.TRUE, BooleanLiteral.TRUE);
|
||||
typeCheckResult = firstInputIsBoolean.checkInputDataTypes();
|
||||
Assertions.assertTrue(typeCheckResult.success());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user