Clickhouse 数据库中的物化视图未显示数据

Materialized view in clickhouse database not showing data

我用的是Clickhouse数据库。

我有分段的文本。我需要将所有文本分组在一行中,不要重复段

count(segment) = total Segment.

我创建第一个 table 来插入片段。 然后我创建一个 MATERIALIZED 视图以删除重复的行并对所有段进行分组。

然后将其移动到第二个 table,但我的问题是视图不显示值。 当我 运行 查询时它工作正常

第一个 Table :

CREATE table test_table_1
( 
    id UInt16,
    text String,
    totalSegment UInt16,
    segmentNumber UInt16,
    reference UInt16,
    insertTime DateTime
)
ENGINE = ReplacingMergeTree()
order by (id , text , totalSegment , segmentNumber , reference );

第二个Table:

CREATE table test_table_2
(
    message String,
    reference UInt16,
    totalSegment UInt16
)
ENGINE = MergeTree()
order by (reference );

物化视图:

CREATE MATERIALIZED VIEW consumer To test_table_2
as
SELECT  groupArray(text) as message ,reference ,totalSegment 
from ( 
    select * 
    from 
    ( 
        SELECT COUNT(*) as countSegment, totalSegment, reference 
        from test_table_1
        where (text,totalSegment,reference,insertTime) in (
                    select    text,totalSegment,reference, max(insertTime) as insertTime 
                    from      test_table_1 
                    group by  text,totalSegment,segmentNumber,reference
        )
        group by  totalSegment, reference
        HAVING count(*) = totalSegment 
        )as a
        left join (
                select    text,segmentNumber,reference, max(insertTime) as insertTime 
                from      test_table_1 
                group by  text,segmentNumber,reference
        )as b using (reference)
        order by segmentNumber 
    )
grousp by reference ,totalSegment
order by reference ;

插入数据:

INSERT INTO test_table_1 (id,text, totalSegment, segmentNumber, reference,insertTime) VALUES(1, 'A1 ', 3, 1, '101', now() );
INSERT INTO test_table_1 (id,text, totalSegment, segmentNumber, reference,insertTime) VALUES(2, 'B1 ', 2, 1, '202', now() );
INSERT INTO test_table_1 (id,text, totalSegment, segmentNumber, reference,insertTime) VALUES(3, 'C2 ', 3, 2, '303', now() );
INSERT INTO test_table_1 (id,text, totalSegment, segmentNumber, reference,insertTime) VALUES(4, 'A3 ', 3, 3, '101', now() );
INSERT INTO test_table_1 (id,text, totalSegment, segmentNumber, reference,insertTime) VALUES(5, 'A2 ', 3, 2, '101', now() );
INSERT INTO test_table_1 (id,text, totalSegment, segmentNumber, reference,insertTime) VALUES(6, 'C1 ', 3, 1, '303', now() );
INSERT INTO test_table_1 (id,text, totalSegment, segmentNumber, reference,insertTime) VALUES(7, 'C3 ', 3, 3, '303', now() );
INSERT INTO test_table_1 (id,text, totalSegment, segmentNumber, reference,insertTime) VALUES(8, 'B2 ', 2, 2, '202', now() );

MV 是一个插入触发器。它从不读取源代码 table -- test_table_1 !!!

https://den-crane.github.io/Everything_you_should_know_about_materialized_views_commented.pdf

https://youtu.be/ckChUkC3Pns?t=9326