本文整理汇总了Java中com.taobao.tddl.rule.model.Field类的典型用法代码示例。如果您正苦于以下问题:Java Field类的具体用法?Java Field怎么用?Java Field使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Field类属于com.taobao.tddl.rule.model包,在下文中一共展示了Field类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: defaultRoute
import com.taobao.tddl.rule.model.Field; //导入依赖的package包/类
/**
* 没有分库分表的逻辑表,返回指定库表
*
* @param vtab
* @param vtrCurrent
* @return
*/
private MatcherResult defaultRoute(String vtab, VirtualTableRoot vtrCurrent) {
TargetDB targetDb = new TargetDB();
// 设置默认的链接库,比如就是groupKey
targetDb.setDbIndex(this.getDefaultDbIndex(vtab, vtrCurrent));
// 设置表名,同名不做转化
Map<String, Field> tableNames = new HashMap<String, Field>(1);
tableNames.put(vtab, null);
targetDb.setTableNames(tableNames);
return new MatcherResult(Arrays.asList(targetDb),
new HashMap<String, Comparative>(),
new HashMap<String, Comparative>());
}
示例2: toMapField
import com.taobao.tddl.rule.model.Field; //导入依赖的package包/类
private Map<String, Field> toMapField(Map<String/* rule计算结果 */, Samples/* 得到该结果的样本 */> values) {
Map<String, Field> res = new HashMap<String, Field>(values.size());
for (Map.Entry<String, Samples> e : values.entrySet()) {
Field f = new Field(e.getValue().size());
f.setSourceKeys(e.getValue().getColumnEnumerates());
res.put(e.getKey(), f);
}
return res;
}
示例3: buildTargetDbList
import com.taobao.tddl.rule.model.Field; //导入依赖的package包/类
private List<TargetDB> buildTargetDbList(Map<String, Set<String>> topology) {
List<TargetDB> targetDbList = new ArrayList<TargetDB>(topology.size());
for (Map.Entry<String, Set<String>> e : topology.entrySet()) {
TargetDB db = new TargetDB();
Map<String, Field> tableNames = new HashMap<String, Field>(e.getValue().size());
for (String tbName : e.getValue()) {
tableNames.put(tbName, null);
}
db.setDbIndex(e.getKey());
db.setTableNames(tableNames);
targetDbList.add(db);
}
return targetDbList;
}
示例4: buildTargetDbListWithSourceKey
import com.taobao.tddl.rule.model.Field; //导入依赖的package包/类
private List<TargetDB> buildTargetDbListWithSourceKey(Map<String, Map<String, Field>> topology) {
List<TargetDB> targetDbList = new ArrayList<TargetDB>(topology.size());
for (Map.Entry<String, Map<String, Field>> e : topology.entrySet()) {
TargetDB db = new TargetDB();
db.setDbIndex(e.getKey());
db.setTableNames(e.getValue());
targetDbList.add(db);
}
return targetDbList;
}
示例5: buildMergeTable
import com.taobao.tddl.rule.model.Field; //导入依赖的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;
}
}
示例6: buildMergeTableInOneDB
import com.taobao.tddl.rule.model.Field; //导入依赖的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;
}
示例7: buildMergeTableInOneDB
import com.taobao.tddl.rule.model.Field; //导入依赖的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;
}