Search in sources :

Example 1 with FileInputFactory

use of io.crate.operation.collect.files.FileInputFactory in project crate by crate.

the class MapSideDataCollectOperationTest method testFileUriCollect.

@Test
public void testFileUriCollect() throws Exception {
    ClusterService clusterService = new NoopClusterService();
    Functions functions = getFunctions();
    CollectSourceResolver collectSourceResolver = mock(CollectSourceResolver.class);
    when(collectSourceResolver.getService(any(RoutedCollectPhase.class))).thenReturn(new FileCollectSource(functions, clusterService, Collections.<String, FileInputFactory>emptyMap()));
    MapSideDataCollectOperation collectOperation = new MapSideDataCollectOperation(collectSourceResolver, threadPool);
    File tmpFile = temporaryFolder.newFile("fileUriCollectOperation.json");
    try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tmpFile), StandardCharsets.UTF_8)) {
        writer.write("{\"name\": \"Arthur\", \"id\": 4, \"details\": {\"age\": 38}}\n");
        writer.write("{\"id\": 5, \"name\": \"Trillian\", \"details\": {\"age\": 33}}\n");
    }
    FileUriCollectPhase collectNode = new FileUriCollectPhase(UUID.randomUUID(), 0, "test", Collections.singletonList("noop_id"), Literal.of(Paths.get(tmpFile.toURI()).toUri().toString()), Arrays.<Symbol>asList(createReference("name", DataTypes.STRING), createReference(new ColumnIdent("details", "age"), DataTypes.INTEGER)), Collections.emptyList(), null, false);
    String threadPoolName = JobCollectContext.threadPoolName(collectNode, "noop_id");
    TestingBatchConsumer consumer = new TestingBatchConsumer();
    JobCollectContext jobCollectContext = mock(JobCollectContext.class);
    CrateCollector collectors = collectOperation.createCollector(collectNode, consumer, jobCollectContext);
    collectOperation.launchCollector(collectors, threadPoolName);
    assertThat(new CollectionBucket(consumer.getResult()), contains(isRow("Arthur", 38), isRow("Trillian", 33)));
}
Also used : CollectSourceResolver(io.crate.operation.collect.sources.CollectSourceResolver) Functions(io.crate.metadata.Functions) FileUriCollectPhase(io.crate.planner.node.dql.FileUriCollectPhase) ColumnIdent(io.crate.metadata.ColumnIdent) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) FileCollectSource(io.crate.operation.collect.sources.FileCollectSource) FileOutputStream(java.io.FileOutputStream) FileInputFactory(io.crate.operation.collect.files.FileInputFactory) OutputStreamWriter(java.io.OutputStreamWriter) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) File(java.io.File) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) CollectionBucket(io.crate.data.CollectionBucket) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

CollectionBucket (io.crate.data.CollectionBucket)1 ColumnIdent (io.crate.metadata.ColumnIdent)1 Functions (io.crate.metadata.Functions)1 FileInputFactory (io.crate.operation.collect.files.FileInputFactory)1 CollectSourceResolver (io.crate.operation.collect.sources.CollectSourceResolver)1 FileCollectSource (io.crate.operation.collect.sources.FileCollectSource)1 FileUriCollectPhase (io.crate.planner.node.dql.FileUriCollectPhase)1 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)1 CrateUnitTest (io.crate.test.integration.CrateUnitTest)1 TestingBatchConsumer (io.crate.testing.TestingBatchConsumer)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ClusterService (org.elasticsearch.cluster.ClusterService)1 NoopClusterService (org.elasticsearch.test.cluster.NoopClusterService)1 Test (org.junit.Test)1