Search in sources :

Example 1 with ArrayLiteral

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

the class GenericPropertiesConverter method genericPropertyToSetting.

/**
     * Put a genericProperty into a settings-structure
     */
static void genericPropertyToSetting(Settings.Builder builder, String name, Expression value, Row parameters) {
    if (value instanceof ArrayLiteral) {
        ArrayLiteral array = (ArrayLiteral) value;
        List<String> values = new ArrayList<>(array.values().size());
        for (Expression expression : array.values()) {
            values.add(ExpressionToStringVisitor.convert(expression, parameters));
        }
        builder.putArray(name, values.toArray(new String[values.size()]));
    } else {
        builder.put(name, ExpressionToStringVisitor.convert(value, parameters));
    }
}
Also used : Expression(io.crate.sql.tree.Expression) ArrayLiteral(io.crate.sql.tree.ArrayLiteral)

Example 2 with ArrayLiteral

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

the class TestStatementBuilder method testArrayLiteral.

@Test
public void testArrayLiteral() {
    ArrayLiteral emptyArrayLiteral = (ArrayLiteral) SqlParser.createExpression("[]");
    assertThat(emptyArrayLiteral.values().size(), is(0));
    ArrayLiteral singleArrayLiteral = (ArrayLiteral) SqlParser.createExpression("[1]");
    assertThat(singleArrayLiteral.values().size(), is(1));
    assertThat(singleArrayLiteral.values().get(0), instanceOf(IntegerLiteral.class));
    ArrayLiteral multipleArrayLiteral = (ArrayLiteral) SqlParser.createExpression("['str', -12.56, {}, ['another', 'array']]");
    assertThat(multipleArrayLiteral.values().size(), is(4));
    assertThat(multipleArrayLiteral.values().get(0), instanceOf(StringLiteral.class));
    assertThat(multipleArrayLiteral.values().get(1), instanceOf(NegativeExpression.class));
    assertThat(multipleArrayLiteral.values().get(2), instanceOf(ObjectLiteral.class));
    assertThat(multipleArrayLiteral.values().get(3), instanceOf(ArrayLiteral.class));
}
Also used : ObjectLiteral(io.crate.sql.tree.ObjectLiteral) EscapedCharStringLiteral(io.crate.sql.tree.EscapedCharStringLiteral) StringLiteral(io.crate.sql.tree.StringLiteral) ArrayLiteral(io.crate.sql.tree.ArrayLiteral) IntegerLiteral(io.crate.sql.tree.IntegerLiteral) NegativeExpression(io.crate.sql.tree.NegativeExpression) Test(org.junit.Test)

Aggregations

ArrayLiteral (io.crate.sql.tree.ArrayLiteral)2 EscapedCharStringLiteral (io.crate.sql.tree.EscapedCharStringLiteral)1 Expression (io.crate.sql.tree.Expression)1 IntegerLiteral (io.crate.sql.tree.IntegerLiteral)1 NegativeExpression (io.crate.sql.tree.NegativeExpression)1 ObjectLiteral (io.crate.sql.tree.ObjectLiteral)1 StringLiteral (io.crate.sql.tree.StringLiteral)1 Test (org.junit.Test)1