如何将 Hive 外部 Table 数据类型从双精度更改为十进制

How to Change Hive External Table Data Type from Double to Decimal

我正在尝试将 HIVE 外部 table 上的几列从双精度更改为十进制。我删除并重新创建了 table 和 运行 msck repair 语句。但是,我无法从 Hive 或 Impala select table 因为它 returns 这些错误:

Hive: ERROR processing query/statement. Error Code: 0, SQL state: File 'hdfs://ns-bigdata/user/warehouse/fact/TEST_FACT/key=2458773/000000_0' has an incompatible Parquet schema for column 'testing.fact_table.tot_amt'. Column type: DECIMAL(28,7), Parquet schema:
optional double tot_amt [i:29 d:1 r:0] 
Impala: ERROR processing query/statement. Error Code: 0, SQL state: File 'hdfs://ns-bigdata/user/warehouse/fact/TEST_FACT/key=2458773/000000_0' has an incompatible Parquet schema for column 'testing.fact_table.tot_amt'. Column type: DECIMAL(28,7), Parquet schema:
optional double tot_amt [i:29 d:1 r:0] 

是否可以将数据类型从双精度更改为十进制? 另外,删除+重新创建 table 和更改 table 之间有什么区别?

你能不能像下面这样使用 alter table 将双精度转换为十进制。请确保您的 decimal 列可以容纳所有 double 数据。它适用于 impala 和蜂巢。

alter table table_name change col col decimal(5,4); -- notice col name mentioned twice

Alter table - 如果您想在 table 的末尾添加一个新列而不是清除所有数据,这很有用。更简单、更快但功能有限。

删除,创建 table - 当您想要重组列、文件格式、所有列以分区 tables 时很有用。