本文整理匯總了Java中com.taobao.tddl.optimizer.core.ast.query.TableNode.select方法的典型用法代碼示例。如果您正苦於以下問題:Java TableNode.select方法的具體用法?Java TableNode.select怎麽用?Java TableNode.select使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.taobao.tddl.optimizer.core.ast.query.TableNode
的用法示例。
在下文中一共展示了TableNode.select方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testDistinct
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //導入方法依賴的package包/類
@Test
public void testDistinct() throws SqlParserException {
String sql = "SELECT COUNT(DISTINCT ID) FROM TABLE1";
QueryTreeNode qn = query(sql);
TableNode table1 = new TableNode("TABLE1");
IColumn c = ASTNodeFactory.getInstance().createColumn();
c.setColumnName("ID");
c.setDistinct(true);
IFunction f = ASTNodeFactory.getInstance().createFunction();
f.setFunctionName("COUNT");
f.setColumnName("COUNT(DISTINCT ID)");
List args = new ArrayList();
args.add(c);
f.setArgs(args);
qn.build();
QueryTreeNode qnExpected = table1.select(f);
qnExpected.build();
assertEquals(qn, qnExpected);
}
示例2: TableNode
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //導入方法依賴的package包/類
@Test
public void test_單表查詢_存在聚合函數_limit不下推() {
TableNode table = new TableNode("TABLE1");
table.limit(10, 20);
table.select("count(distinct id)");
QueryTreeNode qn = table;
IQueryTree qc = (IQueryTree) optimizer.optimizeAndAssignment(qn, null, extraCmd);
Assert.assertTrue(qc instanceof IMerge);
Assert.assertEquals(QUERY_CONCURRENCY.GROUP_CONCURRENT, ((IMerge) qc).getQueryConcurrency());// 並行
Assert.assertEquals(10L, qc.getLimitFrom());
Assert.assertEquals(20L, qc.getLimitTo());
IDataNodeExecutor dne = ((IMerge) qc).getSubNodes().get(0);
Assert.assertTrue(dne instanceof IQuery);
IQuery query = (IQuery) dne;
Assert.assertEquals(null, query.getLimitFrom());
Assert.assertEquals(null, query.getLimitTo());
}
示例3: TableNode
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //導入方法依賴的package包/類
@Test
public void test_TableNode轉化為index到kv_複雜條件查詢() {
TableNode table = new TableNode("TABLE1");
table.select("(ID + NAME) AS NEWNAME"); // 設置為函數
table.query("NAME = 1 AND ID > 3 AND SCHOOL = 1");
table.orderBy("SCHOOL", false);// 增加一個隱藏列
table.groupBy("NEWNAME");
build(table);
QueryTreeNode qn = table.convertToJoinIfNeed();
Assert.assertTrue(qn instanceof JoinNode);
Assert.assertEquals("TABLE1._NAME.NAME = 1", ((JoinNode) qn).getLeftNode().getKeyFilter().toString());
Assert.assertEquals("TABLE1._NAME.ID > 3", ((JoinNode) qn).getLeftNode().getResultFilter().toString());
Assert.assertEquals("TABLE1.SCHOOL = 1", ((JoinNode) qn).getRightNode().getResultFilter().toString());
Assert.assertEquals("TABLE1._NAME.ID = TABLE1.ID", ((JoinNode) qn).getJoinFilter().get(0).toString());
}
示例4: testDistinct
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //導入方法依賴的package包/類
@Test
public void testDistinct() throws SqlParserException, QueryException {
String sql = "SELECT COUNT(DISTINCT ID) FROM TABLE1";
QueryTreeNode qn = query(sql);
TableNode table1 = new TableNode("TABLE1");
IColumn c = ASTNodeFactory.getInstance().createColumn();
c.setColumnName("ID");
c.setDistinct(true);
IFunction f = ASTNodeFactory.getInstance().createFunction();
f.setFunctionName("COUNT");
f.setColumnName("COUNT(DISTINCT ID)");
List args = new ArrayList();
args.add(c);
f.setArgs(args);
qn.build();
QueryTreeNode qnExpected = table1.select(f);
qnExpected.build();
assertEquals(qn, qnExpected);
}
示例5: query
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //導入方法依賴的package包/類
@Test
public void testFunction_提前計算() throws SqlParserException {
String sql = "SELECT 1+1 FROM TABLE1";
QueryTreeNode qn = query(sql);
qn.build();
TableNode table1 = new TableNode("TABLE1");
QueryTreeNode qnExpected = table1.select("2");
qnExpected.build();
assertEquals(qn, qnExpected);
}
示例6: query
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //導入方法依賴的package包/類
@Test
public void testFunction_提前計算() throws SqlParserException, QueryException {
String sql = "SELECT 1+1 FROM TABLE1";
QueryTreeNode qn = query(sql);
qn.build();
TableNode table1 = new TableNode("TABLE1");
QueryTreeNode qnExpected = table1.select("2");
qnExpected.build();
assertEquals(qn, qnExpected);
}
示例7: COUNT
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //導入方法依賴的package包/類
@Test
public void testWhere_字段多級子查詢() throws QueryException, SqlParserException {
String subSql = "SELECT B.* FROM TABLE2 B WHERE B.ID=1 GROUP BY SCHOOL HAVING COUNT(*) > 1 ORDER BY ID DESC LIMIT 1";
String sql = "SELECT NAME FROM TABLE1 WHERE NAME=(SELECT C.NAME FROM (" + subSql + ") C )";
QueryTreeNode qn = query(sql);
qn.build();
TableNode table1 = new TableNode("TABLE1");
QueryTreeNode qnExpected = table1.select("NAME");
TableNode table2 = new TableNode("TABLE2");
table2.alias("C").setSubAlias("B").select("*").query("B.ID=1");
table2.groupBy("SCHOOL");
table2.having("COUNT(*) > 1");
table2.orderBy("ID", false);
table2.limit(0, 1);
table2.setSubQuery(true);
QueryNode subQuery = new QueryNode(table2);
subQuery.select("C.NAME");
IColumn column = ASTNodeFactory.getInstance().createColumn().setColumnName("NAME");
IBooleanFilter filter = ASTNodeFactory.getInstance()
.createBooleanFilter()
.setColumn(column)
.setValue(subQuery)
.setOperation(OPERATION.EQ);
table1.query(filter);
qnExpected.build();
assertEquals(qn, qnExpected);
}