All Projects → koblas → impalathing

koblas / impalathing

Licence: other
A golang driver for impala via thrift

Programming Languages

Thrift
134 projects
go
31211 projects - #10 most used programming language
Makefile
30231 projects

Impalathing is a small Go wrapper library the thrift interface go Impala

It's based on hivething

Working on this you quickly realize that having strings deliminated by tabs is a ugly API... (That's the thrift side of things)

Usage

To add kerberos support this requires header files to build against the GSSAPI C library. They can be installed with:

Ubuntu: sudo apt-get install libkrb5-dev
MacOS: brew install homebrew/dupes/heimdal --without-x11
Debian: yum install -y krb5-devel

in order to use kerberos, you need an extra dependency

go get -tags kerberos github.com/beltran/gosasl

then

go build --tags=kerberos

before starting your application, you should kinit first, for example

kinit -k -t impala.keytab impala/[email protected]

package main

import (
    "log"
    "fmt"
    "time"
    "github.com/koblas/impalathing"
)

func main() {
    host := "impala-host"
    port := 21000

    con, err := impalathing.Connect(host, port)
    // if you use kerberos
    con, err := impalathing.Connect(host, port, impalathing.WithGSSAPISaslTransport()) 
    if err != nil {
        log.Fatal("Error connecting", err)
        return
    }

    query, err := con.Query("SELECT user_id, action, yyyymm FROM engagements LIMIT 10000")

    startTime := time.Now()
    total := 0
    for query.Next() {
        var (
            user_id     string
            action      string
            yyyymm      int
        )

        query.Scan(&user_id, &action, &yyyymm)
        total += 1

        fmt.Println(user_id, action)
    }

    log.Printf("Fetch %d rows(s) in %.2fs", total, time.Duration(time.Since(startTime)).Seconds())
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].