簡體   English   中英

從 Union Avro 中提取模式

[英]Extracting schema from Union Avro

我有以下聯盟:

{
          "name" : "price",
          "type" : [ "null", {
            "type" : "array",
            "items" : {
              "type" : "record",
              "name" : "PriceType",
              "fields" : [ {
                "name" : "text_value",
                "type" : [ "null", "double" ],
                "source" : "element text_value"
              }, {
                "name" : "currency",
                "type" : [ "null", "string" ],
                "default" : null,
                "source" : "attribute currency"
              } ]
            }
          } ],
          "default" : null,
          "source" : "element price"
        }

從這個聯盟中,我使用以下代碼獲得了價格字段的架構:

Schema new_schema=schema.getField("price").schema();

現在我想獲得聯盟的架構:

{
            "type" : "array",
            "items" : {
              "type" : "record",
              "name" : "PriceType",
              "fields" : [ {
                "name" : "text_value",
                "type" : [ "null", "double" ],
                "source" : "element text_value"
              }, {
                "name" : "currency",
                "type" : [ "null", "string" ],
                "default" : null,
                "source" : "attribute currency"
              }

我怎樣才能做到這一點? 我如何在記錄中插入聯合?

由於它是聯合類型,您可以按如下方式提取架構:
new_schema.getTypes().get(0);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM