【发布时间】:2016-11-29 16:39:48
【问题描述】:
需要帮助!!!
我正在使用 flume 将 twitter 提要流式传输到 hdfs 并将其加载到 hive 以进行分析。
步骤如下:
hdfs中的数据:
我已经在 avsc 文件中描述了 avro schema 并将其放入 hadoop:
{"type":"record",
"name":"Doc",
"doc":"adoc",
"fields":[{"name":"id","type":"string"},
{"name":"user_friends_count","type":["int","null"]},
{"name":"user_location","type":["string","null"]},
{"name":"user_description","type":["string","null"]},
{"name":"user_statuses_count","type":["int","null"]},
{"name":"user_followers_count","type":["int","null"]},
{"name":"user_name","type":["string","null"]},
{"name":"user_screen_name","type":["string","null"]},
{"name":"created_at","type":["string","null"]},
{"name":"text","type":["string","null"]},
{"name":"retweet_count","type":["boolean","null"]},
{"name":"retweeted","type":["boolean","null"]},
{"name":"in_reply_to_user_id","type":["long","null"]},
{"name":"source","type":["string","null"]},
{"name":"in_reply_to_status_id","type":["long","null"]},
{"name":"media_url_https","type":["string","null"]},
{"name":"expanded_url","type":["string","null"]}]}
我已经编写了一个 .hql 文件来创建一个表并在其中加载数据:
create table tweetsavro
row format serde
'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
stored as inputformat
'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
outputformat
'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'
tblproperties ('avro.schema.url'='hdfs:///avro_schema/AvroSchemaFile.avsc');
load data inpath '/test/twitter_data/FlumeData.*' overwrite into table tweetsavro;
我已成功运行 .hql 文件,但是当我在 hive 中运行 select *from <tablename> 命令时,它显示以下错误:
tweetsavro 的输出是:
hive> desc tweetsavro;
OK
id string
user_friends_count int
user_location string
user_description string
user_statuses_count int
user_followers_count int
user_name string
user_screen_name string
created_at string
text string
retweet_count boolean
retweeted boolean
in_reply_to_user_id bigint
source string
in_reply_to_status_id bigint
media_url_https string
expanded_url string
Time taken: 0.697 seconds, Fetched: 17 row(s)
【问题讨论】:
-
请不要附上图片,请按照具体
Markdown格式化你的代码/错误。 -
describe tweetsavro的输出是什么? -
我在表或 avro 架构中看不到 long 但错误与长数据有关?
-
您在 tweetsavro 描述中看不到 long ,因为 hive 中没有 long 类型。 long 类型在 hive 中转换为 bigint。有关更多信息,请参阅以下内容:cwiki.apache.org/confluence/display/Hive/AvroSerDe
-
这个答案的通用和更简单的版本在 [post] (stackoverflow.com/questions/45865899/…)