}
@Override
public IOperatorNodePushable createPushRuntime(IHyracksTaskContext ctx,
IRecordDescriptorProvider recordDescProvider, int partition, int nPartitions) throws HyracksDataException {
final FrameTupleAccessor fta = new FrameTupleAccessor(ctx.getFrameSize(),
recordDescProvider.getInputRecordDescriptor(getActivityId(), 0));
final int fieldOutputCount = recordDescProvider.getOutputRecordDescriptor(getActivityId(), 0).getFieldCount();
final ByteBuffer frame = ctx.allocateFrame();
final FrameTupleAppender appender = new FrameTupleAppender(ctx.getFrameSize(), fieldOutputCount);
final short partitionId = (short) ctx.getTaskAttemptId().getTaskId().getPartition();
final ITreeNodeIdProvider nodeIdProvider = new TreeNodeIdProvider(partitionId, dataSourceId, totalDataSources);
final String nodeId = ctx.getJobletContext().getApplicationContext().getNodeId();
final DynamicContext dCtx = (DynamicContext) ctx.getJobletContext().getGlobalJobData();
final String collectionName = collectionPartitions[partition % collectionPartitions.length];
final XMLParser parser = new XMLParser(false, nodeIdProvider, nodeId, frame, appender, childSeq,
dCtx.getStaticContext());
return new AbstractUnaryInputUnaryOutputOperatorNodePushable() {
@Override
public void open() throws HyracksDataException {
appender.reset(frame, true);
writer.open();
}
@Override
public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
fta.reset(buffer);
String collectionModifiedName = collectionName.replace("${nodeId}", nodeId);
File collectionDirectory = new File(collectionModifiedName);
// Go through each tuple.
if (collectionDirectory.isDirectory()) {
for (int tupleIndex = 0; tupleIndex < fta.getTupleCount(); ++tupleIndex) {
@SuppressWarnings("unchecked")
Iterator<File> it = FileUtils.iterateFiles(collectionDirectory, new VXQueryIOFileFilter(),
TrueFileFilter.INSTANCE);
while (it.hasNext()) {
File xmlDocument = it.next();
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Starting to read XML document: " + xmlDocument.getAbsolutePath());
}
parser.parseElements(xmlDocument, writer, fta, tupleIndex);
}
}
} else {
throw new HyracksDataException("Invalid directory parameter (" + nodeId + ":"
+ collectionDirectory.getAbsolutePath() + ") passed to collection.");
}
}
@Override
public void fail() throws HyracksDataException {
writer.fail();
}
@Override
public void close() throws HyracksDataException {
// Check if needed?
fta.reset(frame);
if (fta.getTupleCount() > 0) {
FrameUtils.flushFrame(frame, writer);
}
writer.close();
}
};