Last active
June 4, 2024 18:07
-
-
Save maxjustus/154cc5440056b716a67a183ab1d21b71 to your computer and use it in GitHub Desktop.
aggregating EmbeddedRocksDB using Null engine and MV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- https://fiddle.clickhouse.com/43192eb8-cf28-4654-ad07-b7a78bdcb872 | |
CREATE TABLE users (uid Int16, names Array(Tuple(name String, age Int16))) | |
ENGINE=EmbeddedRocksDB | |
primary key uid; | |
INSERT INTO users VALUES (1231, [('John', 33)]); | |
INSERT INTO users VALUES (6666, [('Ksenia', 48)]); | |
INSERT INTO users VALUES (8888, [('Alice', 50)]); | |
SELECT * FROM users; | |
create table users_insert (uid Int64, name Tuple(name String, age Int16)) engine = Null; | |
create materialized view users_agg | |
to users | |
AS | |
with grouped_inserted as ( | |
select uid, groupUniqArray(name) as names from users_insert group by uid | |
) | |
select uid, arrayDistinct(arrayConcat(u.names, grouped_inserted.names)) as names from grouped_inserted | |
left any join users u on u.uid = grouped_inserted.uid; | |
insert into users_insert (uid, name) values | |
(1231, ('Jen', 33)), (31, ('hi', 31)), (31, ('hey', 32)); | |
SELECT * FROM users; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment