2017-05-27 4 views
0

ネストされたavroスキーマを使用してハイブテーブルを作成しようとしています。しかし、それは動作しません。私はcdh5.7.2でハイブ1.1を使用しています。ハイブはネストされたavroスキーマのテーブルを作成できません

[ 
    { 
     "type": "record", 
     "name": "Id", 
     "namespace": "com.test.app_list", 
     "doc": "Device ID", 
     "fields": [ 
      { 
       "name": "idType", 
       "type": "int" 
      },{ 
       "name": "id", 
       "type": "string" 
      } 
     ] 
    }, 

    { 
     "type": "record", 
     "name": "AppList", 
     "namespace": "com.test.app_list", 
     "doc": "", 
     "fields": [ 
      { 
       "name": "appId", 
       "type": "string", 
       "avro.java.string": "String" 
      }, 
      { 
       "name": "timestamp", 
       "type": "long" 
      }, 

      { 
       "name": "idList", 
       "type": [{"type": "array", "items": "com.test.app_list.Id"}] 
      } 

     ] 
    } 
] 

とテーブルを作成するために私のsql:ここ

は私のネストされたアブロスキーマです

CREATE EXTERNAL TABLE app_list 
ROW FORMAT SERDE 
'org.apache.hadoop.hive.serde2.avro.AvroSerDe' 
STORED AS INPUTFORMAT 
'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat' 
OUTPUTFORMAT 
'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat' 
TBLPROPERTIES (
'avro.schema.url'='/hive/schema/test_app_list.avsc'); 

しかし、ハイブは私を与える:

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. java.lang.RuntimeException: MetaException(message:org.apache.hadoop.hive.serde2.avro.AvroSerdeException Schema for table must be of type RECORD. Received type: UNION) 

hiveドキュメント番組:Supports arbitrarily nested schemas.から:https://cwiki.apache.org/confluence/display/Hive/AvroSerDe#AvroSerDe-Overview–WorkingwithAvrofromHive

データサンプル:

{ 
    "appId":{"string":"com.test.app"}, 
    "timestamp":{"long":1495893601606}, 
    "idList":{ 
     "array":[ 
      {"idType":15,"id":"6c:5c:14:c3:a5:39"}, 
      {"idType":13,"id":"eb297afe56ff340b6bb7de5c5ab09193"} 
     ] 
    } 

} 

しかし、私はどのように知りません。私はこれを解決するためにいくつかの助けが必要です。ありがとう!

+0

すでにデータサンプルが追加されています。 –

答えて

0

あなたのavroスキーマの最上位レベルがレコードタイプであると予想されます。そのため、Hiveはこれを許可しません。回避策はレコードとして最上位レベルを作成し、内部はレコードタイプとして2つのフィールドを作成することができます。

{ 
     "type": "record", 
     "name": "myRecord", 
     "namespace": "com.test.app_list" 
      "fields": [ 
    { 
     "type": "record", 
     "name": "Id", 
     "doc": "Device ID", 
     "fields": [ 
      { 
       "name": "idType", 
       "type": "int" 
      },{ 
       "name": "id", 
       "type": "string" 
      } 
     ] 
    }, 

    { 
     "type": "record", 
     "name": "AppList", 
     "doc": "", 
     "fields": [ 
      { 
       "name": "appId", 
       "type": "string", 
       "avro.java.string": "String" 
      }, 
      { 
       "name": "timestamp", 
       "type": "long" 
      }, 

      { 
       "name": "idList", 
       "type": [{"type": "array", "items": "com.test.app_list.Id"}] 
      } 

     ] 
    } 
    ] 
} 
+0

ありがとうございます。私はあなたのヒントに続いてスキーマを変更しました。そして、それは動作します。 –

関連する問題