如果我想将TableRow或String的SCollection输出到Google云存储(GCS),则分别使用saveAsTableRowJsonFile或saveAsTextFile。这两种方法最终都使用
private[scio] def pathWithShards(path: String) = path.replaceAll("\\/+$", "") + "/part"
强制文件名以“ part”开头。是使用saveAsCustomOutput输出自定义分片文件的唯一方法吗?
答案 0 :(得分:3)
我必须通过saveAsCustomOutput在光束代码中完成
import org.apache.beam.sdk.util.Transport
val jsonFactory: JsonFactory = Transport.getJsonFactory
val outputPath = "gs://foo/bar_" // file prefix will be bar_
@BigQueryType.toTable()
case class Clazz(foo: String, bar: String)
val collection: SCollection[Clazz] = ....
collection.map(Clazz.toTableRow).
map(jsonFactory.toString).
saveAsCustomOutput(name = "CustomWrite", io.TextIO.write()
.to(outputPath)
.withSuffix("")
.withWritableByteChannelFactory(FileBasedSink.CompressionType.GZIP))
答案 1 :(得分:0)
Scio的SCollection#saveAs*
API被公认为是通用接收器的包装器,可模拟其他流行系统的行为,在这种情况下,还可以模拟Hadoop Map / Reduce前缀输出文件。因此,如果您想直接访问较低级别的Beam API,SCollection#saveAsCustomOutput
是正确的选择。