EV-ClickHouse
view release on metacpan or search on metacpan
server's input format as is: over HTTP as the request body (gzipped
with `compress`), on the native protocol inline with the query in one
round trip, uncompressed, the whole body held in memory on both sides.
`columns_at`, `empty_as_default` and `defaults` do not apply. A
`Native` block from [ClickHouse::Encoder](https://metacpan.org/pod/ClickHouse%3A%3AEncoder) declaring `Nullable(T)`
columns, with `input_format_null_as_default => 1`, makes the
server fill the column `DEFAULT` for each NULL (with `async_insert`
this needs ClickHouse 24.12 or later):
$ch->insert('t (a, b)', $enc->encode(\@rows),
{ data_format => 'Native', input_format_null_as_default => 1 },
sub { my (undef, $err) = @_; ... });
- `data_block => 1`
With `data_format => 'Native'` on the native protocol, send the
block as protocol Data instead, compressed when `compress` is on.
Its columns must match the insert's names and the table's types
(`String` may stand for `LowCardinality(String)`); a mismatch fails
the insert, since this path stores a NULL as the type's zero rather
than the column `DEFAULT`.
- `columns_at => \@positions`
With arrayref data, column `j` of the insert reads
`$row->[$positions[j]]`, so wider records need no per-row copy.
Positions past the end of a row read as `undef`. The number of
positions must match the insert's columns.
$ch->insert('t (a, b, c)', \@records, { columns_at => [7, 2, 11] }, $cb);
## ping
$ch->ping(sub { my ($result, $err) = @_ });
Send a no-op round trip to verify the connection is alive. On success
`$result` is true, `$err` is `undef`. On error: `(undef, $error)`.
## is\_healthy
$ch->is_healthy(sub { my ($ok, $err) = @_ });
$ch->is_healthy(sub { ... }, $timeout_seconds);
Bounded health probe: wraps ["ping"](#ping) with a deadline (default 5s). The
callback receives `(1, undef)` on a successful round trip, or
`(0, $msg)` on ping error or timeout. Failure does **not** tear down the
connection; recovery (`reset`, host rotation, etc.) is the caller's
choice. Useful for L4 load-balancer probes and self-monitoring loops.
## ping\_round\_trip
$ch->ping_round_trip(sub {
my ($seconds, $err) = @_;
die "ping: $err" if $err;
printf "rtt = %.3fms\n", $seconds * 1000;
});
Issue a single PING and report wall-clock latency in seconds. Lighter
than installing ["track\_query\_durations"](#track_query_durations) for a one-shot probe;
returns `(undef, $err)` on transport failure. Pairs well with
["is\_healthy"](#is_healthy) for health-check endpoints that want both liveness and
latency.
## slow\_query\_log
my $prev = $ch->slow_query_log(0.1, sub {
my ($qid, $rows, $bytes, $code, $dur, $err) = @_;
warn sprintf("SLOW %.3fs %s\n", $dur, $qid // '?');
});
Filtered variant of ["on\_query\_complete"](#on_query_complete) that fires only when the
query took at least `$threshold` seconds. Returns the previous
`on_query_complete` so the caller can restore it. The previous
handler is also chained on every call, so installing this on top of
existing instrumentation is safe.
## server\_setting
$ch->server_setting('max_threads', sub {
my ($value, $err) = @_;
warn "max_threads = $value\n";
});
Looks one value up from `system.settings`. Convenient one-liner for
"what's the server's effective `$x`?". Returns `undef` via the
callback if the setting name isn't present on this server.
## row\_count
$ch->row_count('events', sub { ... });
$ch->row_count('events', "ts > now() - interval 1 hour", sub { ... });
`select count() from $table [where $where]`. `$where` is interpolated
literally; use parameterized predicates via the ["query"](#query) `params`
mechanism for user-supplied filters. Returns the row count or
`(undef, $err)`.
## table\_size
$ch->table_size('events', sub {
my ($info, $err) = @_;
# $info = { rows => N, bytes_on_disk => N, data_uncompressed_bytes => N }
});
Sums `system.parts` for the (optionally database-qualified) table
and returns a hashref. Active parts only - does not count detached
parts. Suitable for ops dashboards; not authoritative for per-row
billing (parts may double-count rows during MERGE).
## ddl
$ch->ddl("create table t (n UInt32) engine=Memory", sub {
my (undef, $err) = @_; die "ddl: $err" if $err;
});
Strict variant of ["query"](#query) for DDL/DML. Identical wire behaviour;
the separate name is a readability marker for migration scripts so
the intent of each call is obvious at the call site.
## dictionary\_reload
( run in 1.056 second using v1.01-cache-2.11-cpan-eb134014566 )