News for hackers. Stuff that matters.
Re:Show HN: ScratchDB – Open-Source Snowflake on ClickHouse by giovannibonetti on Friday October 27, 2023 @03:42PM (#38042978)
Great product! Thanks for sharing it!

Question: I thought Clickhouse already has native support for flattening JSON [1], although it was released recently (version 22.3.1). Did you start working on it [2] before that? Or is it a different take? I'm curious about the pros and cons of each one.

[1] https://clickhouse.com/docs/en/integrations/data-formats/jso... [2] https://scratchdb.com/blog/flatten-json/

Re:Show HN: ScratchDB – Open-Source Snowflake on ClickHouse by memset on Friday October 27, 2023 @04:17PM (#38043367)
This is a really good question. My snarky answer is "the way we ingest JSON doesn't require 50 pages and n configuration settings to explain."

Here's a more factual one:

- We don't use tuples for nested JSON. We just use underscores to show parent_child relationships in keys.

- We don't use arrays. Instead, we make it easy to split into multiple rows so you can use regular SQL.

I haven't directly compared Clickhouse's all of different JSON treatments compared to what I've implemented, but my goal was to build something that you could run and would "just work the way it should."

Re:Show HN: ScratchDB – Open-Source Snowflake on ClickHouse by antoniojtorres on Friday October 27, 2023 @05:02PM (#38043875)
ClickHouse JSON certainly has some sharp edges because they do a lot of schema inference to transparently column store the component parts, which makes it tricky with anything that could be irregular.

Big fan of CH on my end. Will follow your project closely.

Re:Show HN: ScratchDB – Open-Source Snowflake on ClickHouse by zepolen on Friday October 27, 2023 @05:54PM (#38044513)
What happens with this?

  {
    "some_key": "1"
    "some": {
      "key": "2"
    }
  }
Re:Show HN: ScratchDB – Open-Source Snowflake on ClickHouse by memset on Friday October 27, 2023 @06:24PM (#38044792)
Probably an error! Should create a ticket for that. What would we want the behavior to be?

(This hasn't come up with existing customers because theoretically it could and we should handle it.)

Re:Show HN: ScratchDB – Open-Source Snowflake on ClickHouse by namtab00 on Friday October 27, 2023 @07:08PM (#38045145)
maybe double the underscore on conflict?

some_key =1

some__key = 2

Re:Show HN: ScratchDB – Open-Source Snowflake on ClickHouse by dicriseg on Friday October 27, 2023 @07:38PM (#38045353)
The convention when flattening is exactly that I thought - an underscore per level of nesting. This is what I would expect to see too.
Re:Show HN: ScratchDB – Open-Source Snowflake on ClickHouse by memset on Friday October 27, 2023 @07:26PM (#38045261)
Agree. (What if the original users key has the double underscore?) maybe this can be defined as a param?
Re:Show HN: ScratchDB – Open-Source Snowflake on ClickHouse by namtab00 on Friday October 27, 2023 @07:53PM (#38045457)
> What if the original users key has the double underscore?

Double it again.

some_key = 1

some__key = 2

some____key = 3

This is analogous to what C#11 does to allow raw string literal quotes containing those same quotes. https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...

Re:Show HN: ScratchDB – Open-Source Snowflake on ClickHouse by gostsamo on Saturday October 28, 2023 @01:30AM (#38047415)
escape the underscore. this is the only sane one, I think.
Re:Show HN: ScratchDB – Open-Source Snowflake on ClickHouse by mosen on Friday October 27, 2023 @06:45PM (#38044969)
I tested it with the “explode” flattening mode, and it resulted in { “some_key”: “2” }
Re:Show HN: ScratchDB – Open-Source Snowflake on ClickHouse by memset on Friday October 27, 2023 @07:26PM (#38045268)
Feel free to create a gh issue - really interested in what the right solution would be here!
Re:Show HN: ScratchDB – Open-Source Snowflake on ClickHouse by datatrashfire on Friday October 27, 2023 @06:37PM (#38044901)
as a huge clickhouse fan, i have to agree json is simply not a great experience even with all the changes in the last year
Re:Show HN: ScratchDB – Open-Source Snowflake on ClickHouse by lionkor on Friday October 27, 2023 @09:01PM (#38045943)
maybe use the json flattening RFC instead of inventing your own?
Re:Show HN: ScratchDB – Open-Source Snowflake on ClickHouse by zX41ZdbW on Friday October 27, 2023 @07:20PM (#38045224)
Schema inference for nested JSON objects is a feature of ClickHouse 23.9. I've made a video about it: https://www.youtube.com/watch?v=yS8YU-rBpMM&t=1846s