我正在进行 hive建立外部表的工作 这是我的建表语句 """CREATE EXTERNAL TABLE lzwgogogo ( cust_id STRING, fname STRING, fname STRING, lname STRING, email STRING, level STRING, phone MAP<STRING, STRING>, order_ids ARRAY<STRING>, order_value STRUCT< min_value: DOUBLE, max_value: DOUBLE, avg_value: DOUBLE, total_value: DOUBLE > ) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' COLLECTION ITEMS TERMINATED BY ',' MAP KEYS TERMINATED BY ':' STORED AS TEXTFILE LOCATION '/dualcore'; """ 这是hdfs上 /dualcore的数据 """ 1001|John|Doe|john@example.com|Silver|home:1234567890,work:9876543210|order1,order2,order3|{"min_value":10.5,"max_value":50.2,"avg_value":30.1,"total_value":100.3} 1002|John|Doe|john@example.com|Silver|home:1234567890,work:9876543210|order1,order2,order3|{"min_value":10.5,"max_value":50.2,"avg_value":30.1,"total_value":100.2} 1003|John|Doe|john@example.com|Silver|home:1234567890,work:9876543210|order1,order2,order3|{"min_value":10.5,"max_value":50.2,"avg_value":30.1,"total_value":100.1}""" 为什么我查询hive表 时 order_values中的数据都为nul
时间: 2023-08-10 09:07:38 浏览: 177
mysql数据抽取,自动生成hive建表语句
根据你提供的建表语句和数据,我注意到在建表语句中,你将字段名为"order_value"的struct类型定义为:
```
order_value STRUCT<
min_value: DOUBLE,
max_value: DOUBLE,
avg_value: DOUBLE,
total_value: DOUBLE
>
```
然而,在你提供的数据中,该字段被命名为"order_values"。这导致Hive无法正确解析数据并将其加载到表中。
要解决此问题,你需要将建表语句中的字段名从"order_value"改为"order_values",使其与数据中的字段名一致。修改后的建表语句如下:
```sql
CREATE EXTERNAL TABLE lzwgogogo (
cust_id STRING,
fname STRING,
fname STRING,
lname STRING,
email STRING,
level STRING,
phone MAP<STRING, STRING>,
order_ids ARRAY<STRING>,
order_values STRUCT<
min_value: DOUBLE,
max_value: DOUBLE,
avg_value: DOUBLE,
total_value: DOUBLE > )
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '|'
COLLECTION ITEMS TERMINATED BY ','
MAP KEYS TERMINATED BY ':'
STORED AS TEXTFILE
LOCATION '/dualcore';
```
修改后,重新运行建表语句,并加载数据到表中,你应该能正确查询到"order_values"字段的值了。
阅读全文