如何使用嵌套数据将分区添加到配置单元 table?
how to add partition to hive table with nested data?
我正在使用
将我的日志从 S3 加载到 Hive 中
CREATE TABLE logs(
`col1` struct<`country`:string,`page`:string,`date`:string>
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
LOCATION 's3a://application-logs/sample/' ;
我的数据是这样的
{
"col1": {
"country": "India",
"page": "/signup",
"date": "2018-01-01"
}
}
如果我想在 col1.country、col1.page、col1.date 上创建分区
我应该如何将其包含在创建语句中,我试过 colName.fieldName,但没有成功。
你可以不说列名直接试试,像下面这样
CREATE TABLE logs(
`col1` struct<`country`:string,`page`:string,`date`:string>
)
partitioned by (country string, page string, date string)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
LOCATION 's3a://application-logs/sample/' ;
请注意,外部表不会直接检测分区,您必须更改和添加分区,如下所示:
ALTER TABLE logs ADD PARTITION (country=india, pager=whatever, date=whatever) location '/hdfs/path/';
#You might also need to repair the table at the end
msck repair table schemaName.tableName
我正在使用
将我的日志从 S3 加载到 Hive 中 CREATE TABLE logs(
`col1` struct<`country`:string,`page`:string,`date`:string>
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
LOCATION 's3a://application-logs/sample/' ;
我的数据是这样的
{
"col1": {
"country": "India",
"page": "/signup",
"date": "2018-01-01"
}
}
如果我想在 col1.country、col1.page、col1.date 上创建分区 我应该如何将其包含在创建语句中,我试过 colName.fieldName,但没有成功。
你可以不说列名直接试试,像下面这样
CREATE TABLE logs(
`col1` struct<`country`:string,`page`:string,`date`:string>
)
partitioned by (country string, page string, date string)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
LOCATION 's3a://application-logs/sample/' ;
请注意,外部表不会直接检测分区,您必须更改和添加分区,如下所示:
ALTER TABLE logs ADD PARTITION (country=india, pager=whatever, date=whatever) location '/hdfs/path/';
#You might also need to repair the table at the end
msck repair table schemaName.tableName