From 0e6dc63db6004771ce514a0949abbf87830bd8b4 Mon Sep 17 00:00:00 2001 From: serprex <159546+serprex@users.noreply.github.com> Date: Sun, 22 Nov 2026 04:52:25 +0000 Subject: [PATCH] remove chc_type_format --- clickhouse.h | 21 --------------------- doc/clickhouse.md | 6 ------ test/test_block_compare.h | 22 ++++------------------ test/test_block_decode.c | 15 +++------------ test/test_type_parse.c | 11 ----------- 5 files changed, 7 insertions(+), 68 deletions(-) diff --git a/clickhouse.h b/clickhouse.h index cbac6dc..ed8e97c 100644 --- a/clickhouse.h +++ b/clickhouse.h @@ -256,12 +256,6 @@ const char *chc_type_tuple_field_name(const chc_type *t, size_t i, /* Return an aggregate function name without parameters, or NULL when absent */ const char *chc_type_agg_function(const chc_type *t, size_t *out_len); -/* Reproduce the printable type name into buf. Returns the number of bytes - * that would have been written (snprintf-style); use to size buf on a - * second pass when the return value >= buf_len. buf may be NULL when - * buf_len == 0 (length query). */ -size_t chc_type_format(const chc_type *t, char *buf, size_t buf_len); - /* -------------------------------------------------------------------------- */ /* Columns */ /* -------------------------------------------------------------------------- */ @@ -1881,21 +1875,6 @@ chc_type_parse(const char *name, size_t name_len, return CHC_OK; } -size_t -chc_type_format(const chc_type *t, char *buf, size_t buf_len) -{ - if (!t) return 0; - if (t->name && t->name_len) { - if (buf && buf_len) { - size_t take = t->name_len < buf_len - 1 ? t->name_len : buf_len - 1; - memcpy(buf, t->name, take); - buf[take] = '\0'; - } - return t->name_len; - } - return 0; -} - /* -------- column internals ---------- */ /* Public API defines struct chc_column */ diff --git a/doc/clickhouse.md b/doc/clickhouse.md index 5ced39c..71aff9c 100644 --- a/doc/clickhouse.md +++ b/doc/clickhouse.md @@ -193,14 +193,8 @@ const char *chc_type_tuple_field_name (const chc_type *t, size_t i, size_t *out_len); const char *chc_type_agg_function (const chc_type *t, size_t *out_len); - -size_t chc_type_format (const chc_type *t, - char *buf, size_t buf_len); ``` -`chc_type_format` is snprintf-style: pass `NULL`/0 to query length, then -allocate & call again. - `chc_type_tuple_field_name` covers `Nested` as well as `Tuple`; both label their children, `Nested(a UInt32, b String)` reading back `a` & `b`. diff --git a/test/test_block_compare.h b/test/test_block_compare.h index d662034..c7086c4 100644 --- a/test/test_block_compare.h +++ b/test/test_block_compare.h @@ -6,7 +6,6 @@ #define CLICKHOUSE_TEST_BLOCK_COMPARE_H #include -#include #include static int test_col_eq(const chc_column *a, const chc_column *b); @@ -15,23 +14,10 @@ static int test_type_eq(const chc_type *a, const chc_type *b) { if (!a || !b) return a == b; - size_t na = chc_type_format(a, NULL, 0); - size_t nb = chc_type_format(b, NULL, 0); - if (na != nb) return 0; - - char *sa = malloc(na + 1); - char *sb = malloc(nb + 1); - if (!sa || !sb) { - free(sa); - free(sb); - return 0; - } - chc_type_format(a, sa, na + 1); - chc_type_format(b, sb, nb + 1); - int eq = memcmp(sa, sb, na) == 0; - free(sa); - free(sb); - return eq; + size_t na, nb; + const char *sa = chc_type_name(a, &na); + const char *sb = chc_type_name(b, &nb); + return na == nb && memcmp(sa, sb, na) == 0; } static int diff --git a/test/test_block_decode.c b/test/test_block_decode.c index 84f0a0c..3094012 100644 --- a/test/test_block_decode.c +++ b/test/test_block_decode.c @@ -961,18 +961,9 @@ static void test_type_parse_roundtrip(void) { fail_count++; continue; } - char buf[128]; - size_t need = chc_type_format(t, buf, sizeof buf); - if (need >= sizeof buf) { - fprintf(stderr, "%s: format overflow\n", types[i]); - fail_count++; - } - /* Round-trip should be identical or a normalized form */ - if (strcmp(types[i], buf) != 0) { - /* For Enum the input has spaces in the formatted output too, OK */ - fprintf(stderr, "%s: round-trip mismatch -> %s\n", types[i], buf); - /* not a hard fail: we exact-match the source string today */ - } + size_t len; + const char *nm = chc_type_name(t, &len); + CHECK_STR_EQ(nm, len, types[i]); chc_type_destroy(t, &al); } } diff --git a/test/test_type_parse.c b/test/test_type_parse.c index 3593c6a..eb55126 100644 --- a/test/test_type_parse.c +++ b/test/test_type_parse.c @@ -196,16 +196,6 @@ test_decimal_precision(void) chc_type_destroy(i32, &al); } -static void -test_format_unnamed(void) -{ - current_test = "format_unnamed"; - chc_type t = {}; /* only the parser fills in name */ - char buf[8] = "junk"; - CHECK_EQ_U64(chc_type_format(&t, buf, sizeof buf), 0); - CHECK_EQ_U64(chc_type_format(NULL, buf, sizeof buf), 0); -} - static void test_datetime_timezone(void) { @@ -360,7 +350,6 @@ main(void) test_depth_limit(); test_accessors(); test_decimal_precision(); - test_format_unnamed(); test_datetime_timezone(); test_aggregate_function(); test_nested_json_params();