prestgo

package module
v0.0.0-...-a58f98c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2018 License: MIT Imports: 13 Imported by: 0

README

This driver is now deprecated

Please use github.com/prestodb/presto-go-client instead.

prestgo

A pure Go database driver for the Presto query engine.

Installation

Simply run

go get github.com/avct/prestgo/...

This will install the Presto database driver and the prq tool for running queries from the command line.

Documentation is at http://godoc.org/github.com/avct/prestgo

Usage

Prestgo conforms to the Go standard library Driver interface. This means it works transparently with the database/sql package. Simply import the github.com/avct/prestgo package to auto-register the driver:

import "github.com/avct/prestgo"

If you don't intend to use any prestgo-specific functions directly, you can import using the blank identifier which will still register the driver:

import _ "github.com/avct/prestgo"

The driver name is prestgo and it supports the standard Presto data source name format presto://user@hostname:port/catalog/schema. All parts of the data source name are optional, defaulting to port 8080 on localhost with hive catalog, default schema and a user of prestgo.

Here's how to get a list of tables from a Presto server:

package main

import (
	"database/sql"
	"fmt"
	"log"

	_ "github.com/avct/prestgo"
)

func main() {
	db, err := sql.Open("prestgo", "presto://example:8080/hive/default")
	if err != nil {
		log.Fatalf("failed to connect to presto: %v", err)
	}

	rows, err := db.Query("SHOW TABLES")
	if err != nil {
		log.Fatalf("failed to run query: %v", err)
	}

	defer rows.Close()

	for rows.Next() {
		var name string
		if err := rows.Scan(&name); err != nil {
			log.Fatal(err.Error())
		}

		fmt.Printf("%s\n", name)
	}
	if err := rows.Err(); err != nil {
		log.Fatal(err.Error())
	}
}

The included command line query tool prq can be used like this:

prq "presto://example:8080/hive/default" "SHOW TABLES"

Features

  • SELECT, SHOW, DESCRIBE
  • Pagination of results
  • varchar, bigint, boolean, double and timestamp datatypes
  • Custom HTTP clients

Future

(aka: Things you could help with)

  • Parameterised queries
  • INSERT queries
  • DDL (ALTER/CREATE/DROP TABLE)
  • Cancelling of queries
  • User authentication
  • json, date, time, interval, array, row and map datatypes

Authors

Originally written by Ian Davis.

Contributors

Your name here...

Contributing

  • Do submit your changes as a pull request
  • Do your best to adhere to the existing coding conventions and idioms.
  • Do supply unit tests if possible.
  • Do run go fmt on the code before committing
  • Do feel free to add yourself to the Contributors list in the README.md. Alphabetical order applies.
  • Don't touch the Authors section. An existing author will add you if your contributions are significant enough.

License

This software is released under the MIT License, please see the accompanying LICENSE file.

Documentation

Index

Constants

View Source
const (
	DefaultPort     = "8080"
	DefaultCatalog  = "hive"
	DefaultSchema   = "default"
	DefaultUsername = "prestgo"

	TimestampFormat = "2006-01-02 15:04:05.000"
)

Default data source parameters

View Source
const (
	// This type captures boolean values true and false
	Boolean = "boolean"

	// A 64-bit signed two’s complement integer with a minimum value of -2^63 and a maximum value of 2^63 - 1.
	BigInt = "bigint"

	// Integer assumed to be an alias for BigInt.
	Integer = "integer"

	// A double is a 64-bit inexact, variable-precision implementing the IEEE Standard 754 for Binary Floating-Point Arithmetic.
	Double = "double"

	// Variable length character data.
	VarChar = "varchar"

	// Variable length binary data.
	VarBinary = "varbinary"

	// Variable length json data.
	JSON = "json"

	// Calendar date (year, month, day).
	// Example: DATE '2001-08-22'
	Date = "date"

	// Time of day (hour, minute, second, millisecond) without a time zone. Values of this type are parsed and rendered in the session time zone.
	// Example: TIME '01:02:03.456'
	Time = "time"

	// Instant in time that includes the date and time of day without a time zone. Values of this type are parsed and rendered in the session time zone.
	// Example: TIMESTAMP '2001-08-22 03:04:05.321'
	Timestamp = "timestamp"

	// Instant in time that includes the date and time of day with a time zone. Values of this type are parsed and rendered in the provided time zone.
	// Example: TIMESTAMP '2001-08-22 03:04:05.321' AT TIME ZONE 'America/Los_Angeles'
	TimestampWithTimezone = "timestamp with time zone"

	// MapVarchar is a map from string-keys to string-values.
	MapVarchar = "map(varchar,varchar)"

	// Array of variable length character data.
	ArrayVarchar = "array(varchar)"
)
View Source
const (
	QueryStateQueued   = "QUEUED"
	QueryStatePlanning = "PLANNING"
	QueryStateStarting = "STARTING"
	QueryStateRunning  = "RUNNING"
	QueryStateFinished = "FINISHED"
	QueryStateCanceled = "CANCELED"
	QueryStateFailed   = "FAILED"
)
View Source
const DriverName = "prestgo"

Name of the driver to use when calling `sql.Open`

Variables

View Source
var (
	// ErrNotSupported is returned when an unsupported feature is requested.
	ErrNotSupported = errors.New(DriverName + ": not supported")

	// ErrQueryFailed indicates that a network or server failure prevented the driver obtaining a query result.
	ErrQueryFailed = errors.New(DriverName + ": query failed")

	// ErrQueryCanceled indicates that a query was canceled before results could be retrieved.
	ErrQueryCanceled = errors.New(DriverName + ": query canceled")
)

Functions

func ClientOpen

func ClientOpen(client *http.Client, name string) (driver.Conn, error)

ClientOpen creates a connection to the specified data source name using the supplied HTTP client. The data source name should be of the form "presto://hostname:port/catalog/schema?source=x&session=y".

func Open

func Open(name string) (driver.Conn, error)

Open creates a connection to the specified data source name which should be of the form "presto://hostname:port/catalog/schema?source=x&session=y". http.DefaultClient will be used for communicating with the Presto server.

Types

This section is empty.

Directories

Path Synopsis
cmd
prq
Command prq is a command line interface for running presto queries
Command prq is a command line interface for running presto queries

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL