Hive 结构到字符串的转换

Hive Struct to String conversion

我有一个 table 里面有一个结构 - 让我们说:

create external table table1 ( 
    a int,
    b STRUCT <c:double,d:double>,
    e string
)

我在此 table 上执行 select 并得到类似 -

的结果

1100 {"c":12.3,"d":45.6} str

但是当我将此数据插入另一个 table -

create external table table2 (
    a string,
    b string,
    c string
)

insert overwrite table table2
select a,b,c
from table1;

我得到以下奇怪的行为,表明 hive 中结构和字符串之间的转换没有按预期工作

select * from table2;

会导致 -

1100 12.345.6 str

结果是结构中的一种奇怪的值串联,在处理更复杂的结构时甚至会发生更奇怪的事情

  1. 有没有办法阻止这种自动转换?让 hive 在这种情况下抛出错误?

  2. 是否有一种干净的方法来更改此自动转换以不同方式工作?

  1. 我们无法阻止直接 insert overwrite table table2 select a,b,c from table1; 调用时的自动转换。后面发生的只是 concat 来自 struct 的所有值。

  2. 您可以编写通用 UDF 来玩 struct ref: http://www.dataiku.com/blog/2013/05/01/a-complete-guide-to-writing-hive-udf.html

更快的方式:

如果您的目的是从结构中获取值并将其存储为原始值,请尝试如下所示,

create external table table2 (
    a string,
    b_c string,
    b_d string,
    c string
)

insert overwrite table table2
select a,b.c,b.e,c
from table1;

如果有帮助请告诉我。