analytic clause

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@975 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-10-15 08:56:13 +00:00
parent f0c29c44a8
commit d13849f812
3 changed files with 24 additions and 6 deletions
@@ -436,12 +436,12 @@ public class OracleExprParser extends SQLExprParser {
if (lexer.stringVal().equalsIgnoreCase("PRECEDING")) {
lexer.nextToken();
windowing.setExpr(new SQLIdentifierExpr("UNBOUNDED PRECEDING"));
over.setWindowing(windowing);
} else {
throw new ParserException("syntax error");
}
throw new ParserException("syntax error");
}
throw new ParserException("TODO");
over.setWindowing(windowing);
}
}
@@ -135,9 +135,8 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
public boolean visit(OracleAnalytic x) {
boolean space = false;
if (x.getPartitionBy().size() > 0) {
print("PARTITION BY (");
print("PARTITION BY ");
printAndAccept(x.getPartitionBy(), ", ");
print(")");
space = true;
}
@@ -9,7 +9,7 @@ import junit.framework.TestCase;
public class OracleAnalyticTest extends TestCase {
public void test_isEmpty() throws Exception {
public void test_0() throws Exception {
String sql = "SELECT last_name, salary, STDDEV(salary) OVER (ORDER BY hire_date) \"StdDev\" " +
"FROM employees " +
"WHERE department_id = 30;";
@@ -27,4 +27,23 @@ public class OracleAnalyticTest extends TestCase {
System.out.println(text);
}
public void test_1() throws Exception {
String sql = "SELECT submit_date, num_votes, TRUNC(AVG(num_votes) OVER(PARTITION BY submit_date ORDER BY submit_date ROWS UNBOUNDED PRECEDING)) AVG_VOTE_PER_DAY\n" +
"FROM vote_count\n" +
"ORDER BY submit_date;\n";
String expect = "SELECT submit_date, num_votes, TRUNC(AVG(num_votes) OVER (PARTITION BY submit_date ORDER BY submit_date ROWS UNBOUNDED PRECEDING)) AS AVG_VOTE_PER_DAY\n" +
"FROM vote_count\n" +
"ORDER BY submit_date;\n";
OracleStatementParser parser = new OracleStatementParser(sql);
SQLSelectStatement stmt = (SQLSelectStatement) parser
.parseStatementList().get(0);
String text = TestUtils.outputOracle(stmt);
Assert.assertEquals(expect, text);
System.out.println(text);
}
}