Search in sources :

Example 16 with InputFactory

use of io.crate.expression.InputFactory in project crate by crate.

the class FileReadingIteratorTest method prepare.

@Before
public void prepare() {
    NodeContext nodeCtx = new NodeContext(new Functions(Map.of()));
    inputFactory = new InputFactory(nodeCtx);
}
Also used : InputFactory(io.crate.expression.InputFactory) NodeContext(io.crate.metadata.NodeContext) Functions(io.crate.metadata.Functions) Before(org.junit.Before)

Example 17 with InputFactory

use of io.crate.expression.InputFactory in project crate by crate.

the class NodeStatsTest method testNoRequestIfNotRequired.

@Test
public void testNoRequestIfNotRequired() throws Exception {
    List<Symbol> toCollect = new ArrayList<>();
    toCollect.add(idRef);
    when(collectPhase.toCollect()).thenReturn(toCollect);
    BatchIterator iterator = NodeStats.newInstance(transportNodeStatsAction, collectPhase, nodes, txnCtx, new InputFactory(nodeCtx));
    iterator.loadNextBatch();
    // Because only id and name are selected, transportNodesStatsAction should be never used
    verifyNoMoreInteractions(transportNodeStatsAction);
}
Also used : InputFactory(io.crate.expression.InputFactory) Symbol(io.crate.expression.symbol.Symbol) ArrayList(java.util.ArrayList) BatchIterator(io.crate.data.BatchIterator) Test(org.junit.Test)

Example 18 with InputFactory

use of io.crate.expression.InputFactory in project crate by crate.

the class NodeStatsTest method testRequestsAreIssued.

@Test
public void testRequestsAreIssued() throws Exception {
    List<Symbol> toCollect = new ArrayList<>();
    toCollect.add(idRef);
    toCollect.add(nameRef);
    when(collectPhase.toCollect()).thenReturn(toCollect);
    BatchIterator iterator = NodeStats.newInstance(transportNodeStatsAction, collectPhase, nodes, txnCtx, new InputFactory(nodeCtx));
    iterator.loadNextBatch();
    verifyNoMoreInteractions(transportNodeStatsAction);
}
Also used : InputFactory(io.crate.expression.InputFactory) Symbol(io.crate.expression.symbol.Symbol) ArrayList(java.util.ArrayList) BatchIterator(io.crate.data.BatchIterator) Test(org.junit.Test)

Example 19 with InputFactory

use of io.crate.expression.InputFactory in project crate by crate.

the class AbstractWindowFunctionTest method prepareFunctions.

@Before
public void prepareFunctions() {
    DocTableInfo tableInfo = SQLExecutor.tableInfo(new RelationName("doc", "t1"), "create table doc.t1 (x int, y bigint, z string, d double)", clusterService);
    DocTableRelation tableRelation = new DocTableRelation(tableInfo);
    Map<RelationName, AnalyzedRelation> tableSources = Map.of(tableInfo.ident(), tableRelation);
    memoryManager = new OnHeapMemoryManager(bytes -> {
    });
    sqlExpressions = new SqlExpressions(tableSources, tableRelation, User.CRATE_USER, additionalModules);
    inputFactory = new InputFactory(sqlExpressions.nodeCtx);
}
Also used : Input(io.crate.data.Input) TransactionContext(io.crate.metadata.TransactionContext) SqlExpressions(io.crate.testing.SqlExpressions) Arrays(java.util.Arrays) Array(java.lang.reflect.Array) RelationName(io.crate.metadata.RelationName) SENTINEL(io.crate.data.SentinelRow.SENTINEL) BatchIterator(io.crate.data.BatchIterator) ReferenceResolver(io.crate.expression.reference.ReferenceResolver) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) RowN(io.crate.data.RowN) Map(java.util.Map) SQLExecutor(io.crate.testing.SQLExecutor) Before(org.junit.Before) DocTableInfo(io.crate.metadata.doc.DocTableInfo) User(io.crate.user.User) AbstractModule(org.elasticsearch.common.inject.AbstractModule) AggregationFunction(io.crate.execution.engine.aggregation.AggregationFunction) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) ColumnIdent(io.crate.metadata.ColumnIdent) Comparators.createComparator(io.crate.execution.engine.sort.Comparators.createComparator) RamAccounting(io.crate.breaker.RamAccounting) Collectors(java.util.stream.Collectors) Lists2(io.crate.common.collections.Lists2) InputCollectExpression(io.crate.execution.engine.collect.InputCollectExpression) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ExpressionsInput(io.crate.expression.ExpressionsInput) List(java.util.List) OrderBy(io.crate.analyze.OrderBy) BatchIterators(io.crate.data.BatchIterators) Version(org.elasticsearch.Version) DocTableRelation(io.crate.analyze.relations.DocTableRelation) Row(io.crate.data.Row) Literal(io.crate.expression.symbol.Literal) Symbol(io.crate.expression.symbol.Symbol) FunctionImplementation(io.crate.metadata.FunctionImplementation) Matcher(org.hamcrest.Matcher) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) InputColumns(io.crate.execution.dsl.projection.builder.InputColumns) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) InputFactory(io.crate.expression.InputFactory) Comparator(java.util.Comparator) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) InputFactory(io.crate.expression.InputFactory) DocTableInfo(io.crate.metadata.doc.DocTableInfo) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) RelationName(io.crate.metadata.RelationName) DocTableRelation(io.crate.analyze.relations.DocTableRelation) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) SqlExpressions(io.crate.testing.SqlExpressions) Before(org.junit.Before)

Example 20 with InputFactory

use of io.crate.expression.InputFactory 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)

Aggregations

InputFactory (io.crate.expression.InputFactory)26 Symbol (io.crate.expression.symbol.Symbol)13 ArrayList (java.util.ArrayList)13 Before (org.junit.Before)10 RamAccounting (io.crate.breaker.RamAccounting)8 Input (io.crate.data.Input)8 NodeContext (io.crate.metadata.NodeContext)8 Test (org.junit.Test)8 Row (io.crate.data.Row)7 OrderBy (io.crate.analyze.OrderBy)6 BatchIterator (io.crate.data.BatchIterator)6 CollectExpression (io.crate.execution.engine.collect.CollectExpression)6 Reference (io.crate.metadata.Reference)6 DocTableInfo (io.crate.metadata.doc.DocTableInfo)6 Nullable (javax.annotation.Nullable)6 InMemoryBatchIterator (io.crate.data.InMemoryBatchIterator)5 SENTINEL (io.crate.data.SentinelRow.SENTINEL)5 NodeLimits (io.crate.execution.jobs.NodeLimits)5 InputColumn (io.crate.expression.symbol.InputColumn)5 Functions (io.crate.metadata.Functions)5