Java Code Examples for com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr#addParameter()

The following examples show how to use com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr#addParameter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemDecimalTypeConvert.java    From dble with GNU General Public License v2.0 6 votes vote down vote up
@Override
public SQLExpr toExpression() {
    SQLMethodInvokeExpr method = new SQLMethodInvokeExpr();
    method.setMethodName("CONVERT");
    method.addParameter(args.get(0).toExpression());
    if (precision >= 0 || dec > 0) {
        SQLMethodInvokeExpr dataType = new SQLMethodInvokeExpr();
        dataType.setMethodName("DECIMAL");
        if (precision >= 0) {
            dataType.addParameter(new SQLIntegerExpr(precision));
        }
        if (dec > 0) {
            dataType.addParameter(new SQLIntegerExpr(dec));
        }
        method.addParameter(dataType);
    } else {
        method.addParameter(new SQLIdentifierExpr("DECIMAL"));
    }
    return method;
}
 
Example 2
Source File: WhereParser.java    From elasticsearch-sql with Apache License 2.0 6 votes vote down vote up
private boolean explanSpecialCondWithBothSidesAreLiterals(SQLBinaryOpExpr bExpr, Where where) throws SqlParseException {
    if ((bExpr.getLeft() instanceof SQLNumericLiteralExpr || bExpr.getLeft() instanceof SQLCharExpr) &&
            (bExpr.getRight() instanceof SQLNumericLiteralExpr || bExpr.getRight() instanceof SQLCharExpr)
            ) {
        SQLMethodInvokeExpr sqlMethodInvokeExpr = new SQLMethodInvokeExpr("script", null);
        String operator = bExpr.getOperator().getName();
        if (operator.equals("=")) {
            operator = "==";
        }
        sqlMethodInvokeExpr.addParameter(
                new SQLCharExpr(Util.expr2Object(bExpr.getLeft(), "'") +
                        " " + operator + " " +
                        Util.expr2Object(bExpr.getRight(), "'"))
        );

        explanCond("AND", sqlMethodInvokeExpr, where);
        return true;
    }
    return false;
}
 
Example 3
Source File: WhereParser.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
private boolean explanSpecialCondWithBothSidesAreProperty(SQLBinaryOpExpr bExpr, Where where) throws SqlParseException {
    //join is not support
    if ((bExpr.getLeft() instanceof SQLPropertyExpr || bExpr.getLeft() instanceof SQLIdentifierExpr) &&
            (bExpr.getRight() instanceof SQLPropertyExpr || bExpr.getRight() instanceof SQLIdentifierExpr) &&
            Sets.newHashSet("=", "<", ">", ">=", "<=","<>","!=").contains(bExpr.getOperator().getName()) &&
            !Util.isFromJoinOrUnionTable(bExpr)

            ) {
        SQLMethodInvokeExpr sqlMethodInvokeExpr = new SQLMethodInvokeExpr("script", null);
        String operator = bExpr.getOperator().getName();
        if (operator.equals("=")) {
            operator = "==";
        }else
        if (operator.equals("<>")) {
            operator = "!=";
        }

        String leftProperty = Util.expr2Object(bExpr.getLeft()).toString();
        String rightProperty = Util.expr2Object(bExpr.getRight()).toString();
        if (leftProperty.split("\\.").length > 1) {

            leftProperty = leftProperty.substring(leftProperty.split("\\.")[0].length() + 1);
        }

        if (rightProperty.split("\\.").length > 1) {
            rightProperty = rightProperty.substring(rightProperty.split("\\.")[0].length() + 1);
        }

        sqlMethodInvokeExpr.addParameter(new SQLCharExpr(
                "doc['" + leftProperty + "'].value " +
                        operator +
                        " doc['" + rightProperty + "'].value"));


        explanCond("AND", sqlMethodInvokeExpr, where);
        return true;
    }
    return false;
}
 
Example 4
Source File: ItemSumAnd.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SQLExpr toExpression() {
    SQLMethodInvokeExpr method = new SQLMethodInvokeExpr(funcName());
    for (Item arg : args) {
        method.addParameter(arg.toExpression());
    }
    return method;
}
 
Example 5
Source File: ItemSumStd.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SQLExpr toExpression() {
    SQLMethodInvokeExpr method = new SQLMethodInvokeExpr(funcName());
    for (Item arg : args) {
        method.addParameter(arg.toExpression());
    }
    return method;
}
 
Example 6
Source File: ItemSumVariance.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SQLExpr toExpression() {
    SQLMethodInvokeExpr method = new SQLMethodInvokeExpr(funcName());
    for (Item arg : args) {
        method.addParameter(arg.toExpression());
    }
    return method;
}
 
Example 7
Source File: ElasticSqlExprParser.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
protected SQLExpr parsePosition() {

        SQLExpr subStr = this.primary();
        accept(Token.IN);
        SQLExpr str = this.expr();
        accept(Token.RPAREN);

        SQLMethodInvokeExpr locate = new SQLMethodInvokeExpr("LOCATE");
        locate.addParameter(subStr);
        locate.addParameter(str);

        return primaryRest(locate);
    }
 
Example 8
Source File: ItemFuncOrd.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SQLExpr toExpression() {
    SQLMethodInvokeExpr method = new SQLMethodInvokeExpr(funcName());
    for (Item arg : args) {
        method.addParameter(arg.toExpression());
    }
    return method;
}
 
Example 9
Source File: ItemDateAddInterval.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SQLExpr toExpression() {
    String funcName = funcName();
    if (dateSubInterval) {
        funcName = "date_sub";
    }
    SQLMethodInvokeExpr method = new SQLMethodInvokeExpr(funcName);
    method.addParameter(args.get(0).toExpression());
    SQLIntervalExpr intervalExpr = new SQLIntervalExpr();
    intervalExpr.setValue(args.get(1).toExpression());
    intervalExpr.setUnit(intType);
    method.addParameter(intervalExpr);
    return method;
}
 
Example 10
Source File: ItemFuncUnknown.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SQLExpr toExpression() {
    SQLMethodInvokeExpr method = new SQLMethodInvokeExpr(funcName);
    for (Item arg : args) {
        method.addParameter(arg.toExpression());
    }
    return method;
}
 
Example 11
Source File: ItemNCharTypeConvert.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SQLExpr toExpression() {
    SQLMethodInvokeExpr method = new SQLMethodInvokeExpr();
    method.setMethodName("CONVERT");
    method.addParameter(args.get(0).toExpression());
    if (castLength >= 0) {
        SQLMethodInvokeExpr dataType = new SQLMethodInvokeExpr();
        dataType.setMethodName("NCHAR");
        dataType.addParameter(new SQLIntegerExpr(castLength));
        method.addParameter(dataType);
    } else {
        method.addParameter(new SQLIdentifierExpr("NCHAR"));
    }
    return method;
}
 
Example 12
Source File: ItemFuncTimestampDiff.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SQLExpr toExpression() {
    SQLMethodInvokeExpr method = new SQLMethodInvokeExpr(funcName());
    method.addParameter(new SQLIdentifierExpr(intType.toString()));
    for (Item arg : args) {
        method.addParameter(arg.toExpression());
    }
    return method;
}
 
Example 13
Source File: ItemFuncUnsignedConvert.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SQLExpr toExpression() {
    SQLMethodInvokeExpr method = new SQLMethodInvokeExpr();
    method.setMethodName("CONVERT");
    method.addParameter(args.get(0).toExpression());
    method.addParameter(new SQLIdentifierExpr("UNSIGNED"));
    return method;
}
 
Example 14
Source File: ItemDatetimeTypeConvert.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SQLExpr toExpression() {
    SQLMethodInvokeExpr method = new SQLMethodInvokeExpr();
    method.setMethodName("CONVERT");
    method.addParameter(args.get(0).toExpression());
    if (decimals != NOT_FIXED_DEC) {
        SQLMethodInvokeExpr dataType = new SQLMethodInvokeExpr();
        dataType.setMethodName("DATETIME");
        dataType.addParameter(new SQLIntegerExpr(decimals));
        method.addParameter(dataType);
    } else {
        method.addParameter(new SQLIdentifierExpr("DATETIME"));
    }
    return method;
}
 
Example 15
Source File: ItemCharTypeConvert.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SQLExpr toExpression() {
    SQLMethodInvokeExpr method = new SQLMethodInvokeExpr();
    method.setMethodName("CONVERT");
    method.addParameter(args.get(0).toExpression());
    if (castLength >= 0) {
        SQLMethodInvokeExpr dataType = new SQLMethodInvokeExpr();
        dataType.setMethodName("CHAR");
        dataType.addParameter(new SQLIntegerExpr(castLength));
        method.addParameter(dataType);
    } else {
        method.addParameter(new SQLIdentifierExpr("CHAR"));
    }
    return method;
}
 
Example 16
Source File: ItemFuncBinaryConvert.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SQLExpr toExpression() {
    SQLMethodInvokeExpr method = new SQLMethodInvokeExpr();
    method.setMethodName("CONVERT");
    method.addParameter(args.get(0).toExpression());
    if (decimals != NOT_FIXED_DEC) {
        SQLMethodInvokeExpr dataType = new SQLMethodInvokeExpr();
        dataType.setMethodName("BINARY");
        dataType.addParameter(new SQLIntegerExpr(decimals));
        method.addParameter(dataType);
    } else {
        method.addParameter(new SQLIdentifierExpr("BINARY"));
    }
    return method;
}
 
Example 17
Source File: ItemTimeTypeConvert.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SQLExpr toExpression() {
    SQLMethodInvokeExpr method = new SQLMethodInvokeExpr();
    method.setMethodName("CONVERT");
    method.addParameter(args.get(0).toExpression());
    if (decimals != NOT_FIXED_DEC) {
        SQLMethodInvokeExpr dataType = new SQLMethodInvokeExpr();
        dataType.setMethodName("TIME");
        dataType.addParameter(new SQLIntegerExpr(decimals));
        method.addParameter(dataType);
    } else {
        method.addParameter(new SQLIdentifierExpr("TIME"));
    }
    return method;
}
 
Example 18
Source File: ItemFuncSignedConvert.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SQLExpr toExpression() {
    SQLMethodInvokeExpr method = new SQLMethodInvokeExpr();
    method.setMethodName("CONVERT");
    method.addParameter(args.get(0).toExpression());
    method.addParameter(new SQLIdentifierExpr("SIGNED"));
    return method;
}
 
Example 19
Source File: ItemFuncSoundex.java    From dble with GNU General Public License v2.0 4 votes vote down vote up
@Override
public SQLExpr toExpression() {
    SQLMethodInvokeExpr method = new SQLMethodInvokeExpr(funcName());
    method.addParameter(args.get(0).toExpression());
    return method;
}
 
Example 20
Source File: FieldMaker.java    From elasticsearch-sql with Apache License 2.0 4 votes vote down vote up
private static SQLMethodInvokeExpr convertBinaryOperatorToMethod(String operator, SQLBinaryOpExpr expr) {
    SQLMethodInvokeExpr methodInvokeExpr = new SQLMethodInvokeExpr(operator, null);
    methodInvokeExpr.addParameter(expr.getLeft());
    methodInvokeExpr.addParameter(expr.getRight());
    return methodInvokeExpr;
}