Skip to content

Accept type aliases and other letter cases in CreateColumnByType - #656

Open
HawkForge wants to merge 1 commit into
ClickHouse:masterfrom
HawkForge:fix/type-name-aliases
Open

HawkForge wants to merge 1 commit into
ClickHouse:masterfrom
HawkForge:fix/type-name-aliases

Conversation

@HawkForge

@HawkForge HawkForge commented Dec 6, 2026 •

Copy link
Copy Markdown

CreateColumnByType() only knew the canonical type names. The server also accepts the aliases of system.data_type_families (BIGINT, TEXT, BOOLEAN, DOUBLE PRECISION, INET4, ...) and the case-insensitive type names in any letter case (datetime, decimal(9, 2), DATE, json), so a column could not be made from the type name of the table's own DDL: the root gave nullptr, and a name inside a container gave a Void column.

The parser now resolves a name to the canonical one before it picks the type code and the meta type:

  • the aliases of the server (whose canonical type the library supports), in any letter case;
  • the families with case_insensitive = 1, plus Array, Map, Enum8 and Enum16, which the server also reads in any letter case;
  • an alias with several words (DOUBLE PRECISION, NATIONAL CHARACTER LARGE OBJECT, INT UNSIGNED, ...) is read as one name. This includes the 14 names that end in SIGNED or UNSIGNED (see the comment on the issue); without it INT UNSIGNED would be a field INT of type UNSIGNED, so UInt64. A name that is not the start of such an alias is still a field name, as in Tuple(a Int32).

Names that the server reads case-sensitively (int64, string, nullable(...), tuple(...), lowcardinality(...), ...) are still not accepted, as on the server. Enum, Geometry and Decimal256 are not mapped, as the library has no column for them.

Tests:

  • CreateColumnByTypeNameAlias in ut/CreateColumnByType_ut.cpp: aliases, SIGNED/UNSIGNED forms, letter case, and aliases inside Nullable, Array, Map, LowCardinality and named Tuple; plus TypeNameAliasUnknownNames and BoolAlias.
  • ClientCase.TypeNameAliasesFromTypeName in ut/client_ut.cpp: inserts columns made from BIGINT, TEXT, INT UNSIGNED, DOUBLE PRECISION and datetime into a table with those column types and reads the values back.

The new tests fail without the change (63 failures). The whole clickhouse-cpp-ut suite passes against a local server (1139 tests).

Fixes #652


Note

Medium Risk
Changes central type-string parsing used by column creation; incorrect alias or tuple-field disambiguation could mis-resolve types at runtime, though behavior is aligned with server rules and heavily tested.

Overview
CreateColumnByType() and the type parser now accept the same type spellings ClickHouse uses in DDL, so columns can be built from names like BIGINT, TEXT, or datetime instead of only canonical forms like Int64.

The parser in type_parser.cpp resolves identifiers through GetCanonicalTypeName: server aliases (system.data_type_families), case-insensitive families (Bool, DateTime, Array, …), and multi-word aliases (DOUBLE PRECISION, INT UNSIGNED, NATIONAL CHARACTER LARGE OBJECT) by joining consecutive name tokens when they form a known alias. Case-sensitive names the server rejects (int64, nullable(...), partial alias prefixes) still fail as before.

Unit tests cover aliases, SIGNED/UNSIGNED, casing, nested wrappers, and rejection cases; ClientCase.TypeNameAliasesFromTypeName round-trips an insert using DDL-style type strings against a matching temporary table.

Reviewed by Cursor Bugbot for commit 193a9ed. Bugbot is set up for automated code reviews on this repo. Configure here.

The server accepts type aliases (BIGINT, TEXT, BOOLEAN, DOUBLE PRECISION,
...) and the case-insensitive type names in any letter case, but the
parser only knew the canonical names, so such names gave nullptr at the
root and a Void column inside a container.

The parser now maps the aliases from system.data_type_families, and
the case-insensitive families (plus Array, Map, Enum8 and Enum16, which
the server also reads in any case), to the canonical name. Names that
the server reads case-sensitively (Int64, String, Nullable, Tuple, ...)
stay case-sensitive. An alias with several words is read as one name,
so INT UNSIGNED is UInt32 and not a field INT of type UNSIGNED.

Closes ClickHouse#652
@HawkForge
HawkForge requested review from a team and slabko as code owners December 6, 2026 10:22

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 193a9ed. Configure here.

if (!type_->name.empty() && token.type == Token::Name && IsMultiWordAliasPart(type_->name, token.value)) {
// A word of an alias with several words, e.g. "UNSIGNED" in "INT UNSIGNED".
type_->name += ' ';
type_->name += token.value.to_string();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoted tuple fields join aliases

Medium Severity

Alias joining appends the next bare word to any name already stored, including a quoted identifier. A quoted tuple field that begins a multi-word alias is absorbed into the type: the field name is dropped, and a shorter integer alias can be chosen instead of standalone SIGNED or UNSIGNED.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 193a9ed. Configure here.

@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown

AI review gate — Cursor Bugbot found issues

  • Cursor Bugbot found issues that are not resolved (check concluded 'neutral').

Unresolved findings (1):

What to do:

  • Fix the findings and push. The reviewer re-reviews the new commit and the gate re-runs by itself.
  • A finding you think is wrong: a maintainer of the repository (maintain or admin role, the author included) replies in its thread with why and resolves it, then re-run the gate.
  • Finding wrong, or reviewer stuck? Ask a human with write access who is not the PR author to approve this exact commit, then re-run the gate. Their approval stands in for the AI review (a new push needs a new approval).

Re-run the gate with “Re-run jobs” after an approval or a finished review. A push re-runs it automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant