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

fix: when parsing where conditions, you need to match according to table name+table alias #2407

Merged
merged 1 commit into from
Jan 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/main/java/com/actiontech/dble/plan/util/FilterUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import com.actiontech.dble.plan.node.PlanNode;
import com.actiontech.dble.plan.node.TableNode;
import com.actiontech.dble.util.CollectionUtil;
import com.actiontech.dble.util.StringUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import java.util.*;

Expand All @@ -31,7 +34,7 @@ private FilterUtils() {
public static List<Item> splitFilter(Item filter) {
if (filter == null)
throw new RuntimeException("check filter before split");
List<Item> filterList = new ArrayList<>();
Set<Item> filterSet = Sets.newHashSet();
if (filter.type() == Item.ItemType.COND_ITEM) {
ItemCond cond = (ItemCond) filter;
if (cond.functype() == Functype.COND_AND_FUNC) {
Expand All @@ -40,7 +43,7 @@ public static List<Item> splitFilter(Item filter) {
if (subFilter == null)
continue;
List<Item> subSplits = splitFilter(subFilter);
filterList.addAll(subSplits);
filterSet.addAll(subSplits);
}
} else if (cond.functype() == Functype.COND_OR_FUNC) {

Expand All @@ -60,17 +63,17 @@ public static List<Item> splitFilter(Item filter) {
ItemCondOr x = new ItemCondOr(entry.getValue());
x.getReferTables().addAll(entry.getValue().get(0).getReferTables());
x.setWithUnValAble(true);
filterList.add(x);
filterSet.add(x);
}
}
filterList.add(cond);
filterSet.add(cond);
} else {
filterList.add(cond);
filterSet.add(cond);
}
} else {
filterList.add(filter);
filterSet.add(filter);
}
return filterList;
return Lists.newArrayList(filterSet);
}

/**
Expand Down Expand Up @@ -99,6 +102,9 @@ public static Map<String, List<Item>> gourpByRefertTable(Item self, Set<List<Ite
for (PlanNode refertTable : self.getReferTables()) { // Traversing related tables
if (refertTable instanceof TableNode) {
String tableName = ((TableNode) refertTable).getTableName();
if (!StringUtil.isEmpty(refertTable.getAlias())) {
tableName += refertTable.getAlias();
}

//this loop is to check wether the table has filter in every Subconditions (....where subcondition1 or subcondition2 )
for (List<Item> singleList : saveSet) {
Expand All @@ -110,7 +116,11 @@ public static Map<String, List<Item>> gourpByRefertTable(Item self, Set<List<Ite
if (x.getReferTables().size() == 1) {
for (PlanNode backTable : x.getReferTables()) {
if (backTable instanceof TableNode) {
if (((TableNode) backTable).getTableName().equals(tableName)) {
String backTableName = ((TableNode) backTable).getTableName();
if (!StringUtil.isEmpty(backTable.getAlias())) {
backTableName += backTable.getAlias();
}
if (backTableName.equals(tableName)) {
hasOutTable = true;
if (!itemMapForSingle.containsKey(tableName)) {
itemMapForSingle.put(tableName, new ArrayList<Item>());
Expand Down