2017-08-29 49 views
0

我正在嘗試編寫源文件存儲在GCS中的文本文件。代碼運行良好,但不是一個XML文件,而是生成多個XML文件。 (XML文件的數量似乎遵循源文本文件中存在的記錄總數)。我在使用'DataflowRunner'時觀察了這種情況。通過Apache Beam寫入XML時生成多個文件

當我在本地運行相同的代碼,然後生成兩個文件。第一個包含所有具有適當元素的記錄,第二個僅包含打開和關閉根元素。

有關這種意外行爲發生的任何想法?請在下面找到我使用的代碼片段:

PCollection<String>input_records=p.apply(TextIO.read().from("gs://balajee_test/xml_source.txt")); 

    PCollection<XMLFormatter> input_object= input_records.apply(ParDo.of(new DoFn<String,XMLFormatter>(){ 
     @ProcessElement 

     public void processElement(ProcessContext c) 
     { 
      String elements[]=c.element().toString().split(","); 

      c.output(new XMLFormatter(elements[0],elements[1],elements[2],elements[3],elements[4])); 

      System.out.println("Values to be written have been provided to constructor "); 

     } 
    })).setCoder(AvroCoder.of(XMLFormatter.class)); 

    input_object.apply(XmlIO.<XMLFormatter>write() 
       .withRecordClass(XMLFormatter.class) 
       .withRootElement("library") 
       .to("gs://balajee_test/book_output")); 

請讓我知道在輸出端一個XML文件(book_output.xml)的方式。

回答

0

XmlIO.write().to()被記錄如下:

/** 
* Writes to files with the given path prefix. 
* 
* <p>Output files will have the name {@literal {filenamePrefix}-0000i-of-0000n.xml} where n is 
* the number of output bundles. 
*/ 

即預計它可能產生多個文件:例如如果跑步者選擇將你的數據處理成3個任務(「捆綁」),你會得到3個文件。在某些情況下,某些部分可能會變空,但寫入的總數據總是與預期數據相加。

要求IO只生成一個文件是一個合理的請求,如果你的數據不是特別大。它在TextIO和AvroIO中通過.withoutSharding()得到支持,但尚未在XmlIO中受支持。請隨意file a JIRA與功能要求。

+0

https://issues.apache.org/jira/browse/BEAM-2826 –

+0

提交相同的JIRA請求。 –