Skip to content

Remove redundant CAST to String for LowCardinality/Enum/UUID#262

Merged
azat merged 5 commits into
mainfrom
remove-redundant-cast
Jun 14, 2026
Merged

Remove redundant CAST to String for LowCardinality/Enum/UUID#262
azat merged 5 commits into
mainfrom
remove-redundant-cast

Conversation

@azat

@azat azat commented Jun 14, 2026

Copy link
Copy Markdown
Owner

No description provided.

azat and others added 3 commits June 14, 2026 13:53
With LowCardinality re-enabled over the native protocol (f20b45f), typed
block.get::<String> coerces LC via LowCardinalityAccessor, so the casts
that only existed to satisfy clickhouse-rs FromSql are now redundant:

  - text_log logger_name (LC(String)) and query_id (String) interpreter
    readers;
  - error_log.error and logger_names.logger_name (both LC(String)) view
    providers.

The view path dispatches on sql_type() rather than reading as String, so
teach SQLQueryView to render LowCardinality(String) (the only LC inner
type in our queries) instead of hitting the unreachable!() arm.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
clickhouse-rs reads an Enum column as its bare integer (the name mapping
is dropped by FromSql), and SQLQueryView dispatched on sql_type() and hit
unreachable!() for it - hence the ::String casts in the view providers.
Read the integer via Enum8/Enum16 and resolve the name from the Vec carried
by SqlType::Enum8/Enum16, falling back to the integer for an unknown value.

Lets the backups, dictionaries and part_log providers drop their enum casts
(status, event_type, merge_algorithm). UUID columns still hit unreachable!()
and keep their casts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
SQLQueryView dispatched on sql_type() and hit unreachable!() for UUID
columns, so the view providers cast them with ::String. Read the column
as uuid::Uuid (the only FromSql target clickhouse-rs offers for it) and
format it, which yields the same canonical hyphenated text as
toString(uuid).

Drops the casts in the merges, table_parts, part_log, tables and replicas
providers. uuid is pulled in as a direct dependency (it was already in the
tree via clickhouse-rs).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@azat azat force-pushed the remove-redundant-cast branch from 0122858 to 467fbb5 Compare June 14, 2026 12:02
azat and others added 2 commits June 14, 2026 14:08
The perfetto and text_log readers consumed Enum columns (level,
event_type, trace_type, status, type, interface, operation) as their name
via block.get::<String>, which clickhouse-rs rejects - hence the ::String
casts in the queries. Add column_as_string(), which reads Enum8/Enum16 and
resolves the name from the mapping carried by the column type (String and
LowCardinality(String) fall through to a plain read), and use it from both
readers. auth_type stays a SQL coalesce(auth_type, '') since it is
Nullable(Enum) and the '' branch already forces a String result.

The integration tests asserted on the raw blocks, so they read the same
enum columns through column_as_string now too.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The view duplicated the Enum8/Enum16 name resolution and UUID formatting
that column_as_string already does for the interpreter readers. Teach
column_as_string to format UUID too and fold the view's String,
LowCardinality(String), Enum8/16 and UUID arms into one fallback that
calls it. Unsupported types now surface an error from the String read
instead of unreachable!() panicking the TUI.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@azat azat merged commit aad57cf into main Jun 14, 2026
9 checks passed
@azat azat deleted the remove-redundant-cast branch June 14, 2026 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant