hadoop:查询/读取avro文件

yvgpqqbh  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(400)

我正在存储从复杂的json对象导入到avro格式的数据。
json对象由具有嵌套对象和对象数组的对象表示。avro架构如下所示:

  1. {
  2. "type" : "record",
  3. "name" : "userInfo",
  4. "namespace" : "my.example",
  5. "fields" : [{"name" : "username",
  6. "type" : "string",
  7. "default" : "NONE"},
  8. {"name" : "age",
  9. "type" : "int",
  10. "default" : -1},
  11. {"name" : "phone",
  12. "type" : "string",
  13. "default" : "NONE"},
  14. {"name" : "housenum",
  15. "type" : "string",
  16. "default" : "NONE"},
  17. {"name" : "address",
  18. "type" : {
  19. "type" : "record",
  20. "name" : "mailing_address",
  21. "fields" : [
  22. {"name" : "street",
  23. "type" : "string",
  24. "default" : "NONE"},
  25. {"name" : "city",
  26. "type" : "string",
  27. "default" : "NONE"},
  28. {"name" : "state_prov",
  29. "type" : "string",
  30. "default" : "NONE"},
  31. {"name" : "country",
  32. "type" : "string",
  33. "default" : "NONE"},
  34. {"name" : "zip",
  35. "type" : "string",
  36. "default" : "NONE"}
  37. ]},
  38. "default" : {}
  39. }
  40. ]
  41. }

我使用nifi将json转换为avro,并在hadoop中存储序列化文件(目前我只使用纯hadoop):

我的问题是:
出于测试目的,我想查询存储hdfs(avro格式)的数据。
所以在这一点上我有点困惑,因为围绕hadoop的很多工具和技术。。我怎样才能用正确的方法做这件事?什么工具和工作流程?

wmvff8tz

wmvff8tz1#

您应该能够在写入avro数据的hdfs位置上创建一个外部配置单元表。
这篇文章有几个例子:
https://community.hortonworks.com/questions/22135/is-there-a-way-to-create-hive-table-based-on-avro.html
https://cwiki.apache.org/confluence/display/hive/avroserde

相关问题