use of io.crate.sql.tree.Expression in project crate by crate.
the class ESClusterUpdateSettingsTaskTest method testUpdateMultipleSettingsWithParameters.
@Test
public void testUpdateMultipleSettingsWithParameters() throws Exception {
Map<String, List<Expression>> settings = new HashMap<String, List<Expression>>() {
{
put("stats.operations_log_size", ImmutableList.<Expression>of(new ParameterExpression(1)));
put("stats.jobs_log_size", ImmutableList.<Expression>of(new ParameterExpression(2)));
}
};
Settings expected = Settings.builder().put("stats.operations_log_size", 10).put("stats.jobs_log_size", 25).build();
assertThat(ESClusterUpdateSettingsTask.buildSettingsFrom(settings, new RowN(new Object[] { 10, 25 })), is(expected));
}
use of io.crate.sql.tree.Expression in project crate by crate.
the class GenericPropertiesConverter method settingsFromProperties.
public static Settings.Builder settingsFromProperties(Optional<GenericProperties> properties, ParameterContext parameterContext, Map<String, ? extends SettingsApplier> settingAppliers) {
Settings.Builder builder = Settings.builder();
setDefaults(settingAppliers, builder);
if (properties.isPresent()) {
for (Map.Entry<String, Expression> entry : properties.get().properties().entrySet()) {
SettingsApplier settingsApplier = settingAppliers.get(entry.getKey());
if (settingsApplier == null) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "setting '%s' not supported", entry.getKey()));
}
settingsApplier.apply(builder, parameterContext.parameters(), entry.getValue());
}
}
return builder;
}
use of io.crate.sql.tree.Expression in project crate by crate.
the class SetAnalyzerTest method testObjectValue.
@Test
public void testObjectValue() throws Exception {
SetAnalyzedStatement analysis = analyze("SET GLOBAL PERSISTENT cluster.graceful_stop = {timeout='1h'}");
Multimap<String, Expression> map = LinkedListMultimap.create();
map.put("timeout", Literal.fromObject("1h"));
Literal expected = new ObjectLiteral(map);
assertThat(analysis.settings().get("cluster.graceful_stop").get(0), Matchers.<Expression>is(expected));
}
use of io.crate.sql.tree.Expression in project crate by crate.
the class SetAnalyzerTest method testSetRuntimeSettingSubscript.
@Test
public void testSetRuntimeSettingSubscript() {
SetAnalyzedStatement analysis = analyze("SET GLOBAL TRANSIENT cluster['routing']['allocation']['include'] = {_host = 'host1.example.com'}");
Expression expression = analysis.settings().get("cluster.routing.allocation.include").get(0);
assertThat(expression.toString(), is("{\"_host\"= 'host1.example.com'}"));
}
use of io.crate.sql.tree.Expression 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));
}
Aggregations