fix(rowbinary): support compiling empty Tuple() type AST - #1001
Draft
sidsri14 wants to merge 1 commit into
Draft
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves the AST compilation failure for empty tuples (
Tuple()) in@clickhouse/rowbinary.Background & Root Cause
When
@clickhouse/datatype-parserparses an empty tuple type string (such asTuple()orTuple(Tuple())), it returns a node withkind: NodeKind.DataTypeandname: "Tuple"(rather thanNodeKind.TupleDataTypewhich is returned for multi-element tuples likeTuple(UInt8, String)).In
skills/clickhouse-js-node-rowbinary/src/readers/compile.ts,dataTypeReader()did not have a handler forcase "Tuple". As a result, folding an empty tuple AST fell through to the default branch and threw:Additionally,
tupleReader()previously checkednamedvianames.length === readers.length && names.every((n) => n.length > 0). For empty tuples wherenamesandreadersare both empty arrays ([]),[].every(...)evaluated totrue, causing an empty tuple to be erroneously dispatched toreadTupleNamed({})(which returns an object{}) instead ofreadTuple([])(which returns an array[]).Changes
compile.ts: Addedcase "Tuple": return tupleReader(node);todataTypeReader().compile.ts: UpdatedtupleReader()sonamedrequiresnames.length > 0before treating a tuple as a named object tuple.compile.test.ts: Added unit tests validating thatTuple(),Tuple(Tuple()), andTuple(Tuple(), UInt8)compile cleanly and decode the expected zero-byte tuples without error.Verification
npm run typecheckinskills/clickhouse-js-node-rowbinarypassed with 0 errors.npx vitest run -t "empty Tuple" tests/compile.test.tspassed 3/3 tests cleanly.npx tsc -p tsconfig.build.jsonbuilt without errors.Partially addresses #1000.