use of io.crate.sql.tree.Expression in project crate by crate.
the class TransportExecutorDDLTest method testClusterUpdateSettingsTask.
@Test
public void testClusterUpdateSettingsTask() throws Exception {
final String persistentSetting = "stats.enabled";
final String transientSetting = "bulk.request_timeout";
// Update persistent only
Map<String, List<Expression>> persistentSettings = new HashMap<String, List<Expression>>() {
{
put(persistentSetting, ImmutableList.<Expression>of(Literal.fromObject(true)));
}
};
ESClusterUpdateSettingsPlan node = new ESClusterUpdateSettingsPlan(UUID.randomUUID(), persistentSettings);
Bucket objects = executePlan(node);
assertThat(objects, contains(isRow(1L)));
assertEquals("true", client().admin().cluster().prepareState().execute().actionGet().getState().metaData().persistentSettings().get(persistentSetting));
// Update transient only
Map<String, List<Expression>> transientSettings = new HashMap<String, List<Expression>>() {
{
put(transientSetting, ImmutableList.<Expression>of(Literal.fromObject("123s")));
}
};
node = new ESClusterUpdateSettingsPlan(UUID.randomUUID(), ImmutableMap.<String, List<Expression>>of(), transientSettings);
objects = executePlan(node);
assertThat(objects, contains(isRow(1L)));
assertEquals("123000ms", client().admin().cluster().prepareState().execute().actionGet().getState().metaData().transientSettings().get(transientSetting));
// Update persistent & transient
persistentSettings = new HashMap<String, List<Expression>>() {
{
put(persistentSetting, ImmutableList.<Expression>of(Literal.fromObject(false)));
}
};
transientSettings = new HashMap<String, List<Expression>>() {
{
put(transientSetting, ImmutableList.<Expression>of(Literal.fromObject("243s")));
}
};
node = new ESClusterUpdateSettingsPlan(UUID.randomUUID(), persistentSettings, transientSettings);
objects = executePlan(node);
MetaData md = client().admin().cluster().prepareState().execute().actionGet().getState().metaData();
assertThat(objects, contains(isRow(1L)));
assertEquals("false", md.persistentSettings().get(persistentSetting));
assertEquals("243000ms", md.transientSettings().get(transientSetting));
}
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 DocIndexMetaData method initializeGeneratedExpressions.
private void initializeGeneratedExpressions() {
if (generatedColumnReferences.isEmpty()) {
return;
}
Collection<Reference> references = this.references.values();
TableReferenceResolver tableReferenceResolver = new TableReferenceResolver(references);
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, SessionContext.SYSTEM_SESSION, ParamTypeHints.EMPTY, tableReferenceResolver, null);
ExpressionAnalysisContext context = new ExpressionAnalysisContext();
for (Reference reference : generatedColumnReferences) {
GeneratedReference generatedReference = (GeneratedReference) reference;
Expression expression = SqlParser.createExpression(generatedReference.formattedGeneratedExpression());
generatedReference.generatedExpression(expressionAnalyzer.convert(expression, context));
generatedReference.referencedReferences(ImmutableList.copyOf(tableReferenceResolver.references()));
tableReferenceResolver.references().clear();
}
}
use of io.crate.sql.tree.Expression 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.Expression in project crate by crate.
the class TablePropertiesAnalyzer method analyze.
public static void analyze(TableParameter tableParameter, TableParameterInfo tableParameterInfo, Optional<GenericProperties> properties, Row parameters, boolean withDefaults) {
if (withDefaults) {
SettingsApplier settingsApplier = SETTINGS_APPLIER.get(TableParameterInfo.NUMBER_OF_REPLICAS);
tableParameter.settingsBuilder().put(settingsApplier.getDefault());
for (String mappingEntry : tableParameterInfo.supportedMappings()) {
MappingsApplier mappingsApplier = MAPPINGS_APPLIER.get(mappingEntry);
tableParameter.mappings().put(mappingsApplier.name, mappingsApplier.getDefault());
}
}
if (properties.isPresent()) {
Map<String, Expression> tableProperties = properties.get().properties();
validateTableProperties(tableParameterInfo, tableProperties.keySet());
for (String setting : tableParameterInfo.supportedSettings()) {
String settingName = ES_TO_CRATE_SETTINGS_MAP.get(setting);
if (tableProperties.containsKey(settingName)) {
SettingsApplier settingsApplier = SETTINGS_APPLIER.get(setting);
settingsApplier.apply(tableParameter.settingsBuilder(), parameters, tableProperties.get(settingName));
}
}
for (String mappingEntry : tableParameterInfo.supportedMappings()) {
String mappingName = ES_TO_CRATE_MAPPINGS_MAP.get(mappingEntry);
if (tableProperties.containsKey(mappingName)) {
MappingsApplier mappingsApplier = MAPPINGS_APPLIER.get(mappingEntry);
mappingsApplier.apply(tableParameter.mappings(), parameters, tableProperties.get(mappingName));
}
}
}
}
Aggregations