Search in sources :

Example 1 with NestableCollectExpression

use of io.crate.execution.engine.collect.NestableCollectExpression in project crate by crate.

the class JobsLogService method createFilter.

private ExpressionsInput<JobContextLog, Boolean> createFilter(String filterExpression, String settingName) {
    Symbol filter = asSymbol(filterExpression);
    if (!filter.valueType().equals(DataTypes.BOOLEAN)) {
        throw new IllegalArgumentException("Filter expression for " + settingName + " must result in a boolean, not: " + filter.valueType() + " (`" + filter + "`)");
    }
    InputFactory.Context<NestableCollectExpression<JobContextLog, ?>> ctx = inputFactory.ctxForRefs(systemTransactionCtx, refResolver);
    @SuppressWarnings("unchecked") Input<Boolean> filterInput = (Input<Boolean>) ctx.add(filter);
    return new ExpressionsInput<>(filterInput, ctx.expressions());
}
Also used : InputFactory(io.crate.expression.InputFactory) Input(io.crate.data.Input) ExpressionsInput(io.crate.expression.ExpressionsInput) Symbol(io.crate.expression.symbol.Symbol) NestableCollectExpression(io.crate.execution.engine.collect.NestableCollectExpression) ExpressionsInput(io.crate.expression.ExpressionsInput)

Example 2 with NestableCollectExpression

use of io.crate.execution.engine.collect.NestableCollectExpression in project crate by crate.

the class NodeStatsContextFieldResolverTest method testConnectionsHttpLookupAndExpression.

@Test
public void testConnectionsHttpLookupAndExpression() {
    NodeStatsContext statsContext = resolver.forTopColumnIdents(Collections.singletonList(SysNodesTableInfo.Columns.CONNECTIONS));
    RowCollectExpressionFactory<NodeStatsContext> expressionFactory = SysNodesTableInfo.create().expressions().get(SysNodesTableInfo.Columns.CONNECTIONS);
    NestableCollectExpression<NodeStatsContext, ?> expression = expressionFactory.create();
    NestableCollectExpression http = (NestableCollectExpression) expression.getChild("http");
    NestableCollectExpression open = (NestableCollectExpression) http.getChild("open");
    open.setNextRow(statsContext);
    assertThat(open.value(), is(20L));
    NestableCollectExpression total = (NestableCollectExpression) http.getChild("total");
    total.setNextRow(statsContext);
    assertThat(total.value(), is(30L));
}
Also used : NestableCollectExpression(io.crate.execution.engine.collect.NestableCollectExpression) Test(org.junit.Test)

Example 3 with NestableCollectExpression

use of io.crate.execution.engine.collect.NestableCollectExpression in project crate by crate.

the class ProjectionToProjectorVisitor method visitSysUpdateProjection.

@Override
public Projector visitSysUpdateProjection(SysUpdateProjection projection, Context context) {
    Map<Reference, Symbol> assignments = projection.assignments();
    assert !assignments.isEmpty() : "at least one assignment is required";
    List<Input<?>> valueInputs = new ArrayList<>(assignments.size());
    List<ColumnIdent> assignmentCols = new ArrayList<>(assignments.size());
    RelationName relationName = null;
    InputFactory.Context<NestableCollectExpression<?, ?>> readCtx = null;
    for (Map.Entry<Reference, Symbol> e : assignments.entrySet()) {
        Reference ref = e.getKey();
        assert relationName == null || relationName.equals(ref.ident().tableIdent()) : "mixed table assignments found";
        relationName = ref.ident().tableIdent();
        if (readCtx == null) {
            StaticTableDefinition<?> tableDefinition = staticTableDefinitionGetter.apply(relationName);
            readCtx = inputFactory.ctxForRefs(context.txnCtx, tableDefinition.getReferenceResolver());
        }
        assignmentCols.add(ref.column());
        Input<?> sourceInput = readCtx.add(e.getValue());
        valueInputs.add(sourceInput);
    }
    SysRowUpdater<?> rowUpdater = sysUpdaterGetter.apply(relationName);
    assert readCtx != null : "readCtx must not be null";
    assert rowUpdater != null : "row updater needs to exist";
    Consumer<Object> rowWriter = rowUpdater.newRowWriter(assignmentCols, valueInputs, readCtx.expressions());
    if (projection.returnValues() == null) {
        return new SysUpdateProjector(rowWriter);
    } else {
        InputFactory.Context<NestableCollectExpression<SysNodeCheck, ?>> cntx = new InputFactory(nodeCtx).ctxForRefs(context.txnCtx, new StaticTableReferenceResolver<>(SysNodeChecksTableInfo.create().expressions()));
        cntx.add(List.of(projection.returnValues()));
        return new SysUpdateResultSetProjector(rowUpdater, rowWriter, cntx.expressions(), cntx.topLevelInputs());
    }
}
Also used : InputFactory(io.crate.expression.InputFactory) Reference(io.crate.metadata.Reference) Symbol(io.crate.expression.symbol.Symbol) NestableCollectExpression(io.crate.execution.engine.collect.NestableCollectExpression) ArrayList(java.util.ArrayList) ColumnIdent(io.crate.metadata.ColumnIdent) Input(io.crate.data.Input) SysUpdateProjector(io.crate.execution.dml.SysUpdateProjector) SysUpdateResultSetProjector(io.crate.execution.dml.SysUpdateResultSetProjector) RelationName(io.crate.metadata.RelationName) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with NestableCollectExpression

use of io.crate.execution.engine.collect.NestableCollectExpression in project crate by crate.

the class NodeStatsContextFieldResolverTest method testNumberOfPSqlConnectionsCanBeRetrieved.

@Test
public void testNumberOfPSqlConnectionsCanBeRetrieved() {
    // tests the resolver and the expression
    NodeStatsContext statsContext = resolver.forTopColumnIdents(Collections.singletonList(SysNodesTableInfo.Columns.CONNECTIONS));
    RowCollectExpressionFactory<NodeStatsContext> expressionFactory = SysNodesTableInfo.create().expressions().get(SysNodesTableInfo.Columns.CONNECTIONS);
    NestableCollectExpression<NodeStatsContext, ?> expression = expressionFactory.create();
    NestableCollectExpression psql = (NestableCollectExpression) expression.getChild("psql");
    NestableCollectExpression open = (NestableCollectExpression) psql.getChild("open");
    open.setNextRow(statsContext);
    assertThat(open.value(), is(2L));
    NestableCollectExpression total = (NestableCollectExpression) psql.getChild("total");
    total.setNextRow(statsContext);
    assertThat(total.value(), is(4L));
}
Also used : NestableCollectExpression(io.crate.execution.engine.collect.NestableCollectExpression) Test(org.junit.Test)

Example 5 with NestableCollectExpression

use of io.crate.execution.engine.collect.NestableCollectExpression in project crate by crate.

the class NodeStatsContextFieldResolverTest method testNumberOfTransportConnectionsCanBeRetrieved.

@Test
public void testNumberOfTransportConnectionsCanBeRetrieved() {
    // tests the resolver and the expression
    NodeStatsContext statsContext = resolver.forTopColumnIdents(Collections.singletonList(SysNodesTableInfo.Columns.CONNECTIONS));
    RowCollectExpressionFactory<NodeStatsContext> expressionFactory = SysNodesTableInfo.create().expressions().get(SysNodesTableInfo.Columns.CONNECTIONS);
    NestableCollectExpression<NodeStatsContext, ?> expression = expressionFactory.create();
    NestableCollectExpression psql = (NestableCollectExpression) expression.getChild("transport");
    NestableCollectExpression open = (NestableCollectExpression) psql.getChild("open");
    open.setNextRow(statsContext);
    assertThat(open.value(), is(12L));
}
Also used : NestableCollectExpression(io.crate.execution.engine.collect.NestableCollectExpression) Test(org.junit.Test)

Aggregations

NestableCollectExpression (io.crate.execution.engine.collect.NestableCollectExpression)5 Test (org.junit.Test)3 Input (io.crate.data.Input)2 InputFactory (io.crate.expression.InputFactory)2 Symbol (io.crate.expression.symbol.Symbol)2 SysUpdateProjector (io.crate.execution.dml.SysUpdateProjector)1 SysUpdateResultSetProjector (io.crate.execution.dml.SysUpdateResultSetProjector)1 ExpressionsInput (io.crate.expression.ExpressionsInput)1 ColumnIdent (io.crate.metadata.ColumnIdent)1 Reference (io.crate.metadata.Reference)1 RelationName (io.crate.metadata.RelationName)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1