Search in sources :

Example 1 with IAWriter

use of org.apache.hyracks.algebricks.data.IAWriter in project asterixdb by apache.

the class SinkWriterRuntimeFactory method createPushRuntime.

@Override
public IPushRuntime createPushRuntime(IHyracksTaskContext ctx) throws HyracksDataException {
    try {
        PrintStream filePrintStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFile)));
        IAWriter w = writerFactory.createWriter(fields, filePrintStream, printerFactories, inputRecordDesc);
        return new SinkWriterRuntime(w, filePrintStream, inputRecordDesc, true);
    } catch (IOException e) {
        throw new HyracksDataException(e);
    }
}
Also used : PrintStream(java.io.PrintStream) IAWriter(org.apache.hyracks.algebricks.data.IAWriter) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 2 with IAWriter

use of org.apache.hyracks.algebricks.data.IAWriter in project asterixdb by apache.

the class SerializedDataWriterFactory method createWriter.

@Override
public IAWriter createWriter(final int[] fields, final PrintStream ps, IPrinterFactory[] printerFactories, final RecordDescriptor inputRecordDescriptor) {
    return new IAWriter() {

        @Override
        public void init() throws HyracksDataException {
            // dump the SerializerDeserializers to disk
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream oos = new ObjectOutputStream(baos);
                oos.writeObject(inputRecordDescriptor);
                baos.writeTo(ps);
                oos.close();
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
        }

        @Override
        public void printTuple(IFrameTupleAccessor tAccess, int tIdx) throws HyracksDataException {
            for (int i = 0; i < fields.length; i++) {
                int fldStart = tAccess.getTupleStartOffset(tIdx) + tAccess.getFieldSlotsLength() + tAccess.getFieldStartOffset(tIdx, fields[i]);
                int fldLen = tAccess.getFieldLength(tIdx, fields[i]);
                ps.write(tAccess.getBuffer().array(), fldStart, fldLen);
            }
        }
    };
}
Also used : IAWriter(org.apache.hyracks.algebricks.data.IAWriter) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

IOException (java.io.IOException)2 IAWriter (org.apache.hyracks.algebricks.data.IAWriter)2 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)2 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 PrintStream (java.io.PrintStream)1 IFrameTupleAccessor (org.apache.hyracks.api.comm.IFrameTupleAccessor)1