本文整理汇总了Java中com.taobao.tddl.optimizer.core.plan.query.IQuery类的典型用法代码示例。如果您正苦于以下问题:Java IQuery类的具体用法?Java IQuery怎么用?Java IQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IQuery类属于com.taobao.tddl.optimizer.core.plan.query包,在下文中一共展示了IQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入依赖的package包/类
@Override
public void visit(IColumn column) {
// 别名加在select之外,如(select * from table) as t1,列名之前不能使用这个别名
// 别名加在select之内,如select * from table as t1,列名之前可以使用这个别名
if (query instanceof IQueryTree && !((IQueryTree) query).isSubQuery()
&& ((IQueryTree) query).getAlias() != null && column.getTableName() != null) {
sqlBuilder.append(((IQueryTree) query).getAlias());
} else {
if (query instanceof IQuery && column.getTableName() != null) {
sqlBuilder.append(((IQuery) query).getTableName());
} else {
if (query instanceof IQueryTree && column.getTableName() != null) {
sqlBuilder.append(column.getTableName());
} else {
sqlBuilder.append(column.getColumnName());
return;
}
}
}
sqlBuilder.append(".");
sqlBuilder.append(column.getColumnName());
}
示例2: handle
import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入依赖的package包/类
@Override
public ISchematicCursor handle(IDataNodeExecutor executor, ExecutionContext executionContext) throws TddlException {
// 先做查询
ISchematicCursor cursor = doQuery(null, executor, executionContext);
if (executor.getSql() == null || (executor instanceof IQuery && ((IQuery) executor).getIndexName() != null)) {
IQueryTree IQueryTree = (IQueryTree) executor;
cursor = processValueFilter(cursor, executionContext, IQueryTree);
cursor = processGroupByAndOrderBy(cursor, executionContext, IQueryTree);
cursor = processLimitFromTo(cursor, executionContext, IQueryTree);
cursor = processColumnAndAlias(cursor, executionContext, IQueryTree);
}
return cursor;
}
示例3: executeAgg
import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入依赖的package包/类
protected ISchematicCursor executeAgg(ISchematicCursor cursor, IDataNodeExecutor executor,
boolean closeResultCursor, IRepository repo, List<IFunction> aggregates,
List<IOrderBy> groupBycols, ExecutionContext executionContext)
throws TddlException {
List<ISelectable> _retColumns = null;
if (executor instanceof IQuery) {
_retColumns = ((IQuery) executor).getColumns();
} else if (executor instanceof IJoin) {
_retColumns = ((IJoin) executor).getColumns();
} else if (executor instanceof IMerge) {
_retColumns = ((IMerge) executor).getColumns();
}
if (_retColumns != null) {
if ((aggregates != null && !aggregates.isEmpty()) || (groupBycols != null && !groupBycols.isEmpty())) {
cursor = repo.getCursorFactory().aggregateCursor(executionContext,
cursor,
aggregates,
groupBycols,
_retColumns,
false);
}
}
return cursor;
}
示例4: getMergeJoinQuery
import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入依赖的package包/类
private IJoin getMergeJoinQuery() {
IJoin j = this.getJoin();
j.setLeftOuter(true);
j.setRightOuter(true);
IQuery q1 = this.getQuery(1);
IQuery q2 = this.getQuery(2);
IQuery q3 = this.getQuery(3);
IQuery q4 = this.getQuery(4);
IMerge leftMerge = this.getMerge(7);
leftMerge.addSubNode(q1).addSubNode(q2).addSubNode(q3);
j.setLeftNode(leftMerge);
j.setRightNode(q4);
return j;
}
示例5: buildOrderBy
import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入依赖的package包/类
public static List<IOrderBy> buildOrderBy(IDataNodeExecutor executor, IndexMeta indexMeta, String tableName) {
IQuery query = ((IQuery) executor);
List<IOrderBy> orderBy = null;
orderBy = query.getOrderBys();
if (orderBy == null || orderBy.isEmpty()) {
List<IOrderBy> groupBys = query.getGroupBys();
orderBy = groupBys;
}
if (orderBy == null || orderBy.isEmpty()) {
orderBy = ExecUtils.getOrderBy(indexMeta);
}
List<IOrderBy> orderbys = ExecUtils.copyOrderBys(orderBy);
return orderbys;
}
示例6: canComposeOneSql
import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入依赖的package包/类
protected boolean canComposeOneSql(IDataNodeExecutor executor) {
if (executor instanceof IQuery) {
IQuery iq = (IQuery) executor;
IQueryTree iqc = iq.getSubQuery();
if (iqc == null) {
return true;
}
String groupNode1 = iq.getDataNode();
String groupNode2 = iqc.getDataNode();
if (TStringUtil.equals(groupNode1, groupNode2)) {
return isConsistent(iqc, groupNode1);
} else {
return false;
}
} else {
return true;
}
}
示例7: isConsistent
import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入依赖的package包/类
private boolean isConsistent(IQueryTree iqc, String groupNode1) {
if (iqc instanceof IQuery) {
IQuery iq = (IQuery) iqc;
IQueryTree iqc1 = iq.getSubQuery();
if (iqc1 == null) {
return true;
} else {
String groupNode2 = iqc.getDataNode();
if (TStringUtil.equals(groupNode1, groupNode2)) {
return isConsistent(iqc, groupNode1);
} else {
return false;
}
}
} else {
return false;
}
}
示例8: allocThread
import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入依赖的package包/类
private void allocThread(IDataNodeExecutor dne, int i) {
dne.setThread(i);
if (dne instanceof IPut) {
if (((IPut) dne).getQueryTree() != null) {
this.allocThread(((IPut) dne).getQueryTree(), i + 1);
}
} else if (dne instanceof IQuery) {
if (((IQuery) dne).getSubQuery() != null) {
this.allocThread(((IQuery) dne).getSubQuery(), i + 1);
}
} else if (dne instanceof IMerge) {
for (IDataNodeExecutor sub : ((IMerge) dne).getSubNodes()) {
this.allocThread(sub, i + 1);
}
} else if (dne instanceof IJoin) {
this.allocThread(((IJoin) dne).getLeftNode(), i + 1);
this.allocThread(((IJoin) dne).getRightNode(), i + 1);
}
}
示例9: findMergeAndSetConcurrent
import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入依赖的package包/类
private void findMergeAndSetConcurrent(IDataNodeExecutor dne, Map<String, Object> extraCmd) {
if (dne instanceof IMerge) {
QUERY_CONCURRENCY concurrency = judgeMergeConcurrent(extraCmd, (IMerge) dne);
((IMerge) dne).setQueryConcurrency(concurrency);
for (IDataNodeExecutor child : ((IMerge) dne).getSubNodes()) {
this.findMergeAndSetConcurrent(child, extraCmd);
}
}
if (dne instanceof IJoin) {
this.findMergeAndSetConcurrent(((IJoin) dne).getLeftNode(), extraCmd);
this.findMergeAndSetConcurrent(((IJoin) dne).getRightNode(), extraCmd);
}
if (dne instanceof IQuery && ((IQuery) dne).getSubQuery() != null) {
this.findMergeAndSetConcurrent(((IQuery) dne).getSubQuery(), extraCmd);
}
}
示例10: findEveryJoin
import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入依赖的package包/类
private IDataNodeExecutor findEveryJoin(IDataNodeExecutor dne, boolean isExpandLeft, boolean isExpandRight,
Map<String, Object> extraCmd) {
if (dne instanceof IMerge) {
List<IDataNodeExecutor> subs = ((IMerge) dne).getSubNodes();
for (int i = 0; i < subs.size(); i++) {
subs.set(i, this.findEveryJoin(subs.get(i), isExpandLeft, isExpandRight, extraCmd));
}
((IMerge) dne).setSubNodes(subs);
return dne;
} else if (dne instanceof IQuery) {
return dne;
} else if (dne instanceof IJoin) {
((IJoin) dne).setLeftNode((IQueryTree) this.findEveryJoin(((IJoin) dne).getLeftNode(),
isExpandLeft,
isExpandRight,
extraCmd));
((IJoin) dne).setRightNode((IQueryTree) this.findEveryJoin(((IJoin) dne).getRightNode(),
isExpandLeft,
isExpandRight,
extraCmd));
return this.processJoin((IJoin) dne, isExpandLeft, isExpandRight, extraCmd);
}
return dne;
}
示例11: fillRequestIDAndSubRequestIDFromRoot
import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入依赖的package包/类
public int fillRequestIDAndSubRequestIDFromRoot(IDataNodeExecutor qc, int subRequestID) {
qc.setSubRequestID(subRequestID);
qc.setRequestID(RequestIDGen.genRequestID());
qc.setRequestHostName(hostname);
if (qc instanceof IQuery && ((IQuery) qc).getSubQuery() != null) {
subRequestID = this.fillRequestIDAndSubRequestIDFromRoot(((IQuery) qc).getSubQuery(), subRequestID + 1);
} else if (qc instanceof IMerge) {
for (IDataNodeExecutor sub : ((IMerge) qc).getSubNode()) {
subRequestID = this.fillRequestIDAndSubRequestIDFromRoot(sub, subRequestID + 1);
}
} else if (qc instanceof IJoin) {
subRequestID = this.fillRequestIDAndSubRequestIDFromRoot(((IJoin) qc).getLeftNode(), subRequestID + 1);
subRequestID = this.fillRequestIDAndSubRequestIDFromRoot(((IJoin) qc).getRightNode(), subRequestID + 1);
}
return subRequestID;
}
示例12: TableNode
import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入依赖的package包/类
@Test
public void test_单表查询_复杂条件IN展开() {
TableNode table = new TableNode("TABLE1");
table.query("SCHOOL=1 AND (ID IN (4,3))");
extraCmd.put(ConnectionProperties.CHOOSE_INDEX_MERGE, true);
extraCmd.put(ConnectionProperties.EXPAND_IN, true);
extraCmd.put(ConnectionProperties.EXPAND_OR, true);
IQueryTree qc = (IQueryTree) optimizer.optimizeAndAssignment(table, null, extraCmd);
extraCmd.put(ConnectionProperties.CHOOSE_INDEX_MERGE, false);
extraCmd.put(ConnectionProperties.EXPAND_IN, false);
extraCmd.put(ConnectionProperties.EXPAND_OR, false);
Assert.assertTrue(qc instanceof IMerge);
Assert.assertTrue(((IMerge) qc).isUnion());// 是union查询
Assert.assertTrue(((IMerge) qc).getSubNodes().get(0) instanceof IQuery);
Assert.assertTrue(((IMerge) qc).getSubNodes().get(1) instanceof IQuery);
IQuery query1 = (IQuery) ((IMerge) qc).getSubNodes().get(0);
Assert.assertEquals("TABLE1.ID = 4", query1.getKeyFilter().toString());
Assert.assertEquals("TABLE1.SCHOOL = 1", query1.getValueFilter().toString());
IQuery query2 = (IQuery) ((IMerge) qc).getSubNodes().get(1);
Assert.assertEquals("TABLE1.ID = 3", query2.getKeyFilter().toString());
Assert.assertEquals("TABLE1.SCHOOL = 1", query2.getValueFilter().toString());
}
示例13: toDataNodeExecutor
import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入依赖的package包/类
public IQueryTree toDataNodeExecutor() throws QueryException {
IQuery query = ASTNodeFactory.getInstance().createQuery();
query.setAlias(this.getAlias());
query.setColumns(this.getColumnsSelected());
query.setConsistent(this.getConsistent());
query.setGroupBys(this.getGroupBys());
query.setKeyFilter(this.getKeyFilter());
query.setValueFilter(this.getResultFilter());
query.setLimitFrom(this.getLimitFrom());
query.setLimitTo(this.getLimitTo());
query.setLockModel(this.getLockModel());
query.setOrderBys(this.getOrderBys());
query.setSubQuery(this.getChild().toDataNodeExecutor());
query.executeOn(this.getDataNode());
query.setSql(this.getSql());
query.setIsSubQuery(this.isSubQuery());
return query;
}
示例14: IN
import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入依赖的package包/类
@Test
public void testQuery_子查询_in模式() throws SqlParserException {
String sql = "SELECT ID,NAME FROM TABLE1 WHERE NAME IN (SELECT NAME FROM TABLE2 WHERE TABLE2.NAME = TABLE1.NAME) AND ID IN (1,2)";
IQueryTree qc = (IQueryTree) optimizer.optimizeAndAssignment(sql, null, extraCmd, true);
Assert.assertTrue(qc instanceof IMerge);
IQuery query1 = (IQuery) ((IMerge) qc).getSubNodes().get(0);
IQuery query2 = (IQuery) ((IMerge) qc).getSubNodes().get(1);
IFunction subquery1 = (IFunction) ((List) query1.getSubqueryFilter().getArgs().get(1)).get(0);
IFunction subquery2 = (IFunction) ((List) query2.getSubqueryFilter().getArgs().get(1)).get(0);
Assert.assertTrue(subquery1.getArgs().get(0) instanceof IQuery);
IQuery merge1 = (IQuery) subquery1.getArgs().get(0);
IQuery merge2 = (IQuery) subquery2.getArgs().get(0);
Assert.assertEquals(merge1.getSubqueryOnFilterId(), merge2.getSubqueryOnFilterId());
}
示例15: EXISTS
import com.taobao.tddl.optimizer.core.plan.query.IQuery; //导入依赖的package包/类
@Test
public void testQuery_子查询_not_exist模式() throws SqlParserException {
String sql = "SELECT * FROM TABLE1 WHERE NOT EXISTS (SELECT ID FROM TABLE2 WHERE TABLE2.NAME = TABLE1.NAME)";
IQueryTree qc = (IQueryTree) optimizer.optimizeAndAssignment(sql, null, extraCmd, true);
Assert.assertTrue(qc instanceof IMerge);
IQuery query1 = (IQuery) ((IMerge) qc).getSubNodes().get(0);
IQuery query2 = (IQuery) ((IMerge) qc).getSubNodes().get(1);
IFunction subquery1 = (IFunction) query1.getSubqueryFilter().getArgs().get(0);
IFunction subquery2 = (IFunction) query2.getSubqueryFilter().getArgs().get(0);
Assert.assertTrue(subquery1 == subquery2);
Assert.assertEquals("NOT", subquery1.getFunctionName());
// 结构为: NOT(func) -> FILTER -> SUBQUERY_SCALAR(func) -> subquery
Assert.assertTrue((IQuery) ((IFunction) ((IBooleanFilter) subquery1.getArgs().get(0)).getArgs().get(0)).getArgs()
.get(0) instanceof IQuery);
}