Coder Social home page Coder Social logo

go-impala's Introduction

go-impala is a Go driver for Apache Impala

As far as we know, this is the only pure golang driver for Apache Impala that has TLS and LDAP support.

We at Bipp, want to make large scale data analytics accesible to every business user.

As part of that, we are commited to making this is a production grade driver that be used in serious enterprise scenarios in lieu of the ODBC/JDBC drivers.

Issues and contributions are welcome.

Using

package main

// Simple program to list databases and the tables

import (
	"context"
	"fmt"
	"log"

	impala "github.com/bippio/go-impala"
)

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

	opts := impala.DefaultOptions

	// enable LDAP authentication:
	opts.UseLDAP = true
	opts.Username = "<ldap username>"
	opts.Password = "<ldap password>"

	// enable TLS
	opts.UseTLS = true
	opts.CACertPath = "/path/to/cacert"

	con, err := impala.Connect(host, port, &opts)
	if err != nil {
		log.Fatal(err)
	}

	ctx := context.Background()

	var rows impala.RowSet

	// get all databases for the connection object
	query := fmt.Sprintf("SHOW DATABASES")
	rows, err = con.Query(ctx, query)
	if err != nil {
		log.Fatal("error in retriving databases: ", err)
	}

	databases := make([]string, 0) // databases will contain all the DBs to enumerate later
	for {
		row := make(map[string]interface{})
		err = rows.MapScan(row)
		if err != nil {
			log.Println(err)
			continue
		}
		if db, ok := row["name"].(string); ok {
			databases = append(databases, db)
		}
	}
	log.Println("List of Databases", databases)

	for _, d := range databases {
		q := "SHOW TABLES IN " + d

		rows, err = con.Query(ctx, q)
		if err != nil {
			log.Printf("error in querying database %s: %s", d, err.Error())
			continue
		}

		tables := make([]string, 0) // databases will contain all the DBs to enumerate later
		for rows.Next(ctx) {
			row := make(map[string]interface{})
			err = rows.MapScan(row)
			if err != nil {
				log.Println(err)
				continue
			}
			if tab, ok := row["name"].(string); ok {
				tables = append(tables, tab)
			}
		}
		log.Printf("List of Tables in Database %s: %v\n", d, tables)
	}
}

Initial fork from impalathing

go-impala's People

Contributors

intamyuto avatar shaloi avatar koblas avatar vishjosh avatar noahhl avatar alileza avatar ikkeps avatar timarmstrong avatar

Watchers

Fafnir Crow avatar James Cloos avatar LaKindra Hampton avatar Eric See avatar

Forkers

isabella232

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.