Java Code Examples for com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlExtractExpr#setUnit()

The following examples show how to use com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlExtractExpr#setUnit() . 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: ElasticSqlExprParser.java    From elasticsearch-sql with Apache License 2.0 6 votes vote down vote up
protected SQLExpr parseExtract() {
    SQLExpr expr;
    if (lexer.token() != Token.IDENTIFIER) {
        throw new ParserException("syntax error. " + lexer.info());
    }

    String unitVal = lexer.stringVal();
    SQLIntervalUnit unit = SQLIntervalUnit.valueOf(unitVal.toUpperCase());
    lexer.nextToken();

    accept(Token.FROM);

    SQLExpr value = expr();

    MySqlExtractExpr extract = new MySqlExtractExpr();
    extract.setValue(value);
    extract.setUnit(unit);
    accept(Token.RPAREN);

    expr = extract;

    return primaryRest(expr);
}
 
Example 2
Source File: ItemExtract.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SQLExpr toExpression() {
    MySqlExtractExpr extract = new MySqlExtractExpr();
    extract.setValue(args.get(0).toExpression());
    extract.setUnit(intType);
    return extract;
}