Search in sources :

Example 16 with SQLSelectOrderByItem

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;
}
Also used : SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)

Example 17 with SQLSelectOrderByItem

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());
}
Also used : SQLOrderBy(com.alibaba.druid.sql.ast.SQLOrderBy) SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem) SQLExprParser(com.alibaba.druid.sql.parser.SQLExprParser)

Example 18 with SQLSelectOrderByItem

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"));
}
Also used : SQLSelectStatement(com.alibaba.druid.sql.ast.statement.SQLSelectStatement) SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SchemaStatVisitor(com.alibaba.druid.sql.visitor.SchemaStatVisitor)

Example 19 with SQLSelectOrderByItem

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);
}
Also used : SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)

Example 20 with SQLSelectOrderByItem

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);
}
Also used : SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)

Aggregations

SQLSelectOrderByItem (com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)34 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)11 SQLOrderBy (com.alibaba.druid.sql.ast.SQLOrderBy)5 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)4 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)3 SQLListExpr (com.alibaba.druid.sql.ast.expr.SQLListExpr)3 SQLNullExpr (com.alibaba.druid.sql.ast.expr.SQLNullExpr)3 SQLColumnDefinition (com.alibaba.druid.sql.ast.statement.SQLColumnDefinition)3 SQLConstraint (com.alibaba.druid.sql.ast.statement.SQLConstraint)3 SQLSelectGroupByClause (com.alibaba.druid.sql.ast.statement.SQLSelectGroupByClause)3 Order (com.actiontech.dble.plan.Order)2 SQLExprImpl (com.alibaba.druid.sql.ast.SQLExprImpl)2 SQLName (com.alibaba.druid.sql.ast.SQLName)2 SQLObject (com.alibaba.druid.sql.ast.SQLObject)2 SQLOrderingSpecification (com.alibaba.druid.sql.ast.SQLOrderingSpecification)2 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)2 SQLInSubQueryExpr (com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr)2 SQLQueryExpr (com.alibaba.druid.sql.ast.expr.SQLQueryExpr)2 SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)2 SQLTableElement (com.alibaba.druid.sql.ast.statement.SQLTableElement)2