Search in sources :

Example 1 with StringLiteral

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

the class RepositoryParamValidatorTest method testS3ConfigParams.

@Test
public void testS3ConfigParams() throws Exception {
    GenericProperties genericProperties = new GenericProperties();
    genericProperties.add(new GenericProperty("access_key", new StringLiteral("foobar")));
    genericProperties.add(new GenericProperty("base_path", new StringLiteral("/data")));
    genericProperties.add(new GenericProperty("bucket", new StringLiteral("myBucket")));
    genericProperties.add(new GenericProperty("buffer_size", new StringLiteral("10k")));
    genericProperties.add(new GenericProperty("canned_acl", new StringLiteral("cannedACL")));
    genericProperties.add(new GenericProperty("chunk_size", new StringLiteral("4g")));
    genericProperties.add(new GenericProperty("compress", new StringLiteral("true")));
    genericProperties.add(new GenericProperty("concurrent_streams", new StringLiteral("12")));
    genericProperties.add(new GenericProperty("endpoint", new StringLiteral("myEndpoint")));
    genericProperties.add(new GenericProperty("max_retries", new StringLiteral("8")));
    genericProperties.add(new GenericProperty("protocol", new StringLiteral("myProtocol")));
    genericProperties.add(new GenericProperty("region", new StringLiteral("Europe-1")));
    genericProperties.add(new GenericProperty("secret_key", new StringLiteral("thisIsASecretKey")));
    genericProperties.add(new GenericProperty("server_side_encryption", new StringLiteral("false")));
    Settings settings = validator.convertAndValidate("s3", Optional.of(genericProperties), ParameterContext.EMPTY);
    assertThat(settings.get("access_key"), is("foobar"));
    assertThat(settings.get("base_path"), is("/data"));
    assertThat(settings.get("bucket"), is("myBucket"));
    assertThat(settings.get("buffer_size"), is("10240b"));
    assertThat(settings.get("canned_acl"), is("cannedACL"));
    assertThat(settings.get("chunk_size"), is("4294967296b"));
    assertThat(settings.get("compress"), is("true"));
    assertThat(settings.get("concurrent_streams"), is("12"));
    assertThat(settings.get("endpoint"), is("myEndpoint"));
    assertThat(settings.get("max_retries"), is("8"));
    assertThat(settings.get("protocol"), is("myProtocol"));
    assertThat(settings.get("region"), is("Europe-1"));
    assertThat(settings.get("secret_key"), is("thisIsASecretKey"));
    assertThat(settings.get("server_side_encryption"), is("false"));
}
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 2 with StringLiteral

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

the class RepositoryParamValidatorTest method testInvalidSetting.

@Test
public void testInvalidSetting() throws Exception {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("setting 'yay' not supported");
    GenericProperties genericProperties = new GenericProperties();
    genericProperties.add(new GenericProperty("location", new StringLiteral("foo")));
    genericProperties.add(new GenericProperty("yay", new StringLiteral("invalid")));
    validator.convertAndValidate("fs", Optional.of(genericProperties), ParameterContext.EMPTY);
}
Also used : StringLiteral(io.crate.sql.tree.StringLiteral) GenericProperty(io.crate.sql.tree.GenericProperty) GenericProperties(io.crate.sql.tree.GenericProperties) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with StringLiteral

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

the class TestStatementBuilder method testSubscriptExpression.

@Test
public void testSubscriptExpression() {
    Expression expression = SqlParser.createExpression("a['sub']");
    assertThat(expression, instanceOf(SubscriptExpression.class));
    SubscriptExpression subscript = (SubscriptExpression) expression;
    assertThat(subscript.index(), instanceOf(StringLiteral.class));
    assertThat(((StringLiteral) subscript.index()).getValue(), is("sub"));
    assertThat(subscript.base(), instanceOf(QualifiedNameReference.class));
    expression = SqlParser.createExpression("[1,2,3][1]");
    assertThat(expression, instanceOf(SubscriptExpression.class));
    subscript = (SubscriptExpression) expression;
    assertThat(subscript.index(), instanceOf(IntegerLiteral.class));
    assertThat(((IntegerLiteral) subscript.index()).getValue(), is(1));
    assertThat(subscript.base(), instanceOf(ArrayLiteral.class));
}
Also used : 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) SubscriptExpression(io.crate.sql.tree.SubscriptExpression) ArrayLiteral(io.crate.sql.tree.ArrayLiteral) QualifiedNameReference(io.crate.sql.tree.QualifiedNameReference) IntegerLiteral(io.crate.sql.tree.IntegerLiteral) Test(org.junit.Test)

Example 4 with StringLiteral

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

the class AstBuilder method visitMaybeParametrizedDataType.

@Override
public Node visitMaybeParametrizedDataType(SqlBaseParser.MaybeParametrizedDataTypeContext context) {
    StringLiteral name = (StringLiteral) visit(context.baseDataType());
    var parameters = new ArrayList<Integer>(context.integerLiteral().size());
    for (var param : context.integerLiteral()) {
        var literal = visit(param);
        int val;
        if (literal instanceof LongLiteral) {
            val = Math.toIntExact(((LongLiteral) literal).getValue());
        } else {
            val = ((IntegerLiteral) literal).getValue();
        }
        parameters.add(val);
    }
    return new ColumnType<>(name.getValue(), parameters);
}
Also used : ObjectColumnType(io.crate.sql.tree.ObjectColumnType) CollectionColumnType(io.crate.sql.tree.CollectionColumnType) ColumnType(io.crate.sql.tree.ColumnType) EscapedCharStringLiteral(io.crate.sql.tree.EscapedCharStringLiteral) StringLiteral(io.crate.sql.tree.StringLiteral) LongLiteral(io.crate.sql.tree.LongLiteral) ArrayList(java.util.ArrayList) IndexColumnConstraint(io.crate.sql.tree.IndexColumnConstraint) CheckConstraint(io.crate.sql.tree.CheckConstraint) NotNullColumnConstraint(io.crate.sql.tree.NotNullColumnConstraint) PrimaryKeyColumnConstraint(io.crate.sql.tree.PrimaryKeyColumnConstraint) ColumnConstraint(io.crate.sql.tree.ColumnConstraint) DropCheckConstraint(io.crate.sql.tree.DropCheckConstraint) CheckColumnConstraint(io.crate.sql.tree.CheckColumnConstraint) PrimaryKeyConstraint(io.crate.sql.tree.PrimaryKeyConstraint)

Example 5 with StringLiteral

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

the class DeallocateAnalyzer method analyze.

public static AnalyzedDeallocate analyze(DeallocateStatement deallocateStatement) {
    Expression preparedStmtExpression = deallocateStatement.preparedStmt();
    String preparedStmt = null;
    if (preparedStmtExpression != null) {
        if (preparedStmtExpression instanceof StringLiteral) {
            preparedStmt = ((StringLiteral) preparedStmtExpression).getValue();
        } else if (preparedStmtExpression instanceof QualifiedNameReference) {
            preparedStmt = ((QualifiedNameReference) preparedStmtExpression).getName().toString();
        } else {
            throw new AssertionError("Expression " + preparedStmtExpression.toString() + " not supported as " + "preparedStmt expression for DEALLOCATE");
        }
    }
    return new AnalyzedDeallocate(preparedStmt);
}
Also used : StringLiteral(io.crate.sql.tree.StringLiteral) Expression(io.crate.sql.tree.Expression) QualifiedNameReference(io.crate.sql.tree.QualifiedNameReference)

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