EV-ClickHouse

 view release on metacpan or  search on metacpan

lib/EV/ClickHouse.pm  view on Meta::CPAN

round trip, uncompressed, the whole body held in memory on both sides.
C<columns_at>, C<empty_as_default> and C<defaults> do not apply. A
C<Native> block from L<ClickHouse::Encoder> declaring C<Nullable(T)>
columns, with C<input_format_null_as_default =E<gt> 1>, makes the
server fill the column C<DEFAULT> for each NULL (with C<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) = @_; ... });

=item C<data_block =E<gt> 1>

With C<data_format =E<gt> 'Native'> on the native protocol, send the
block as protocol Data instead, compressed when C<compress> is on.
Its columns must match the insert's names and the table's types
(C<String> may stand for C<LowCardinality(String)>); a mismatch fails
the insert, since this path stores a NULL as the type's zero rather
than the column C<DEFAULT>.

=item C<columns_at =E<gt> \@positions>

With arrayref data, column C<j> of the insert reads
C<< $row->[$positions[j]] >>, so wider records need no per-row copy.
Positions past the end of a row read as C<undef>. The number of
positions must match the insert's columns.

    $ch->insert('t (a, b, c)', \@records, { columns_at => [7, 2, 11] }, $cb);

=back

=head2 ping

    $ch->ping(sub { my ($result, $err) = @_ });

Send a no-op round trip to verify the connection is alive. On success
C<$result> is true, C<$err> is C<undef>. On error: C<(undef, $error)>.

=head2 is_healthy

    $ch->is_healthy(sub { my ($ok, $err) = @_ });
    $ch->is_healthy(sub { ... }, $timeout_seconds);

Bounded health probe: wraps L</ping> with a deadline (default 5s). The
callback receives C<(1, undef)> on a successful round trip, or
C<(0, $msg)> on ping error or timeout. Failure does B<not> tear down the
connection; recovery (C<reset>, host rotation, etc.) is the caller's
choice. Useful for L4 load-balancer probes and self-monitoring loops.

=head2 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 L</track_query_durations> for a one-shot probe;
returns C<(undef, $err)> on transport failure. Pairs well with
L</is_healthy> for health-check endpoints that want both liveness and
latency.

=head2 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 L</on_query_complete> that fires only when the
query took at least C<$threshold> seconds. Returns the previous
C<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.

=head2 server_setting

    $ch->server_setting('max_threads', sub {
        my ($value, $err) = @_;
        warn "max_threads = $value\n";
    });

Looks one value up from C<system.settings>. Convenient one-liner for
"what's the server's effective C<$x>?". Returns C<undef> via the
callback if the setting name isn't present on this server.

=head2 row_count

    $ch->row_count('events', sub { ... });
    $ch->row_count('events', "ts > now() - interval 1 hour", sub { ... });

C<select count() from $table [where $where]>. C<$where> is interpolated
literally; use parameterized predicates via the L</query> C<params>
mechanism for user-supplied filters. Returns the row count or
C<(undef, $err)>.

=head2 table_size

    $ch->table_size('events', sub {
        my ($info, $err) = @_;
        # $info = { rows => N, bytes_on_disk => N, data_uncompressed_bytes => N }
    });

Sums C<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).

=head2 ddl

    $ch->ddl("create table t (n UInt32) engine=Memory", sub {
        my (undef, $err) = @_; die "ddl: $err" if $err;
    });

Strict variant of L</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.

=head2 dictionary_reload



( run in 2.042 seconds using v1.01-cache-2.11-cpan-eb134014566 )