• Stars
    star
    225
  • Rank 177,187 (Top 4 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created about 7 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Presto client for the Go programming language.

Presto client

A Presto client for the Go programming language.

Build Status GoDoc

Features

  • Native Go implementation
  • Connections over HTTP or HTTPS
  • HTTP Basic and Kerberos authentication
  • Per-query user information for access control
  • Support custom HTTP client (tunable conn pools, timeouts, TLS)
  • Supports conversion from Presto to native Go data types
    • string, sql.NullString
    • int64, presto.NullInt64
    • float64, presto.NullFloat64
    • map, presto.NullMap
    • time.Time, presto.NullTime
    • Up to 3-dimensional arrays to Go slices, of any supported type

Requirements

  • Go 1.18 or newer
  • Presto 0.16x or newer

Installation

You need a working environment with Go installed and $GOPATH set.

Download and install presto database/sql driver:

go get github.com/prestodb/presto-go-client/presto

Make sure you have Git installed and in your $PATH.

Usage

This Presto client is an implementation of Go's database/sql/driver interface. In order to use it, you need to import the package and use the database/sql API then.

Only read operations are supported, such as SHOW and SELECT.

Use presto as driverName and a valid DSN as the dataSourceName.

Example:

import "database/sql"
import _ "github.com/prestodb/presto-go-client/presto"

dsn := "http://user@localhost:8080?catalog=default&schema=test"
db, err := sql.Open("presto", dsn)

Authentication

Both HTTP Basic and Kerberos authentication are supported.

HTTP Basic authentication

If the DSN contains a password, the client enables HTTP Basic authentication by setting the Authorization header in every request to presto.

HTTP Basic authentication is only supported on encrypted connections over HTTPS.

Kerberos authentication

This driver supports Kerberos authentication by setting up the Kerberos fields in the Config struct.

Please refer to the Coordinator Kerberos Authentication for server-side configuration.

System access control and per-query user information

It's possible to pass user information to presto, different from the principal used to authenticate to the coordinator. See the System Access Control documentation for details.

In order to pass user information in queries to presto, you have to add a NamedArg to the query parameters where the key is X-Presto-User. This parameter is used by the driver to inform presto about the user executing the query regardless of the authentication method for the actual connection, and its value is NOT passed to the query.

Example:

db.Query("SELECT * FROM foobar WHERE id=?", 1, sql.Named("X-Presto-User", string("Alice")))

The position of the X-Presto-User NamedArg is irrelevant and does not affect the query in any way.

DSN (Data Source Name)

The Data Source Name is a URL with a mandatory username, and optional query string parameters that are supported by this driver, in the following format:

http[s]://user[:pass]@host[:port][?parameters]

The easiest way to build your DSN is by using the Config.FormatDSN helper function.

The driver supports both HTTP and HTTPS. If you use HTTPS it's recommended that you also provide a custom http.Client that can validate (or skip) the security checks of the server certificate, and/or to configure TLS client authentication.

Parameters

Parameters are case-sensitive

Refer to the Presto Concepts documentation for more information.

source
Type:           string
Valid values:   string describing the source of the connection to presto
Default:        empty

The source parameter is optional, but if used, can help presto admins troubleshoot queries and trace them back to the original client.

catalog
Type:           string
Valid values:   the name of a catalog configured in the presto server
Default:        empty

The catalog parameter defines the presto catalog where schemas exist to organize tables.

schema
Type:           string
Valid values:   the name of an existing schema in the catalog
Default:        empty

The schema parameter defines the presto schema where tables exist. This is also known as namespace in some environments.

session_properties
Type:           string
Valid values:   comma-separated list of key=value session properties
Default:        empty

The session_properties parameter must contain valid parameters accepted by the presto server. Run SHOW SESSION in presto to get the current list.

custom_client
Type:           string
Valid values:   the name of a client previously registered to the driver
Default:        empty (defaults to http.DefaultClient)

The custom_client parameter allows the use of custom http.Client for the communication with presto.

Register your custom client in the driver, then refer to it by name in the DSN, on the call to sql.Open:

foobarClient := &http.Client{
    Transport: &http.Transport{
        Proxy: http.ProxyFromEnvironment,
        DialContext: (&net.Dialer{
            Timeout:   30 * time.Second,
            KeepAlive: 30 * time.Second,
            DualStack: true,
        }).DialContext,
        MaxIdleConns:          100,
        IdleConnTimeout:       90 * time.Second,
        TLSHandshakeTimeout:   10 * time.Second,
        ExpectContinueTimeout: 1 * time.Second,
        TLSClientConfig:       &tls.Config{
        // your config here...
        },
    },
}
presto.RegisterCustomClient("foobar", foobarClient)
db, err := sql.Open("presto", "https://user@localhost:8080?custom_client=foobar")

Examples

http://user@localhost:8080?source=hello&catalog=default&schema=foobar
https://user@localhost:8443?session_properties=query_max_run_time=10m,query_priority=2

License

As described in the LICENSE file.

More Repositories

1

presto

The official home of the Presto distributed SQL query engine for big data
Java
15,970
star
2

presto-python-client

Python DB-API client for Presto
Python
236
star
3

presto-admin

A tool to install, configure and manage Presto installations
Python
171
star
4

RPresto

DBI-based adapter for Presto for the statistical programming language R.
R
129
star
5

tempto

A testing framework for Presto
Java
61
star
6

presto-yarn

Java
57
star
7

f8-2019-demo

A tutorial on how to get started with Presto.
Jupyter Notebook
56
star
8

ambari-presto-service

Ambari service for Presto
Python
44
star
9

docker-images

Docker images for Presto integration testing
Dockerfile
35
star
10

presto-kubernetes-operator

Go
32
star
11

benchto

Framework for running macro benchmarks in a clustered environment
JavaScript
24
star
12

presto-hive-apache

Shaded version of Apache Hive for Presto
Java
19
star
13

presto-jdbc-java6

Presto JDBC driver compatible with Java 6
Java
18
star
14

prestorials

Tutorials and examples of how to deploy Presto and connect it to different data sources
17
star
15

presto-hadoop-apache2

Shaded version of Apache Hadoop 2.x for Presto
Java
14
star
16

presto-query-predictor

A query predictor pipeline and service to predict resource usages of Presto queries
Python
14
star
17

presto-helm-charts

Presto Helm Charts
12
star
18

presto-landscape

Presto Landscape
10
star
19

sql

A Modern SQL frontend based on SQL16 with extensions for streaming, graph, rich types, etc, including parser, resolver, rewriters, etc.
Java
10
star
20

presto-js-client

Monorepo for Presto JavaScript packages
TypeScript
10
star
21

presto-hadoop-cdh4

Shaded version of CDH4 Hadoop for Presto
Java
7
star
22

tsc

Presto Foundation TSC
7
star
23

prestodb.github.io

Presto website
HTML
6
star
24

presto-maven-plugin

Maven packaging and lifecycle for Presto plugins
Java
6
star
25

orc-protobuf

Compiled ORC protobuf definitions
4
star
26

foundation

Presto Foundation
3
star
27

presto-hive-jdbc

Shaded version of Apache Hive JDBC driver for Presto
3
star
28

presto-hadoop-apache1

Shaded version of Apache Hadoop 1.x for Presto
Java
3
star
29

presto-release-tools

Standard utilities to release Presto
Java
2
star
30

testing-mysql-server

Embedded MySQL server for use in tests
Java
1
star
31

artwork

Presto artwork assets. Please adhere to the Linux Foundation trademark policy.
1
star
32

presto-hive-dwrf

Presto Hive DWRF
Java
1
star
33

presto-cassandra-driver

Shaded version of DataStax Java Driver for Apache Cassandra
Java
1
star