use of com.alibaba.druid.sql.ast.expr.SQLAggregateExpr in project druid by alibaba.
the class WallVisitorUtils method isSimpleCountTableSource.
public static boolean isSimpleCountTableSource(WallVisitor visitor, SQLSelect select) {
SQLSelectQuery query = select.getQuery();
if (query instanceof SQLSelectQueryBlock) {
SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) query;
boolean allawTrueWhere = false;
if (queryBlock.getWhere() == null) {
allawTrueWhere = true;
} else {
Object whereValue = getValue(visitor, queryBlock.getWhere());
if (whereValue == Boolean.TRUE) {
allawTrueWhere = true;
} else if (whereValue == Boolean.FALSE) {
return false;
}
}
boolean simpleCount = false;
if (queryBlock.getSelectList().size() == 1) {
SQLExpr selectItemExpr = queryBlock.getSelectList().get(0).getExpr();
if (selectItemExpr instanceof SQLAggregateExpr) {
if (((SQLAggregateExpr) selectItemExpr).getMethodName().equalsIgnoreCase("COUNT")) {
simpleCount = true;
}
}
}
if (allawTrueWhere && simpleCount) {
return true;
}
}
return false;
}
use of com.alibaba.druid.sql.ast.expr.SQLAggregateExpr in project druid by alibaba.
the class EqualTest_aggreate_over method test_exits.
public void test_exits() throws Exception {
String sql = "count(*) OVER (ORDER BY f1)";
String sql_c = "count(id) OVER (ORDER BY f2)";
SQLAggregateExpr exprA, exprB, exprC;
{
SQLExprParser parser = new SQLExprParser(sql);
exprA = (SQLAggregateExpr) parser.expr();
}
{
SQLExprParser parser = new SQLExprParser(sql);
exprB = (SQLAggregateExpr) parser.expr();
}
{
SQLExprParser parser = new SQLExprParser(sql_c);
exprC = (SQLAggregateExpr) parser.expr();
}
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 SQLAggregateExpr(null), new SQLAggregateExpr(null));
Assert.assertEquals(new SQLAggregateExpr(null).hashCode(), new SQLAggregateExpr(null).hashCode());
}
Aggregations