Menu

Post image 1
Post image 2
1 / 2
0

arrayJoin in ClickHouse: Why Your Rows Are Duplicating (and How to Control It)

DEV Community·Mohamed Hussain S·about 1 month ago
#7wHLVViO
#why#clickhouse#sql#fullscreen#arrayjoin#rows
Reading 0:00
15s threshold

When working with arrays in ClickHouse, arrayJoin feels straightforward. Until your query suddenly returns far more rows than expected. The Use Case Let’s say you have a table like this: CREATE TABLE events ( user_id UInt32 , actions Array ( String ) ) ENGINE = MergeTree ORDER BY user_id ; Enter fullscreen mode Exit fullscreen mode Example row: user_id : 1 actions : [ ' click' , ' scroll' , ' purchase' ] Enter fullscreen mode Exit fullscreen mode Now you want each action as a separate row. The Tool: arrayJoin SELECT user_id , arrayJoin ( actions ) AS action FROM events ; Enter fullscreen mode Exit fullscreen mode Output: 1 click 1 scroll 1 purchase Enter fullscreen mode Exit fullscreen mode So far, everything looks correct.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More