use of com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleAnalyticWindowing in project druid by alibaba.
the class OracleExprParser method parseAggregateExpr.
protected SQLAggregateExpr parseAggregateExpr(String methodName) {
methodName = methodName.toUpperCase();
SQLAggregateExpr aggregateExpr;
if (lexer.token() == Token.UNIQUE) {
aggregateExpr = new SQLAggregateExpr(methodName, SQLAggregateOption.UNIQUE);
lexer.nextToken();
} else if (lexer.token() == (Token.ALL)) {
aggregateExpr = new SQLAggregateExpr(methodName, SQLAggregateOption.ALL);
lexer.nextToken();
} else if (lexer.token() == (Token.DISTINCT)) {
aggregateExpr = new SQLAggregateExpr(methodName, SQLAggregateOption.DISTINCT);
lexer.nextToken();
} else {
aggregateExpr = new SQLAggregateExpr(methodName);
}
exprList(aggregateExpr.getArguments(), aggregateExpr);
if (lexer.stringVal().equalsIgnoreCase("IGNORE")) {
lexer.nextToken();
identifierEquals("NULLS");
aggregateExpr.setIgnoreNulls(true);
}
accept(Token.RPAREN);
if (identifierEquals("WITHIN")) {
lexer.nextToken();
accept(Token.GROUP);
accept(Token.LPAREN);
SQLOrderBy withinGroup = this.parseOrderBy();
aggregateExpr.setWithinGroup(withinGroup);
accept(Token.RPAREN);
}
if (lexer.token() == Token.KEEP) {
lexer.nextToken();
SQLKeep keep = new SQLKeep();
accept(Token.LPAREN);
acceptIdentifier("DENSE_RANK");
if (identifierEquals("FIRST")) {
lexer.nextToken();
keep.setDenseRank(DenseRank.FIRST);
} else {
acceptIdentifier("LAST");
keep.setDenseRank(DenseRank.LAST);
}
SQLOrderBy orderBy = this.parseOrderBy();
keep.setOrderBy(orderBy);
aggregateExpr.setKeep(keep);
accept(Token.RPAREN);
}
if (lexer.token() == Token.OVER) {
OracleAnalytic over = new OracleAnalytic();
lexer.nextToken();
accept(Token.LPAREN);
if (identifierEquals("PARTITION")) {
lexer.nextToken();
accept(Token.BY);
if (lexer.token() == (Token.LPAREN)) {
lexer.nextToken();
exprList(over.getPartitionBy(), over);
accept(Token.RPAREN);
} else {
exprList(over.getPartitionBy(), over);
}
}
over.setOrderBy(parseOrderBy());
if (over.getOrderBy() != null) {
OracleAnalyticWindowing windowing = null;
if (lexer.stringVal().equalsIgnoreCase("ROWS")) {
lexer.nextToken();
windowing = new OracleAnalyticWindowing();
windowing.setType(OracleAnalyticWindowing.Type.ROWS);
} else if (lexer.stringVal().equalsIgnoreCase("RANGE")) {
lexer.nextToken();
windowing = new OracleAnalyticWindowing();
windowing.setType(OracleAnalyticWindowing.Type.RANGE);
}
if (windowing != null) {
if (lexer.stringVal().equalsIgnoreCase("CURRENT")) {
lexer.nextToken();
if (lexer.stringVal().equalsIgnoreCase("ROW")) {
lexer.nextToken();
windowing.setExpr(new SQLIdentifierExpr("CURRENT ROW"));
over.setWindowing(windowing);
}
throw new ParserException("syntax error");
}
if (lexer.stringVal().equalsIgnoreCase("UNBOUNDED")) {
lexer.nextToken();
if (lexer.stringVal().equalsIgnoreCase("PRECEDING")) {
lexer.nextToken();
windowing.setExpr(new SQLIdentifierExpr("UNBOUNDED PRECEDING"));
} else {
throw new ParserException("syntax error");
}
}
over.setWindowing(windowing);
}
}
accept(Token.RPAREN);
aggregateExpr.setOver(over);
}
return aggregateExpr;
}
use of com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleAnalyticWindowing in project druid by alibaba.
the class OracleASTVisitorAdapterTest method test_adapter.
public void test_adapter() throws Exception {
OracleASTVisitorAdapter adapter = new OracleASTVisitorAdapter();
new OraclePLSQLCommitStatement().accept(adapter);
new OracleAnalytic().accept(adapter);
new OracleAnalyticWindowing().accept(adapter);
new SQLDateExpr().accept(adapter);
new OracleDbLinkExpr().accept(adapter);
new OracleSelectForUpdate().accept(adapter);
new OracleSelectHierachicalQueryClause().accept(adapter);
new OracleSelectPivot.Item().accept(adapter);
new OracleSelectPivot().accept(adapter);
new CheckOption().accept(adapter);
new ReadOnly().accept(adapter);
new OracleSelectUnPivot().accept(adapter);
new SQLTimestampExpr().accept(adapter);
new PartitionExtensionClause().accept(adapter);
new VersionsFlashbackQueryClause().accept(adapter);
new VersionsFlashbackQueryClause().accept(adapter);
new AsOfFlashbackQueryClause().accept(adapter);
new SQLGroupingSetExpr().accept(adapter);
new OracleWithSubqueryEntry().accept(adapter);
new OracleFileSpecification().accept(adapter);
new OracleAlterTablespaceAddDataFile().accept(adapter);
new OracleAlterTablespaceStatement().accept(adapter);
new SQLCreateSequenceStatement().accept(adapter);
new SQLLoopStatement().accept(adapter);
new OracleIntervalExpr().accept(adapter);
new OracleDeleteStatement().accept(adapter);
new OracleUpdateStatement().accept(adapter);
new SampleClause().accept(adapter);
new OracleSelectTableReference().accept(adapter);
new SearchClause().accept(adapter);
new CycleClause().accept(adapter);
new OracleBinaryFloatExpr().accept(adapter);
new OracleBinaryDoubleExpr().accept(adapter);
new OracleCursorExpr().accept(adapter);
new OracleIsSetExpr().accept(adapter);
new ReturnRowsClause().accept(adapter);
new ModelClause().accept(adapter);
new MainModelClause().accept(adapter);
new ModelColumnClause().accept(adapter);
new QueryPartitionClause().accept(adapter);
new ModelColumn().accept(adapter);
new ModelRulesClause().accept(adapter);
new CellAssignmentItem().accept(adapter);
new CellAssignment().accept(adapter);
new SQLMergeStatement().accept(adapter);
new MergeUpdateClause().accept(adapter);
new MergeInsertClause().accept(adapter);
new SQLErrorLoggingClause().accept(adapter);
new OracleReturningClause().accept(adapter);
new OracleInsertStatement().accept(adapter);
new InsertIntoClause().accept(adapter);
new OracleMultiInsertStatement().accept(adapter);
new ConditionalInsertClause().accept(adapter);
new ConditionalInsertClauseItem().accept(adapter);
new OracleSelectQueryBlock().accept(adapter);
new SQLBlockStatement().accept(adapter);
new OracleLockTableStatement().accept(adapter);
new OracleAlterSessionStatement().accept(adapter);
new OracleExprStatement().accept(adapter);
new OracleDatetimeExpr().accept(adapter);
new OracleExceptionStatement().accept(adapter);
new OracleExceptionStatement.Item().accept(adapter);
new OracleArgumentExpr().accept(adapter);
new OracleSetTransactionStatement().accept(adapter);
new SQLDropSequenceStatement().accept(adapter);
new OracleDataTypeIntervalDay().accept(adapter);
new OracleDataTypeIntervalYear().accept(adapter);
new OracleDataTypeTimestamp().accept(adapter);
new OracleDropDbLinkStatement().accept(adapter);
new OracleCreateDatabaseDbLinkStatement().accept(adapter);
new SQLCreateProcedureStatement().accept(adapter);
new OracleSavePointStatement().accept(adapter);
new SQLFetchStatement().accept(adapter);
new OracleExitStatement().accept(adapter);
new OracleExplainStatement().accept(adapter);
new OracleAlterProcedureStatement().accept(adapter);
new OracleAlterTableDropPartition().accept(adapter);
new OracleAlterTableTruncatePartition().accept(adapter);
new OracleAlterTableSplitPartition.TableSpaceItem().accept(adapter);
new OracleAlterTableSplitPartition.UpdateIndexesClause().accept(adapter);
new OracleAlterTableSplitPartition.NestedTablePartitionSpec().accept(adapter);
new OracleAlterTableSplitPartition().accept(adapter);
new OracleAlterTableModify().accept(adapter);
new OracleCreateIndexStatement().accept(adapter);
new OracleAlterIndexStatement().accept(adapter);
new OracleForStatement().accept(adapter);
new OracleAlterIndexStatement().accept(adapter);
new OracleRangeExpr().accept(adapter);
new OraclePrimaryKey().accept(adapter);
new OracleCreateTableStatement().accept(adapter);
new SQLAlterTableRename().accept(adapter);
new OracleStorageClause().accept(adapter);
new OracleGotoStatement().accept(adapter);
new OracleLabelStatement().accept(adapter);
new SQLParameter().accept(adapter);
new OracleCommitStatement().accept(adapter);
new OracleAlterTriggerStatement().accept(adapter);
new OracleAlterSynonymStatement().accept(adapter);
new AsOfSnapshotClause().accept(adapter);
new OracleAlterViewStatement().accept(adapter);
new OracleAlterTableMoveTablespace().accept(adapter);
new OracleSizeExpr().accept(adapter);
}
Aggregations