Package io.crate.operation.projectors

Examples of io.crate.operation.projectors.CollectingProjector


    @Test
    public void testCollectFromS3Uri() throws Throwable {
        // this test just verifies the s3 schema detection and bucketName / prefix extraction from the uri.
        // real s3 interaction is mocked completely.
        CollectingProjector projector = getObjects("s3://fakebucket/foo");
        projector.result().get();
    }
View Full Code Here


        getObjects("/some/path/that/shouldnt/exist/*");
    }

    @Test (expected = IllegalArgumentException.class)
    public void testRelativeImport() throws Throwable {
        CollectingProjector projector = getObjects("xy");
        assertCorrectResult(projector.result().get());
    }
View Full Code Here

        assertCorrectResult(projector.result().get());
    }

    @Test
    public void testCollectFromUriWithGlob() throws Throwable {
        CollectingProjector projector = getObjects(tmpFile.getParent() + "/file*.json");
        assertCorrectResult(projector.result().get());
    }
View Full Code Here

        assertCorrectResult(projector.result().get());
    }

    @Test
    public void testCollectFromDirectory() throws Throwable {
        CollectingProjector projector = getObjects(tmpFile.getParent() + "/*");
        assertCorrectResult(projector.result().get());
    }
View Full Code Here

        assertCorrectResult(projector.result().get());
    }

    @Test
    public void testDoCollectRaw() throws Throwable {
        CollectingProjector projector = getObjects(tmpFile.getAbsolutePath());
        assertCorrectResult(projector.result().get());
    }
View Full Code Here

        assertCorrectResult(projector.result().get());
    }

    @Test
    public void testDoCollectRawFromCompressed() throws Throwable {
        CollectingProjector projector = getObjects(tmpFileGz.getAbsolutePath(), "gzip");
        assertCorrectResult(projector.result().get());
    }
View Full Code Here

    private CollectingProjector getObjects(String fileUri) throws Throwable {
        return getObjects(fileUri, null);
    }

    private CollectingProjector getObjects(String fileUri, String compression) throws Throwable {
        CollectingProjector projector = new CollectingProjector();
        FileCollectInputSymbolVisitor.Context context =
                inputSymbolVisitor.process(createReference("_raw", DataTypes.STRING));
        FileReadingCollector collector = new FileReadingCollector(
                fileUri,
                context.topLevelInputs(),
                context.expressions(),
                projector,
                FileReadingCollector.FileFormat.JSON,
                compression,
                ImmutableMap.<String, FileInputFactory>of("s3", new FileInputFactory() {
                    @Override
                    public FileInput create() throws IOException {
                        return new S3FileInput(new S3ClientHelper() {
                            @Override
                            protected AmazonS3 initClient(String accessKey, String secretKey) throws IOException {
                                AmazonS3 client = mock(AmazonS3Client.class);
                                ObjectListing objectListing = mock(ObjectListing.class);
                                S3ObjectSummary summary = mock(S3ObjectSummary.class);
                                S3Object s3Object = mock(S3Object.class);

                                S3ObjectInputStream inputStream = mock(S3ObjectInputStream.class);

                                when(client.listObjects(anyString(), anyString())).thenReturn(objectListing);
                                when(objectListing.getObjectSummaries()).thenReturn(Arrays.asList(summary));
                                when(summary.getKey()).thenReturn("foo");
                                when(client.getObject("fakebucket", "foo")).thenReturn(s3Object);
                                when(s3Object.getObjectContent()).thenReturn(inputStream);
                                when(inputStream.read(new byte[anyInt()], anyInt(), anyByte())).thenReturn(-1);
                                when(client.listNextBatchOfObjects(any(ObjectListing.class))).thenReturn(objectListing);
                                when(objectListing.isTruncated()).thenReturn(false);
                                return client;
                            }
                        });
                    }
                }),
                false,
                1,
                0
        );
        projector.startProjection();
        collector.doCollect();
        return projector;
    }
View Full Code Here

            public Boolean value() {
                return true;
            }
        };

        CollectingProjector projector = getProjector(
                container,
                Arrays.<Input<?>>asList(digestExpression, ctimeExpression),
                Arrays.<BlobCollectorExpression<?>>asList(digestExpression, ctimeExpression),
                condition
        );
        Object[][] result = projector.result().get();

        assertEquals(digest, ((BytesRef)result[0][0]).utf8ToString());
        assertEquals(mtime, result[0][1]);
    }
View Full Code Here

    private CollectingProjector getProjector(BlobContainer container,
                                             List<Input<?>> inputs,
                                             List<BlobCollectorExpression<?>> expressions,
                                             Input<Boolean> condition) throws Exception {
        CollectingProjector projector = new CollectingProjector();
        BlobShard blobShard = mock(BlobShard.class);
        when(blobShard.blobContainer()).thenReturn(container);

        BlobDocCollector collector = new BlobDocCollector(
                blobShard,
                inputs,
                expressions,
                condition,
                projector
        );

        projector.startProjection();
        collector.doCollect();
        return projector;
    }
View Full Code Here

    public ShardProjectorChain(int numShards, List<Projection> projections, ProjectionToProjectorVisitor nodeProjectorVisitor) {
        this.projections = projections;
        nodeProjectors = new ArrayList<>();

        if (projections.size() == 0) {
            firstNodeProjector = new CollectingProjector();
            lastProjector = (ResultProvider) firstNodeProjector;
            nodeProjectors.add(firstNodeProjector);
            shardProjectors = ImmutableList.of();
            return;
        }

        int idx = 0;
        for (Projection projection : projections) {
            if (projection.requiredGranularity() == RowGranularity.SHARD) {
                shardProjectionsIndex = idx;
                break; // we can quit here since currently
                       // there can be only 1 projection on the shard
            }
            idx++;
        }

        Projector previousProjector = null;
        // create the node level projectors
        for (int i = shardProjectionsIndex + 1; i < projections.size(); i++) {
            Projector projector = nodeProjectorVisitor.process(projections.get(i));
            nodeProjectors.add(projector);
            if (previousProjector != null) {
                previousProjector.downstream(projector);
            } else {
                firstNodeProjector = projector;
            }
            previousProjector = projector;
        }
        if (shardProjectionsIndex >= 0) {
            shardProjectors = new ArrayList<>((shardProjectionsIndex + 1) * numShards);
            // shardprojector will be created later
            if (nodeProjectors.isEmpty()) {
                // no node projectors
                previousProjector = firstNodeProjector = new CollectingProjector();
            }
        } else {
            shardProjectors = ImmutableList.of();
        }
        assert previousProjector != null;
        if (previousProjector instanceof ResultProvider) {
            lastProjector = (ResultProvider) previousProjector;
        } else {
            lastProjector = new CollectingProjector();
            previousProjector.downstream((Projector) lastProjector);
        }
    }
View Full Code Here

TOP

Related Classes of io.crate.operation.projectors.CollectingProjector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.