Skip to content

fix(rowbinary): support compiling empty Tuple() type AST - #1001

Draft
sidsri14 wants to merge 1 commit into
ClickHouse:mainfrom
sidsri14:fix/rowbinary-empty-tuple-compile
Draft

fix(rowbinary): support compiling empty Tuple() type AST#1001
sidsri14 wants to merge 1 commit into
ClickHouse:mainfrom
sidsri14:fix/rowbinary-empty-tuple-compile

Conversation

@sidsri14

Copy link
Copy Markdown

Summary

Resolves the AST compilation failure for empty tuples (Tuple()) in @clickhouse/rowbinary.

Background & Root Cause

When @clickhouse/datatype-parser parses an empty tuple type string (such as Tuple() or Tuple(Tuple())), it returns a node with kind: NodeKind.DataType and name: "Tuple" (rather than NodeKind.TupleDataType which is returned for multi-element tuples like Tuple(UInt8, String)).

In skills/clickhouse-js-node-rowbinary/src/readers/compile.ts, dataTypeReader() did not have a handler for case "Tuple". As a result, folding an empty tuple AST fell through to the default branch and threw:

RowBinaryTypeError: unsupported RowBinary type: Tuple

Additionally, tupleReader() previously checked named via names.length === readers.length && names.every((n) => n.length > 0). For empty tuples where names and readers are both empty arrays ([]), [].every(...) evaluated to true, causing an empty tuple to be erroneously dispatched to readTupleNamed({}) (which returns an object {}) instead of readTuple([]) (which returns an array []).

Changes

  1. compile.ts: Added case "Tuple": return tupleReader(node); to dataTypeReader().
  2. compile.ts: Updated tupleReader() so named requires names.length > 0 before treating a tuple as a named object tuple.
  3. compile.test.ts: Added unit tests validating that Tuple(), Tuple(Tuple()), and Tuple(Tuple(), UInt8) compile cleanly and decode the expected zero-byte tuples without error.

Verification

  • npm run typecheck in skills/clickhouse-js-node-rowbinary passed with 0 errors.
  • npx vitest run -t "empty Tuple" tests/compile.test.ts passed 3/3 tests cleanly.
  • npx tsc -p tsconfig.build.json built without errors.

Partially addresses #1000.

When a type string contains an empty Tuple (such as Tuple() or Tuple(Tuple())), the datatype parser returns a DataType node with name: 'Tuple' and empty arguments rather than a TupleDataType node.
Without a case in dataTypeReader, folding the AST threw a RowBinaryTypeError: unsupported RowBinary type: Tuple.

This adds case 'Tuple' to dataTypeReader and ensures tupleReader only treats tuples as named when names.length > 0.
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