如何实现avro别名

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

我是新来的avro,而试图使用avro别名属性,我得到下面的错误。
查询: select department_id , office_name from test.depart_alias; semanticexception[error 10004]:行1:23无效的表别名或列引用“office\u name”:(可能的列名为:department\u id、department\u name)
我的avsc格式的json文件是

{
  "type" : "record",
  "name" : "departments",
  "doc" : "Sqoop import of departments",
  "fields" : [ {
    "name" : "department_id",
    "type" : [ "null", "int" ],
    "default" : null,
    "columnName" : "department_id",
    "sqlType" : "4"
  }, {
    "name" : "department_name",
    "type" : [ "null", "string" ],
    "default" : null,
    "aliases" : [ "office_name" ],
    "columnName" : "department_name",
    "sqlType" : "12"
  } ],
  "tableName" : "departments"

我想用办公室名作为部门名的别名。我该如何实施
谢谢

nhjlsmyf

nhjlsmyf1#

如果旧的列字段名为department\u name,则架构应如下所示

{
  "type" : "record",
  "name" : "departments",
  "doc" : "Sqoop import of departments",
  "fields" : [ {
    "name" : "department_id",
    "type" : [ "null", "int" ],
    "default" : null,
    "columnName" : "department_id",
    "sqlType" : "4"
  }, {
    "name" : "office_name",
    "type" : [ "null", "string" ],
    "default" : null,
    "aliases" : [ "department_name" ], <- old columns here
    "columnName" : "department_name",
    "sqlType" : "12"
  } ],
  "tableName" : "departments"

旧列名或“别名”应该放在别名数组中。

相关问题