【问题标题】:How to Change Hive External Table Data Type from Double to Decimal如何将 Hive 外部表数据类型从 Double 更改为 Decimal
【发布时间】:2022-01-15 03:26:04
【问题描述】:

我正在尝试将 HIVE 外部表上的几列从双精度更改为十进制。我已删除、重新创建表并运行 msck repair 语句。但是,我无法从 Hive 或 Impala 中选择表,因为它返回以下错误:

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] 

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

【问题讨论】:

    标签: database hive bigdata impala


    【解决方案1】:

    您可以使用下面的更改表将双精度转换为十进制吗?请确保您的小数列可以保存所有双精度数据。它适用于 impala 和 hive。

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-23
      • 1970-01-01
      • 2021-11-22
      • 1970-01-01
      • 2017-02-22
      • 2015-01-07
      • 1970-01-01
      相关资源
      最近更新 更多