无法在配置单元中创建表

llycmphe  于 2021-06-27  发布在  Hive
关注(0)|答案(1)|浏览(313)

我正在尝试使用联机找到的以下架构在hive 3.0中创建表:

CREATE TABLE tweets (
id BIGINT,
created_at STRING,
source STRING,
favorited BOOLEAN,
retweeted_status STRUCT< text : STRING, user : STRUCT<screen_name : STRING,name : STRING>, retweet_count : INT>,
entities STRUCT< urls : ARRAY<STRUT<expanded_url : STRING>>,
user_mentions : ARRAY<STRUCT<screen_name : STRING,name : STRING>>,
hashtags : ARRAY<STRUCT<text : STRING>>>,
text STRING,
user STRUCT< screen_name : STRING, name : STRING, friends_count : INT, followers_count : INT, statuses_count : INT, verified : BOOLEAN, utc_offset : INT, time_zone : STRING>, 
in_reply_to_screen_name STRING
) 
ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JSONSerDe';


当我按enter键时,输入NoviableException。我是第一次使用Hive没有经验有人能告诉我什么是错误的模式?

aemubtdh

aemubtdh1#

user是保留关键字如果我们在配置单元中使用关键字,则需要用(backticks)将关键字括起来 例子:用户`
尝试下面的create table语句

CREATE TABLE tweets (
    id BIGINT,
    created_at STRING,
    source STRING,
    favorited BOOLEAN,
    retweeted_status STRUCT< text : STRING, `user` : STRUCT<screen_name : STRING,name : STRING>, retweet_count : INT>,
    entities STRUCT< urls : ARRAY<STRUCT<expanded_url : STRING>>,
    user_mentions : ARRAY<STRUCT<screen_name : STRING,name : STRING>>,
    hashtags : ARRAY<STRUCT<text : STRING>>>,
    text STRING,
    `user` STRUCT< screen_name : STRING, name : STRING, friends_count : INT, followers_count : INT, statuses_count : INT, verified : BOOLEAN, utc_offset : INT, time_zone : STRING>, 
    in_reply_to_screen_name STRING
    ) 
    ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
    Location '/user/flume/tweets/';

我可以用上述ddl创建表:

desc tweets;
+--------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+--------------------+--+
|         col_name         |                                                                     data_type                                                                     |      comment       |
+--------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+--------------------+--+
| id                       | bigint                                                                                                                                            | from deserializer  |
| created_at               | string                                                                                                                                            | from deserializer  |
| source                   | string                                                                                                                                            | from deserializer  |
| favorited                | boolean                                                                                                                                           | from deserializer  |
| retweeted_status         | struct<text:string,user:struct<screen_name:string,name:string>,retweet_count:int>                                                                 | from deserializer  |
| entities                 | struct<urls:array<struct<expanded_url:string>>,user_mentions:array<struct<screen_name:string,name:string>>,hashtags:array<struct<text:string>>>   | from deserializer  |
| text                     | string                                                                                                                                            | from deserializer  |
| user                     | struct<screen_name:string,name:string,friends_count:int,followers_count:int,statuses_count:int,verified:boolean,utc_offset:int,time_zone:string>  | from deserializer  |
| in_reply_to_screen_name  | string                                                                                                                                            | from deserializer  |
+--------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+--------------------+--+

更新:
当我们运行select语句时,配置单元在读取时充当模式配置单元在表所指向的目录(/user/hive/warehouse/tweets/)中查找文件,然后根据ddl语句读取这些数据,但在这种情况下,目录中不存在数据,因此select语句不返回任何记录。
要解决此问题,请执行以下操作:
选项1。将数据从 /user/flume/tweets//user/hive/warehouse/tweets/ 目录,然后您可以从表中选择数据。

`hadoop fs -mv /user/flume/tweets/  /user/hive/warehouse/tweets/`

(或)
选项2。我们需要在上面创建Hive表 /user/flume/tweets/ 在这个目录中,您就可以看到tweets表中的数据(使用上面的createtable语句)。

相关问题