从avro架构创建配置单元表时出错

n9vozmp4  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(563)

我试图通过从存储在s3中的avro数据中提取模式来创建一个配置单元表。使用s3 kafka连接器将数据存储在s3中。我正在向制作人发布一个简单的pojo。
用于从avro中提取模式的代码data:-

for filename in os.listdir(temp_folder_path):
    filename = temp_folder_path + filename
        if filename.endswith('avro'):
            os.system(
                'java -jar /path/to/avro-jar/avro-tools-1.8.2.jar getschema {0} > {1}'.format(
                filename, filename.replace('avro', 'avsc')))

然后将提取的模式保存在s3 bucket中。
创建表query:-

CREATE EXTERNAL TABLE IF NOT EXISTS `db_name_service.table_name_change_log` PARTITIONED BY (`year` bigint,
 `month` bigint, `day` bigint, `hour` bigint) 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' LOCATION 's3://bucket/topics/topic_name' 
 TBLPROPERTIES ( 'avro.schema.url'='s3://bucket/schemas/topic_name.avsc')

error:-

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: BYTES)

schema:-

{ "type": "record", "name": "Employee", "doc" : "Represents an Employee at a company", "fields": [ {"name": 
"firstName", "type": "string", "doc": "The persons given name"}, {"name": "nickName", "type": ["null",
 "string"], "default" : null}, {"name": "lastName", "type": "string"}, {"name": "age", "type": "int",
  "default": -1}, {"name": "phoneNumber", "type": "string"} ] }

我可以使用此命令查看主题中的数据 ./confluent-4.1.1/bin/kafka-avro-console-consumer --topic test2_singular --bootstrap-server localhost:9092 --from-beginning ```
{"firstName":"A:0","nickName":{"string":"C"},"lastName":"C","age":0,"phoneNumber":"123"}

{"firstName":"A:1","nickName":{"string":"C"},"lastName":"C","age":1,"phoneNumber":"123"}

jpfvwuh4

jpfvwuh41#

表的架构必须是record类型。接收类型:字节
唯一可能发生这种情况的方法是在连接接收器配置中不使用avroconverter。
您还需要从s3文件中提取模式。
提示:使用lambda函数监视bucket中的avro文件创建有助于获取模式,而无需扫描整个bucket或随机文件,并用于通知hive/aws粘合表模式更新

相关问题