rowbinary: readGeometry and writeGeometry throw for a Geometry that holds a MultiPoint (discriminant 6), and MultiPoint has no reader

Open Beginner friendly
#1,282 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript
Domain
backend

Research direction

Start with src/readers/geo.ts and src/writers/geo.ts, then inspect the NULLARY mapping in src/readers/compile.ts; the issue also identifies src/readers/reader.md and the rowbinary allowlist. Run the provided reproduction against ClickHouse 26.8 or later, and confirm that MultiPoint columns and Geometry discriminant 6 can be read and written, with the relevant rowbinary tests updated.

Written by the indexing model from the issue text.

Description

bug data-types documentation
Describe the bug

@clickhouse/rowbinary cannot read a Geometry value that holds a MultiPoint. Since ClickHouse 26.8, MultiPoint is a geo type and an alternative of Geometry. One MultiPoint row in a Geometry column makes the whole result fail:

  • compileRowBinaryWithNamesAndTypes and readGeometry throw RangeError: RowBinary: unknown Geometry discriminant 6, also when the Geometry is inside Array, Map or Tuple.
  • writeGeometry throws the same error for the discriminant 6, so a MultiPoint cannot be written to a Geometry column.
  • A MultiPoint column (also Array(MultiPoint)) on the header path throws RowBinaryTypeError: unsupported RowBinary type: MultiPoint.

Geometry values of the other six geo types decode correctly.

Steps to reproduce
  1. Start ClickHouse 26.8 or later.
  2. Run the program below (CLICKHOUSE_URL, default http://localhost:8123). It makes a table with a Geometry column that has a Point row and a MultiPoint row.
Expected behaviour

The readers return the rows that the server returns in JSONEachRow (the first line of the output). In RowBinary, the server sends the MultiPoint row as the discriminant 06, then an Array(Point) value (06 02 and four Float64). The RowBinary docs list the Geometry discriminants 0 to 6, with 6 = MultiPoint. The Native format docs say that the Geometry discriminants are fixed and that new geo types are only added at the end, so 0 to 5 keep their meaning.

Code example
Reproduction program (JavaScript, 53 lines)
import { createClient, ClickHouseLogLevel } from '@clickhouse/client'
import { Cursor, compileRowBinaryWithNamesAndTypes, readGeometry } from '@clickhouse/rowbinary'
import { Sink, writeGeometry } from '@clickhouse/rowbinary/writer'

const client = createClient({
  url: process.env.CLICKHOUSE_URL ?? 'http://localhost:8123',
  log: { level: ClickHouseLogLevel.OFF },
})

async function bytes(query) {
  const { stream } = await client.exec({ query })
  const chunks = []
  for await (const chunk of stream) chunks.push(chunk)
  return Buffer.concat(chunks)
}

async function run(label, fn) {
  try {
    console.log(`${label}: ${JSON.stringify(await fn())}`)
  } catch (e) {
    console.log(`${label}: ${e.name}: ${e.message}`)
  }
}

async function header(query) {
  const cursor = new Cursor(await bytes(`${query} FORMAT RowBinaryWithNamesAndTypes`))
  const { readRows } = compileRowBinaryWithNamesAndTypes(cursor)
  return readRows(cursor)
}

await client.command({ query: 'DROP TABLE IF EXISTS geo_repro' })
await client.command({ query: 'CREATE TABLE geo_repro (id UInt8, g Geometry) ENGINE = MergeTree ORDER BY id' })
await client.command({
  query: `INSERT INTO geo_repro SELECT 1, CAST(CAST((1, 2) AS Point) AS Geometry)
          UNION ALL SELECT 2, CAST(CAST([(3, 4), (5, 6)] AS MultiPoint) AS Geometry)`,
})

const server = (await client.query({ query: 'SELECT id, g FROM geo_repro ORDER BY id', format: 'JSONEachRow' }))
await run('server, JSONEachRow', () => server.json())
await run('Geometry column, header path', () => header('SELECT id, g FROM geo_repro ORDER BY id'))
await run('contrast, without the MultiPoint row', () => header('SELECT id, g FROM geo_repro WHERE id = 1'))
await run('MultiPoint column, header path', () => header('SELECT CAST([(3, 4), (5, 6)] AS MultiPoint) AS m'))
await run('readGeometry, FORMAT RowBinary', async () =>
  readGeometry(new Cursor(await bytes('SELECT g FROM geo_repro WHERE id = 2 FORMAT RowBinary'))),
)
await run('writeGeometry, discriminant 6', () => {
  const sink = new Sink(Buffer.alloc(64))
  writeGeometry(sink, [6, [[3, 4], [5, 6]]])
  return Buffer.from(sink.bytes()).toString('hex')
})

await client.command({ query: 'DROP TABLE geo_repro' })
await client.close()
Error log
server, JSONEachRow: [{"id":1,"g":[1,2]},{"id":2,"g":[[3,4],[5,6]]}]
Geometry column, header path: RangeError: RowBinary: unknown Geometry discriminant 6
contrast, without the MultiPoint row: [{"id":1,"g":[1,2]}]
MultiPoint column, header path: RowBinaryTypeError: unsupported RowBinary type: MultiPoint
readGeometry, FORMAT RowBinary: RangeError: RowBinary: unknown Geometry discriminant 6
writeGeometry, discriminant 6: RangeError: RowBinary: unknown Geometry discriminant 6
Root cause
  • readGeometry (skills/clickhouse-js-node-rowbinary/src/readers/geo.ts:85) and writeGeometry (src/writers/geo.ts:90) know only the discriminants 0 to 5 and 0xFF. Every other value goes to the default branch, which throws (geo.ts:104, writers/geo.ts:119).
  • The package has no MultiPoint reader or writer, and the NULLARY table of astToReader (src/readers/compile.ts:271) has no MultiPoint entry, so the header path throws at compile.ts:204.

The JSDoc of readGeometry and GeometryValue, and the type table of reader.md, name only the six older geo types. The fix is small: a MultiPoint reader and writer (the wire is Array(Point), as for Ring), a NULLARY entry, and the case 6 in both Geometry switches.

Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.

Related: the upstream SQL test harness records these failures with "Issue: not filed yet" in tests/clickhouse-test-runner/rowbinary-allowlist.txt: group [rowbinary-geometry-discriminant] (2 tests) and 04509_multipoint_type in group [rowbinary-unsupported-types].

Configuration
Environment
  • Client version: main at 0873ef2 (@clickhouse/rowbinary 0.2.0, @clickhouse/client 1.25.0)
  • Language version: Node.js 22.23.5
  • OS: Linux (container)
ClickHouse server
  • ClickHouse Server version: 26.11.7.10. 26.8.49.6 also sends the discriminant 6; 26.7.38.18 has no MultiPoint type.
  • ClickHouse Server non-default settings, if any: none

Classification: impact: none · area: Data types & formats (Geometry, MultiPoint)


Found by automated analysis (Polyglot AI) while working on #216. Verified against a live server.

Dominant language
TypeScript
Stars
332
Forks
94
Avg merge
19h 15m
Merged PRs (30d)
43

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ClickHouse/clickhouse-js

All issues in ClickHouse/clickhouse-js

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.