Hive 如何将配置单元的数据类型从字符串更改为多维数组以正确拆分列

Hive 如何将配置单元的数据类型从字符串更改为多维数组以正确拆分列,hive,Hive,我有一张蜂巢桌,像: +----------+----------------------------------------------------------------------------------------------+ | DEVTYPE | POINTS | +----------+-----------

我有一张蜂巢桌,像:

+----------+----------------------------------------------------------------------------------------------+
| DEVTYPE  |                POINTS                                                                        |
+----------+----------------------------------------------------------------------------------------------+
| Array    | [['1538006400', '629928.0625'], ['1538611200', '629928.0625'], ['1539216000', '629928.0625']]|
| Array    | [['1541030400', '629928.0625'], ['1541635200', '629928.0625'], ['1542240000', '629928.0625']]|       
| Array    | [['1544054400', '629928.0625'], ['1544659200', '629928.0625'], ['1545264000', '629928.125']] |
| Array    | [['1547078400', '629928.0625'], ['1547683200', '629928.0625'], ['1548288000', '629928.0625']]|
| Array    | [['1550102400', '629928.0625'], ['1550707200', '629928.125'], ['1551312000', '629928.0625']] |
+----------+----------------------------------------------------------------------------------------------+
但是当我描述这个表时,我发现POINTS列的数据类型是字符串。 我想将其转换为数组类型,以便将其拆分为几列以正确分析数据

我试图通过更改列数据类型进行更改,但它给了我一个错误

alter table my_table change points points array<double>;
你知道如何解决这个问题吗?我怎样才能使这个列像一个数组一样兼容,可以拆分成不同的列。
任何帮助我都将不胜感激。

以下方法可能会对您有所帮助,请注意:(如果需要,可转换为双精度)

CREATE TABLE my_TABLE 2(devtype字符串注释“来自反序列化程序”,
点数组注释“来自反序列化程序”)行格式分隔
以“:”结尾的字段存储为文本文件;
在表my_中插入表值(“数组”,“1538006400”,“629928.0625]”,
['1538611200', '629928.0625'], ['1539216000', '629928.0625']]");
在表my_table2中插入选择devtype,array(
数组(修剪(regexp\u替换(拆分(点,“,”[0]”,“\\[\\\\\[\\\\'\\\'\\'\\\]\\\\].'',”),
修剪(regexp\u替换(拆分(点,”,”[1],“\\[\\\\[\\\\\'\\\'\\\'\\]\\\\]\\\\],”),
数组(trim(regexp\u replace(拆分(点,“,”[2]”,“\\[\\\\[\\\\'\\\'\\'\\\]\\\].”,”),
修剪(regexp\u替换(拆分(点,“,”[3],“\\[\\\\[\\\\\'\\\'\\\'\\]\\\\]\\\\],”),
数组(trim(regexp\u replace(拆分(点,“,”[4]”,“\\[\\\\\[\\\\'\\'\\'\\\]\\\].'',”),
修剪(regexp\u替换(拆分(点,“,”[5],“\\[\\\\[\\\\\\'\\\\'\\\]\\\\]\\\\][124\\\]\\\][5],”))
从我的表格\u tmp;
配置单元>从my_table2中选择开发类型、点[0][0]、点[1][0]、点[2][0];
好啊
阵列1538006400 1538611200 1539216000
配置单元>从my_table2中选择开发类型、点[0][1]、点[1][1]、点[2][1];
好啊
阵列629928.0625 629928.0625 629928.0625

show create table points的输出
please?创建外部表
my_table
points
string COMMENT'from deserializer',
devtype
string COMMENT'from deserializer');好的,今天晚些时候让我来研究一下,让你知道:)Hi@smart_coder实际上这个摄取是由自动表摄取命令完成的,我们使用python pandas将JSON平坦化,然后我们摄取,但是pandas通过将每个列作为对象类型或字符串类型来规范JSON。这就是为什么那个自动摄取命令创建了这个摄取数据的查询。非常感谢。如果这方面有任何解决办法,我会更高兴。
alter table my_table change points points array<array<double>>; 
Error: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Unable to alter table. The following columns have types incompatible with the existing columns in their respective positions :
points (state=08S01,code=1)
CREATE TABLE my_table2( devtype string COMMENT 'from deserializer', 
points array<array<string>> COMMENT 'from deserializer') row format delimited 
fields terminated by ':' stored as textfile;

insert into table my_table values( "Array","[['1538006400', '629928.0625'],
 ['1538611200', '629928.0625'], ['1539216000', '629928.0625']]");

insert into table my_table2 select devtype, array(
array(trim(regexp_replace(split(points,",")[0],"\\[|\\[\\[\\'|\\'|\\]|\\]\\]",'')),
trim(regexp_replace(split(points,",")[1],"\\[|\\[\\[\\'|\\'|\\]|\\]\\]",''))), 
array(trim(regexp_replace(split(points,",")[2],"\\[|\\[\\[\\'|\\'|\\]|\\]\\]",'')),
trim(regexp_replace(split(points,",")[3],"\\[|\\[\\[\\'|\\'|\\]|\\]\\]",''))), 
array(trim(regexp_replace(split(points,",")[4],"\\[|\\[\\[\\'|\\'|\\]|\\]\\]",'')),
trim(regexp_replace(split(points,",")[5],"\\[|\\[\\[\\'|\\'|\\]|\\]\\]",'')))) 
from my_table_tmp;


hive> select devtype, points[0][0],points[1][0],points[2][0] from my_table2;
OK
Array   1538006400      1538611200      1539216000

hive> select devtype, points[0][1],points[1][1],points[2][1] from my_table2;
OK
Array   629928.0625     629928.0625     629928.0625