Search in sources :

Example 1 with IResultSerializerFactory

use of org.apache.hyracks.api.dataflow.value.IResultSerializerFactory in project asterixdb by apache.

the class MetadataProvider method getResultHandleRuntime.

@Override
public Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> getResultHandleRuntime(IDataSink sink, int[] printColumns, IPrinterFactory[] printerFactories, RecordDescriptor inputDesc, boolean ordered, JobSpecification spec) throws AlgebricksException {
    ResultSetDataSink rsds = (ResultSetDataSink) sink;
    ResultSetSinkId rssId = rsds.getId();
    ResultSetId rsId = rssId.getResultSetId();
    ResultWriterOperatorDescriptor resultWriter = null;
    try {
        IResultSerializerFactory resultSerializedAppenderFactory = resultSerializerFactoryProvider.getAqlResultSerializerFactoryProvider(printColumns, printerFactories, getWriterFactory());
        resultWriter = new ResultWriterOperatorDescriptor(spec, rsId, ordered, getResultAsyncMode(), resultSerializedAppenderFactory);
    } catch (IOException e) {
        throw new AlgebricksException(e);
    }
    return new Pair<>(resultWriter, null);
}
Also used : ResultSetId(org.apache.hyracks.api.dataset.ResultSetId) IResultSerializerFactory(org.apache.hyracks.api.dataflow.value.IResultSerializerFactory) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) IOException(java.io.IOException) ResultWriterOperatorDescriptor(org.apache.hyracks.dataflow.std.result.ResultWriterOperatorDescriptor) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 2 with IResultSerializerFactory

use of org.apache.hyracks.api.dataflow.value.IResultSerializerFactory in project asterixdb by apache.

the class ResultSerializerFactoryProvider method getResultSerializerFactoryProvider.

public IResultSerializerFactory getResultSerializerFactoryProvider() {
    return new IResultSerializerFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public IResultSerializer createResultSerializer(final RecordDescriptor recordDesc, final PrintStream printStream) {
            return new IResultSerializer() {

                private static final long serialVersionUID = 1L;

                ByteBufferInputStream bbis = new ByteBufferInputStream();

                DataInputStream di = new DataInputStream(bbis);

                @Override
                public void init() throws HyracksDataException {
                }

                @Override
                public boolean appendTuple(IFrameTupleAccessor tAccess, int tIdx) throws HyracksDataException {
                    int start = tAccess.getTupleStartOffset(tIdx) + tAccess.getFieldSlotsLength();
                    bbis.setByteBuffer(tAccess.getBuffer(), start);
                    Object[] record = new Object[recordDesc.getFieldCount()];
                    for (int i = 0; i < record.length; ++i) {
                        Object instance = recordDesc.getFields()[i].deserialize(di);
                        if (i == 0) {
                            printStream.print(String.valueOf(instance));
                        } else {
                            printStream.print(", " + String.valueOf(instance));
                        }
                    }
                    printStream.println();
                    return true;
                }
            };
        }
    };
}
Also used : PrintStream(java.io.PrintStream) IResultSerializer(org.apache.hyracks.api.dataflow.value.IResultSerializer) RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) IResultSerializerFactory(org.apache.hyracks.api.dataflow.value.IResultSerializerFactory) ByteBufferInputStream(org.apache.hyracks.dataflow.common.comm.util.ByteBufferInputStream) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor) DataInputStream(java.io.DataInputStream)

Aggregations

IResultSerializerFactory (org.apache.hyracks.api.dataflow.value.IResultSerializerFactory)2 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)1 Pair (org.apache.hyracks.algebricks.common.utils.Pair)1 IFrameTupleAccessor (org.apache.hyracks.api.comm.IFrameTupleAccessor)1 IResultSerializer (org.apache.hyracks.api.dataflow.value.IResultSerializer)1 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)1 ResultSetId (org.apache.hyracks.api.dataset.ResultSetId)1 ByteBufferInputStream (org.apache.hyracks.dataflow.common.comm.util.ByteBufferInputStream)1 ResultWriterOperatorDescriptor (org.apache.hyracks.dataflow.std.result.ResultWriterOperatorDescriptor)1