Search in sources :

Example 1 with LookupAdapter

use of org.apache.asterix.external.dataset.adapter.LookupAdapter in project asterixdb by apache.

the class LookupAdapterFactory method createAdapter.

public LookupAdapter<T> createAdapter(IHyracksTaskContext ctx, int partition, RecordDescriptor inRecDesc, ExternalFileIndexAccessor snapshotAccessor, IFrameWriter writer) throws HyracksDataException {
    try {
        IRecordDataParser<T> dataParser = dataParserFactory.createRecordParser(ctx);
        ILookupRecordReader<? extends T> reader = readerFactory.createRecordReader(ctx, partition, snapshotAccessor);
        reader.configure(configuration);
        RecordIdReader ridReader = RecordIdReaderFactory.create(configuration, ridFields);
        return new LookupAdapter<>(dataParser, reader, inRecDesc, ridReader, retainInput, retainMissing, isMissingWriterFactory, ctx, writer);
    } catch (Exception e) {
        throw new HyracksDataException(e);
    }
}
Also used : RecordIdReader(org.apache.asterix.external.indexing.RecordIdReader) LookupAdapter(org.apache.asterix.external.dataset.adapter.LookupAdapter) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 2 with LookupAdapter

use of org.apache.asterix.external.dataset.adapter.LookupAdapter in project asterixdb by apache.

the class ExternalLookupOperatorDescriptor method createPushRuntime.

@Override
public IOperatorNodePushable createPushRuntime(final IHyracksTaskContext ctx, final IRecordDescriptorProvider recordDescProvider, final int partition, int nPartitions) throws HyracksDataException {
    // Create a file index accessor to be used for files lookup operations
    final ExternalFileIndexAccessor snapshotAccessor = new ExternalFileIndexAccessor(dataflowHelperFactory.create(ctx, partition), searchOpCallbackFactory, version);
    return new AbstractUnaryInputUnaryOutputOperatorNodePushable() {

        // The adapter that uses the file index along with the coming tuples to access files in HDFS
        private LookupAdapter<?> adapter;

        private boolean indexOpen = false;

        @Override
        public void open() throws HyracksDataException {
            try {
                adapter = adapterFactory.createAdapter(ctx, partition, recordDescProvider.getInputRecordDescriptor(getActivityId(), 0), snapshotAccessor, writer);
                // Open the file index accessor here
                snapshotAccessor.open();
                indexOpen = true;
                adapter.open();
            } catch (Throwable th) {
                throw new HyracksDataException(th);
            }
        }

        @Override
        public void close() throws HyracksDataException {
            HyracksDataException hde = null;
            if (indexOpen) {
                try {
                    snapshotAccessor.close();
                } catch (Throwable th) {
                    hde = new HyracksDataException(th);
                }
                try {
                    adapter.close();
                } catch (Throwable th) {
                    if (hde == null) {
                        hde = new HyracksDataException(th);
                    } else {
                        hde.addSuppressed(th);
                    }
                }
            }
        }

        @Override
        public void fail() throws HyracksDataException {
            try {
                adapter.fail();
            } catch (Throwable th) {
                throw new HyracksDataException(th);
            }
        }

        @Override
        public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
            try {
                adapter.nextFrame(buffer);
            } catch (Throwable th) {
                throw new HyracksDataException(th);
            }
        }

        @Override
        public void flush() throws HyracksDataException {
            adapter.flush();
        }
    };
}
Also used : ExternalFileIndexAccessor(org.apache.asterix.external.indexing.ExternalFileIndexAccessor) AbstractUnaryInputUnaryOutputOperatorNodePushable(org.apache.hyracks.dataflow.std.base.AbstractUnaryInputUnaryOutputOperatorNodePushable) LookupAdapter(org.apache.asterix.external.dataset.adapter.LookupAdapter) ByteBuffer(java.nio.ByteBuffer) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

LookupAdapter (org.apache.asterix.external.dataset.adapter.LookupAdapter)2 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)2 ByteBuffer (java.nio.ByteBuffer)1 ExternalFileIndexAccessor (org.apache.asterix.external.indexing.ExternalFileIndexAccessor)1 RecordIdReader (org.apache.asterix.external.indexing.RecordIdReader)1 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)1 AbstractUnaryInputUnaryOutputOperatorNodePushable (org.apache.hyracks.dataflow.std.base.AbstractUnaryInputUnaryOutputOperatorNodePushable)1