clickhouse icon indicating copy to clipboard operation
clickhouse copied to clipboard

feat: allow inserting Map using singlequoted JSON

Open mtrimolet opened this issue 3 years ago • 6 comments
trafficstars

Inserting a value for a Map field can be done using a key-value format which is a kind of singlequoted JSON (see Map(key, value) | ClickHouse Docs.

This is a proposal to use this feature from CH, enabling insertion for Map fields.

mtrimolet avatar Jun 13 '22 10:06 mtrimolet

Able to you add some test for null insert?

TimonKK avatar Aug 15 '22 22:08 TimonKK

It seems the Map type can't be a Nullable by design (error below).

Query : CREATE TABLE ... rec3 Nullable(Map(String, UInt8)) [cut for clarity] Result : Error: Nested type Map(String, UInt8) cannot be inside Nullable type. (ILLEGAL_TYPE_OF_ARGUMENT) (version 21.12.4.1 (official build))

As for the other way around, yes I can add this in the tests if you confirm that it's what you intended.

Query : CREATE TABLE ... rec3 Map(String, Nullable(UInt8)) [cut for clarity] Row Data (JS) : { ... rec3: { a: null } ... } [cut for clarity] Result : OK

mtrimolet avatar Aug 19 '22 14:08 mtrimolet

There's a point to be made about nested Map/Array (see citation below), for which I expect this implementation to fail. But maybe it should be issued separately as it concerns more general aspects of this lib.

From Map(key, value) | ClickHouse Docs :

Parameters

  • key — [...]
  • value — The value part of the pair. Arbitrary type, including Map and Array.

mtrimolet avatar Aug 22 '22 09:08 mtrimolet

Any updates on this? Is there a solution that I can use for now?

Sh4yy avatar Aug 30 '22 21:08 Sh4yy

There's a point to be made about nested Map/Array (see citation below), for which I expect this implementation to fail.

Actually it seems to work just fine.

mtrimolet avatar Sep 06 '22 09:09 mtrimolet

Yep, I'm using a fork of your PR at the moment. I would appreciate it if this gets merged so I can switch over.

Sh4yy avatar Sep 09 '22 01:09 Sh4yy