clickhouse-js icon indicating copy to clipboard operation
clickhouse-js copied to clipboard

parseColumnType throws on named Tuple types (Tuple(name Type, ...))

Open polyglotAI-bot opened this issue 5 months ago • 1 comments

Summary

parseColumnType (exported @experimental from @clickhouse/client / @clickhouse/client-web, and re-exported from @clickhouse/client-common) throws ColumnTypeParseError: Unsupported column type when given a named Tuple type such as Tuple(s String, i Int64) — the exact shape ClickHouse returns from DESCRIBE TABLE (and in the RowBinaryWithNamesAndTypes / Native headers) for a column declared as a named tuple. Unnamed tuples (Tuple(String, Int64)) parse fine.

Reproduction

import { parseColumnType } from "@clickhouse/client"; // or client-web / client-common
parseColumnType("Tuple(s String, i Int64)");
// throws: ColumnTypeParseError: Unsupported column type  { columnType: "s String" }

Root cause

parseTupleType strips the Tuple( … ) wrapper and uses getElementsTypes to split the body on top-level commas, then passes each element verbatim to parseColumnType. For a named tuple the elements are "s String" / "i Int64" (name + space + type); "s String" matches no known type prefix and is not in SimpleColumnTypes, so it hits the else branch in parseColumnType (packages/client-common/src/parse/column_types.ts:217) and throws. There is no logic to strip the optional element-name prefix before recursing.

Expected

parseColumnType("Tuple(s String, i Int64)") should return a ParsedColumnTuple with elements String and Int64 (and, ideally, the element names preserved).

Notes

  • Realistic trigger: inspect column types via DESCRIBE TABLE, then feed them back into the parser.
  • Mirrors the upstream Java bug https://github.com/ClickHouse/clickhouse-java/issues/889 (ClickHouseColumn.parse("col Tuple(s String, i Int64)") → Unknown data type: s String).
  • Server version is not load-bearing (purely client-side string parsing).

polyglotAI-bot avatar Jun 26 '26 19:06 polyglotAI-bot

I can take this. I'll add focused common-parser tests for named tuple elements (including quoted names), parse the optional element-name prefix without changing the deprecated return shape, and update the affected package changelogs.

sidsri14 avatar Jul 24 '26 13:07 sidsri14

Closing as not planned. parseColumnType is deprecated on main, and fixes to deprecated code are not released:

https://github.com/ClickHouse/clickhouse-js/blob/5b7f7e46b369910fd2d008619c0a39f7028f3cf8/packages/client-common/src/parse/column_types.ts#L188-L194

Use parseDataType from the @clickhouse/datatype-parser package instead.

@sidsri14, thank you for the offer to work on this. A PR for it would not be merged.

polyglotAI-bot avatar Nov 09 '26 09:11 polyglotAI-bot