Flume使用Hive作为Sink总结

项目中打算使用Flume把数据直接传到Hive表而不是HDFS上。使用Hive作为Sink,Flume版本为1.7.0。

开始时候遇到Failed connecting to EndPoint错误,Caused by: org.apache.hive.hcatalog.streaming.StreamingException: Cannot stream to table that has not been bucketed

原来使用Hive做为Sink,Hive表必须cluster by bucket。


修改表之后重启Flume,又遇到

org.apache.flume.EventDeliveryException: java.lang.ClassCastException: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat cannot be cast to org.apache.hadoop.hive.ql.io.AcidOutputFormat 错误。

看了下源码实现AcidOutputFormat的类只有OrcOutputFormat,那么答案显而易见,Hive表需要stored as orc。


重启之后又遇到错误,

Failed connecting to EndPoint

Caused by: org.apache.hive.hcatalog.streaming.InvalidColumn: Column 'URL' not found in table for input field 81

原来在Flume配置的Hive 列名必须都为小写字母。

再重启之后成功运行。

总结如下,Hive表必须设置bucket并且 stored as orc。


Flume Hive Sink:

tier1.sinks.sink_sitevisit.channel = channel_sitevisit
tier1.sinks.sink_sitevisit.type = hive
tier1.sinks.sink_sitevisit.hive.metastore = thrift://localhost:9083
tier1.sinks.sink_sitevisit.hive.database = sitevisit
tier1.sinks.sink_sitevisit.hive.table = visitlog
tier1.sinks.sink_sitevisit.hive.partition = %Y-%m-%d
tier1.sinks.sink_sitevisit.hive.txnsPerBatchAsk = 10
tier1.sinks.sink_sitevisit.hive.batchSize = 1500
tier1.sinks.sink_sitevisit.serializer = DELIMITED
tier1.sinks.sink_sitevisit.serializer.fieldnames = visitor_id,user_id,session_id,url,keyword
tier1.sinks.sink_sitevisit.roundUnit = hour
tier1.sinks.sink_sitevisit.roundValue = 1


Hive table:

create table weblogs ( id int , msg string )
    partitioned by (continent string, country string, time string)
    clustered by (id) into 2 buckets
    stored as orc;

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
好的,我可以回答这个问题。您可以按照以下步骤来使用Flume采集Kafka数据到HDFS和Hive中: 1. 首先,确保您已经安装了Flume、Kafka、HDFS和Hive等必要的软件。 2. 然后,在Flume的配置文件中添加Kafka作为Source和HDFS/Hive作为Sink。例如,以下是一个简单的配置文件示例: ``` agent.sources = kafka-source agent.channels = hdfs-channel agent.sinks = hdfs-sink hive-sink agent.sources.kafka-source.type = org.apache.flume.source.kafka.KafkaSource agent.sources.kafka-source.batchSize = 1000 agent.sources.kafka-source.kafka.bootstrap.servers = localhost:9092 agent.sources.kafka-source.kafka.topics = my-topic agent.sources.kafka-source.kafka.consumer.group.id = my-group agent.channels.hdfs-channel.type = memory agent.channels.hdfs-channel.capacity = 10000 agent.channels.hdfs-channel.transactionCapacity = 100 agent.sinks.hdfs-sink.type = hdfs agent.sinks.hdfs-sink.hdfs.path = hdfs://localhost:9000/flume/kafka agent.sinks.hdfs-sink.hdfs.fileType = DataStream agent.sinks.hdfs-sink.hdfs.writeFormat = Text agent.sinks.hdfs-sink.channel = hdfs-channel agent.sinks.hive-sink.type = hive agent.sinks.hive-sink.hive.metastore = thrift://localhost:9083 agent.sinks.hive-sink.hive.database = my-db agent.sinks.hive-sink.hive.table = my-table agent.sinks.hive-sink.hive.partition = dt=%Y-%m-%d agent.sinks.hive-sink.channel = hdfs-channel ``` 在上面的配置文件中,我们使用Kafka作为Source,将数据写入到HDFS和Hive中。我们使用Memory Channel将数据缓存在内存中,然后将其写入到HDFS和Hive中。在Hive Sink中,我们还定义了一个分区,以便按日期对数据进行分区。 3. 最后,运行Flume代理以开始从Kafka读取数据并将其写入到HDFS和Hive中。您可以使用以下命令来启动Flume代理: ``` $ bin/flume-ng agent -n agent -c conf -f conf/flume-kafka-hdfs-hive.conf ``` 这样,Flume代理就会开始从Kafka读取数据,并将其写入到HDFS和Hive中。 希望这些信息能够帮助您采集Kafka数据到HDFS和Hive中。如果您有任何其他问题,请随时问我。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值