因為報表前端用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();
}
{
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的結果,對於多線程調用的可用性持懷疑態度。