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());
}
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));
}
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());
}
}
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));
}
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));
}
Aggregations