Search in sources :

Example 1 with ParameterSymbol

use of io.crate.expression.symbol.ParameterSymbol in project crate by crate.

the class UpdateSettingsPlanTest method testUpdateMultipleSettingsWithParameters.

@Test
public void testUpdateMultipleSettingsWithParameters() throws Exception {
    List<Assignment<Symbol>> settings = List.of(new Assignment<>(Literal.of("stats.operations_log_size"), List.of(new ParameterSymbol(0, DataTypes.LONG))), new Assignment<>(Literal.of("stats.jobs_log_size"), List.of(new ParameterSymbol(1, DataTypes.LONG))));
    Settings expected = Settings.builder().put("stats.operations_log_size", 10).put("stats.jobs_log_size", 25).build();
    assertThat(buildSettingsFrom(settings, symbolEvaluator(new RowN(new Object[] { 10, 25 }))), is(expected));
}
Also used : Assignment(io.crate.sql.tree.Assignment) RowN(io.crate.data.RowN) ParameterSymbol(io.crate.expression.symbol.ParameterSymbol) SessionSettings(io.crate.metadata.settings.SessionSettings) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 2 with ParameterSymbol

use of io.crate.expression.symbol.ParameterSymbol in project crate by crate.

the class UpdateSettingsPlanTest method testUpdateObjectWithParameter.

@Test
public void testUpdateObjectWithParameter() throws Exception {
    List<Assignment<Symbol>> settings = List.of(new Assignment<>(Literal.of("stats"), List.of(new ParameterSymbol(0, ObjectType.UNTYPED))));
    Map<String, Object> param = MapBuilder.<String, Object>newMapBuilder().put("enabled", true).put("breaker", MapBuilder.newMapBuilder().put("log", MapBuilder.newMapBuilder().put("jobs", MapBuilder.newMapBuilder().put("overhead", 1.05d).map()).map()).map()).map();
    Settings expected = Settings.builder().put("stats.enabled", true).put("stats.breaker.log.jobs.overhead", 1.05d).build();
    assertThat(buildSettingsFrom(settings, symbolEvaluator(new RowN(new Object[] { param }))), is(expected));
}
Also used : Assignment(io.crate.sql.tree.Assignment) RowN(io.crate.data.RowN) ParameterSymbol(io.crate.expression.symbol.ParameterSymbol) SessionSettings(io.crate.metadata.settings.SessionSettings) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 3 with ParameterSymbol

use of io.crate.expression.symbol.ParameterSymbol in project crate by crate.

the class SelectivityFunctions method eqSelectivity.

private static double eqSelectivity(Symbol leftArg, Symbol rightArg, Stats stats, @Nullable Row params) {
    ColumnIdent column = getColumn(leftArg);
    if (column == null) {
        return DEFAULT_EQ_SEL;
    }
    var columnStats = stats.statsByColumn().get(column);
    if (columnStats == null) {
        return DEFAULT_EQ_SEL;
    }
    if (rightArg instanceof ParameterSymbol && params != null) {
        var value = params.get(((ParameterSymbol) rightArg).index());
        return eqSelectivityFromValueAndStats(value, columnStats);
    }
    if (rightArg instanceof Literal) {
        return eqSelectivityFromValueAndStats(((Literal) rightArg).value(), columnStats);
    }
    return 1.0 / columnStats.approxDistinct();
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) Literal(io.crate.expression.symbol.Literal) ParameterSymbol(io.crate.expression.symbol.ParameterSymbol)

Aggregations

ParameterSymbol (io.crate.expression.symbol.ParameterSymbol)3 RowN (io.crate.data.RowN)2 SessionSettings (io.crate.metadata.settings.SessionSettings)2 Assignment (io.crate.sql.tree.Assignment)2 Settings (org.elasticsearch.common.settings.Settings)2 Test (org.junit.Test)2 Literal (io.crate.expression.symbol.Literal)1 ColumnIdent (io.crate.metadata.ColumnIdent)1