我是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"
我想使用office name作为department_name的别名。 我应该如何实施呢?
由于
答案 0 :(得分:3)
如果您的旧列字段名为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"
旧列名或“别名”应该在别名数组中。