2017-06-06 39 views
2

有沒有辦法使用Apache Beam BigQueryIO創建日期分區表,換句話說,有沒有辦法將分區裝飾器用於尚未創建的表?以編程方式創建日期分區表

我知道我可以先創建一個表,然後我可以在我的代碼中使用分區裝飾器,但由於我從行的字段動態確定TableDestination,因此無法預先創建這些表。

我的代碼是這樣的:

rows.apply("Write rows", 
    BigQueryIO.writeTableRows() 
     .to(new SerializableFunction<ValueInSingleWindow<TableRow>, TableDestination>() { 
      @Override 
      public TableDestination apply(ValueInSingleWindow<TableRow> value) { 
      TableRow t = value.getValue(); 

      String tableName = ... // get from the fields of table row 
      String partition = ... // get the date part that will be used for decorator 

      TableDestination td = new TableDestination(
         "project-id:dataset-id." + tableName + "$" + partition, ""); 
       return td; 
      } 
     }).withSchema(someSchema) 
     .withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND) 
    .withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED)); 

有了這個,它試圖創建一個project-id:dataset-id.tableName$partition表,它抱怨$不能在表名內部使用。

回答

2

看來這目前是不可能的。

在官方的BEAM JIRA問題列表中有這樣的要求:BEAM-2390an official pull request,所以看起來這將很快就可能實現!

0

表格ID格式:The ID of the table. The ID must contain only letters (a-z, A-Z), numbers (0-9), or underscores (_). The maximum length is 1,024 characters.檢查BigQuery doc

+0

'$'符號代表分區裝飾器,這是我的問題的本質。通常情況下,如果我事先創建一個表,我可以使用該符號來指定我的分區,但是我無法將它用於尚未創建的表。 – Ali