我希望找到一种通过Hive获取以下AVSC文件内容的方法,并将嵌套模式"RENTALRECORDTYPE“外部化,以实现模式重用。
{
"type": "record",
"name": "EMPLOYEE",
"namespace": "",
"doc": "EMPLOYEE is a person that works here",
"fields": [
{
"name": "RENTALRECORD",
"type": {
"type": "record",
"name": "RENTALRECORDTYPE",
"namespace": "",
"doc": "Rental record is a record that is kept on every item rented",
"fields": [
{
"name": "due_date",
"doc": "The date when item is due",
"type": "int"
}
]
}
},
{
"name": "hire_date",
"doc": "Employee date of hire",
"type": "int"
}
]
}这种定义模式的方法工作得很好。我能够发出以下HiveQL语句,并成功地创建了该表。
CREATE EXTERNAL TABLE employee
STORED AS AVRO
LOCATION '/user/dtom/store/data/employee'
TBLPROPERTIES ('avro.schema.url'='/user/dtom/store/schema/employee.avsc');但是,我希望能够引用现有模式,而不是重复多个模式中的记录定义。例如,将生成两个AVSC文件,而不是单个模式文件。即rentalrecord.avsc和employee.avsc。
rentalrecord.avsc
{
"type": "record",
"name": "RENTALRECORD",
"namespace": "",
"doc": "A record that is kept for every rental",
"fields": [
{
"name": "due_date",
"doc": "The date on which the rental is due back to the store",
"type": "int"
}
]
}employee.avsc
{
"type": "record",
"name": "EMPLOYEE",
"namespace": "",
"doc": "EMPLOYEE is a person that works for the VIDEO STORE",
"fields": [
{
"name": "rentalrecord",
"doc": "A rental record is a record on every rental",
"type": "RENTALRECORD"
},
{
"name": "hire_date",
"doc": "Employee date of hire",
"type": "int"
}
]
}在上述场景中,我们希望能够将employee.avsc RENTALRECORD模式定义外部化,并能够在employee.avsc和其他地方重用它。
当试图使用以下两条HiveQL语句导入架构时,它会失败…
CREATE EXTERNAL TABLE rentalrecord
STORED AS AVRO
LOCATION '/user/dtom/store/data/rentalrecord'
TBLPROPERTIES ('avro.schema.url'='/user/dtom/store/schema /rentalrecord.avsc');
CREATE EXTERNAL TABLE employee
STORED AS AVRO
LOCATION '/user/dtom/store/data/employee'
TBLPROPERTIES ('avro.schema.url'='/user/dtom/store/schema/employee.avsc');rentalrecord.avsc已成功导入,但employee.avsc在第一个字段定义上失败。类型“RENTALRECORD”的字段。以下错误由Hive…输出
失败:执行错误,从org.apache.hadoop.hive.ql.exec.DDLTask返回代码1。MetaException(message:org.apache.hadoop.hive.serde2.SerDeException遇到了异常确定模式。返回指示问题的信号架构:"RENTALRECORD“不是定义的名称。"rentalrecord“字段的类型必须是已定义的名称或{" type ":.}表达式。
我的研究告诉我,Avro文件确实支持这种模式恢复形式。所以要么我遗漏了一些东西,要么这是一些不被蜂巢所支持的东西。
任何帮助都将不胜感激。
发布于 2018-04-17 10:38:25
我定义了一个包含所有引用的AVDL,然后使用带有idl2schemata选项的avro文件来生成avsc。生成的avsc就像一个魅力的蜂巢!
https://stackoverflow.com/questions/47836004
复制相似问题