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
- func AccountKeys() []string
- func CheckAudienceSQL(sql string) (string, error)
- func ExcludedKeys() []string
- func NewQueryID() string
- func ParseBlockedCIDRs(s string) ([]netip.Prefix, error)
- func SetDialPolicy(p DialPolicy) error
- func WithStatement(ctx context.Context, settings map[string]any, queryID string) context.Context
- type Details
- type DialPolicy
Constants ¶
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.
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 ¶
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 ParseBlockedCIDRs ¶
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 ¶
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.
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.