Help us shape the future of Go! Take the 2026 Go Developer Survey

clickhousequery

package
v1.35.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package clickhousequery is the public surface that callers of the ClickHouse driver use for per-statement settings, query ids, the dial policy, the query guard and adapter error details.

Index

Constants

View Source
const MaxAudienceSQLBytes = 240 * 1024

MaxAudienceSQLBytes bounds the audience query text. It stays below the server default max_query_size (262144) and leaves room for the DESCRIBE and INSERT ... SELECT wrappers. Lookout applies the same number.

View Source
const MaxRunBudget = 2 * time.Hour

MaxRunBudget is the longest statement budget the driver supports. The transport's response-header timeout sits above it, so a caller's run budget must stay at or below it.

Variables

This section is empty.

Functions

func AccountKeys

func AccountKeys() []string

AccountKeys returns a fresh copy of the account fields the driver accepts.

func CheckAudienceSQL

func CheckAudienceSQL(sql string) (string, error)

CheckAudienceSQL returns the normalised query text, or CH_QUERY_INVALID naming the first refused construct. The normalised text is the input less one terminal semicolon and the trailing whitespace; nothing else changes. The error never contains query text. The guard refuses system, information_schema and INFORMATION_SCHEMA table references: a customer can still grant system.query_log and system.processes to the sync credential, and they expose other database users' query text.

func ExcludedKeys

func ExcludedKeys() []string

ExcludedKeys returns a fresh copy of options other drivers or older drafts accept that this driver refuses when set.

func NewQueryID

func NewQueryID() string

NewQueryID returns a fresh "retl-<UUID>" query id.

func ParseBlockedCIDRs

func ParseBlockedCIDRs(s string) ([]netip.Prefix, error)

ParseBlockedCIDRs parses a comma-separated list of CIDR ranges. One bad entry fails the whole call. rudder-sources calls it once per entry of RSOURCES_SQLSOURCE_CLICKHOUSE_BLOCKEDCIDRS and skips a bad entry with a warning, so the block list never stops the service.

func SetDialPolicy

func SetDialPolicy(p DialPolicy) error

SetDialPolicy installs the operator policy once. rudder-sources calls it lazily from NewClient. Before installation, connections use the fixed refused address set without operator CIDRs or test switches. Installation affects subsequent dials, including those from existing pools, but does not close established connections. AllowPlainHTTP is checked when NewDB parses the config, so that test switch must be installed before NewDB. A malformed prefix or a second explicit call returns an error.

func WithStatement

func WithStatement(ctx context.Context, settings map[string]any, queryID string) context.Context

WithStatement returns a context that sends settings and queryID with the next statement. It copies settings, so a later change by the caller has no effect. The map replaces any map on the parent context, and the driver then adds none of its own defaults. A read map must set readonly > 0 and cancel_http_readonly_queries_on_client_close = 1, so the server stops the read when its context ends.

Types

type Details

type Details struct {
	Code, Category, Field string
	// Detail is the adapter message that Error prints after the code. It
	// never holds server text or a credential, so a caller can show it as is.
	Detail     string
	ServerCode int32
	RetryAfter time.Duration
}

Details are the bounded fields of a ClickHouse adapter error.

func Describe

func Describe(err error) (Details, bool)

Describe returns the details of the first adapter error in err's chain.

type DialPolicy

type DialPolicy struct {
	// BlockedPrefixes adds refused ranges to the fixed refused address set.
	BlockedPrefixes []netip.Prefix
	// AllowLoopback admits loopback answers. Test builds only: production
	// code never sets it, because a loopback answer reaches the pod itself.
	AllowLoopback bool
	// AllowPlainHTTP lets the parser admit secure=false. Test builds only:
	// production code never sets it, because plain HTTP sends the password
	// in clear text.
	AllowPlainHTTP bool
}

DialPolicy carries the operator address rules for every ClickHouse connection in the process.

Jump to

Keyboard shortcuts

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