chclient

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2018 License: MIT Imports: 9 Imported by: 0

README

chclient - fast http client for ClickHouse

Features

  • Optimized for reading large responses.
  • May read more than 20M rows per second on a single CPU core thanks to tsvreader.
  • Easily reads responses with billion rows thanks to response streaming. There is no need to fit the whole response in memory.
  • Works ideally with chproxy.
  • Sends requests to fallback address if requests to primary clickhouse address fail.

Documentation

See these docs.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTimeout = 30 * time.Second

DefaultTimeout is the default timeout for Client.

Functions

This section is empty.

Types

type Client

type Client struct {
	// Addr is clickhouse address to connect to.
	//
	// localhost:8123 is used by default.
	Addr string

	// FallbackAddr is a fallback clickhouse address that is used
	// if request to Addr fails.
	//
	// By default there is no fallback address.
	FallbackAddr string

	// User to use when connecting to clickhouse.
	//
	// User is `default` if not set.
	User string

	// Password to use when connecting to clickhouse.
	//
	// Password is empty if not set.
	Password string

	// Database to use.
	//
	// Database is `default` if not set.
	Database string

	// Whether to send requests over https.
	//
	// Requests are sent over http by default.
	UseHTTPS bool

	// Whether to request compressed responses from clickhouse.
	//
	// Response compression may reduce network usage.
	//
	// Response compression is disabled by default.
	CompressResponse bool

	// Timeout is the maximum duration for the query.
	//
	// DefaultTimeout is used by default.
	Timeout time.Duration

	// URLParams to add to URL before requesting clickhouse.
	//
	// For instance,
	//
	//     Client.URLParams = []string{
	//         "default_format=Pretty",
	//         "no_cache=1",
	//     }
	URLParams []string
}

Client is http client for clickhouse.

The client is optimized for SELECT queries.

Best used with github.com/Vertamedia/chproxy.

func (*Client) Do

func (c *Client) Do(query string, f ReadRowsFunc) error

Do sends the given query to clickhouse and calls f for reading query results.

The maximum query duration is limited by Client.Timeout.

f may be nil if query result isn't needed.

func (*Client) DoContext

func (c *Client) DoContext(ctx context.Context, query string, f ReadRowsFunc) error

DoContext sends the given query using the given ctx to clickhouse and calls f for reading query results.

The maximum query duration may be limited with the ctx.

f may be nil if query result isn't needed.

func (*Client) Ping

func (c *Client) Ping() error

Ping verifies that the client can connect to clickhouse.

type ReadRowsFunc

type ReadRowsFunc func(r *tsvreader.Reader) error

ReadRowsFunc must read rows from r.

Jump to

Keyboard shortcuts

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