use of org.apache.hyracks.api.comm.IFrameWriter in project asterixdb by apache.
the class FileRemoveOperatorDescriptor method createPushRuntime.
@Override
public IOperatorNodePushable createPushRuntime(IHyracksTaskContext ctx, IRecordDescriptorProvider recordDescProvider, int partition, int nPartitions) throws HyracksDataException {
final FileSplit split = fileSplitProvider.getFileSplits()[partition];
final IIOManager ioManager = ctx.getIoManager();
return new AbstractOperatorNodePushable() {
@Override
public void setOutputFrameWriter(int index, IFrameWriter writer, RecordDescriptor recordDesc) {
throw new IllegalStateException();
}
@Override
public void initialize() throws HyracksDataException {
// will only work for files inside the io devices
File f = split.getFile(ioManager);
if (quietly) {
FileUtils.deleteQuietly(f);
} else {
try {
FileUtils.deleteDirectory(f);
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
}
@Override
public IFrameWriter getInputFrameWriter(int index) {
throw new IllegalStateException();
}
@Override
public int getInputArity() {
return 0;
}
@Override
public void deinitialize() throws HyracksDataException {
}
};
}
use of org.apache.hyracks.api.comm.IFrameWriter in project asterixdb by apache.
the class MToNBroadcastConnectorDescriptor method createPartitioner.
@Override
public IFrameWriter createPartitioner(IHyracksTaskContext ctx, RecordDescriptor recordDesc, IPartitionWriterFactory edwFactory, int index, int nProducerPartitions, int nConsumerPartitions) throws HyracksDataException {
final IFrameWriter[] epWriters = new IFrameWriter[nConsumerPartitions];
final boolean[] isOpen = new boolean[nConsumerPartitions];
for (int i = 0; i < nConsumerPartitions; ++i) {
epWriters[i] = edwFactory.createFrameWriter(i);
}
return new IFrameWriter() {
@Override
public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
// Record the current position, instead of using buffer.mark().
// The latter will be problematic because epWriters[i].nextFrame(buffer)
// can flip or clear the buffer.
int pos = buffer.position();
for (int i = 0; i < epWriters.length; ++i) {
if (i != 0) {
buffer.position(pos);
}
epWriters[i].nextFrame(buffer);
}
}
@Override
public void fail() throws HyracksDataException {
HyracksDataException failException = null;
for (int i = 0; i < epWriters.length; ++i) {
if (isOpen[i]) {
try {
epWriters[i].fail();
} catch (Throwable th) {
if (failException == null) {
failException = new HyracksDataException(th);
} else {
failException.addSuppressed(th);
}
}
}
}
if (failException != null) {
throw failException;
}
}
@Override
public void close() throws HyracksDataException {
HyracksDataException closeException = null;
for (int i = 0; i < epWriters.length; ++i) {
if (isOpen[i]) {
try {
epWriters[i].close();
} catch (Throwable th) {
if (closeException == null) {
closeException = new HyracksDataException(th);
} else {
closeException.addSuppressed(th);
}
}
}
}
if (closeException != null) {
throw closeException;
}
}
@Override
public void open() throws HyracksDataException {
for (int i = 0; i < epWriters.length; ++i) {
isOpen[i] = true;
epWriters[i].open();
}
}
@Override
public void flush() throws HyracksDataException {
for (IFrameWriter writer : epWriters) {
writer.flush();
}
}
};
}
Aggregations