Search in sources :

Example 1 with Context

use of com.hazelcast.jet.core.Processor.Context in project hazelcast by hazelcast.

the class TestAbstractSqlConnector method fullScanReader.

@Nonnull
@Override
public Vertex fullScanReader(@Nonnull DAG dag, @Nonnull Table table_, @Nullable Expression<Boolean> predicate, @Nonnull List<Expression<?>> projection, @Nullable FunctionEx<ExpressionEvalContext, EventTimePolicy<JetSqlRow>> eventTimePolicyProvider) {
    TestTable table = (TestTable) table_;
    List<Object[]> rows = table.rows;
    boolean streaming = table.streaming;
    FunctionEx<Context, TestDataGenerator> createContextFn = ctx -> {
        ExpressionEvalContext evalContext = ExpressionEvalContext.from(ctx);
        EventTimePolicy<JetSqlRow> eventTimePolicy = eventTimePolicyProvider == null ? EventTimePolicy.noEventTime() : eventTimePolicyProvider.apply(evalContext);
        return new TestDataGenerator(rows, predicate, projection, evalContext, eventTimePolicy, streaming);
    };
    ProcessorMetaSupplier pms = createProcessorSupplier(createContextFn);
    return dag.newUniqueVertex(table.toString(), pms);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) Context(com.hazelcast.jet.core.Processor.Context) Traverser(com.hazelcast.jet.Traverser) Arrays(java.util.Arrays) PlanObjectKey(com.hazelcast.sql.impl.optimizer.PlanObjectKey) EventTimePolicy(com.hazelcast.jet.core.EventTimePolicy) QueryDataTypeFamily(com.hazelcast.sql.impl.type.QueryDataTypeFamily) ArrayList(java.util.ArrayList) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) String.join(java.lang.String.join) Map(java.util.Map) ConstantTableStatistics(com.hazelcast.sql.impl.schema.ConstantTableStatistics) SqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnector) DAG(com.hazelcast.jet.core.DAG) Expression(com.hazelcast.sql.impl.expression.Expression) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) EventTimeMapper(com.hazelcast.jet.core.EventTimeMapper) QueryException(com.hazelcast.sql.impl.QueryException) FunctionEx(com.hazelcast.function.FunctionEx) SqlService(com.hazelcast.sql.SqlService) NodeEngine(com.hazelcast.spi.impl.NodeEngine) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) JetTable(com.hazelcast.jet.sql.impl.schema.JetTable) Traversers(com.hazelcast.jet.Traversers) ExpressionUtil(com.hazelcast.jet.sql.impl.ExpressionUtil) Collectors.joining(java.util.stream.Collectors.joining) Objects(java.util.Objects) Vertex(com.hazelcast.jet.core.Vertex) TableField(com.hazelcast.sql.impl.schema.TableField) List(java.util.List) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) QueryDataTypeUtils.resolveTypeForTypeFamily(com.hazelcast.sql.impl.type.QueryDataTypeUtils.resolveTypeForTypeFamily) Context(com.hazelcast.jet.core.Processor.Context) MappingField(com.hazelcast.sql.impl.schema.MappingField) SourceBuilder(com.hazelcast.jet.pipeline.SourceBuilder) Table(com.hazelcast.sql.impl.schema.Table) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) EventTimePolicy(com.hazelcast.jet.core.EventTimePolicy) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Nonnull(javax.annotation.Nonnull)

Example 2 with Context

use of com.hazelcast.jet.core.Processor.Context in project hazelcast by hazelcast.

the class SessionWindowP_failoverTest method init.

private void init(ProcessingGuarantee guarantee) throws Exception {
    AggregateOperation1<Object, LongAccumulator, Long> aggrOp = counting();
    p = new SessionWindowP<>(5000, 0L, singletonList((ToLongFunctionEx<Entry<?, Long>>) Entry::getValue), singletonList(entryKey()), aggrOp, KeyedWindowResult::new);
    Outbox outbox = new TestOutbox(128);
    Context context = new TestProcessorContext().setProcessingGuarantee(guarantee);
    p.init(outbox, context);
}
Also used : LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Context(com.hazelcast.jet.core.Processor.Context) Entry(java.util.Map.Entry) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) Outbox(com.hazelcast.jet.core.Outbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext)

Example 3 with Context

use of com.hazelcast.jet.core.Processor.Context in project hazelcast by hazelcast.

the class SlidingWindowP_failoverTest method init.

private void init(ProcessingGuarantee guarantee) throws Exception {
    SlidingWindowPolicy wDef = SlidingWindowPolicy.tumblingWinPolicy(1);
    AggregateOperation1<Object, LongAccumulator, Long> aggrOp = counting();
    p = new SlidingWindowP<>(singletonList(entryKey()), singletonList((ToLongFunctionEx<Entry<?, Long>>) Entry::getValue), wDef, 0L, aggrOp, KeyedWindowResult::new, true);
    Outbox outbox = new TestOutbox(128);
    Context context = new TestProcessorContext().setProcessingGuarantee(guarantee);
    p.init(outbox, context);
}
Also used : LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Context(com.hazelcast.jet.core.Processor.Context) Entry(java.util.Map.Entry) SlidingWindowPolicy(com.hazelcast.jet.core.SlidingWindowPolicy) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) Outbox(com.hazelcast.jet.core.Outbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext)

Example 4 with Context

use of com.hazelcast.jet.core.Processor.Context in project hazelcast by hazelcast.

the class StreamSourceTest method test.

private void test(long idleTimeout) {
    StreamSource<Object> source = SourceBuilder.stream("src", Context::globalProcessorIndex).distributed(1).fillBufferFn((index, buf) -> {
        // idle, there should be no output.
        if (index == 0) {
            buf.add("item");
            Thread.sleep(10);
        }
    }).build();
    if (idleTimeout != DEFAULT_IDLE_TIMEOUT) {
        source = source.setPartitionIdleTimeout(idleTimeout);
    }
    Pipeline p = Pipeline.create();
    p.readFrom(source).withTimestamps(o -> System.currentTimeMillis(), 0).window(WindowDefinition.tumbling(100)).aggregate(counting()).writeTo(sink);
    Job job = allHazelcastInstances()[0].getJet().newJob(p);
    if (idleTimeout > 10_000) {
        assertTrueAllTheTime(() -> assertEquals("unexpected sink size", 0, sinkList.size()), 5);
    } else if (idleTimeout < 1000) {
        assertTrueEventually(() -> assertTrue("sink empty", sinkList.size() > 0));
    } else {
        fail("test not designed for idleTimeout=" + idleTimeout);
    }
    cancelAndJoin(job);
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) QuickTest(com.hazelcast.test.annotation.QuickTest) DEFAULT_IDLE_TIMEOUT(com.hazelcast.jet.core.EventTimePolicy.DEFAULT_IDLE_TIMEOUT) Context(com.hazelcast.jet.core.Processor.Context) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Assert.fail(org.junit.Assert.fail) Category(org.junit.experimental.categories.Category) Assert.assertEquals(org.junit.Assert.assertEquals) Job(com.hazelcast.jet.Job) Job(com.hazelcast.jet.Job)

Example 5 with Context

use of com.hazelcast.jet.core.Processor.Context in project hazelcast-jet by hazelcast.

the class SessionWindowP_failoverTest method init.

private void init(ProcessingGuarantee guarantee) {
    AggregateOperation1<Object, LongAccumulator, Long> aggrOp = counting();
    p = new SessionWindowP<>(5000, singletonList((DistributedToLongFunction<Entry<?, Long>>) Entry::getValue), singletonList(entryKey()), aggrOp, WindowResult::new);
    Outbox outbox = new TestOutbox(128);
    Context context = new TestProcessorContext().setProcessingGuarantee(guarantee);
    p.init(outbox, context);
}
Also used : LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Context(com.hazelcast.jet.core.Processor.Context) Entry(java.util.Map.Entry) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) Outbox(com.hazelcast.jet.core.Outbox) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext)

Aggregations

Context (com.hazelcast.jet.core.Processor.Context)8 TestOutbox (com.hazelcast.jet.core.test.TestOutbox)6 TestProcessorContext (com.hazelcast.jet.core.test.TestProcessorContext)6 LongAccumulator (com.hazelcast.jet.accumulator.LongAccumulator)4 Outbox (com.hazelcast.jet.core.Outbox)4 Entry (java.util.Map.Entry)4 SlidingWindowPolicy (com.hazelcast.jet.core.SlidingWindowPolicy)2 FunctionEx (com.hazelcast.function.FunctionEx)1 Job (com.hazelcast.jet.Job)1 Traverser (com.hazelcast.jet.Traverser)1 Traversers (com.hazelcast.jet.Traversers)1 AggregateOperations.counting (com.hazelcast.jet.aggregate.AggregateOperations.counting)1 DAG (com.hazelcast.jet.core.DAG)1 EventTimeMapper (com.hazelcast.jet.core.EventTimeMapper)1 EventTimePolicy (com.hazelcast.jet.core.EventTimePolicy)1 DEFAULT_IDLE_TIMEOUT (com.hazelcast.jet.core.EventTimePolicy.DEFAULT_IDLE_TIMEOUT)1 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)1 Vertex (com.hazelcast.jet.core.Vertex)1 TimestampedEntry (com.hazelcast.jet.datamodel.TimestampedEntry)1 SourceBuilder (com.hazelcast.jet.pipeline.SourceBuilder)1