Search in sources :

Example 1 with SQLArrayExpr

use of com.alibaba.druid.sql.ast.expr.SQLArrayExpr in project druid by alibaba.

the class OdpsExprParser method primaryRest.

public SQLExpr primaryRest(SQLExpr expr) {
    if (lexer.token() == Token.COLON) {
        lexer.nextToken();
        expr = dotRest(expr);
        return expr;
    }
    if (lexer.token() == Token.LBRACKET) {
        SQLArrayExpr array = new SQLArrayExpr();
        array.setExpr(expr);
        lexer.nextToken();
        this.exprList(array.getValues(), array);
        accept(Token.RBRACKET);
        return primaryRest(array);
    }
    return super.primaryRest(expr);
}
Also used : SQLArrayExpr(com.alibaba.druid.sql.ast.expr.SQLArrayExpr)

Example 2 with SQLArrayExpr

use of com.alibaba.druid.sql.ast.expr.SQLArrayExpr in project druid by alibaba.

the class PGExprParser method primary.

public SQLExpr primary() {
    if (lexer.token() == Token.ARRAY) {
        SQLArrayExpr array = new SQLArrayExpr();
        array.setExpr(new SQLIdentifierExpr(lexer.stringVal()));
        lexer.nextToken();
        accept(Token.LBRACKET);
        this.exprList(array.getValues(), array);
        accept(Token.RBRACKET);
        return primaryRest(array);
    } else if (lexer.token() == Token.POUND) {
        lexer.nextToken();
        if (lexer.token() == Token.LBRACE) {
            lexer.nextToken();
            String varName = lexer.stringVal();
            lexer.nextToken();
            accept(Token.RBRACE);
            SQLVariantRefExpr expr = new SQLVariantRefExpr("#{" + varName + "}");
            return primaryRest(expr);
        } else {
            SQLExpr value = this.primary();
            SQLUnaryExpr expr = new SQLUnaryExpr(SQLUnaryOperator.Pound, value);
            return primaryRest(expr);
        }
    }
    return super.primary();
}
Also used : SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLVariantRefExpr(com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr) SQLUnaryExpr(com.alibaba.druid.sql.ast.expr.SQLUnaryExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) SQLArrayExpr(com.alibaba.druid.sql.ast.expr.SQLArrayExpr)

Example 3 with SQLArrayExpr

use of com.alibaba.druid.sql.ast.expr.SQLArrayExpr in project druid by alibaba.

the class PGExprParser method primaryRest.

public SQLExpr primaryRest(SQLExpr expr) {
    if (lexer.token() == Token.COLONCOLON) {
        lexer.nextToken();
        SQLDataType dataType = this.parseDataType();
        PGTypeCastExpr castExpr = new PGTypeCastExpr();
        castExpr.setExpr(expr);
        castExpr.setDataType(dataType);
        return primaryRest(castExpr);
    }
    if (lexer.token() == Token.LBRACKET) {
        SQLArrayExpr array = new SQLArrayExpr();
        array.setExpr(expr);
        lexer.nextToken();
        this.exprList(array.getValues(), array);
        accept(Token.RBRACKET);
        return primaryRest(array);
    }
    if (expr.getClass() == SQLIdentifierExpr.class) {
        String ident = ((SQLIdentifierExpr) expr).getName();
        if ("TIMESTAMP".equalsIgnoreCase(ident)) {
            if (//
            lexer.token() != Token.LITERAL_ALIAS && //
            lexer.token() != Token.LITERAL_CHARS && lexer.token() != Token.WITH) {
                return new SQLIdentifierExpr("TIMESTAMP");
            }
            SQLTimestampExpr timestamp = new SQLTimestampExpr();
            if (lexer.token() == Token.WITH) {
                lexer.nextToken();
                acceptIdentifier("TIME");
                acceptIdentifier("ZONE");
                timestamp.setWithTimeZone(true);
            }
            String literal = lexer.stringVal();
            timestamp.setLiteral(literal);
            accept(Token.LITERAL_CHARS);
            if (identifierEquals("AT")) {
                lexer.nextToken();
                acceptIdentifier("TIME");
                acceptIdentifier("ZONE");
                String timezone = lexer.stringVal();
                timestamp.setTimeZone(timezone);
                accept(Token.LITERAL_CHARS);
            }
            return primaryRest(timestamp);
        } else if ("EXTRACT".equalsIgnoreCase(ident)) {
            accept(Token.LPAREN);
            PGExtractExpr extract = new PGExtractExpr();
            String fieldName = lexer.stringVal();
            PGDateField field = PGDateField.valueOf(fieldName.toUpperCase());
            lexer.nextToken();
            extract.setField(field);
            accept(Token.FROM);
            SQLExpr source = this.expr();
            extract.setSource(source);
            accept(Token.RPAREN);
            return primaryRest(extract);
        } else if ("POINT".equalsIgnoreCase(ident)) {
            SQLExpr value = this.primary();
            PGPointExpr point = new PGPointExpr();
            point.setValue(value);
            return primaryRest(point);
        } else if ("BOX".equalsIgnoreCase(ident)) {
            SQLExpr value = this.primary();
            PGBoxExpr box = new PGBoxExpr();
            box.setValue(value);
            return primaryRest(box);
        } else if ("macaddr".equalsIgnoreCase(ident)) {
            SQLExpr value = this.primary();
            PGMacAddrExpr macaddr = new PGMacAddrExpr();
            macaddr.setValue(value);
            return primaryRest(macaddr);
        } else if ("inet".equalsIgnoreCase(ident)) {
            SQLExpr value = this.primary();
            PGInetExpr inet = new PGInetExpr();
            inet.setValue(value);
            return primaryRest(inet);
        } else if ("cidr".equalsIgnoreCase(ident)) {
            SQLExpr value = this.primary();
            PGCidrExpr cidr = new PGCidrExpr();
            cidr.setValue(value);
            return primaryRest(cidr);
        } else if ("polygon".equalsIgnoreCase(ident)) {
            SQLExpr value = this.primary();
            PGPolygonExpr polygon = new PGPolygonExpr();
            polygon.setValue(value);
            return primaryRest(polygon);
        } else if ("circle".equalsIgnoreCase(ident)) {
            SQLExpr value = this.primary();
            PGCircleExpr circle = new PGCircleExpr();
            circle.setValue(value);
            return primaryRest(circle);
        } else if ("lseg".equalsIgnoreCase(ident)) {
            SQLExpr value = this.primary();
            PGLineSegmentsExpr lseg = new PGLineSegmentsExpr();
            lseg.setValue(value);
            return primaryRest(lseg);
        } else if (ident.equalsIgnoreCase("b") && lexer.token() == Token.LITERAL_CHARS) {
            String charValue = lexer.stringVal();
            lexer.nextToken();
            expr = new SQLBinaryExpr(charValue);
            return primaryRest(expr);
        }
    }
    return super.primaryRest(expr);
}
Also used : SQLBinaryExpr(com.alibaba.druid.sql.ast.expr.SQLBinaryExpr) SQLDataType(com.alibaba.druid.sql.ast.SQLDataType) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) PGPointExpr(com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGPointExpr) PGLineSegmentsExpr(com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGLineSegmentsExpr) PGMacAddrExpr(com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGMacAddrExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) PGInetExpr(com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGInetExpr) SQLTimestampExpr(com.alibaba.druid.sql.ast.expr.SQLTimestampExpr) PGTypeCastExpr(com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGTypeCastExpr) PGPolygonExpr(com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGPolygonExpr) PGCidrExpr(com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGCidrExpr) PGDateField(com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGDateField) PGCircleExpr(com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGCircleExpr) PGBoxExpr(com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGBoxExpr) SQLArrayExpr(com.alibaba.druid.sql.ast.expr.SQLArrayExpr) PGExtractExpr(com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGExtractExpr)

Aggregations

SQLArrayExpr (com.alibaba.druid.sql.ast.expr.SQLArrayExpr)3 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)2 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)2 SQLDataType (com.alibaba.druid.sql.ast.SQLDataType)1 SQLBinaryExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryExpr)1 SQLTimestampExpr (com.alibaba.druid.sql.ast.expr.SQLTimestampExpr)1 SQLUnaryExpr (com.alibaba.druid.sql.ast.expr.SQLUnaryExpr)1 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)1 PGBoxExpr (com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGBoxExpr)1 PGCidrExpr (com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGCidrExpr)1 PGCircleExpr (com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGCircleExpr)1 PGDateField (com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGDateField)1 PGExtractExpr (com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGExtractExpr)1 PGInetExpr (com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGInetExpr)1 PGLineSegmentsExpr (com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGLineSegmentsExpr)1 PGMacAddrExpr (com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGMacAddrExpr)1 PGPointExpr (com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGPointExpr)1 PGPolygonExpr (com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGPolygonExpr)1 PGTypeCastExpr (com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGTypeCastExpr)1