use of org.apache.beam.runners.dataflow.util.CloudObject in project beam by apache.
the class AvroByteReaderFactoryTest method runTestCreateAvroReader.
NativeReader<?> runTestCreateAvroReader(String filename, @Nullable Long start, @Nullable Long end, CloudObject encoding) throws Exception {
CloudObject spec = CloudObject.forClassName("AvroSource");
addString(spec, "filename", filename);
if (start != null) {
addLong(spec, "start_offset", start);
}
if (end != null) {
addLong(spec, "end_offset", end);
}
Source cloudSource = new Source();
cloudSource.setSpec(spec);
cloudSource.setCodec(encoding);
NativeReader<?> reader = ReaderRegistry.defaultRegistry().create(cloudSource, PipelineOptionsFactory.create(), // ExecutionContext
null, null);
return reader;
}
use of org.apache.beam.runners.dataflow.util.CloudObject in project beam by apache.
the class ConcatReaderTest method createSourceForTestReader.
private Source createSourceForTestReader(TestReader<String> testReader) {
Source source = new Source();
CloudObject specObj = CloudObject.forClass(TestReader.class);
specObj.put(READER_OBJECT, testReader);
source.setSpec(specObj);
return source;
}
use of org.apache.beam.runners.dataflow.util.CloudObject in project beam by apache.
the class BeamFnMapTaskExecutorFactory method createWriteOperation.
OperationNode createWriteOperation(ParallelInstructionNode node, PipelineOptions options, SinkFactory sinkFactory, DataflowExecutionContext executionContext, DataflowOperationContext context) throws Exception {
ParallelInstruction instruction = node.getParallelInstruction();
WriteInstruction write = instruction.getWrite();
Coder<?> coder = CloudObjects.coderFromCloudObject(CloudObject.fromSpec(write.getSink().getCodec()));
CloudObject cloudSink = CloudObject.fromSpec(write.getSink().getSpec());
Sink<?> sink = sinkFactory.create(cloudSink, coder, options, executionContext, context);
return OperationNode.create(WriteOperation.create(sink, EMPTY_OUTPUT_RECEIVER_ARRAY, context));
}
use of org.apache.beam.runners.dataflow.util.CloudObject in project beam by apache.
the class BeamFnMapTaskExecutorFactory method createReadOperation.
OperationNode createReadOperation(Network<Node, Edge> network, ParallelInstructionNode node, PipelineOptions options, ReaderFactory readerFactory, DataflowExecutionContext<?> executionContext, DataflowOperationContext operationContext) throws Exception {
ParallelInstruction instruction = node.getParallelInstruction();
ReadInstruction read = instruction.getRead();
Source cloudSource = CloudSourceUtils.flattenBaseSpecs(read.getSource());
CloudObject sourceSpec = CloudObject.fromSpec(cloudSource.getSpec());
Coder<?> coder = CloudObjects.coderFromCloudObject(CloudObject.fromSpec(cloudSource.getCodec()));
NativeReader<?> reader = readerFactory.create(sourceSpec, coder, options, executionContext, operationContext);
OutputReceiver[] receivers = getOutputReceivers(network, node);
return OperationNode.create(ReadOperation.create(reader, receivers, operationContext));
}
use of org.apache.beam.runners.dataflow.util.CloudObject in project beam by apache.
the class LengthPrefixUnknownCodersTest method testLengthPrefixParDoInstructionCoder.
@Test
public void testLengthPrefixParDoInstructionCoder() throws Exception {
ParDoInstruction parDo = new ParDoInstruction();
CloudObject spec = CloudObject.forClassName(MERGE_BUCKETS_DO_FN);
spec.put(WorkerPropertyNames.INPUT_CODER, CloudObjects.asCloudObject(windowedValueCoder, /*sdkComponents=*/
null));
parDo.setUserFn(spec);
instruction.setParDo(parDo);
ParallelInstruction prefixedInstruction = forParallelInstruction(instruction, false);
assertEqualsAsJson(CloudObjects.asCloudObject(prefixedWindowedValueCoder, /*sdkComponents=*/
null), prefixedInstruction.getParDo().getUserFn().get(WorkerPropertyNames.INPUT_CODER));
// Should not mutate the instruction.
assertEqualsAsJson(CloudObjects.asCloudObject(windowedValueCoder, /*sdkComponents=*/
null), parDo.getUserFn().get(WorkerPropertyNames.INPUT_CODER));
}
Aggregations