Search in sources :

Example 1 with Expression

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));
}
Also used : ESClusterUpdateSettingsPlan(io.crate.planner.node.ddl.ESClusterUpdateSettingsPlan) Expression(io.crate.sql.tree.Expression) Bucket(io.crate.data.Bucket) MetaData(org.elasticsearch.cluster.metadata.MetaData) ImmutableList(com.google.common.collect.ImmutableList) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Example 2 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 3 with Expression

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();
    }
}
Also used : ExpressionAnalysisContext(io.crate.analyze.expressions.ExpressionAnalysisContext) Expression(io.crate.sql.tree.Expression) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) TableReferenceResolver(io.crate.analyze.expressions.TableReferenceResolver)

Example 4 with Expression

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));
    }
}
Also used : Expression(io.crate.sql.tree.Expression) ArrayLiteral(io.crate.sql.tree.ArrayLiteral)

Example 5 with Expression

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

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