GoHive: A Hive Driver for Go
Go programmers usually call the standard package database/sql
to access databases. database/sql
relies on database drivers to work with database management systems. A growing list of drivers is at https://github.com/golang/go/wiki/SQLDrivers, where we cannot find one for Apache Hive at the moment we wrote this package.
Walkthrough the Code
-
driver.go
As required by
database/sql
,driver.go
defines typegohive.Driver
that implements thedatabase/sql/driver.Driver
interface, which has a methodOpen
. Theinit()
method registers the typegohive.Driver
. -
connection.go
The
Open
method ofdatabase/sql/driver.Driver
is supposed to return a connection, which is a type that implements thedatabase/sql/driver.Conn
interface.connection.go
defines the typegohive.Driver
that implementsdatabase/sql/driver.Conn
.gohive.Driver
also implementsdatabase/sql/driver.QueryerContext
by defining methodQueryContext
to run queries and to return rows. -
rows.go
rows.go
defines typegohive.Rows
that implements the interfacedatabase/sql/driver.Rows
.
Access Hive through Thrift
For contributors who are curious how this driver talks to Hive via its Thrift interface, here is Hive’s Thrift service definition.
Running Hive in Containers
For the convenience of the development of this package, we provide Dockerfiles that install and run Hive in Docker containers.