大數據

DataWorks百問百答64:數據集成如何同步Mongodb不同數據類型?

mongodb源端原始數據如下(數據無實際場景):
dataworks64-1.png

  • 同步一層子屬性

例1:同步id:
{
"name": "id",
"type": "string"
}
例2:同步services:
{
"name": "services",
"type": "object"
},

  • 同步複雜類型的子屬性:

同步services下的子屬性optional:
{
"name": "services.optional",
"type": "document.string"
},
注意:array類型無法取到array下的具體數據,需要作為整體同步
          type值需要小寫。

  • 多個字段合併成一個json串:

使用MongoDBReader插件讀出數據時,支持將MongoDB裡document中多個字段合併成一個json串;
舉例來說將Mongo中的字段導入到ODPS,有字段如下(下文均省略了value使用key來代替整個字段)的三個document,其中 a b 是所有doc均有的公共字段, x_n是不固定字段:
   doc1:a b x_1 x_2
   doc2:  a b x_2 x_3 x_4
   doc3:  a b x_5
需要一一對應的字段在配置文件裡明確指出,需要合併的字段則需另取名稱(不可與document中已存在字段同名),並指定類型為 "combine" ,如:
"column": [
{
 "name": "a",
 "type": "string",
},
{
  "name": "b",
  "type": "string",
},
{
    "name": "doc",
"type": "combine",
 }
]
最終導出到ODPS效果為:

odps_column1 odps_column2 odps_column3
a b {x_1,x_2}
a b {x_1,x_2,x_3}
a b {x_5}

DataWorks百問百答歷史記錄 請點擊這裡查看>>

更多DataWorks技術和產品信息,歡迎加入【DataWorks釘釘交流群】

Leave a Reply

Your email address will not be published. Required fields are marked *