forked from apache/doris
-
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.
[feature](nereids) Materialized view rewrite basic util implementation
- Loading branch information
Showing
18 changed files
with
1,047 additions
and
174 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
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
108 changes: 108 additions & 0 deletions
108
...-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/PredicatesSplitter.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,108 @@ | ||
// 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.exploration.mv; | ||
|
||
import org.apache.doris.nereids.trees.expressions.Alias; | ||
import org.apache.doris.nereids.trees.expressions.Cast; | ||
import org.apache.doris.nereids.trees.expressions.ComparisonPredicate; | ||
import org.apache.doris.nereids.trees.expressions.CompoundPredicate; | ||
import org.apache.doris.nereids.trees.expressions.EqualTo; | ||
import org.apache.doris.nereids.trees.expressions.Expression; | ||
import org.apache.doris.nereids.trees.expressions.NullSafeEqual; | ||
import org.apache.doris.nereids.trees.expressions.Or; | ||
import org.apache.doris.nereids.trees.expressions.SlotReference; | ||
import org.apache.doris.nereids.trees.expressions.literal.Literal; | ||
import org.apache.doris.nereids.trees.expressions.visitor.DefaultExpressionVisitor; | ||
import org.apache.doris.nereids.util.ExpressionUtils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Split the expression to equal, range and residual predicate. | ||
* Should instance when used. | ||
*/ | ||
public class PredicatesSplitter { | ||
|
||
private List<Expression> equalPredicates = new ArrayList<>(); | ||
private List<Expression> rangePredicates = new ArrayList<>(); | ||
private List<Expression> residualPredicates = new ArrayList<>(); | ||
private List<Expression> conjunctExpressions; | ||
|
||
private final PredicateExtract instance = new PredicateExtract(); | ||
|
||
public PredicatesSplitter(Expression target) { | ||
this.conjunctExpressions = ExpressionUtils.extractConjunction(target); | ||
for (Expression expression : conjunctExpressions) { | ||
expression.accept(instance, expression); | ||
} | ||
} | ||
|
||
/**PredicateExtract*/ | ||
public class PredicateExtract extends DefaultExpressionVisitor<Void, Expression> { | ||
|
||
@Override | ||
public Void visitComparisonPredicate(ComparisonPredicate comparisonPredicate, Expression sourceExpression) { | ||
Expression leftArg = comparisonPredicate.getArgument(0); | ||
Expression rightArg = comparisonPredicate.getArgument(1); | ||
boolean leftArgOnlyContainsColumnRef = containOnlyColumnRef(leftArg, true); | ||
boolean rightArgOnlyContainsColumnRef = containOnlyColumnRef(rightArg, true); | ||
if (comparisonPredicate instanceof EqualTo || comparisonPredicate instanceof NullSafeEqual) { | ||
if (leftArgOnlyContainsColumnRef && rightArgOnlyContainsColumnRef) { | ||
equalPredicates.add(comparisonPredicate); | ||
return null; | ||
} | ||
} else if ((leftArgOnlyContainsColumnRef && rightArg instanceof Literal) | ||
|| (rightArgOnlyContainsColumnRef && leftArg instanceof Literal)) { | ||
rangePredicates.add(comparisonPredicate); | ||
} else { | ||
residualPredicates.add(comparisonPredicate); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Void visitCompoundPredicate(CompoundPredicate compoundPredicate, Expression context) { | ||
if (compoundPredicate instanceof Or) { | ||
residualPredicates.add(compoundPredicate); | ||
return null; | ||
} | ||
return super.visitCompoundPredicate(compoundPredicate, context); | ||
} | ||
} | ||
|
||
public Predicates.SplitPredicate getSplitPredicate() { | ||
return Predicates.SplitPredicate.of( | ||
equalPredicates.isEmpty() ? null : ExpressionUtils.and(equalPredicates), | ||
rangePredicates.isEmpty() ? null : ExpressionUtils.and(rangePredicates), | ||
residualPredicates.isEmpty() ? null : ExpressionUtils.and(residualPredicates)); | ||
} | ||
|
||
private static boolean containOnlyColumnRef(Expression expression, boolean allowCast) { | ||
if (expression instanceof SlotReference && ((SlotReference) expression).isColumnFromTable()) { | ||
return true; | ||
} | ||
if (allowCast && expression instanceof Cast) { | ||
return containOnlyColumnRef(((Cast) expression).child(), true); | ||
} | ||
if (expression instanceof Alias) { | ||
return containOnlyColumnRef(((Alias) expression).child(), true); | ||
} | ||
return false; | ||
} | ||
} |
63 changes: 0 additions & 63 deletions
63
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/RelationMapping.java
This file was deleted.
Oops, something went wrong.
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
48 changes: 48 additions & 0 deletions
48
...in/java/org/apache/doris/nereids/rules/exploration/mv/mapping/ExpressionIndexMapping.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,48 @@ | ||
// 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.exploration.mv.mapping; | ||
|
||
import org.apache.doris.nereids.trees.expressions.Expression; | ||
|
||
import com.google.common.collect.ArrayListMultimap; | ||
import com.google.common.collect.Multimap; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Expression and it's index mapping | ||
*/ | ||
public class ExpressionIndexMapping extends Mapping { | ||
private final Multimap<Expression, Integer> expressionIndexMapping; | ||
|
||
public ExpressionIndexMapping(Multimap<Expression, Integer> expressionIndexMapping) { | ||
this.expressionIndexMapping = expressionIndexMapping; | ||
} | ||
|
||
public Multimap<Expression, Integer> getExpressionIndexMapping() { | ||
return expressionIndexMapping; | ||
} | ||
|
||
public static ExpressionIndexMapping generate(List<? extends Expression> expressions) { | ||
Multimap<Expression, Integer> expressionIndexMapping = ArrayListMultimap.create(); | ||
for (int i = 0; i < expressions.size(); i++) { | ||
expressionIndexMapping.put(expressions.get(i), i); | ||
} | ||
return new ExpressionIndexMapping(expressionIndexMapping); | ||
} | ||
} |
Oops, something went wrong.