0

我正在将我的日志从 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,但没有成功。

4

1 回答 1

0

您可以直接尝试而不提及列名,如下所示

 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
于 2018-01-22T16:12:58.323 回答