本文整理匯總了Java中com.taobao.tddl.optimizer.core.ast.query.TableNode.copy方法的典型用法代碼示例。如果您正苦於以下問題:Java TableNode.copy方法的具體用法?Java TableNode.copy怎麽用?Java TableNode.copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.taobao.tddl.optimizer.core.ast.query.TableNode
的用法示例。
在下文中一共展示了TableNode.copy方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildMergeTable
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //導入方法依賴的package包/類
/**
* 根據執行的目標節點,構建MergeNode
*/
private static QueryTreeNode buildMergeTable(TableNode table, List<TargetDB> dataNodeChoosed,
Map<String, Object> extraCmd, boolean traceIn) {
long maxRowCount = 0;
String maxRowCountDataNode = dataNodeChoosed.get(0).getDbIndex();
List<List<QueryTreeNode>> subs = new ArrayList();
// 單庫單表是大多數場景,此時無需複製執行計劃
// 大部分情況隻有一張表
boolean needCopy = false;
if (dataNodeChoosed.size() > 0 && dataNodeChoosed.get(0).getTableNameMap().size() > 0) {
Map<String, Field> tabMap = dataNodeChoosed.get(0).getTableNameMap();
Entry<String, Field> entry = tabMap.entrySet().iterator().next();
// 如果存在in,則必須使用複製
if (traceIn && entry.getValue() != null) {
needCopy |= traceSourceInFilter(table.getKeyFilter(), entry.getValue().getSourceKeys(), true);
needCopy |= traceSourceInFilter(table.getResultFilter(), entry.getValue().getSourceKeys(), true);
}
if (!chooseShareNode(extraCmd) && tabMap.size() > 1) {
// 如果不使用share模式,並且多於一張表,那就采用複製模式
needCopy = true;
}
if (!needCopy && tabMap.size() > 1) {
table = table.copy(); // 針對share模式,需要複製一份
}
}
int index = 0;
for (TargetDB target : dataNodeChoosed) {
OneDbNodeWithCount oneDbNodeWithCount = buildMergeTableInOneDB(table, target, index, needCopy, traceIn);
if (!oneDbNodeWithCount.subs.isEmpty()) {
subs.add(oneDbNodeWithCount.subs);
}
index += target.getTableNameMap().size();
if (oneDbNodeWithCount.totalRowCount > maxRowCount) {
maxRowCount = oneDbNodeWithCount.totalRowCount;
maxRowCountDataNode = target.getDbIndex();
}
}
if (subs.isEmpty()) {
throw new EmptyResultFilterException();
} else if (subs.size() == 1 && subs.get(0).size() == 1) {
return subs.get(0).get(0); // 隻有單庫
} else {
// 多庫執行
MergeNode merge = new MergeNode();
merge.setAlias(table.getAlias());
merge.setSubQuery(table.isSubQuery());
merge.setSubAlias(table.getSubAlias());
merge.executeOn(maxRowCountDataNode);
merge.setSubqueryOnFilterId(table.getSubqueryOnFilterId());
for (List<QueryTreeNode> subList : subs) {
for (QueryTreeNode sub : subList) {
merge.merge(sub);
}
}
merge.setBroadcast(false);// merge不可能是廣播表
merge.build();// build過程中會複製子節點的信息
return merge;
}
}
示例2: buildMergeTableInOneDB
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //導入方法依賴的package包/類
/**
* 構建單庫的執行節點
*/
private static OneDbNodeWithCount buildMergeTableInOneDB(TableNode table, TargetDB targetDB, int baseIndex,
boolean needCopy, boolean traceIn) {
long totalRowCount = 0;
OneDbNodeWithCount oneDbNodeWithCount = new OneDbNodeWithCount();
Map<String, Field> tabMap = targetDB.getTableNameMap();
int i = baseIndex;
for (String targetTable : tabMap.keySet()) {
TableNode node = table;
if (needCopy) {
node = table.copy();
// tddl的traceSource在分庫不分表,和全表掃描時無法使用 mengshi
if (traceIn && tabMap.get(targetTable) != null && tabMap.get(targetTable).getSourceKeys() != null) {
traceSourceInFilter(node.getKeyFilter(), tabMap.get(targetTable).getSourceKeys(), false);
traceSourceInFilter(node.getResultFilter(), tabMap.get(targetTable).getSourceKeys(), false);
}
}
if (needCopy) {
node.setActualTableName(targetTable);
node.executeOn(targetDB.getDbIndex());
node.setExtra(getIdentifierExtra((KVIndexNode) node, 0));// 設置標誌
oneDbNodeWithCount.subs.add(node);
} else {
node.setActualTableName(targetTable, i);
node.executeOn(targetDB.getDbIndex(), i);
node.setExtra(getIdentifierExtra((KVIndexNode) node, i), i);// 設置標誌
// 添加一個代理對象
oneDbNodeWithCount.subs.add((QueryTreeNode) new NodeDelegate(node, i).getProxy());
i = i + 1;
}
// 暫時先用邏輯表名,以後可能是索引名
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.totalRowCount = totalRowCount;
return oneDbNodeWithCount;
}
示例3: 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;
}