use of org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor in project asterixdb by apache.
the class SubplanRuntimeFactory method createOneOutputPushRuntime.
@Override
public AbstractOneInputOneOutputPushRuntime createOneOutputPushRuntime(final IHyracksTaskContext ctx) throws HyracksDataException {
RecordDescriptor pipelineOutputRecordDescriptor = null;
final PipelineAssembler pa = new PipelineAssembler(pipeline, 1, 1, inputRecordDesc, pipelineOutputRecordDescriptor);
final IMissingWriter[] nullWriters = new IMissingWriter[missingWriterFactories.length];
for (int i = 0; i < missingWriterFactories.length; i++) {
nullWriters[i] = missingWriterFactories[i].createMissingWriter();
}
return new AbstractOneInputOneOutputOneFramePushRuntime() {
/**
* Computes the outer product between a given tuple and the frames
* passed.
*/
class TupleOuterProduct implements IFrameWriter {
private boolean smthWasWritten = false;
private FrameTupleAccessor ta = new FrameTupleAccessor(pipeline.getRecordDescriptors()[pipeline.getRecordDescriptors().length - 1]);
private ArrayTupleBuilder tb = new ArrayTupleBuilder(nullWriters.length);
@Override
public void open() throws HyracksDataException {
smthWasWritten = false;
}
@Override
public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
ta.reset(buffer);
int nTuple = ta.getTupleCount();
for (int t = 0; t < nTuple; t++) {
appendConcat(tRef.getFrameTupleAccessor(), tRef.getTupleIndex(), ta, t);
}
smthWasWritten = true;
}
@Override
public void close() throws HyracksDataException {
if (!smthWasWritten) {
// the case when we need to write nulls
appendNullsToTuple();
appendToFrameFromTupleBuilder(tb);
}
}
@Override
public void fail() throws HyracksDataException {
writer.fail();
}
private void appendNullsToTuple() throws HyracksDataException {
tb.reset();
int n0 = tRef.getFieldCount();
for (int f = 0; f < n0; f++) {
tb.addField(tRef.getFrameTupleAccessor(), tRef.getTupleIndex(), f);
}
DataOutput dos = tb.getDataOutput();
for (int i = 0; i < nullWriters.length; i++) {
nullWriters[i].writeMissing(dos);
tb.addFieldEndOffset();
}
}
}
IFrameWriter endPipe = new TupleOuterProduct();
NestedTupleSourceRuntime startOfPipeline = (NestedTupleSourceRuntime) pa.assemblePipeline(endPipe, ctx);
boolean first = true;
@Override
public void open() throws HyracksDataException {
writer.open();
if (first) {
first = false;
initAccessAppendRef(ctx);
}
}
@Override
public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
tAccess.reset(buffer);
int nTuple = tAccess.getTupleCount();
for (int t = 0; t < nTuple; t++) {
tRef.reset(tAccess, t);
startOfPipeline.writeTuple(buffer, t);
try {
startOfPipeline.open();
} catch (Exception e) {
startOfPipeline.fail();
throw e;
} finally {
startOfPipeline.close();
}
}
}
@Override
public void flush() throws HyracksDataException {
writer.flush();
}
};
}
use of org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor in project asterixdb by apache.
the class AbstractOneInputOneOutputOneFieldFramePushRuntime method initAccessAppendFieldRef.
protected final void initAccessAppendFieldRef(IHyracksTaskContext ctx) throws HyracksDataException {
frame = new VSizeFrame(ctx);
appender = new FrameFixedFieldTupleAppender(inputRecordDesc.getFieldCount());
appender.reset(frame, true);
tAccess = new FrameTupleAccessor(inputRecordDesc);
tRef = new FrameTupleReference();
}
use of org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor in project asterixdb by apache.
the class AbstractOneInputOneOutputOneFramePushRuntime method initAccessAppend.
protected final void initAccessAppend(IHyracksTaskContext ctx) throws HyracksDataException {
frame = new VSizeFrame(ctx);
appender = new FrameTupleAppender(frame);
tAccess = new FrameTupleAccessor(inputRecordDesc);
}
use of org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor in project asterixdb by apache.
the class RunMergingFrameReaderTest method assertFrameIsSorted.
private void assertFrameIsSorted(IFrame frame, List<Map<Integer, String>> keyValueMapList) throws HyracksDataException {
FrameTupleAccessor fta = new FrameTupleAccessor(RecordDesc);
ByteBufferInputStream bbis = new ByteBufferInputStream();
DataInputStream di = new DataInputStream(bbis);
fta.reset(frame.getBuffer());
// fta.prettyPrint();
int preKey = Integer.MIN_VALUE;
for (int i = 0; i < fta.getTupleCount(); i++) {
bbis.setByteBuffer(fta.getBuffer(), fta.getTupleStartOffset(i) + fta.getFieldStartOffset(i, 0) + fta.getFieldSlotsLength());
int key = (int) RecordDesc.getFields()[0].deserialize(di);
bbis.setByteBuffer(fta.getBuffer(), fta.getTupleStartOffset(i) + fta.getFieldStartOffset(i, 1) + fta.getFieldSlotsLength());
String value = (String) RecordDesc.getFields()[1].deserialize(di);
boolean found = false;
for (Map<Integer, String> map : keyValueMapList) {
if (map.containsKey(key) && map.get(key).equals(value)) {
found = true;
map.remove(key);
break;
}
}
assertTrue(found);
assertTrue(preKey <= key);
preKey = key;
}
}
use of org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor in project asterixdb by apache.
the class BinaryTokenizerOperatorNodePushable method open.
@Override
public void open() throws HyracksDataException {
writer.open();
accessor = new FrameTupleAccessor(inputRecDesc);
builder = new ArrayTupleBuilder(outputRecDesc.getFieldCount());
builderData = builder.getFieldData();
appender = new FrameTupleAppender(new VSizeFrame(ctx), true);
}
Aggregations