use of com.alibaba.druid.sql.ast.statement.SQLUnionQuery in project druid by alibaba.
the class PagerUtils method clearOrderBy.
private static void clearOrderBy(SQLSelectQuery query) {
if (query instanceof SQLSelectQueryBlock) {
SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) query;
if (queryBlock instanceof MySqlSelectQueryBlock) {
MySqlSelectQueryBlock mysqlQueryBlock = (MySqlSelectQueryBlock) queryBlock;
if (mysqlQueryBlock.getOrderBy() != null) {
mysqlQueryBlock.setOrderBy(null);
}
} else if (queryBlock instanceof PGSelectQueryBlock) {
PGSelectQueryBlock pgQueryBlock = (PGSelectQueryBlock) queryBlock;
if (pgQueryBlock.getOrderBy() != null) {
pgQueryBlock.setOrderBy(null);
}
}
return;
}
if (query instanceof SQLUnionQuery) {
SQLUnionQuery union = (SQLUnionQuery) query;
if (union.getOrderBy() != null) {
union.setOrderBy(null);
}
clearOrderBy(union.getLeft());
clearOrderBy(union.getRight());
}
}
use of com.alibaba.druid.sql.ast.statement.SQLUnionQuery in project druid by alibaba.
the class MySqlSelectTest_138_ads_minus method test_0.
public void test_0() throws Exception {
String sql = "SELECT DISTINCT o_orderkey\n" + "FROM simple_query2.orders__0\n" + "WHERE o_orderdate > '1995-09-31'\n" + "UNION\n" + "SELECT DISTINCT o_orderkey\n" + "FROM simple_query2.orders__0\n" + "WHERE o_orderdate > '1994-09-31'\n" + "INTERSECT\n" + "SELECT DISTINCT o_orderkey\n" + "FROM simple_query2.orders__0\n" + "WHERE o_orderdate > '1996-09-31'\n" + "MINUS\n" + "SELECT DISTINCT o_orderkey\n" + "FROM simple_query2.orders__0\n" + "WHERE o_orderdate > '1994-09-31'\n";
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
SQLSelectStatement stmt = (SQLSelectStatement) statementList.get(0);
assertEquals(1, statementList.size());
assertEquals("SELECT DISTINCT o_orderkey\n" + "FROM simple_query2.orders__0\n" + "WHERE o_orderdate > '1995-09-31'\n" + "UNION\n" + "SELECT DISTINCT o_orderkey\n" + "FROM simple_query2.orders__0\n" + "WHERE o_orderdate > '1994-09-31'\n" + "INTERSECT\n" + "SELECT DISTINCT o_orderkey\n" + "FROM simple_query2.orders__0\n" + "WHERE o_orderdate > '1996-09-31'\n" + "MINUS\n" + "SELECT DISTINCT o_orderkey\n" + "FROM simple_query2.orders__0\n" + "WHERE o_orderdate > '1994-09-31'", stmt.toString());
SQLUnionQuery q1 = (SQLUnionQuery) stmt.getSelect().getQuery();
assertTrue(q1.getRight() instanceof SQLSelectQueryBlock);
SQLUnionQuery q2 = (SQLUnionQuery) q1.getLeft();
assertTrue(q2.getRight() instanceof SQLSelectQueryBlock);
SQLUnionQuery q3 = (SQLUnionQuery) q2.getLeft();
assertTrue(q3.getRight() instanceof SQLSelectQueryBlock);
assertTrue(q3.getLeft() instanceof SQLSelectQueryBlock);
}
use of com.alibaba.druid.sql.ast.statement.SQLUnionQuery in project druid by alibaba.
the class MySqlSelectTest_174_union method test_0.
public void test_0() throws Exception {
String sql = "select id from a where a.id < 10 union select id from b where a.id < 10 limit 10";
//
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
SQLSelectStatement stmt = (SQLSelectStatement) statementList.get(0);
assertEquals(1, statementList.size());
assertEquals("SELECT id\n" + "FROM a\n" + "WHERE a.id < 10\n" + "UNION\n" + "SELECT id\n" + "FROM b\n" + "WHERE a.id < 10\n" + "LIMIT 10", stmt.toString());
SQLUnionQuery union = (SQLUnionQuery) stmt.getSelect().getQuery();
SQLLimit limit = union.getLimit();
assertNotNull(limit);
}
use of com.alibaba.druid.sql.ast.statement.SQLUnionQuery in project druid by alibaba.
the class MySqlSelectTest_99_union_order method test_0.
public void test_0() throws Exception {
String sql = "select id as id1 from ll union select id as id1 from rr order by id desc;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
assertEquals(1, statementList.size());
SQLSelectStatement stmt = (SQLSelectStatement) statementList.get(0);
assertEquals("SELECT id AS id1\n" + "FROM ll\n" + "UNION\n" + "SELECT id AS id1\n" + "FROM rr\n" + "ORDER BY id DESC;", stmt.toString());
SQLUnionQuery union = (SQLUnionQuery) stmt.getSelect().getQuery();
assertNotNull(union.getOrderBy());
// SQLCommentHint hint = (SQLCommentHint) stmt.getSelect().getHints().get(0);
// assertEquals("+ xxx ", hint.getText());
}
use of com.alibaba.druid.sql.ast.statement.SQLUnionQuery in project druid by alibaba.
the class OracleSelectTest116 method test_0.
public void test_0() throws Exception {
String sql = "\n" + "select a from a1 union select a from a2 union select a from a3 union select a from a4";
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ORACLE);
assertEquals(1, statementList.size());
SQLSelectStatement stmt = (SQLSelectStatement) statementList.get(0);
System.out.println(stmt);
SQLUnionQuery union = (SQLUnionQuery) stmt.getSelect().getQuery();
assertTrue(union.getLeft() instanceof SQLUnionQuery);
assertFalse(union.getRight() instanceof SQLUnionQuery);
assertTrue(((SQLUnionQuery) union.getLeft()).getLeft() instanceof SQLUnionQuery);
assertFalse(((SQLUnionQuery) union.getLeft()).getRight() instanceof SQLUnionQuery);
assertEquals("SELECT a\n" + "FROM a1\n" + "UNION\n" + "SELECT a\n" + "FROM a2\n" + "UNION\n" + "SELECT a\n" + "FROM a3\n" + "UNION\n" + "SELECT a\n" + "FROM a4", stmt.toString());
}
Aggregations