use of com.hazelcast.jet.core.Vertex in project hazelcast by hazelcast.
the class StreamSourceTransform method addToDag.
@Override
public void addToDag(Planner p, Context context) {
if (emitsWatermarks || eventTimePolicy == null) {
// Reached when the source either emits both JetEvents and watermarks
// or neither. In these cases we don't have to insert watermarks.
final ProcessorMetaSupplier metaSupplier = metaSupplierFn.apply(eventTimePolicy != null ? eventTimePolicy : noEventTime());
determineLocalParallelism(metaSupplier.preferredLocalParallelism(), context, false);
p.addVertex(this, name(), determinedLocalParallelism(), metaSupplier);
} else {
// ------------
// | sourceP |
// ------------
// |
// isolated
// v
// -------------
// | insertWmP |
// -------------
String v1name = name();
final ProcessorMetaSupplier metaSupplier = metaSupplierFn.apply(eventTimePolicy);
determineLocalParallelism(metaSupplier.preferredLocalParallelism(), context, false);
Vertex v1 = p.dag.newVertex(v1name, metaSupplier).localParallelism(determinedLocalParallelism());
PlannerVertex pv2 = p.addVertex(this, v1name + "-add-timestamps", determinedLocalParallelism(), insertWatermarksP(eventTimePolicy));
p.dag.edge(between(v1, pv2.v).isolated());
}
}
use of com.hazelcast.jet.core.Vertex 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);
}
use of com.hazelcast.jet.core.Vertex in project hazelcast by hazelcast.
the class TestAllTypesSqlConnector 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) {
if (eventTimePolicyProvider != null) {
throw QueryException.error("Ordering function are not supported for " + TYPE_NAME + " mappings");
}
BatchSource<JetSqlRow> source = SourceBuilder.batch("batch", ExpressionEvalContext::from).<JetSqlRow>fillBufferFn((ctx, buf) -> {
JetSqlRow row = ExpressionUtil.evaluate(predicate, projection, VALUES, ctx);
if (row != null) {
buf.add(row);
}
buf.close();
}).build();
ProcessorMetaSupplier pms = ((BatchSourceTransform<JetSqlRow>) source).metaSupplier;
return dag.newUniqueVertex(table.toString(), pms);
}
use of com.hazelcast.jet.core.Vertex in project hazelcast by hazelcast.
the class WriteFilePTest method test_rollByDate.
@Test
public void test_rollByDate() {
int numItems = 10;
DAG dag = new DAG();
Vertex src = dag.newVertex("src", () -> new SlowSourceP(semaphore, numItems)).localParallelism(1);
@SuppressWarnings("Convert2MethodRef") Vertex sink = dag.newVertex("sink", WriteFileP.metaSupplier(directory.toString(), Objects::toString, "utf-8", "SSS", DISABLE_ROLLING, true, (LongSupplier & Serializable) () -> clock.get()));
dag.edge(between(src, sink));
Job job = instance().getJet().newJob(dag);
for (int i = 0; i < numItems; i++) {
// When
semaphore.release();
String stringValue = i + System.lineSeparator();
// Then
Path file = directory.resolve(String.format("%03d-0", i));
assertTrueEventually(() -> assertTrue("file not found: " + file, Files.exists(file)), 5);
assertTrueEventually(() -> assertEquals(stringValue, new String(Files.readAllBytes(file), StandardCharsets.UTF_8)), 5);
clock.incrementAndGet();
}
job.join();
}
use of com.hazelcast.jet.core.Vertex in project hazelcast by hazelcast.
the class WriteFilePTest method when_slowSource_then_fileFlushedAfterEachItem.
@Test
public void when_slowSource_then_fileFlushedAfterEachItem() {
// Given
int numItems = 10;
DAG dag = new DAG();
Vertex source = dag.newVertex("source", () -> new SlowSourceP(semaphore, numItems)).localParallelism(1);
Vertex sink = dag.newVertex("sink", writeFileP(directory.toString(), StandardCharsets.UTF_8, null, DISABLE_ROLLING, true, Object::toString)).localParallelism(1);
dag.edge(between(source, sink));
Job job = instance().getJet().newJob(dag);
for (int i = 0; i < numItems; i++) {
// When
semaphore.release();
int finalI = i;
// Then
assertTrueEventually(() -> checkFileContents(0, finalI + 1, false, false, true), 5);
}
// wait for the job to finish
job.join();
}
Aggregations