Search in sources :

Example 6 with StringLiteral

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

the class RepositoryParamValidatorTest method testHdfsDynamicConfParam.

@Test
public void testHdfsDynamicConfParam() throws Exception {
    GenericProperties genericProperties = new GenericProperties();
    genericProperties.add(new GenericProperty("path", new StringLiteral("/data")));
    genericProperties.add(new GenericProperty("conf.foobar", new StringLiteral("bar")));
    Settings settings = validator.convertAndValidate("hdfs", Optional.of(genericProperties), ParameterContext.EMPTY);
    assertThat(settings.get("conf.foobar"), is("bar"));
}
Also used : StringLiteral(io.crate.sql.tree.StringLiteral) GenericProperty(io.crate.sql.tree.GenericProperty) GenericProperties(io.crate.sql.tree.GenericProperties) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 7 with StringLiteral

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

the class ESClusterUpdateSettingsTaskTest method testUpdateSettingsWithStringValue.

@Test
public void testUpdateSettingsWithStringValue() throws Exception {
    Map<String, List<Expression>> settings = new HashMap<String, List<Expression>>() {

        {
            put("cluster.graceful_stop.min_availability", ImmutableList.<Expression>of(new StringLiteral("full")));
        }
    };
    Settings expected = Settings.builder().put("cluster.graceful_stop.min_availability", "full").build();
    assertThat(ESClusterUpdateSettingsTask.buildSettingsFrom(settings, Row.EMPTY), is(expected));
}
Also used : StringLiteral(io.crate.sql.tree.StringLiteral) HashMap(java.util.HashMap) ParameterExpression(io.crate.sql.tree.ParameterExpression) Expression(io.crate.sql.tree.Expression) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with StringLiteral

use of io.crate.sql.tree.StringLiteral 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 9 with StringLiteral

use of io.crate.sql.tree.StringLiteral 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 10 with StringLiteral

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

the class AstBuilder method visitQuotedIdentifier.

@Override
public Node visitQuotedIdentifier(SqlBaseParser.QuotedIdentifierContext context) {
    String token = context.getText();
    String identifier = token.substring(1, token.length() - 1).replace("\"\"", "\"");
    return new StringLiteral(identifier);
}
Also used : EscapedCharStringLiteral(io.crate.sql.tree.EscapedCharStringLiteral) StringLiteral(io.crate.sql.tree.StringLiteral) BitString(io.crate.sql.tree.BitString)

Aggregations

StringLiteral (io.crate.sql.tree.StringLiteral)10 Test (org.junit.Test)6 EscapedCharStringLiteral (io.crate.sql.tree.EscapedCharStringLiteral)5 Expression (io.crate.sql.tree.Expression)5 ParameterExpression (io.crate.sql.tree.ParameterExpression)4 CrateUnitTest (io.crate.test.integration.CrateUnitTest)4 ArrayComparisonExpression (io.crate.sql.tree.ArrayComparisonExpression)3 ComparisonExpression (io.crate.sql.tree.ComparisonExpression)3 GenericProperties (io.crate.sql.tree.GenericProperties)3 GenericProperty (io.crate.sql.tree.GenericProperty)3 NegativeExpression (io.crate.sql.tree.NegativeExpression)3 QualifiedNameReference (io.crate.sql.tree.QualifiedNameReference)3 SubqueryExpression (io.crate.sql.tree.SubqueryExpression)3 SubscriptExpression (io.crate.sql.tree.SubscriptExpression)3 Settings (org.elasticsearch.common.settings.Settings)3 FunctionCall (io.crate.sql.tree.FunctionCall)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArithmeticExpression (io.crate.sql.tree.ArithmeticExpression)1 ArrayLiteral (io.crate.sql.tree.ArrayLiteral)1 ArraySliceExpression (io.crate.sql.tree.ArraySliceExpression)1