Search in sources :

Example 1 with BatchSource

use of com.hazelcast.jet.pipeline.BatchSource in project hazelcast by hazelcast.

the class CommonElasticSourcesTest method given_documents_when_readFromElasticSourceWithQuery_then_resultHasMatchingDocuments.

@Test
public void given_documents_when_readFromElasticSourceWithQuery_then_resultHasMatchingDocuments() {
    indexDocument("my-index", of("name", "Frantisek"));
    indexDocument("my-index", of("name", "Vladimir"));
    Pipeline p = Pipeline.create();
    BatchSource<String> source = new ElasticSourceBuilder<>().clientFn(elasticClientSupplier()).searchRequestFn(() -> new SearchRequest("my-index").source(new SearchSourceBuilder().query(QueryBuilders.matchQuery("name", "Frantisek")))).mapToItemFn(hit -> (String) hit.getSourceAsMap().get("name")).build();
    p.readFrom(source).writeTo(Sinks.list(results));
    submitJob(p);
    assertThat(results).containsOnlyOnce("Frantisek");
}
Also used : ResponseException(org.elasticsearch.client.ResponseException) SearchHit(org.elasticsearch.search.SearchHit) QueryBuilders.matchAllQuery(org.elasticsearch.index.query.QueryBuilders.matchAllQuery) BatchSource(com.hazelcast.jet.pipeline.BatchSource) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) IOException(java.io.IOException) SearchRequest(org.elasticsearch.action.search.SearchRequest) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) ImmutableMap.of(com.google.common.collect.ImmutableMap.of) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) SearchRequest(org.elasticsearch.action.search.SearchRequest) Pipeline(com.hazelcast.jet.pipeline.Pipeline) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) Test(org.junit.Test)

Example 2 with BatchSource

use of com.hazelcast.jet.pipeline.BatchSource in project hazelcast by hazelcast.

the class CommonElasticSourcesTest method given_multipleIndexes_when_readFromElasticSourceWithIndexWildcard_then_resultDocumentsFromAllIndexes.

@Test
public void given_multipleIndexes_when_readFromElasticSourceWithIndexWildcard_then_resultDocumentsFromAllIndexes() {
    indexDocument("my-index-1", of("name", "Frantisek"));
    indexDocument("my-index-2", of("name", "Vladimir"));
    Pipeline p = Pipeline.create();
    BatchSource<String> source = new ElasticSourceBuilder<>().clientFn(elasticClientSupplier()).searchRequestFn(() -> new SearchRequest("my-index-*")).mapToItemFn(hit -> (String) hit.getSourceAsMap().get("name")).build();
    p.readFrom(source).writeTo(Sinks.list(results));
    submitJob(p);
    assertThat(results).containsOnlyOnce("Frantisek", "Vladimir");
}
Also used : ResponseException(org.elasticsearch.client.ResponseException) SearchHit(org.elasticsearch.search.SearchHit) QueryBuilders.matchAllQuery(org.elasticsearch.index.query.QueryBuilders.matchAllQuery) BatchSource(com.hazelcast.jet.pipeline.BatchSource) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) IOException(java.io.IOException) SearchRequest(org.elasticsearch.action.search.SearchRequest) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) ImmutableMap.of(com.google.common.collect.ImmutableMap.of) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) SearchRequest(org.elasticsearch.action.search.SearchRequest) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 3 with BatchSource

use of com.hazelcast.jet.pipeline.BatchSource in project hazelcast by hazelcast.

the class CommonElasticSourcesTest method given_indexWithOneDocument_whenReadFromElasticSource_thenFinishWithOneResult.

@Test
public void given_indexWithOneDocument_whenReadFromElasticSource_thenFinishWithOneResult() {
    indexDocument("my-index", of("name", "Frantisek"));
    Pipeline p = Pipeline.create();
    BatchSource<String> source = new ElasticSourceBuilder<>().clientFn(elasticClientSupplier()).searchRequestFn(() -> new SearchRequest("my-index")).mapToItemFn(hit -> (String) hit.getSourceAsMap().get("name")).build();
    p.readFrom(source).writeTo(Sinks.list(results));
    submitJob(p);
    assertThat(results).containsExactly("Frantisek");
}
Also used : ResponseException(org.elasticsearch.client.ResponseException) SearchHit(org.elasticsearch.search.SearchHit) QueryBuilders.matchAllQuery(org.elasticsearch.index.query.QueryBuilders.matchAllQuery) BatchSource(com.hazelcast.jet.pipeline.BatchSource) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) IOException(java.io.IOException) SearchRequest(org.elasticsearch.action.search.SearchRequest) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) ImmutableMap.of(com.google.common.collect.ImmutableMap.of) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) SearchRequest(org.elasticsearch.action.search.SearchRequest) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 4 with BatchSource

use of com.hazelcast.jet.pipeline.BatchSource 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);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) LocalDateTime(java.time.LocalDateTime) PlanObjectKey(com.hazelcast.sql.impl.optimizer.PlanObjectKey) EventTimePolicy(com.hazelcast.jet.core.EventTimePolicy) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) BigDecimal(java.math.BigDecimal) TEST_SS(com.hazelcast.jet.sql.SqlTestSupport.TEST_SS) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ConstantTableStatistics(com.hazelcast.sql.impl.schema.ConstantTableStatistics) LocalTime(java.time.LocalTime) 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) QueryException(com.hazelcast.sql.impl.QueryException) FunctionEx(com.hazelcast.function.FunctionEx) SqlService(com.hazelcast.sql.SqlService) NodeEngine(com.hazelcast.spi.impl.NodeEngine) BatchSource(com.hazelcast.jet.pipeline.BatchSource) Util.toList(com.hazelcast.jet.impl.util.Util.toList) ImmutableMap(com.google.common.collect.ImmutableMap) BatchSourceTransform(com.hazelcast.jet.impl.pipeline.transform.BatchSourceTransform) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) JetTable(com.hazelcast.jet.sql.impl.schema.JetTable) SqlTestSupport(com.hazelcast.jet.sql.SqlTestSupport) ExpressionUtil(com.hazelcast.jet.sql.impl.ExpressionUtil) 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) OffsetDateTime(java.time.OffsetDateTime) LocalDate(java.time.LocalDate) UTC(java.time.ZoneOffset.UTC) MappingField(com.hazelcast.sql.impl.schema.MappingField) SourceBuilder(com.hazelcast.jet.pipeline.SourceBuilder) Table(com.hazelcast.sql.impl.schema.Table) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) BatchSourceTransform(com.hazelcast.jet.impl.pipeline.transform.BatchSourceTransform) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Nonnull(javax.annotation.Nonnull)

Example 5 with BatchSource

use of com.hazelcast.jet.pipeline.BatchSource in project hazelcast by hazelcast.

the class ManagedContextTest method testSources.

private void testSources(SupplierEx<? extends AnotherSourceContext> sourceSupplier) {
    BatchSource<String> src = SourceBuilder.batch("source", c -> sourceSupplier.get()).<String>fillBufferFn((c, b) -> {
        b.add(c.injectedValue);
        b.close();
    }).build();
    Pipeline pipeline = Pipeline.create();
    pipeline.readFrom(src).writeTo(assertAnyOrder(singletonList(INJECTED_VALUE)));
    hz.getJet().newJob(pipeline).join();
}
Also used : Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) FunctionEx(com.hazelcast.function.FunctionEx) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) ManagedContext(com.hazelcast.core.ManagedContext) BatchSource(com.hazelcast.jet.pipeline.BatchSource) Pipeline(com.hazelcast.jet.pipeline.Pipeline) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) SupplierEx(com.hazelcast.function.SupplierEx) Collections.singletonList(java.util.Collections.singletonList) Sources(com.hazelcast.jet.pipeline.Sources) AssertionSinks.assertAnyOrder(com.hazelcast.jet.pipeline.test.AssertionSinks.assertAnyOrder) TestSources(com.hazelcast.jet.pipeline.test.TestSources) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) ServiceFactory(com.hazelcast.jet.pipeline.ServiceFactory) SinkBuilder(com.hazelcast.jet.pipeline.SinkBuilder) SourceBuilder(com.hazelcast.jet.pipeline.SourceBuilder) ServiceFactories(com.hazelcast.jet.pipeline.ServiceFactories) Sink(com.hazelcast.jet.pipeline.Sink) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Aggregations

BatchSource (com.hazelcast.jet.pipeline.BatchSource)12 Pipeline (com.hazelcast.jet.pipeline.Pipeline)10 Test (org.junit.Test)10 Sinks (com.hazelcast.jet.pipeline.Sinks)9 SourceBuilder (com.hazelcast.jet.pipeline.SourceBuilder)6 List (java.util.List)6 ImmutableMap.of (com.google.common.collect.ImmutableMap.of)5 IOException (java.io.IOException)5 Nonnull (javax.annotation.Nonnull)5 Nullable (javax.annotation.Nullable)5 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)5 SearchRequest (org.elasticsearch.action.search.SearchRequest)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 TestSources (com.hazelcast.jet.pipeline.test.TestSources)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 ConsumerEx (com.hazelcast.function.ConsumerEx)3 Job (com.hazelcast.jet.Job)3 Observable (com.hazelcast.jet.Observable)3 TestInClusterSupport (com.hazelcast.jet.TestInClusterSupport)3