mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
sql parser direct support OVER
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
|
||||
public class OverTest extends TestCase {
|
||||
|
||||
public void test_over() throws Exception {
|
||||
String sql = "SELECT SalesOrderID, ProductID, OrderQty" + //
|
||||
" ,SUM(OrderQty) OVER(PARTITION BY SalesOrderID) AS 'Total'" + //
|
||||
" ,AVG(OrderQty) OVER(PARTITION BY SalesOrderID) AS 'Avg'" + //
|
||||
" ,COUNT(OrderQty) OVER(PARTITION BY SalesOrderID) AS 'Count'" + //
|
||||
" ,MIN(OrderQty) OVER(PARTITION BY SalesOrderID) AS 'Min'" + //
|
||||
" ,MAX(OrderQty) OVER(PARTITION BY SalesOrderID) AS 'Max' " + //
|
||||
"FROM Sales.SalesOrderDetail " + //
|
||||
"WHERE SalesOrderID IN(43659,43664);";
|
||||
|
||||
SQLStatementParser parser = new SQLStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement statemen = statementList.get(0);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = new SchemaStatVisitor();
|
||||
statemen.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
|
||||
Assert.assertEquals(3, visitor.getColumns().size());
|
||||
Assert.assertEquals(1, visitor.getTables().size());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user