Search in sources :

Example 1 with FileLineReferenceResolver

use of io.crate.operation.reference.file.FileLineReferenceResolver in project crate by crate.

the class FileReadingCollectorTest method createBatchIterator.

private BatchIterator createBatchIterator(Collection<String> fileUris, String compression, final S3ObjectInputStream s3InputStream) {
    Reference raw = createReference("_raw", DataTypes.STRING);
    InputFactory.Context<LineCollectorExpression<?>> ctx = inputFactory.ctxForRefs(FileLineReferenceResolver::getImplementation);
    List<Input<?>> inputs = Collections.singletonList(ctx.add(raw));
    return FileReadingIterator.newInstance(fileUris, inputs, ctx.expressions(), compression, ImmutableMap.of(LocalFsFileInputFactory.NAME, new LocalFsFileInputFactory(), S3FileInputFactory.NAME, () -> 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);
            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(s3InputStream);
            when(client.listNextBatchOfObjects(any(ObjectListing.class))).thenReturn(objectListing);
            when(objectListing.isTruncated()).thenReturn(false);
            return client;
        }
    })), false, 1, 0);
}
Also used : InputFactory(io.crate.operation.InputFactory) AmazonS3(com.amazonaws.services.s3.AmazonS3) TestingHelpers.createReference(io.crate.testing.TestingHelpers.createReference) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) FileLineReferenceResolver(io.crate.operation.reference.file.FileLineReferenceResolver) S3ClientHelper(io.crate.external.S3ClientHelper) S3Object(com.amazonaws.services.s3.model.S3Object)

Example 2 with FileLineReferenceResolver

use of io.crate.operation.reference.file.FileLineReferenceResolver in project crate by crate.

the class FileCollectSource method getCollector.

@Override
public CrateCollector getCollector(CollectPhase collectPhase, BatchConsumer consumer, JobCollectContext jobCollectContext) {
    FileUriCollectPhase fileUriCollectPhase = (FileUriCollectPhase) collectPhase;
    InputFactory.Context<LineCollectorExpression<?>> ctx = inputFactory.ctxForRefs(FileLineReferenceResolver::getImplementation);
    ctx.add(collectPhase.toCollect());
    String[] readers = fileUriCollectPhase.nodeIds().toArray(new String[fileUriCollectPhase.nodeIds().size()]);
    Arrays.sort(readers);
    List<String> fileUris;
    fileUris = targetUriToStringList(fileUriCollectPhase.targetUri());
    BatchIterator fileReadingIterator = FileReadingIterator.newInstance(fileUris, ctx.topLevelInputs(), ctx.expressions(), fileUriCollectPhase.compression(), fileInputFactoryMap, fileUriCollectPhase.sharedStorage(), readers.length, Arrays.binarySearch(readers, clusterService.state().nodes().getLocalNodeId()));
    return BatchIteratorCollectorBridge.newInstance(fileReadingIterator, consumer);
}
Also used : FileInputFactory(io.crate.operation.collect.files.FileInputFactory) InputFactory(io.crate.operation.InputFactory) LineCollectorExpression(io.crate.operation.collect.files.LineCollectorExpression) FileLineReferenceResolver(io.crate.operation.reference.file.FileLineReferenceResolver) BatchIterator(io.crate.data.BatchIterator) FileUriCollectPhase(io.crate.planner.node.dql.FileUriCollectPhase)

Example 3 with FileLineReferenceResolver

use of io.crate.operation.reference.file.FileLineReferenceResolver in project crate by crate.

the class FileReadingIteratorTest method createBatchIterator.

private BatchIterator createBatchIterator(Collection<String> fileUris, String compression) {
    Reference raw = createReference("_raw", DataTypes.STRING);
    InputFactory.Context<LineCollectorExpression<?>> ctx = inputFactory.ctxForRefs(FileLineReferenceResolver::getImplementation);
    List<Input<?>> inputs = Collections.singletonList(ctx.add(raw));
    return FileReadingIterator.newInstance(fileUris, inputs, ctx.expressions(), compression, ImmutableMap.of(LocalFsFileInputFactory.NAME, new LocalFsFileInputFactory()), false, 1, 0);
}
Also used : InputFactory(io.crate.operation.InputFactory) Input(io.crate.data.Input) FileLineReferenceResolver(io.crate.operation.reference.file.FileLineReferenceResolver) TestingHelpers.createReference(io.crate.testing.TestingHelpers.createReference)

Aggregations

InputFactory (io.crate.operation.InputFactory)3 FileLineReferenceResolver (io.crate.operation.reference.file.FileLineReferenceResolver)3 TestingHelpers.createReference (io.crate.testing.TestingHelpers.createReference)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)1 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)1 S3Object (com.amazonaws.services.s3.model.S3Object)1 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)1 BatchIterator (io.crate.data.BatchIterator)1 Input (io.crate.data.Input)1 S3ClientHelper (io.crate.external.S3ClientHelper)1 FileInputFactory (io.crate.operation.collect.files.FileInputFactory)1 LineCollectorExpression (io.crate.operation.collect.files.LineCollectorExpression)1 FileUriCollectPhase (io.crate.planner.node.dql.FileUriCollectPhase)1