Search in sources :

Example 6 with Expression

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));
}
Also used : RowN(io.crate.data.RowN) HashMap(java.util.HashMap) ParameterExpression(io.crate.sql.tree.ParameterExpression) Expression(io.crate.sql.tree.Expression) ParameterExpression(io.crate.sql.tree.ParameterExpression) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 7 with Expression

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;
}
Also used : Expression(io.crate.sql.tree.Expression) SettingsApplier(io.crate.metadata.settings.SettingsApplier) Settings(org.elasticsearch.common.settings.Settings)

Example 8 with Expression

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));
}
Also used : ObjectLiteral(io.crate.sql.tree.ObjectLiteral) Expression(io.crate.sql.tree.Expression) Literal(io.crate.sql.tree.Literal) ObjectLiteral(io.crate.sql.tree.ObjectLiteral) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 9 with Expression

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'}"));
}
Also used : Expression(io.crate.sql.tree.Expression) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 10 with Expression

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));
}
Also used : StringLiteral(io.crate.sql.tree.StringLiteral) HashMap(java.util.HashMap) ParameterExpression(io.crate.sql.tree.ParameterExpression) Expression(io.crate.sql.tree.Expression) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

Expression (io.crate.sql.tree.Expression)11 Test (org.junit.Test)6 CrateUnitTest (io.crate.test.integration.CrateUnitTest)5 ImmutableList (com.google.common.collect.ImmutableList)4 ParameterExpression (io.crate.sql.tree.ParameterExpression)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Settings (org.elasticsearch.common.settings.Settings)3 RowN (io.crate.data.RowN)2 SettingsApplier (io.crate.metadata.settings.SettingsApplier)2 ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)1 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)1 TableReferenceResolver (io.crate.analyze.expressions.TableReferenceResolver)1 Field (io.crate.analyze.symbol.Field)1 Symbol (io.crate.analyze.symbol.Symbol)1 Bucket (io.crate.data.Bucket)1 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)1 ESClusterUpdateSettingsPlan (io.crate.planner.node.ddl.ESClusterUpdateSettingsPlan)1 ArrayLiteral (io.crate.sql.tree.ArrayLiteral)1 Literal (io.crate.sql.tree.Literal)1