Search in sources :

Example 1 with OdpsUDTFSQLSelectItem

use of com.alibaba.druid.sql.dialect.odps.ast.OdpsUDTFSQLSelectItem in project druid by alibaba.

the class OdpsExprParser method parseSelectItem.

@Override
public SQLSelectItem parseSelectItem() {
    SQLExpr expr;
    if (lexer.token() == Token.IDENTIFIER) {
        expr = new SQLIdentifierExpr(lexer.stringVal());
        lexer.nextTokenComma();
        if (lexer.token() != Token.COMMA) {
            expr = this.primaryRest(expr);
            expr = this.exprRest(expr);
        }
    } else {
        expr = expr();
    }
    String alias = null;
    if (lexer.token() == Token.AS) {
        lexer.nextToken();
        if (lexer.token() == Token.LPAREN) {
            lexer.nextToken();
            OdpsUDTFSQLSelectItem selectItem = new OdpsUDTFSQLSelectItem();
            selectItem.setExpr(expr);
            for (; ; ) {
                alias = lexer.stringVal();
                lexer.nextToken();
                selectItem.getAliasList().add(alias);
                if (lexer.token() == Token.COMMA) {
                    lexer.nextToken();
                    continue;
                }
                break;
            }
            accept(Token.RPAREN);
            return selectItem;
        } else {
            alias = alias();
        }
    } else {
        alias = as();
    }
    SQLSelectItem item = new SQLSelectItem(expr, alias);
    if (lexer.hasComment() && lexer.isKeepComments()) {
        item.addAfterComment(lexer.readAndResetComments());
    }
    return item;
}
Also used : OdpsUDTFSQLSelectItem(com.alibaba.druid.sql.dialect.odps.ast.OdpsUDTFSQLSelectItem) OdpsUDTFSQLSelectItem(com.alibaba.druid.sql.dialect.odps.ast.OdpsUDTFSQLSelectItem) SQLSelectItem(com.alibaba.druid.sql.ast.statement.SQLSelectItem) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Aggregations

SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)1 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)1 OdpsUDTFSQLSelectItem (com.alibaba.druid.sql.dialect.odps.ast.OdpsUDTFSQLSelectItem)1