[英]How to insert Hive partition column and value into data (parquet) file?
Request:- How can I insert partition key pair into each parquet
file while inserting data into Hive/Impala
table.请求:-在将数据插入
Hive/Impala
表时,如何将分区键对插入每个parquet
文件。
Hive Table DDL [ create external table db.tbl_name ( col1 string, col2 string) Partitioned BY (date_col string) STORED AS parquet LOCATION 'hdfs_path/db/tbl_name' ] Hive 表 DDL [创建外部表 db.tbl_name (col1 string, col2 string) Partitioned BY (date_col string) STORED AS parquet LOCATION 'hdfs_path/db/tbl_name']
Let's insert data into this hive table.让我们将数据插入到这个 hive 表中。
INSERT INTO db.tbl_name PARTITION (date_col=2020-07-26) VALUES ('test1_col1','test1_col2')插入 db.tbl_name 分区 (date_col=2020-07-26) 值 ('test1_col1','test1_col2')
Once records get inserted, let's view data into parquet file using parquet-tools or any other tool.插入记录后,让我们使用 parquet-tools 或任何其他工具将数据查看到 parquet 文件中。
parquet-tool cat hdfs_path/db/tbl_name/date_col=2020-07-26/parquet_file.parquet parquet-tool cat hdfs_path/db/tbl_name/date_col=2020-07-26/parquet_file.parquet
Below would be the view.下面将是视图。
**********************
col1 = test1_col1
col2 = test1_col2
**********************
However, if I fire following HQL query on Hive/Impala, then it will read partition value from metadata.但是,如果我在 Hive/Impala 上执行 HQL 查询,那么它将从元数据中读取分区值。
**Query**- select * from db.tbl_name
**Result** -
col1 col2 date_col
test1_col1 test1_col2 2020-07-26
Question - Is there any way, where we can view partition columnn name and value in parquet file like below.问题- 有什么方法可以在 parquet 文件中查看分区列名称和值,如下所示。
col1 = test1_col1
col2 = test1_col2
date_col = 2020-07-26
Please use this -请使用这个 -
INSERT INTO db.tbl_name PARTITION (date_col) VALUES ('test1_col1','test1_col2','2020-07-26');
Always mention partition name inside brackets() like above.总是在上面的括号()中提到分区名称。 And then in the values/select clause, order the partition column in the end.
然后在 values/select 子句中,最后对分区列进行排序。
Thats all you need to insert into hive/impala partitioned table.这就是您需要插入到 hive/impala 分区表中的所有内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.