gpt4 book ai didi

apache-kafka - 如何编写查询来提取 KSQL 中的所有字段值以及满足条件的值

转载 作者:行者123 更新时间:2023-12-02 20:34:17 24 4
gpt4 key购买 nike

使用以下字段创建流

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

你能帮我解决这个用例吗

最佳答案

第 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

关于apache-kafka - 如何编写查询来提取 KSQL 中的所有字段值以及满足条件的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53663725/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com