如何实现 avro 别名

Ana*_*eep 3 hive avro

我是 avro 的新手,在尝试使用 avro 别名属性时,我遇到了以下错误。

询问 : select department_id , office_name from test.depart_alias;

SemanticException [错误 10004]:第 1:23 行无效的表别名或列引用“office_name”:(可能的列名称为:department_id、department_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"
Run Code Online (Sandbox Code Playgroud)

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

谢谢

hla*_*gos 6

如果您的旧列字段名为 Department_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"
Run Code Online (Sandbox Code Playgroud)

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