use of com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem in project druid by alibaba.
the class SearchClause method clone.
public SearchClause clone() {
SearchClause x = new SearchClause();
x.type = type;
for (SQLSelectOrderByItem item : items) {
SQLSelectOrderByItem item2 = item.clone();
item2.setParent(x);
x.items.add(item2);
}
if (orderingColumn != null) {
x.setOrderingColumn(orderingColumn.clone());
}
return x;
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem in project druid by alibaba.
the class EqualTest_orderBy method test_exits.
public void test_exits() throws Exception {
String sql = "ORDER BY f1";
String sql_c = "ORDER BY f2";
SQLOrderBy exprA, exprB, exprC;
{
SQLExprParser parser = new SQLExprParser(sql);
exprA = (SQLOrderBy) parser.parseOrderBy();
}
{
SQLExprParser parser = new SQLExprParser(sql);
exprB = (SQLOrderBy) parser.parseOrderBy();
}
{
SQLExprParser parser = new SQLExprParser(sql_c);
exprC = (SQLOrderBy) parser.parseOrderBy();
}
Assert.assertEquals(exprA, exprB);
Assert.assertNotEquals(exprA, exprC);
Assert.assertTrue(exprA.equals(exprA));
Assert.assertFalse(exprA.equals(new Object()));
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
Assert.assertEquals(new SQLOrderBy(), new SQLOrderBy());
Assert.assertEquals(new SQLOrderBy().hashCode(), new SQLOrderBy().hashCode());
Assert.assertEquals(new SQLSelectOrderByItem(), new SQLSelectOrderByItem());
Assert.assertEquals(new SQLSelectOrderByItem().hashCode(), new SQLSelectOrderByItem().hashCode());
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem in project druid by alibaba.
the class HiveSelectTest_13_cluster_by method test_0.
public void test_0() throws Exception {
String sql = "select buyer_id,seller_id ,order_id,div_pay_amt,t1.dim_seller.member_id,t1.dim_buyer.member_id from LD_aly.fct_pay_ord_cn_di t1 cluster by buyer_id,seller_id \n";
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.HIVE);
SQLSelectStatement stmt = (SQLSelectStatement) statementList.get(0);
assertEquals("SELECT buyer_id, seller_id, order_id, div_pay_amt, t1.dim_seller.member_id\n" + "\t, t1.dim_buyer.member_id\n" + "FROM LD_aly.fct_pay_ord_cn_di t1\n" + "CLUSTER BY buyer_id, seller_id", stmt.toString());
assertEquals("SELECT buyer_id, seller_id, order_id, div_pay_amt, t1.dim_seller.member_id\n" + "\t, t1.dim_buyer.member_id\n" + "FROM LD_aly.fct_pay_ord_cn_di t1\n" + "CLUSTER BY buyer_id, seller_id", SQLUtils.toSQLString(stmt));
assertEquals(1, statementList.size());
for (SQLSelectOrderByItem item : stmt.getSelect().getQueryBlock().getClusterBy()) {
assertFalse(item.isSortBy());
assertFalse(item.isDistributeBy());
assertTrue(item.isClusterBy());
}
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.HIVE);
stmt.accept(visitor);
// System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
System.out.println("orderBy : " + visitor.getOrderByColumns());
System.out.println("groupBy : " + visitor.getGroupByColumns());
assertEquals(1, visitor.getTables().size());
assertEquals(5, visitor.getColumns().size());
assertEquals(0, visitor.getConditions().size());
assertEquals(0, visitor.getGroupByColumns().size());
assertTrue(visitor.containsColumn("LD_aly.fct_pay_ord_cn_di", "buyer_id"));
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem in project druid by alibaba.
the class SQLZOrderBy method accept0.
protected void accept0(SQLASTVisitor v) {
if (v.visit(this)) {
for (int i = 0; i < this.items.size(); i++) {
final SQLSelectOrderByItem item = this.items.get(i);
item.accept(v);
}
}
v.endVisit(this);
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem in project druid by alibaba.
the class SQLZOrderBy method addItem.
public void addItem(SQLExpr expr, SQLOrderingSpecification type) {
SQLSelectOrderByItem item = createItem();
item.setExpr(expr);
item.setType(type);
addItem(item);
}
Aggregations