3

使用以下字段创建流

CREATE STREAM pageviews_original_string(view_time string, user_id varchar, pageid varchar) WITH (kafka_topic='pageviews',value_format='DELIMITED',KEY='pageid');

将 pageid 与以下值一起更改为大写。

create stream up_case AS SELECT UCASE(pageid), user_id FROM PAGEVIEWS_ORIGINAL_STRING where user_id = 'User_9';

结果

PAGE_26 | User_9
PAGE_67 | User_9
PAGE_39 | User_9
PAGE_80 | User_9
PAGE_40 | User_9
PAGE_92 | User_9

现在我想要的是必须修改和提取条件满足的数据以及剩余的字段值,如下所示

****PAGE_26 | User_9
PAGE_67 | User_9
PAGE_39 | User_9
PAGE_80 | User_9
PAGE_40 | User_9
PAGE_92 | User_9****
Page_66 | User_7
Page_25 | User_2
Page_41 | User_3
Page_34 | User_1
Page_28 | User_2
Page_55 | User_5
Page_77 | User_5
Page_32 | User_8
Page_60 | User_4

你能帮我解决这个用例吗

4

1 回答 1

0

第 1 步:使用更改 user_9 的 pageid 大写的条件创建流

create stream step1 AS SELECT UCASE(pageid) AS upcase, user_id FROM PAGEVIEWS_ORIGINAL_STRING where user_id = 'User_9';

第 2 步:然后通过排除 user_9 创建另一个有条件的流,而不改变所有用户的任何情况

create stream step2 AS select pageid AS upcase, user_id from PAGEVIEWS_ORIGINAL_STRING where user_id != 'User_9';

然后创建了另一个合并两个流的流

ksql> create stream merge_two AS select step1;
insert into merge_two select * from step2;

结果

1544165217141 | 50671 | Page_35 | User_2
1544165217103 | 50661 | Page_10 | User_6
1544165217580 | 50681 | Page_54 | User_2
1544165217699 | 50691 | Page_45 | User_6
1544165218104 | 50701 | Page_20 | User_8
1544165218511 | 50711 | Page_13 | User_2
1544165218931 | 50721 | Page_45 | User_4
1544165219146 | 50731 | Page_68 | User_8
1544165219505 | 50741 | Page_65 | User_4
1544165219713 | 50751 | Page_74 | User_8
1544165219787 | 50761 | Page_30 | User_5
1544165220104 | 50771 | Page_72 | User_2
1544165220421 | 50781 | Page_39 | User_2
1544165220523 | 50791 | Page_55 | User_8
1544165220645 | 50801 | Page_76 | User_6
1544165220818 | 50821 | Page_46 | User_5
1544165220781 | 50811 | Page_60 | User_4
1544165220911 | 50831 | Page_24 | User_4
1544165221102 | 50841 | PAGE_11 | User_9
1544165221377 | 50851 | PAGE_95 | User_9
1544165221685 | 50861 | PAGE_56 | User_9
1544165222164 | 50871 | Page_50 | User_3
1544165222233 | 50881 | Page_12 | User_8
1544165222500 | 50891 | Page_18 | User_3
1544165222913 | 50901 | Page_67 | User_5
1544165223237 | 50911 | Page_30 | User_3
1544165223665 | 50921 | Page_62 | User_8
于 2018-12-07T06:47:53.780 回答