เกิดข้อผิดพลาดในการเขียนสตรีม PubSub ไปยัง Cloud Storage โดยใช้ Dataflow

การใช้ SCIO จาก spotify เพื่อเขียนงานสำหรับ Dataflow ตามตัวอย่าง 2 รายการ เช่นg1 และ e .g2 เพื่อเขียนสตรีม PubSub ไปที่ GCS แต่ได้รับข้อผิดพลาดต่อไปนี้สำหรับโค้ดด้านล่าง

ข้อผิดพลาด

Exception in thread "main" java.lang.IllegalArgumentException: Write can only be applied to a Bounded PCollection 

รหัส

object StreamingPubSub {
  def main(cmdlineArgs: Array[String]): Unit = {
// set up example wiring
val (opts, args) = ScioContext.parseArguments[ExampleOptions](cmdlineArgs)
val dataflowUtils = new DataflowExampleUtils(opts)
dataflowUtils.setup()

val sc = ScioContext(opts)


sc.pubsubTopic(opts.getPubsubTopic)
.timestampBy {
    _ => new Instant(System.currentTimeMillis() - (scala.math.random * RAND_RANGE).toLong)
  }
.withFixedWindows((Duration.standardHours(1)))
.groupBy(_ => Unit)
.toWindowed
.toSCollection
.saveAsTextFile(args("output"))


val result = sc.close()

// CTRL-C to cancel the streaming pipeline
    dataflowUtils.waitToFinish(result.internal)
  }
}

ฉันอาจจะผสมแนวคิดหน้าต่างกับ Bounded PCollection มีวิธีใดที่จะบรรลุเป้าหมายนี้ หรือฉันจำเป็นต้องใช้การแปลงบางอย่างเพื่อให้สิ่งนี้เกิดขึ้น ใคร ๆ ก็สามารถช่วยเหลือได้ในเรื่องนี้




คำตอบ (1)


ฉันเชื่อว่า saveAsTextFile ด้านล่างของ SCIO ใช้การแปลง Write ของ Dataflow ซึ่งรองรับ PCollections ที่มีขอบเขตเท่านั้น Dataflow ยังไม่มี API โดยตรงสำหรับเขียน PCollection ที่ไม่จำกัดไปยัง Google Cloud Storage แม้ว่านี่จะเป็นสิ่งที่เรากำลังตรวจสอบก็ตาม

หากต้องการคง PCollection ที่ไม่มีขอบเขตไว้ที่ใดที่หนึ่ง ให้ลองพิจารณา เช่น BigQuery, Datastore หรือ Bigtable ใน API ของ SCIO คุณสามารถใช้ saveAsBigQuery ได้ เช่น

person Davor Bonaci    schedule 05.10.2016
comment
ขอบคุณสำหรับการตอบสนองที่รวดเร็ว - person DAR; 06.10.2016