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));
}
}
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));
}
Aggregations