【问题标题】:Athena - Union tables with incompatible data typesAthena - 具有不兼容数据类型的联合表
【发布时间】:2021-09-14 11:51:07
【问题描述】:

我们有两个表,其中一个列的数据类型不同。第一个表中的列的类型为int,而第二个表中的同一列的类型为float/real。如果它是一个裸列,我可以将 CAST'ed 转换为一个通用类型,这里的问题是,这些列在 struct 的深处。

我得到的错误是,

SYNTAX_ERROR: line 23:1: column 4 in row(priceconfiguration row(maximumvalue integer, minimumvalue integer, type varchar, value integer)) 查询有不兼容的类型:Union, row(priceconfiguration row(maximumvalue integer, minimumvalue integer, type varchar,实数))

查询(简化)是,

 WITH t1 AS (
   SELECT
     "so"."createdon"
   , "so"."modifiedon"
   , "so"."deletedon"
   , "so"."createdby"
   , "so"."priceconfiguration"
   , "so"."year"
   , "so"."month"
   , "so"."day"
   FROM
     my_db.raw_price so
   UNION ALL    
    SELECT
     "ao"."createdon"
   , "ao"."modifiedon"
   , "ao"."deletedon"
   , "ao"."createdby"
   , "ao"."priceconfiguration"
   , "ao"."year"
   , "ao"."month"
   , "ao"."day"
   FROM
     my_db.src_price ao
) 
SELECT t1.* FROM t1 ORDER BY "modifiedon" DESC

事实上,真正的表比这更复杂,priceconfiguration 列嵌套在表的深处。所以 CASTing 有问题的列是直接不可能的,除非所有的 structs 都未嵌套到有问题的列 CAST

有没有UNION这两个表没有unnesting和casting的方法?

【问题讨论】:

  • 将整个struct 列转换为string。如果您需要再次进入该结构,您可以将其转换回来,将麻烦的value 字段设置为string

标签: hiveql amazon-athena presto


【解决方案1】:

解决方案是将 Athena 引擎版本升级到 v2。

V2 引擎对模式演化有更多支持。根据 AWS 文档,

为 Parquet 格式的数据添加了架构演化支持。

添加了对从以下位置读取数组、映射或行类型列的支持 分区架构与表不同的分区 架构。当表模式在 分区已创建。更改的列类型必须兼容。 对于行类型,可以添加或删除尾随字段,但 对应的字段(按序号)必须具有相同的名称。

参考: https://docs.aws.amazon.com/athena/latest/ug/engine-versions-reference.html

【讨论】:

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