null for String values

1,023 views
Skip to first unread message

Deepanwita Roy

unread,
Feb 27, 2019, 4:30:39 PM2/27/19
to ClickHouse
When I ingest data through ClickHouse Kafka for a column name Fee of type String. If the json I pass is Foo:null, Kafka Engine fails to parse it and ClickHouse "
{} <Error> void DB::StorageKafka::streamThread(): Code: 26, e.displayText() = DB::Exception: Cannot parse JSON string:". For successful parsing of JsonEachRow message I have to specifically pass Foo:"". Is there a better way of dealing with null values

Mikhail Filimonov

unread,
Feb 28, 2019, 2:53:27 AM2/28/19
to ClickHouse
If you need to have null - insert into Nullable column.
If you inserting in regular (not null) String field you need to convert all null to empty strings before.

create temporary table str_nullable ( a Nullable(String), b String);


insert
into str_nullable format JSONEachRow {"a":null}

Ok.
1 rows in set. Elapsed: 0.002 sec.


SELECT
* FROM str_nullable

┌─a────┬─b─┐
ᴺᵁᴸᴸ  
└──────┴───┘
1 rows in set. Elapsed: 0.001 sec.


insert into str_nullable format JSONEachRow {"b":null}

Exception on client:
Code: 26. DB::Exception: Cannot parse JSON string: expected opening quote: (while read the value of key b): (at row 1)

Reply all
Reply to author
Forward
0 new messages