经过两天多的资料查找,反复测试从网上找到的多种方案,加上阿里云售后的支持,终于搞定Go语言连接Apache Hive的问题。
测试环境,阿里云E-MapReduce 2.1 中的Hive, Golang 1.7,开发环境win10。
在阿里云hive-site.xml中需要添加:
<property>
<name>hive.server2.authentication</name>
<value>NOSASL</value>
</property>
代码如下:
package main
import (
"fmt"
"github.com/dazheng/gohive"
)
func main() {
conn, err := gohive.Connect("127.0.0.1:10000", gohive.DefaultOptions)
if err != nil {
fmt.Errorf("Connect error %v", err)
}
defer conn.Close()
_, err = conn.Exec("create table if not exists t(c1 int)")
if err != nil {
fmt.Errorf("Connection.Exec error: %v", err)
}
}
http://blog.csdn.net/dazheng/article/details/53043946