从 Json.Serde 格式 table 复制到格式为 table 的文本文件配置单元
Copy from Json.Serde formatted table into a text file formatted hive table
我对 Hive 完全陌生。
我使用 Json.SerDe
在我的 json 文件之上创建了一个配置单元 table 并加载了数据。
结构如下
CREATE EXTERNAL TABLE JsonTable_raw (
data array<struct<
start_date:string,
end_date:string,
measures:struct<
Visitors:int,
Singlepagevisits:int
>
>
>
) ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
我又创建了一个 table,它没有使用 JsonSerDe
格式化。
CREATE EXTERNAL TABLE JsonTable (
start_date string,
end_date string,
Visitors int,
Singlepagevisits int
)
我尝试使用以下查询
INSERT INTO TABLE JsonTable select
data.start_date,data.end_date,data.measures.Visitors,
data.measures.Singlepagevisits FROM JsonTable_raw;
但它抛出了
NoMatchingMethodException No matching method for class
org.apache.hadoop.hive.ql.udf.UDFToInteger with (array). Possible
choices: FUNC(bigint) FUNC(boolean) FUNC(decimal(38,18))
FUNC(double) FUNC(float) FUNC(smallint) FUNC(string) FUNC(timestamp) FUNC(tinyint) FUNC(void)
现在如何将数据从 JsonTable_raw 复制到 JsonTable?
经过一个小时的搜索和尝试,我终于能够自己完成了。下面是脚本
INSERT INTO TABLE JsonTable
select cols.start_date,cols.end_date,cols.measures.Visitors,
cols.measures.Singlepagevisits
FROM JsonTable_raw jt lateral view explode(jt.data) collection as cols;
我对 Hive 完全陌生。
我使用 Json.SerDe
在我的 json 文件之上创建了一个配置单元 table 并加载了数据。
结构如下
CREATE EXTERNAL TABLE JsonTable_raw (
data array<struct<
start_date:string,
end_date:string,
measures:struct<
Visitors:int,
Singlepagevisits:int
>
>
>
) ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
我又创建了一个 table,它没有使用 JsonSerDe
格式化。
CREATE EXTERNAL TABLE JsonTable (
start_date string,
end_date string,
Visitors int,
Singlepagevisits int
)
我尝试使用以下查询
INSERT INTO TABLE JsonTable select
data.start_date,data.end_date,data.measures.Visitors,
data.measures.Singlepagevisits FROM JsonTable_raw;
但它抛出了
NoMatchingMethodException No matching method for class org.apache.hadoop.hive.ql.udf.UDFToInteger with (array). Possible choices: FUNC(bigint) FUNC(boolean) FUNC(decimal(38,18)) FUNC(double) FUNC(float) FUNC(smallint) FUNC(string) FUNC(timestamp) FUNC(tinyint) FUNC(void)
现在如何将数据从 JsonTable_raw 复制到 JsonTable?
经过一个小时的搜索和尝试,我终于能够自己完成了。下面是脚本
INSERT INTO TABLE JsonTable
select cols.start_date,cols.end_date,cols.measures.Visitors,
cols.measures.Singlepagevisits
FROM JsonTable_raw jt lateral view explode(jt.data) collection as cols;