本文整理匯總了Java中com.taobao.tddl.optimizer.core.ast.query.TableNode.setKeyFilter方法的典型用法代碼示例。如果您正苦於以下問題:Java TableNode.setKeyFilter方法的具體用法?Java TableNode.setKeyFilter怎麽用?Java TableNode.setKeyFilter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.taobao.tddl.optimizer.core.ast.query.TableNode
的用法示例。
在下文中一共展示了TableNode.setKeyFilter方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: build
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //導入方法依賴的package包/類
private void build(TableNode table) {
table.build();
Map<String, Object> extraCmd = new HashMap<String, Object>();
extraCmd.put(ConnectionProperties.CHOOSE_INDEX, true);
IndexMeta index = IndexChooser.findBestIndex(table.getTableMeta(),
new ArrayList<ISelectable>(),
FilterUtils.toDNFNode(table.getWhereFilter()),
table.getTableName(),
extraCmd);
table.useIndex(index);
Map<FilterType, IFilter> result = FilterSpliter.splitByIndex(FilterUtils.toDNFNode(table.getWhereFilter()),
table);
table.setKeyFilter(result.get(FilterType.IndexQueryKeyFilter));
table.setIndexQueryValueFilter(result.get(FilterType.IndexQueryValueFilter));
table.setResultFilter(result.get(FilterType.ResultFilter));
}
示例2: build
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //導入方法依賴的package包/類
private void build(TableNode table) {
table.build();
Map<String, Object> extraCmd = new HashMap<String, Object>();
extraCmd.put(ExtraCmd.CHOOSE_INDEX, true);
IndexMeta index = IndexChooser.findBestIndex(table.getTableMeta(),
new ArrayList<ISelectable>(),
FilterUtils.toDNFNode(table.getWhereFilter()),
table.getTableName(),
extraCmd);
table.useIndex(index);
Map<FilterType, IFilter> result = FilterSpliter.splitByIndex(FilterUtils.toDNFNode(table.getWhereFilter()),
table);
table.setKeyFilter(result.get(FilterType.IndexQueryKeyFilter));
table.setIndexQueryValueFilter(result.get(FilterType.IndexQueryValueFilter));
table.setResultFilter(result.get(FilterType.ResultFilter));
}
示例3: buildTableFilter
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //導入方法依賴的package包/類
private static void buildTableFilter(TableNode tableNode) {
List<List<IFilter>> DNFNodes = FilterUtils.toDNFNodesArray(tableNode.getWhereFilter());
if (DNFNodes.size() == 1) {
// 即使索引沒有選擇主鍵,但是有的filter依舊會在s主鍵上進行,作為valueFilter,所以要把主鍵也傳進去
Map<FilterType, IFilter> filters = FilterSpliter.splitByIndex(DNFNodes.get(0), tableNode);
tableNode.setKeyFilter(filters.get(FilterType.IndexQueryKeyFilter));
tableNode.setResultFilter(filters.get(FilterType.ResultFilter));
tableNode.setIndexQueryValueFilter(filters.get(FilterType.IndexQueryValueFilter));
tableNode.query((IFilter) null);// 清空where
} else {
// 如果存在多個合取方式的的or組合時,無法區分出key/indexValue/result,直接下推
tableNode.setResultFilter(tableNode.getWhereFilter());
tableNode.query((IFilter) null);// 清空where
}
}
示例4: buildTableFilter
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //導入方法依賴的package包/類
private static void buildTableFilter(TableNode tableNode) {
List<List<IFilter>> DNFNodes = FilterUtils.toDNFNodesArray(tableNode.getWhereFilter());
if (DNFNodes.size() == 1) {
// 即使索引沒有選擇主鍵,但是有的filter依舊會在s主鍵上進行,作為valueFilter,所以要把主鍵也傳進去
Map<FilterType, IFilter> filters = FilterSpliter.splitByIndex(DNFNodes.get(0), tableNode);
tableNode.setKeyFilter(filters.get(FilterType.IndexQueryKeyFilter));
tableNode.setResultFilter(filters.get(FilterType.ResultFilter));
tableNode.setIndexQueryValueFilter(filters.get(FilterType.IndexQueryValueFilter));
} else {
// 如果存在多個合取方式的的or組合時,無法區分出key/indexValue/result,直接下推
tableNode.setResultFilter(tableNode.getWhereFilter());
}
}
示例5: splitByDNF
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //導入方法依賴的package包/類
/**
* 根據where中的所有條件按照or進行分隔,生成多個query請求. (主要考慮部分存儲引擎不支持or語法)
*/
public static List<QueryTreeNode> splitByDNF(TableNode node, Map<String, Object> extraCmd) {
if (node.getWhereFilter() == null) {
return new LinkedList<QueryTreeNode>();
}
if (!FilterUtils.isDNF(node.getWhereFilter())) {
throw new IllegalArgumentException("not dnf!!! fuck!!\n" + node.getWhereFilter());
}
List<QueryTreeNode> subQueries = new LinkedList<QueryTreeNode>();
List<List<IFilter>> DNFNodes = FilterUtils.toDNFNodesArray(node.getWhereFilter());
// 判斷是否要處理OR轉化為index merge,比如mysql可以push
// 比如hbase/bdb這一類,OR條件目前隻能是主鍵索引,由執行器層麵去解決
// 如果涉及多字段時就需要拆分為index merge,同時做uniq
boolean needCopy = (DNFNodes.size() > 1);
if (isOptimizeIndexMerge(extraCmd) || DNFNodes.size() == 1) {
for (List<IFilter> DNFNode : DNFNodes) {
List columns = Arrays.asList(FilterUtils.toColumnFiltersMap(DNFNode).keySet().toArray());
String tablename = node.getTableName();
IndexMeta index = IndexChooser.findBestIndex(node.getTableMeta(), columns, DNFNode, tablename, extraCmd);
if (index == null) {
index = node.getTableMeta().getPrimaryIndex();
}
// 如果找不到對應條件的主鍵,可能需要全表掃描
TableNode subQuery = node;
if (needCopy) {
subQuery = node.deepCopy();
}
subQuery.useIndex(index);
if (index == null) {// 如果無主鍵進行全表掃描
subQuery.setFullTableScan(true);
} else {
subQuery.query((IFilter) null);// 清空where
}
Map<FilterType, IFilter> filters = splitByIndex(DNFNode, subQuery);
subQuery.setKeyFilter(filters.get(FilterType.IndexQueryKeyFilter));
subQuery.setIndexQueryValueFilter(filters.get(FilterType.IndexQueryValueFilter));
subQuery.setResultFilter(filters.get(FilterType.ResultFilter));
subQueries.add(subQuery);
}
} else {
node.useIndex(node.getTableMeta().getPrimaryIndex());// 默認選中主鍵
node.setResultFilter(node.getWhereFilter());
}
return subQueries;
}
示例6: buildMergeTableInOneDB
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //導入方法依賴的package包/類
/**
* 構建單庫的執行節點
*/
private static OneDbNodeWithCount buildMergeTableInOneDB(TableNode table, TargetDB targetDB, boolean needCopy) {
long totalRowCount = 0;
OneDbNodeWithCount oneDbNodeWithCount = new OneDbNodeWithCount();
Map<String, Field> tabMap = targetDB.getTableNameMap();
for (String targetTable : tabMap.keySet()) {
TableNode node = null;
if (needCopy) {
node = table.copy();
} else {
node = table;
}
// tddl的traceSource在分庫不分表,和全表掃描時無法使用 mengshi
if (tabMap.get(targetTable) != null && tabMap.get(targetTable).getSourceKeys() != null) {
if (node.getKeyFilter() != null) {
IFilter keyFilterAfterTraceSource = (IFilter) node.getKeyFilter().copy();
traceSourceInFilter(keyFilterAfterTraceSource, tabMap.get(targetTable).getSourceKeys());
node.setKeyFilter(keyFilterAfterTraceSource);
}
if (node.getResultFilter() != null) {
IFilter valueFilterAfterTraceSource = (IFilter) node.getResultFilter().copy();
traceSourceInFilter(valueFilterAfterTraceSource, tabMap.get(targetTable).getSourceKeys());
node.setResultFilter(valueFilterAfterTraceSource);
}
}
node.setActualTableName(targetTable);
node.executeOn(targetDB.getDbIndex());
node.setExtra(getIdentifierExtra((KVIndexNode) node));// 設置標誌
// 暫時先用邏輯表名,以後可能是索引名
String indexName = null;
if (node instanceof KVIndexNode) {
indexName = ((KVIndexNode) node).getKvIndexName();
} else {
indexName = node.getTableMeta().getPrimaryIndex().getName();
}
node.setBroadcast(OptimizerContext.getContext().getRule().isBroadCast(indexName));
totalRowCount += CostEsitimaterFactory.estimate(node).getRowCount();
oneDbNodeWithCount.subs.add(node);
}
oneDbNodeWithCount.totalRowCount = totalRowCount;
return oneDbNodeWithCount;
}
示例7: splitByDNF
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //導入方法依賴的package包/類
/**
* 根據where中的所有條件按照or進行分隔,生成多個query請求. (主要考慮部分存儲引擎不支持or語法)
*/
public static List<QueryTreeNode> splitByDNF(TableNode node, Map<String, Object> extraCmd) throws QueryException {
if (node.getWhereFilter() == null) {
return new LinkedList<QueryTreeNode>();
}
if (!FilterUtils.isDNF(node.getWhereFilter())) {
throw new IllegalArgumentException("not dnf!!! fuck!!\n" + node.getWhereFilter());
}
List<QueryTreeNode> subQueries = new LinkedList<QueryTreeNode>();
List<List<IFilter>> DNFNodes = FilterUtils.toDNFNodesArray(node.getWhereFilter());
// 判斷是否要處理OR轉化為index merge,比如mysql可以push
// 比如hbase/bdb這一類,OR條件目前隻能是主鍵索引,由執行器層麵去解決
// 如果涉及多字段時就需要拆分為index merge,同時做uniq
boolean needCopy = (DNFNodes.size() > 1);
if (isOptimizeIndexMerge(extraCmd) || DNFNodes.size() == 1) {
for (List<IFilter> DNFNode : DNFNodes) {
List columns = Arrays.asList(FilterUtils.toColumnFiltersMap(DNFNode).keySet().toArray());
String tablename = node.getTableName();
IndexMeta index = IndexChooser.findBestIndex(node.getTableMeta(), columns, DNFNode, tablename, extraCmd);
if (index == null) {
index = node.getTableMeta().getPrimaryIndex();
}
// 如果找不到對應條件的主鍵,可能需要全表掃描
TableNode subQuery = node;
if (needCopy) {
subQuery = node.deepCopy();
}
subQuery.useIndex(index);
if (index == null) {// 如果無主鍵進行全表掃描
subQuery.setFullTableScan(true);
}
Map<FilterType, IFilter> filters = splitByIndex(DNFNode, subQuery);
subQuery.setKeyFilter(filters.get(FilterType.IndexQueryKeyFilter));
subQuery.setIndexQueryValueFilter(filters.get(FilterType.IndexQueryValueFilter));
subQuery.setResultFilter(filters.get(FilterType.ResultFilter));
subQueries.add(subQuery);
}
} else {
node.useIndex(node.getTableMeta().getPrimaryIndex());// 默認選中主鍵
node.setResultFilter(node.getWhereFilter());
}
return subQueries;
}