cloudera官方没有提供impala基于golang的驱动,github有github.com/bippio/go-impala
package main import ( "context" "github.com/bippio/go-impala" "log" "time" ) func main() { host := "prd-activity-3" port := 21000 opts := impalathing.DefaultOptions // enable LDAP authentication: opts.UseLDAP = false opts.Username = "<username>" opts.Password = "<password>" // enable TLS opts.UseTLS = false opts.CACertPath = "<ca-cert-path>" con, err := impalathing.Connect(host, port, &opts) if err != nil { log.Fatal(err) } query, err := con.Query(context.Background(), "SELECT * from impalademo.test1") startTime := time.Now() results := query.FetchAll(context.Background()) log.Printf("Fetch %d rows(s) in %.2fs", len(results), time.Duration(time.Since(startTime)).Seconds()) }
端口说明:
21000 :Impala Daemon Beeswax端口,被 impala-shell, Beeswax, Cloudera ODBC 1.2 驱动 用于传递命令和接收结果
21050:Impala Daemon HiveServer2端口,被使用 JDBC 或 Cloudera ODBC 2.0 及以上驱动的诸如 BI 工具之类的应用用来传递命令和接收结
所有通过java jdbc驱动调用的时候就使用21050端口,但是golang是通过thrift协议来调用impala的,就是使用21000端口