Skip to content

Commit

Permalink
规则组的实现
Browse files Browse the repository at this point in the history
  • Loading branch information
Yihao-Xu committed Oct 17, 2024
1 parent 1f13491 commit 9c0eb8f
Show file tree
Hide file tree
Showing 26 changed files with 112 additions and 148 deletions.
12 changes: 3 additions & 9 deletions .github/actions/confWriter/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,13 @@ runs:
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo sed -i 's/enablePushDown=false/enablePushDown=true/g' ${{ inputs.Root-Dir-Path }}/core/target/iginx-core-${VERSION}/conf/config.properties
sed -i 's/FilterPushDownAddSchemaPrefixRule=off,FilterPushDownAddSchemaPrefixRule=off/FilterPushDownAddSchemaPrefixRule=on,FilterPushDownAddSchemaPrefixRule=on/g' ${{ inputs.Root-Dir-Path }}/core/target/iginx-core-${VERSION}/conf/config.properties
sed -i 's/FilterPushDownPathUnionJoinRule=off,FilterPushDownProjectReorderSortRule=off,FilterPushDownRenameRule=off,FilterPushDownSelectRule=off/FilterPushDownPathUnionJoinRule=on,FilterPushDownProjectReorderSortRule=on,FilterPushDownRenameRule=on,FilterPushDownSelectRule=on/g' ${{ inputs.Root-Dir-Path }}/core/target/iginx-core-${VERSION}/conf/config.properties
sed -i 's/FilterPushDownSetOpRule=off,FilterPushDownTransformRule=off,FilterPushIntoJoinConditionRule=off,FilterPushOutJoinConditionRule=off,FilterPushDownGroupByRule=off/FilterPushDownSetOpRule=on,FilterPushDownTransformRule=on,FilterPushIntoJoinConditionRule=on,FilterPushOutJoinConditionRule=on,FilterPushDownGroupByRule=on/g' ${{ inputs.Root-Dir-Path }}/core/target/iginx-core-${VERSION}/conf/config.properties
sed -i 's/FilterPushDownRule=off/FilterPushDownRule=on/g' ${{ inputs.Root-Dir-Path }}/core/target/iginx-core-${VERSION}/conf/config.properties
elif [ "$RUNNER_OS" == "Windows" ]; then
sed -i 's/enablePushDown=false/enablePushDown=true/g' ${{ inputs.Root-Dir-Path }}/core/target/iginx-core-${VERSION}/conf/config.properties
sed -i 's/FilterPushDownAddSchemaPrefixRule=off,FilterPushDownAddSchemaPrefixRule=off/FilterPushDownAddSchemaPrefixRule=on,FilterPushDownAddSchemaPrefixRule=on/g' ${{ inputs.Root-Dir-Path }}/core/target/iginx-core-${VERSION}/conf/config.properties
sed -i 's/FilterPushDownPathUnionJoinRule=off,FilterPushDownProjectReorderSortRule=off,FilterPushDownRenameRule=off,FilterPushDownSelectRule=off/FilterPushDownPathUnionJoinRule=on,FilterPushDownProjectReorderSortRule=on,FilterPushDownRenameRule=on,FilterPushDownSelectRule=on/g' ${{ inputs.Root-Dir-Path }}/core/target/iginx-core-${VERSION}/conf/config.properties
sed -i 's/FilterPushDownSetOpRule=off,FilterPushDownTransformRule=off,FilterPushIntoJoinConditionRule=off,FilterPushOutJoinConditionRule=off,FilterPushDownGroupByRule=off/FilterPushDownSetOpRule=on,FilterPushDownTransformRule=on,FilterPushIntoJoinConditionRule=on,FilterPushOutJoinConditionRule=on,FilterPushDownGroupByRule=on/g' ${{ inputs.Root-Dir-Path }}/core/target/iginx-core-${VERSION}/conf/config.properties
sed -i 's/FilterPushDownRule=off/FilterPushDownRule=on/g' ${{ inputs.Root-Dir-Path }}/core/target/iginx-core-${VERSION}/conf/config.properties
elif [ "$RUNNER_OS" == "macOS" ]; then
sudo sed -i '' 's/enablePushDown=false/enablePushDown=true/g' ${{ inputs.Root-Dir-Path }}/core/target/iginx-core-${VERSION}/conf/config.properties
sed -i '' 's/FilterPushDownAddSchemaPrefixRule=off,FilterPushDownAddSchemaPrefixRule=off/FilterPushDownAddSchemaPrefixRule=on,FilterPushDownAddSchemaPrefixRule=on/g' ${{ inputs.Root-Dir-Path }}/core/target/iginx-core-${VERSION}/conf/config.properties
sed -i '' 's/FilterPushDownPathUnionJoinRule=off,FilterPushDownProjectReorderSortRule=off,FilterPushDownRenameRule=off,FilterPushDownSelectRule=off/FilterPushDownPathUnionJoinRule=on,FilterPushDownProjectReorderSortRule=on,FilterPushDownRenameRule=on,FilterPushDownSelectRule=on/g' ${{ inputs.Root-Dir-Path }}/core/target/iginx-core-${VERSION}/conf/config.properties
sed -i '' 's/FilterPushDownSetOpRule=off,FilterPushDownTransformRule=off,FilterPushIntoJoinConditionRule=off,FilterPushOutJoinConditionRule=off,FilterPushDownGroupByRule=off/FilterPushDownSetOpRule=on,FilterPushDownTransformRule=on,FilterPushIntoJoinConditionRule=on,FilterPushOutJoinConditionRule=on,FilterPushDownGroupByRule=on/g' ${{ inputs.Root-Dir-Path }}/core/target/iginx-core-${VERSION}/conf/config.properties
sed -i '' 's/FilterPushDownRule=off/FilterPushDownRule=on/g' ${{ inputs.Root-Dir-Path }}/core/target/iginx-core-${VERSION}/conf/config.properties
else
echo "$RUNNER_OS is not supported"
exit 1
Expand Down
7 changes: 2 additions & 5 deletions conf/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,8 @@ maxCachedPhysicalTaskPerStorage=500
queryOptimizer=rbo

# 优化器规则
ruleBasedOptimizer=NotFilterRemoveRule=on,FragmentPruningByFilterRule=on,ColumnPruningRule=on,FragmentPruningByPatternRule=on,ConstantPropagationRule=on,FunctionDistinctEliminateRule=on,InExistsDistinctEliminateRule=on,\
FilterConstantFoldingRule=on,RowTransformConstantFoldingRule=on,FilterPushDownAddSchemaPrefixRule=off,FilterPushDownAddSchemaPrefixRule=off,\
FilterPushDownPathUnionJoinRule=off,FilterPushDownProjectReorderSortRule=off,FilterPushDownRenameRule=off,FilterPushDownSelectRule=off,\
FilterPushDownSetOpRule=off,FilterPushDownTransformRule=off,FilterPushIntoJoinConditionRule=off,FilterPushOutJoinConditionRule=off,FilterPushDownGroupByRule=off,\
JoinFactorizationRule=on,SetTransformPushDownPathUnionJoinRule=off
ruleBasedOptimizer=NotFilterRemoveRule=on,FragmentPruningByFilterRule=on,ColumnPruningRule=on,ConstantPropagationRule=on,DistinctEliminateRule=on,\
ConstantFoldingRule=on,FilterPushDownRule=off,JoinFactorizationRule=on,SetTransformPushDownPathUnionJoinRule=off

# ParallelFilter触发行数
parallelFilterThreshold=10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ public ColumnPruningRule() {
* Any
*/
// 匹配任意操作符,但由于策略是ONCE,所以只会匹配到树的顶端
super("ColumnPruningRule", operand(AbstractOperator.class, any()), RuleStrategy.ONCE);
super(
"ColumnPruningRule",
"ColumnPruningRule",
operand(AbstractOperator.class, any()),
RuleStrategy.ONCE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public FilterConstantFoldingRule() {
* |
* Any
*/
super("FilterConstantFoldingRule", operand(Select.class, any()));
super("FilterConstantFoldingRule", "ConstantFoldingRule", operand(Select.class, any()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public FilterPushDownAddSchemaPrefixRule() {
*/
super(
"FilterPushDownAddSchemaPrefixRule",
"FilterPushDownRule",
operand(Select.class, operand(AddSchemaPrefix.class, any())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public FilterPushDownGroupByRule() {
*/
super(
"FilterPushDownGroupByRule",
"FilterPushDownRule",
operand(Select.class, operand(AbstractUnaryOperator.class, any())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public FilterPushDownPathUnionJoinRule() {
*/
super(
"FilterPushDownPathUnionJoinRule",
"FilterPushDownRule",
operand(Select.class, operand(AbstractBinaryOperator.class, any(), any())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public FilterPushDownProjectReorderSortRule() {
*/
super(
"FilterPushDownProjectReorderSortRule",
"FilterPushDownRule",
operand(Select.class, operand(AbstractUnaryOperator.class, any())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public FilterPushDownRenameRule() {
* |
* Rename
*/
super("FilterPushDownRenameRule", operand(Select.class, operand(Rename.class, any())));
super(
"FilterPushDownRenameRule",
"FilterPushDownRule",
operand(Select.class, operand(Rename.class, any())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public FilterPushDownSelectRule() {
* |
* Select
*/
super("FilterPushDownSelectRule", operand(Select.class, operand(Select.class, any())));
super(
"FilterPushDownSelectRule",
"FilterPushDownRule",
operand(Select.class, operand(Select.class, any())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public FilterPushDownSetOpRule() {
*/
super(
"FilterPushDownSetOpRule",
"FilterPushDownRule",
operand(Select.class, operand(AbstractBinaryOperator.class, any(), any())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public FilterPushDownTransformRule() {
*/
super(
"FilterPushDownTransformRule",
"FilterPushDownRule",
operand(Select.class, operand(AbstractUnaryOperator.class, any())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public FilterPushIntoJoinConditionRule() {
*/
super(
"FilterPushIntoJoinConditionRule",
"FilterPushDownRule",
operand(Select.class, operand(AbstractJoin.class, any(), any())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public FilterPushOutJoinConditionRule() {
* / \
* any any
*/
super("FilterPushOutJoinConditionRule", operand(AbstractJoin.class, any(), any()));
super(
"FilterPushOutJoinConditionRule",
"FilterPushDownRule",
operand(AbstractJoin.class, any(), any()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public FragmentPruningByPatternRule() {
* Fragment
*/
// Fragment的检测在matches中进行
super("FragmentPruningByPatternRule", operand(Project.class));
super("FragmentPruningByPatternRule", "ColumnPruningRule", operand(Project.class));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public FunctionDistinctEliminateRule() {
* |
* Any
*/
super("FunctionDistinctEliminateRule", operand(AbstractUnaryOperator.class, any()));
super(
"FunctionDistinctEliminateRule",
"DistinctEliminateRule",
operand(AbstractUnaryOperator.class, any()));
}

public boolean matches(RuleCall call) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public InExistsDistinctEliminateRule() {
* |
* Any
*/
super("InExistsDistinctEliminateRule", operand(Distinct.class, any()));
super("InExistsDistinctEliminateRule", "DistinctEliminateRule", operand(Distinct.class, any()));
}

public boolean matches(RuleCall call) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public RowTransformConstantFoldingRule() {
* |
* Any
*/
super("RowTransformConstantFoldingRule", operand(RowTransform.class, any()));
super(
"RowTransformConstantFoldingRule",
"ConstantFoldingRule",
operand(RowTransform.class, any()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public abstract class Rule {

private final String ruleName;

private final String ruleGroupName;

/** operand describes the local topology we want to match in this rule */
private final Operand operand;

Expand All @@ -42,6 +44,10 @@ protected Rule(String ruleName, Operand operand) {
this(ruleName, operand, DEFAULT_PRIORITY, DEFAULT_STRATEGY);
}

protected Rule(String ruleName, String ruleGroupName, Operand operand) {
this(ruleName, ruleGroupName, operand, DEFAULT_PRIORITY, DEFAULT_STRATEGY);
}

protected Rule(String ruleName, Operand operand, long priority) {
this(ruleName, operand, priority, DEFAULT_STRATEGY);
}
Expand All @@ -50,8 +56,26 @@ protected Rule(String ruleName, Operand operand, RuleStrategy strategy) {
this(ruleName, operand, DEFAULT_PRIORITY, strategy);
}

protected Rule(String ruleName, String ruleGroupName, Operand operand, RuleStrategy strategy) {
this(ruleName, ruleGroupName, operand, DEFAULT_PRIORITY, strategy);
}

protected Rule(String ruleName, Operand operand, long priority, RuleStrategy strategy) {
this.ruleName = ruleName;
this.ruleGroupName = ruleName;
this.operand = operand;
this.priority = priority;
this.strategy = strategy;
}

protected Rule(
String ruleName,
String ruleGroupName,
Operand operand,
long priority,
RuleStrategy strategy) {
this.ruleName = ruleName;
this.ruleGroupName = ruleGroupName;
this.operand = operand;
this.priority = priority;
this.strategy = strategy;
Expand All @@ -61,6 +85,10 @@ public String getRuleName() {
return ruleName;
}

public String getRuleGroupName() {
return ruleGroupName;
}

public Operand getOperand() {
return operand;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void setRulesByConfig() {
Config config = configDescriptor.getConfig();
String[] ruleSettingList = config.getRuleBasedOptimizer().split(",");

Set<String> banRules = new HashSet<>(rules.keySet());
Set<String> banRules = getAllGroup();

for (String ruleSetting : ruleSettingList) {
String[] ruleInfo = ruleSetting.split("=");
Expand All @@ -76,7 +76,15 @@ private void setRulesByConfig() {
}
}

banRulesByName(banRules);
banRulesGroupByName(banRules);
}

private Set<String> getAllGroup() {
Set<String> group = new HashSet<>();
for (Rule rule : rules.values()) {
group.add(rule.getRuleGroupName());
}
return group;
}

private void addRule(Rule rule) {
Expand Down Expand Up @@ -121,30 +129,35 @@ public boolean banRulesByName(Collection<String> ruleNames) {
return true;
}

public boolean banRuleByName(String ruleName) {
if (!rules.containsKey(ruleName)) {
LOGGER.error("IGinX rule collection does not include rule: {}", ruleName);
return false;
public boolean banRulesGroupByName(Collection<String> ruleGroupNames) {
for (String ruleGroupName : ruleGroupNames) {
banRulesGroup(ruleGroupName);
}
bannedRules.put(ruleName, rules.get(ruleName));
return true;
}

public boolean setRules(Map<String, Boolean> rulesChange) {
// Check whether any rule does not exist before setting it
// 先检查是否有不存在的规则,再进行设置
for (String ruleName : rulesChange.keySet()) {
if (!rules.containsKey(ruleName)) {
LOGGER.error("IGinX rule collection does not include rule: {}", ruleName);
return false;
public void banRulesGroup(String ruleGroupName) {
for (Rule rule : rules.values()) {
if (rule.getRuleGroupName().equals(ruleGroupName)) {
banRules(rule);
}
}
}

for (String ruleName : rulesChange.keySet()) {
if (rulesChange.get(ruleName)) {
unbanRule(rules.get(ruleName));
public void unbanRulesGroup(String ruleGroupName) {
for (Rule rule : rules.values()) {
if (rule.getRuleGroupName().equals(ruleGroupName)) {
unbanRule(rule);
}
}
}

public boolean setRules(Map<String, Boolean> rulesChange) {
for (String ruleGroupName : rulesChange.keySet()) {
if (rulesChange.get(ruleGroupName)) {
unbanRulesGroup(ruleGroupName);
} else {
banRules(rules.get(ruleName));
banRulesGroup(ruleGroupName);
}
}

Expand All @@ -153,8 +166,8 @@ public boolean setRules(Map<String, Boolean> rulesChange) {

public Map<String, Boolean> getRulesInfo() {
Map<String, Boolean> rulesInfo = new HashMap<>();
for (String ruleName : rules.keySet()) {
rulesInfo.put(ruleName, !bannedRules.containsKey(ruleName));
for (Rule rule : rules.values()) {
rulesInfo.put(rule.getRuleGroupName(), !bannedRules.containsKey(rule.getRuleName()));
}
return rulesInfo;
}
Expand Down
18 changes: 0 additions & 18 deletions session_py/iginx/iginx_pyclient/thrift/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +0,0 @@
#
# IGinX - the polystore system with high performance
# Copyright (C) Tsinghua University
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

18 changes: 0 additions & 18 deletions session_py/iginx/iginx_pyclient/thrift/rpc/IService.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9c0eb8f

Please sign in to comment.