【问题标题】:Is there anyway to change the datatype of the non-partition column of the external hive table?无论如何要更改外部配置单元表的非分区列的数据类型?
【发布时间】:2020-09-08 07:34:29
【问题描述】:

我正在尝试更改作为分区表的外部 hive 表的非分区列的数据类型?

例如,我有一个名为 trans 的分区表,其中有 5 列。 交易(数据类型 = 字符串),产品(数据类型 = 字符串),数量(数据类型 = 小数(7,2)),年份(数据类型 = int),周(数据类型 = int),日期(数据类型 = 日期)

trans 表是外部的,并按年、周、日期分区。

现在我必须将数量的数据类型从十进制(7,2) 更改为十进制(15,2)。我们怎么能做到呢?我不想用更新的数据类型重新处理整个表。是否有任何直接查询或命令来实现这一点?

我确实使用了命令/查询:

ALTER TABLE trans CHANGE quantity quantity decimal(15,2);

但这改变了配置单元元数据中元数据的数据类型,而不是数据级别的数据类型,这意味着在 Parquet 文件中它没有改变数据类型,因为当我尝试从 spark 中选择数量列时,我在下面提到的错误。

Py4JJavaError: An error occurred while calling o108.showString. 
org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 2.0 failed 10 times, most recent failure: Lost task 0.9 in stage 2.0 : java.lang.UnsupportedOperationException: org.apache.parquet.column.values.dictionary.PlainValuesDictionary$PlainIntegerDictionary

【问题讨论】:

    标签: apache-spark hive hiveddl


    【解决方案1】:

    还有一个差不多的 Jira:HIVE-6784 - parquet-hive should allow column type change

    由于性能影响,它以 Won't Fix 分辨率关闭,请阅读 Jira cmets 了解更多详细信息。

    解决办法是create another table, insert overwrite from original table, then remove original table and rename new table

    【讨论】:

      猜你喜欢
      • 2019-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-01
      • 1970-01-01
      相关资源
      最近更新 更多