Search in sources :

Example 6 with FunctionCall

use of io.crate.sql.tree.FunctionCall in project crate by crate.

the class TestStatementBuilder method testCaseSensitivity.

@Test
public void testCaseSensitivity() {
    Expression expression = SqlParser.createExpression("\"firstName\" = 'myName'");
    QualifiedNameReference nameRef = (QualifiedNameReference) ((ComparisonExpression) expression).getLeft();
    StringLiteral myName = (StringLiteral) ((ComparisonExpression) expression).getRight();
    assertThat(nameRef.getName().getSuffix(), is("firstName"));
    assertThat(myName.getValue(), is("myName"));
    expression = SqlParser.createExpression("FIRSTNAME = 'myName'");
    nameRef = (QualifiedNameReference) ((ComparisonExpression) expression).getLeft();
    assertThat(nameRef.getName().getSuffix(), is("firstname"));
    expression = SqlParser.createExpression("ABS(1)");
    QualifiedName functionName = ((FunctionCall) expression).getName();
    assertThat(functionName.getSuffix(), is("abs"));
}
Also used : ArrayComparisonExpression(io.crate.sql.tree.ArrayComparisonExpression) ComparisonExpression(io.crate.sql.tree.ComparisonExpression) EscapedCharStringLiteral(io.crate.sql.tree.EscapedCharStringLiteral) StringLiteral(io.crate.sql.tree.StringLiteral) SubqueryExpression(io.crate.sql.tree.SubqueryExpression) SubscriptExpression(io.crate.sql.tree.SubscriptExpression) ParameterExpression(io.crate.sql.tree.ParameterExpression) ArrayComparisonExpression(io.crate.sql.tree.ArrayComparisonExpression) Expression(io.crate.sql.tree.Expression) ComparisonExpression(io.crate.sql.tree.ComparisonExpression) NegativeExpression(io.crate.sql.tree.NegativeExpression) QualifiedName(io.crate.sql.tree.QualifiedName) FunctionCall(io.crate.sql.tree.FunctionCall) QualifiedNameReference(io.crate.sql.tree.QualifiedNameReference) Test(org.junit.Test)

Example 7 with FunctionCall

use of io.crate.sql.tree.FunctionCall in project crate by crate.

the class AstBuilder method visitTrim.

@Override
public Node visitTrim(SqlBaseParser.TrimContext ctx) {
    Expression target = (Expression) visit(ctx.target);
    if (ctx.charsToTrim == null && ctx.trimMode == null) {
        return new FunctionCall(QualifiedName.of("trim"), List.of(target));
    }
    Expression charsToTrim = visitIfPresent(ctx.charsToTrim, Expression.class).orElse(new StringLiteral(" "));
    StringLiteral trimMode = new StringLiteral(getTrimMode(ctx.trimMode).value());
    return new FunctionCall(QualifiedName.of("trim"), List.of(target, charsToTrim, trimMode));
}
Also used : EscapedCharStringLiteral(io.crate.sql.tree.EscapedCharStringLiteral) StringLiteral(io.crate.sql.tree.StringLiteral) SubscriptExpression(io.crate.sql.tree.SubscriptExpression) IfExpression(io.crate.sql.tree.IfExpression) NotExpression(io.crate.sql.tree.NotExpression) SearchedCaseExpression(io.crate.sql.tree.SearchedCaseExpression) LogicalBinaryExpression(io.crate.sql.tree.LogicalBinaryExpression) ArraySliceExpression(io.crate.sql.tree.ArraySliceExpression) ArraySubQueryExpression(io.crate.sql.tree.ArraySubQueryExpression) SimpleCaseExpression(io.crate.sql.tree.SimpleCaseExpression) SubqueryExpression(io.crate.sql.tree.SubqueryExpression) InListExpression(io.crate.sql.tree.InListExpression) ParameterExpression(io.crate.sql.tree.ParameterExpression) ArrayComparisonExpression(io.crate.sql.tree.ArrayComparisonExpression) Expression(io.crate.sql.tree.Expression) ComparisonExpression(io.crate.sql.tree.ComparisonExpression) ArithmeticExpression(io.crate.sql.tree.ArithmeticExpression) NegativeExpression(io.crate.sql.tree.NegativeExpression) FunctionCall(io.crate.sql.tree.FunctionCall)

Example 8 with FunctionCall

use of io.crate.sql.tree.FunctionCall in project crate by crate.

the class AstBuilder method visitRight.

@Override
public Node visitRight(SqlBaseParser.RightContext context) {
    Expression strOrColName = (Expression) visit(context.strOrColName);
    Expression len = (Expression) visit(context.len);
    return new FunctionCall(QualifiedName.of("right"), List.of(strOrColName, len));
}
Also used : SubscriptExpression(io.crate.sql.tree.SubscriptExpression) IfExpression(io.crate.sql.tree.IfExpression) NotExpression(io.crate.sql.tree.NotExpression) SearchedCaseExpression(io.crate.sql.tree.SearchedCaseExpression) LogicalBinaryExpression(io.crate.sql.tree.LogicalBinaryExpression) ArraySliceExpression(io.crate.sql.tree.ArraySliceExpression) ArraySubQueryExpression(io.crate.sql.tree.ArraySubQueryExpression) SimpleCaseExpression(io.crate.sql.tree.SimpleCaseExpression) SubqueryExpression(io.crate.sql.tree.SubqueryExpression) InListExpression(io.crate.sql.tree.InListExpression) ParameterExpression(io.crate.sql.tree.ParameterExpression) ArrayComparisonExpression(io.crate.sql.tree.ArrayComparisonExpression) Expression(io.crate.sql.tree.Expression) ComparisonExpression(io.crate.sql.tree.ComparisonExpression) ArithmeticExpression(io.crate.sql.tree.ArithmeticExpression) NegativeExpression(io.crate.sql.tree.NegativeExpression) FunctionCall(io.crate.sql.tree.FunctionCall)

Aggregations

FunctionCall (io.crate.sql.tree.FunctionCall)8 ArrayComparisonExpression (io.crate.sql.tree.ArrayComparisonExpression)7 ComparisonExpression (io.crate.sql.tree.ComparisonExpression)7 Expression (io.crate.sql.tree.Expression)7 NegativeExpression (io.crate.sql.tree.NegativeExpression)7 ParameterExpression (io.crate.sql.tree.ParameterExpression)7 SubqueryExpression (io.crate.sql.tree.SubqueryExpression)7 SubscriptExpression (io.crate.sql.tree.SubscriptExpression)7 ArithmeticExpression (io.crate.sql.tree.ArithmeticExpression)6 ArraySliceExpression (io.crate.sql.tree.ArraySliceExpression)6 ArraySubQueryExpression (io.crate.sql.tree.ArraySubQueryExpression)6 IfExpression (io.crate.sql.tree.IfExpression)6 InListExpression (io.crate.sql.tree.InListExpression)6 LogicalBinaryExpression (io.crate.sql.tree.LogicalBinaryExpression)6 NotExpression (io.crate.sql.tree.NotExpression)6 SearchedCaseExpression (io.crate.sql.tree.SearchedCaseExpression)6 SimpleCaseExpression (io.crate.sql.tree.SimpleCaseExpression)6 EscapedCharStringLiteral (io.crate.sql.tree.EscapedCharStringLiteral)3 QualifiedName (io.crate.sql.tree.QualifiedName)3 StringLiteral (io.crate.sql.tree.StringLiteral)3