TextIO
TextIO
is a utility to create PTransforms for reading and writing text files.
Reading Bounded PCollection — read Utility
Read read()
read creates a source PTransform that produces a bounded PCollection of text lines (PTransform<PBegin, PCollection<String>>
).
Writing PCollection to Text File — write Utility
Write write()
write creates a sink PTransform (PTransform<PCollection<String>, PDone>
).
Demo
import org.apache.beam.sdk.io.TextIO
val lines = TextIO.read().withHintMatchesManyFiles().from("*.txt")
scala> :type lines
org.apache.beam.sdk.io.TextIO.Read
// TextIO.Read is a root PTransform
import org.apache.beam.sdk.transforms.PTransform
assert(lines.isInstanceOf[PTransform[_, _]])
val counts = TextIO.write().to("counts.txt")
scala> :type counts
org.apache.beam.sdk.io.TextIO.Write
// TextIO.Write is a output PTransform
assert(counts.isInstanceOf[PTransform[_, _]])