您的位置:首页 > 其它

HIVE Thrift Server使用总结

2012-09-13 18:19 501 查看
因为报表前端用dot NET MVC写的,要想从HIVE中获取详细数据,目前的方案是使用hive thriftserver。

1. 生成HIVE Thrift对应的C#类文件

遇到的问题是找不到thriftserver.thrift中引用的fb303.thrift文件。解决方案:从thrift源码目录中复制一份过来。然后利用thriftserver.thrift生成了4个类文件,复制到项目中编译报错,不得不将引用的其他三个文件分别利用thrift生成C#类,最后将几十个类文件复制到项目中,修改项目属性,将framework 4 client profile修改为framework 4,编译通过。

client代码如下:

static void Main(string[] args)
{
TTransport transport = new TSocket("192.168.1.1", 10000);
TProtocol protocol = new TBinaryProtocol(transport);
ThriftHive.Client client = new ThriftHive.Client(protocol);

transport.Open();
//client.execute("add file /data/home/script/ad_resolve2.py;");
client.execute("select * from web_pv_log_detail3 where dt = '2012-09-10' limit 10");
Console.WriteLine("the result is:");

var items = client.fetchAll();
foreach (var item in items)
{
Console.WriteLine(item);
}
transport.Close();

Console.ReadLine();
}

2. 启动服务端服务:hive --service hiveserver

3. 测试。发现多次调用execute之后调用fetch,每次会获取到最后一个execute的结果,对于多线程调用的可用性持怀疑态度。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: