{"id":1306,"date":"2023-03-19T08:09:54","date_gmt":"2023-03-19T00:09:54","guid":{"rendered":"http:\/\/viplao.com\/?p=1306"},"modified":"2023-03-19T08:09:56","modified_gmt":"2023-03-19T00:09:56","slug":"%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91-flink-sql-%e4%bd%bf%e7%94%a8-union-%e4%bb%a3%e6%9b%bf-join%e3%80%81cogroup-%e7%bb%8f%e9%aa%8c","status":"publish","type":"post","link":"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91-flink-sql-%e4%bd%bf%e7%94%a8-union-%e4%bb%a3%e6%9b%bf-join%e3%80%81cogroup-%e7%bb%8f%e9%aa%8c\/","title":{"rendered":"\u3010\u8fd0\u7ef4\u5de5\u5177\u3011\u00a0Flink SQL \u4f7f\u7528 union \u4ee3\u66ff join\u3001cogroup \u7ecf\u9a8c"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_71 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">\u6587\u7ae0\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91-flink-sql-%e4%bd%bf%e7%94%a8-union-%e4%bb%a3%e6%9b%bf-join%e3%80%81cogroup-%e7%bb%8f%e9%aa%8c\/#%E9%9C%80%E6%B1%82%E5%9C%BA%E6%99%AF%E5%88%86%E6%9E%90\" title=\"\u9700\u6c42\u573a\u666f\u5206\u6790\">\u9700\u6c42\u573a\u666f\u5206\u6790<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91-flink-sql-%e4%bd%bf%e7%94%a8-union-%e4%bb%a3%e6%9b%bf-join%e3%80%81cogroup-%e7%bb%8f%e9%aa%8c\/#%E9%9C%80%E6%B1%82%E5%9C%BA%E6%99%AF\" title=\"\u9700\u6c42\u573a\u666f\">\u9700\u6c42\u573a\u666f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91-flink-sql-%e4%bd%bf%e7%94%a8-union-%e4%bb%a3%e6%9b%bf-join%e3%80%81cogroup-%e7%bb%8f%e9%aa%8c\/#source_%E8%BE%93%E5%85%A5%E4%BB%A5%E5%8F%8A%E7%89%B9%E7%82%B9\" title=\"source \u8f93\u5165\u4ee5\u53ca\u7279\u70b9\">source \u8f93\u5165\u4ee5\u53ca\u7279\u70b9<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91-flink-sql-%e4%bd%bf%e7%94%a8-union-%e4%bb%a3%e6%9b%bf-join%e3%80%81cogroup-%e7%bb%8f%e9%aa%8c\/#sink_%E8%BE%93%E5%87%BA%E4%BB%A5%E5%8F%8A%E7%89%B9%E7%82%B9\" title=\"sink \u8f93\u51fa\u4ee5\u53ca\u7279\u70b9\">sink \u8f93\u51fa\u4ee5\u53ca\u7279\u70b9<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91-flink-sql-%e4%bd%bf%e7%94%a8-union-%e4%bb%a3%e6%9b%bf-join%e3%80%81cogroup-%e7%bb%8f%e9%aa%8c\/#source%E3%80%81sink_%E6%A0%B7%E4%BE%8B%E6%95%B0%E6%8D%AE\" title=\"source\u3001sink \u6837\u4f8b\u6570\u636e\">source\u3001sink \u6837\u4f8b\u6570\u636e<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91-flink-sql-%e4%bd%bf%e7%94%a8-union-%e4%bb%a3%e6%9b%bf-join%e3%80%81cogroup-%e7%bb%8f%e9%aa%8c\/#%E5%AE%9E%E7%8E%B0%E6%96%B9%E6%A1%88\" title=\"\u5b9e\u73b0\u65b9\u6848\">\u5b9e\u73b0\u65b9\u6848<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91-flink-sql-%e4%bd%bf%e7%94%a8-union-%e4%bb%a3%e6%9b%bf-join%e3%80%81cogroup-%e7%bb%8f%e9%aa%8c\/#cogroup\" title=\"cogroup\">cogroup<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91-flink-sql-%e4%bd%bf%e7%94%a8-union-%e4%bb%a3%e6%9b%bf-join%e3%80%81cogroup-%e7%bb%8f%e9%aa%8c\/#%E4%B8%8A%E8%BF%B0%E5%AE%9E%E7%8E%B0%E5%8F%AF%E8%83%BD%E4%BC%9A%E5%AD%98%E5%9C%A8%E7%9A%84%E9%97%AE%E9%A2%98%E7%82%B9\" title=\"\u4e0a\u8ff0\u5b9e\u73b0\u53ef\u80fd\u4f1a\u5b58\u5728\u7684\u95ee\u9898\u70b9\">\u4e0a\u8ff0\u5b9e\u73b0\u53ef\u80fd\u4f1a\u5b58\u5728\u7684\u95ee\u9898\u70b9<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91-flink-sql-%e4%bd%bf%e7%94%a8-union-%e4%bb%a3%e6%9b%bf-join%e3%80%81cogroup-%e7%bb%8f%e9%aa%8c\/#%E9%80%86%E6%8E%A8%E9%93%BE%E8%B7%AF\" title=\"\u9006\u63a8\u94fe\u8def\">\u9006\u63a8\u94fe\u8def<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91-flink-sql-%e4%bd%bf%e7%94%a8-union-%e4%bb%a3%e6%9b%bf-join%e3%80%81cogroup-%e7%bb%8f%e9%aa%8c\/#union\" title=\"union\">union<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91-flink-sql-%e4%bd%bf%e7%94%a8-union-%e4%bb%a3%e6%9b%bf-join%e3%80%81cogroup-%e7%bb%8f%e9%aa%8c\/#%E6%80%BB%E7%BB%93\" title=\"\u603b\u7ed3\">\u603b\u7ed3<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E9%9C%80%E6%B1%82%E5%9C%BA%E6%99%AF%E5%88%86%E6%9E%90\"><\/span><strong>\u9700\u6c42\u573a\u666f\u5206\u6790<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E9%9C%80%E6%B1%82%E5%9C%BA%E6%99%AF\"><\/span><strong>\u9700\u6c42\u573a\u666f<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u9700\u6c42\u8bf1\u8bf1\u8bf1\u6765\u4e86\u3002\u3002\u3002\u6570\u636e\u4ea7\u54c1\u59b9\u59b9\u60f3\u8981\u7edf\u8ba1\u5355\u4e2a\u77ed\u89c6\u9891\u7c92\u5ea6\u7684<strong>\u300c\u70b9\u8d5e\uff0c\u64ad\u653e\uff0c\u8bc4\u8bba\uff0c\u5206\u4eab\uff0c\u4e3e\u62a5\u300d<\/strong>\u4e94\u7c7b\u5b9e\u65f6\u6307\u6807\uff0c\u5e76\u4e14\u6c47\u603b\u6210 photo_id\u30011 \u5206\u949f\u65f6\u95f4\u7c92\u5ea6\u7684\u5b9e\u65f6\u89c6\u9891\u6d88\u8d39\u5bbd\u8868\uff08\u5373\u5bbd\u8868\u5b57\u6bb5\u81f3\u5c11\u4e3a\uff1a<strong>\u300cphoto_id + play_cnt + like_cnt + comment_cnt + share_cnt + negative_cnt + minute_timestamp\u300d<\/strong>\uff09\u4ea7\u51fa\u81f3\u5b9e\u65f6\u5927\u5c4f\u3002<\/p>\n\n\n\n<p>\u95ee\u9898\u5728\u4e8e\u5bf9\u540c\u4e00\u4e2a\u89c6\u9891\uff0c\u4e94\u7c7b\u89c6\u9891\u6d88\u8d39\u884c\u4e3a\u7684\u89e6\u53d1\u673a\u5236\u4ee5\u53ca\u4e0a\u62a5\u65f6\u95f4\u662f\u4e0d\u540c\uff0c\u4e5f\u5c31\u51b3\u5b9a\u4e86\u5bf9\u5b9e\u65f6\u5904\u7406\u6765\u8bf4\u4e94\u7c7b\u884c\u4e3a\u65e5\u5fd7\u5bf9\u5e94\u7740\u4e94\u4e2a\u4e0d\u540c\u7684\u6570\u636e\u6e90\u3002sql boy \u4eec\u81ea\u7136\u5c31\u60f3\u5230\u4e86 join \u64cd\u4f5c\u5c06\u4e94\u7c7b\u6d88\u8d39\u884c\u4e3a\u65e5\u5fd7\u5408\u5e76\uff0c\u53ef\u662f\u5b9e\u65f6 join(cogroup) \u771f\u7684\u90a3\u4e48\u5b8c\u7f8e\u54a9~\uff0c\u4e0b\u6587\u7ec6\u8c08\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"source_%E8%BE%93%E5%85%A5%E4%BB%A5%E5%8F%8A%E7%89%B9%E7%82%B9\"><\/span><strong>source \u8f93\u5165\u4ee5\u53ca\u7279\u70b9<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u9996\u5148\u6211\u4eec\u5206\u6790\u4e0b\u9700\u6c42\u4e2d\u7684 source \u7279\u70b9\uff1a<\/p>\n\n\n\n<ul>\n<li>photo_id \u7c92\u5ea6 play\uff08\u64ad\u653e\uff09\u3001like\uff08\u70b9\u8d5e\uff09\u3001comment\uff08\u8bc4\u8bba\uff09\u3001share\uff08\u5206\u4eab\uff09\u3001negative\uff08\u4e3e\u62a5\uff09\u660e\u7ec6\u6570\u636e\uff0c<strong>\u300c\u7528\u6237\u64ad\u653e\uff08\u70b9\u8d5e\u3001\u8bc4\u8bba&#8230;\uff09n \u6b21\uff0c\u5ba2\u6237\u7aef\\\u670d\u52a1\u7aef\u5c31\u4f1a\u4e0a\u4f20 n \u6761\u64ad\u653e\uff08\u70b9\u8d5e\u3001\u8bc4\u8bba&#8230;\uff09\u65e5\u5fd7\u81f3\u6570\u636e\u6e90\u300d<\/strong><\/li>\n\n\n\n<li>\u4e94\u7c7b\u89c6\u9891\u6d88\u8d39\u884c\u4e3a\u65e5\u5fd7\u7684 source schema \u90fd\u4e3a\uff1a<strong>\u300cphoto_id + timestamp + \u5176\u4ed6\u7ef4\u5ea6\u300d<\/strong><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"sink_%E8%BE%93%E5%87%BA%E4%BB%A5%E5%8F%8A%E7%89%B9%E7%82%B9\"><\/span><strong>sink \u8f93\u51fa\u4ee5\u53ca\u7279\u70b9<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>sink \u7279\u70b9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul>\n<li>photo_id \u7c92\u5ea6 play\uff08\u64ad\u653e\uff09\u3001like\uff08\u70b9\u8d5e\uff09\u3001comment\uff08\u8bc4\u8bba\uff09\u3001share\uff08\u5206\u4eab\uff09\u3001negative\uff08\u4e3e\u62a5\uff09<strong>\u300c1 \u5206\u949f\u7ea7\u522b\u7a97\u53e3\u805a\u5408\u6570\u636e\u300d<\/strong><\/li>\n\n\n\n<li>\u5b9e\u65f6\u89c6\u9891\u6d88\u8d39\u5bbd\u8868 sink schema \u4e3a\uff1a<strong>\u300cphoto_id + play_cnt + like_cnt + comment_cnt + share_cnt + negative_cnt + minute_timestamp\u300d<\/strong><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"source%E3%80%81sink_%E6%A0%B7%E4%BE%8B%E6%95%B0%E6%8D%AE\"><\/span><strong>source\u3001sink \u6837\u4f8b\u6570\u636e<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic4.zhimg.com\/80\/v2-b96832aa012fee9706dd776283cab637_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u6211\u4eec\u5df2\u7ecf\u5bf9\u6570\u636e\u6e90\u8f93\u5165\u548c\u8f93\u51fa\u6709\u4e86\u5b8c\u6574\u7684\u5206\u6790\uff0c\u90a3\u5c31\u77a7\u77a7\u6709\u4ec0\u4e48\u65b9\u6848\u53ef\u4ee5\u5b9e\u73b0\u4e0a\u8ff0\u9700\u6c42\u5427\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%AE%9E%E7%8E%B0%E6%96%B9%E6%A1%88\"><\/span><strong>\u5b9e\u73b0\u65b9\u6848<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul>\n<li>\u65b9\u68481\uff1a<strong>\u300c\u672c\u5c0f\u8282 cogroup \u65b9\u6848\u300d<\/strong>\u76f4\u63a5\u6d88\u8d39\u539f\u59cb\u65e5\u5fd7\u6570\u636e\uff0c\u5bf9\u4e94\u7c7b\u4e0d\u540c\u7684\u89c6\u9891\u6d88\u8d39\u884c\u4e3a\u65e5\u5fd7\u4f7f\u7528 cogroup \u6216\u8005 join \u8fdb\u884c\u7a97\u53e3\u805a\u5408\u8ba1\u7b97<\/li>\n\n\n\n<li>\u65b9\u68482\uff1a\u5bf9\u4e94\u7c7b\u4e0d\u540c\u7684\u89c6\u9891\u6d88\u8d39\u884c\u4e3a\u65e5\u5fd7\u5206\u522b\u5355\u72ec\u805a\u5408\u8ba1\u7b97\u51fa\u5206\u949f\u7c92\u5ea6\u6307\u6807\u6570\u636e\uff0c\u4e0b\u6e38\u518d\u5bf9\u805a\u5408\u597d\u7684\u6307\u6807\u6570\u636e\u6309\u7167 photo_id \u8fdb\u884c\u5408\u5e76<\/li>\n\n\n\n<li>\u65b9\u68483\uff1a<strong>\u300c\u672c\u5c0f\u8282 union \u65b9\u6848\u300d<\/strong>\u65e2\u7136\u6570\u636e\u6e90 schema \u76f8\u540c\uff0c\u76f4\u63a5\u5bf9\u4e94\u7c7b\u4e0d\u540c\u7684\u89c6\u9891\u6d88\u8d39\u884c\u4e3a\u65e5\u5fd7\u505a union \u64cd\u4f5c\uff0c\u5728\u540e\u7eed\u7684\u7a97\u53e3\u51fd\u6570\u4e2d\u5bf9\u4e94\u7c7b\u6307\u6807\u8fdb\u884c\u805a\u5408\u8ba1\u7b97\u3002\u540e\u6587\u4ecb\u7ecd union \u65b9\u6848\u7684\u8bbe\u8ba1\u8fc7\u7a0b<\/li>\n<\/ul>\n\n\n\n<p>\u6211\u4eec\u5148\u4e0a cogroup \u65b9\u6848\u7684\u793a\u4f8b\u4ee3\u7801\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"cogroup\"><\/span><strong>cogroup<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>cogroup \u5b9e\u73b0\u793a\u4f8b\u5982\u4e0b\uff0c\u793a\u4f8b\u4ee3\u7801\u76f4\u63a5\u4f7f\u7528\u4e86\u5904\u7406\u65f6\u95f4\uff08\u4e5f\u53ef\u66ff\u6362\u4e3a\u4e8b\u4ef6\u65f6\u95f4~\uff09\uff0c\u56e0\u6b64\u5bf9\u6570\u636e\u6e90\u7684\u65f6\u95f4\u6233\u505a\u4e86\u7b80\u5316\uff08\u76f4\u63a5\u5e72\u6389\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Cogroup {\n\n    public static void main(String&#91;] args) throws Exception {\n\n        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();\n\n        \/\/ Long -&gt; photo_id \u64ad\u653e\u4e00\u6b21\n        DataStream&lt;Long&gt; play = SourceFactory.getDataStream(xxx);\n        \/\/ Long -&gt; photo_id \u70b9\u8d5e\u4e00\u6b21\n        DataStream&lt;Long&gt; like = SourceFactory.getDataStream(xxx);\n        \/\/ Long -&gt; photo_id \u8bc4\u8bba\u4e00\u6b21\n        DataStream&lt;Long&gt; comment = SourceFactory.getDataStream(xxx);\n        \/\/ Long -&gt; photo_id \u5206\u4eab\u4e00\u6b21\n        DataStream&lt;Long&gt; share = SourceFactory.getDataStream(xxx);\n        \/\/ Long -&gt; photo_id \u4e3e\u62a5\u4e00\u6b21\n        DataStream&lt;Long&gt; negative = SourceFactory.getDataStream(xxx);\n\n        \/\/ Tuple3&lt;Long, Long, Long&gt; -&gt; photo_id + play_cnt + like_cnt \u64ad\u653e\u548c\u70b9\u8d5e\u7684\u6570\u636e\u5408\u5e76\n        DataStream&lt;Tuple3&lt;Long, Long, Long&gt;&gt; playAndLikeCnt = play\n            .coGroup(like)\n            .where(KeySelectorFactory.get(Function.identity()))\n            .equalTo(KeySelectorFactory.get(Function.identity()))\n            .window(TumblingProcessingTimeWindows.of(Time.seconds(60)))\n            .apply(xxx1);\n\n        \/\/ Tuple4&lt;Long, Long, Long, Long&gt; -&gt; photo_id + play_cnt + like_cnt + comment_cnt \u64ad\u653e\u3001\u70b9\u8d5e\u3001\u8bc4\u8bba\u7684\u6570\u636e\u5408\u5e76\n        DataStream&lt;Tuple4&lt;Long, Long, Long, Long, Long&gt;&gt; playAndLikeAndComment = playAndLikeCnt\n            .coGroup(comment)\n            .where(KeySelectorFactory.get(playAndLikeModel -&gt; playAndLikeModel.f0))\n            .equalTo(KeySelectorFactory.get(Function.identity()))\n            .window(TumblingProcessingTimeWindows.of(Time.seconds(60)))\n            .apply(xxx2);\n\n        \/\/ Tuple5&lt;Long, Long, Long, Long, Long&gt; -&gt; photo_id + play_cnt + like_cnt + comment_cnt + share_cnt \u64ad\u653e\u3001\u70b9\u8d5e\u3001\u8bc4\u8bba\u3001\u5206\u4eab\u7684\u6570\u636e\u5408\u5e76\n        DataStream&lt;Tuple5&lt;Long, Long, Long, Long, Long, Long&gt;&gt; playAndLikeAndCommentAndShare = playAndLikeAndComment\n            .coGroup(share)\n            .where(KeySelectorFactory.get(playAndLikeAndCommentModel -&gt; playAndLikeAndCommentModel.f0))\n            .equalTo(KeySelectorFactory.get(Function.identity()))\n            .window(TumblingProcessingTimeWindows.of(Time.seconds(60)))\n            .apply(xxx2);\n\n        \/\/ Tuple7&lt;Long, Long, Long, Long, Long, Long, Long&gt; -&gt; photo_id + play_cnt + like_cnt + comment_cnt + share_cnt + negative_cnt + minute_timestamp \u64ad\u653e\u3001\u70b9\u8d5e\u3001\u8bc4\u8bba\u3001\u5206\u4eab\u3001\u4e3e\u62a5\u7684\u6570\u636e\u5408\u5e76\n        \/\/ \u540c\u4e0a~\n        DataStream&lt;Tuple7&lt;Long, Long, Long, Long, Long, Long, Long&gt;&gt; playAndLikeAndCommentAndShare = ***;\n\n        env.execute();\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>\u7c97\u66b4\u4e00\u60f3\uff0c\u4e0a\u9762\u8fd9\u6837\u4e00\u641e\u4e0d\u5c31\u7ed3\u675f\u4e86\u4e48\uff0c\u4e8b\u60c5\u6ca1\u90a3\u4e48\u7b80\u5355\uff0c\u6211\u4eec\u6765\u505a\u4e00\u4e2a\u8be6\u7ec6\u70b9\u7684\u5206\u6790\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E4%B8%8A%E8%BF%B0%E5%AE%9E%E7%8E%B0%E5%8F%AF%E8%83%BD%E4%BC%9A%E5%AD%98%E5%9C%A8%E7%9A%84%E9%97%AE%E9%A2%98%E7%82%B9\"><\/span><strong>\u4e0a\u8ff0\u5b9e\u73b0\u53ef\u80fd\u4f1a\u5b58\u5728\u7684\u95ee\u9898\u70b9<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul>\n<li><strong>\u300c\u4ece flink \u6d88\u8d39\u5230 play \u6570\u636e\u6e90\u7684\u4e00\u6761\u6570\u636e\u5230\u6700\u7ec8\u4ea7\u51fa\u8fd9\u6761\u6570\u636e\u88ab\u805a\u5408\u540e\u7684\u6570\u636e\uff0c\u6574\u4e2a\u8fc7\u7a0b\u7684\u6570\u636e\u5ef6\u8fdf &gt; 3 \u5206\u949f&#8230;\u300d<\/strong><\/li>\n\n\n\n<li><strong>\u300c\u5982\u679c\u6570\u636e\u6e90\u6301\u7eed\u589e\u52a0\uff08\u6bd4\u5982\u6dfb\u52a0\u5176\u4ed6\u89c6\u9891\u6d88\u8d39\u64cd\u4f5c\u6570\u636e\u6e90\uff09\uff0c\u5219\u6574\u4e2a\u4efb\u52a1\u7b97\u5b50\u53d8\u591a\uff0c\u6570\u636e\u94fe\u8def\u66f4\u957f\uff0c\u4efb\u52a1\u7a33\u5b9a\u6027\u4f1a\u53d8\u5dee\uff0c\u4ea7\u51fa\u6570\u636e\u5ef6\u8fdf\u4e5f\u4f1a\u968f\u7740\u7a97\u53e3\u8ba1\u7b97\u53d8\u591a\uff0c\u5ef6\u8fdf\u66f4\u4e45\u300d<\/strong><\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>\u275d&nbsp;<strong>\u300c\u6570\u636e\u4ea7\u54c1\u59b9\u59b9\u300d<\/strong>\uff1a \uff0c\u5c0f\u54e5\u54e5\u597d\u68d2\uff0c\u65e2\u7136\u95ee\u9898\u70b9\u90fd\u5206\u6790\u51fa\u6765\u4e86\uff0c\u6280\u672f\u5c0f\u54e5\u54e5\u5c31\u5e2e\u4eba\u5bb6\u89e3\u51b3\u4e00\u4e0b\u561b~<br><strong>\u300c\u5934\u6587\u5b57 \u2229 \u6280\u672f\u5c0f\u54e5\u54e5\u300d<\/strong>\uff1a\u641e\u3002\uff08\u6b22\u8fce\u5173\u6ce8gzh mangodata\uff09<br><strong>\u300c\u5934\u6587\u5b57 \u2229 \u6280\u672f\u5c0f\u54e5\u54e5\u300d<\/strong>\uff1a\u65e2\u7136\u53ef\u80fd\u7531\u4e8e\u8fc7\u591a\u7684\u7a97\u53e3\u5bfc\u81f4\u6570\u636e\u4ea7\u51fa\u5ef6\u8fdf\uff0cjob \u4e0d\u7a33\u5b9a\uff0c\u90a3\u6709\u6ca1\u6709\u4ec0\u4e48\u65b9\u6cd5\u51cf\u5c11\u7a97\u53e3\u6570\u91cf\u5462\uff0c\u601d\u8def\u8f6c\u6362\u4e00\u4e0b\u3002\u6211\u4eec\u76f4\u63a5\u4ee5\u6574\u4e2a job \u4e2d\u53ea\u5305\u542b\u4e00\u4e2a\u7a97\u53e3\u7b97\u5b50\u64cd\u4f5c\u4e3a\u57fa\u70b9\uff0c\u9006\u63a8\u4e00\u4e0b\uff0c\u5219\u6709\u4ee5\u4e0b\u6570\u636e\u94fe\u8def\u3002<br>\u275e<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E9%80%86%E6%8E%A8%E9%93%BE%E8%B7%AF\"><\/span><strong>\u9006\u63a8\u94fe\u8def<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>1 &#8211; 5 \u4e3a\u9006\u63a8\u7684\u6574\u6761\u94fe\u8def\u3002<\/p>\n\n\n\n<ul>\n<li><strong>\u300c1.\u4e94\u7c7b\u6307\u6807\u7684\u6570\u636e\u90fd\u5728\u5355\u4e2a\u7a97\u53e3\u4e2d\u8ba1\u7b97\u300d<\/strong><\/li>\n\n\n\n<li><strong>\u300c2.\u4e94\u7c7b\u6307\u6807\u7684\u7a97\u53e3 model \u76f8\u540c\u300d<\/strong><\/li>\n\n\n\n<li><strong>\u300c3.keyby \u4e2d\u7684 key \u4e00\u81f4\uff08photo_id\uff09\u300d<\/strong><\/li>\n\n\n\n<li><strong>\u300c4.\u4e94\u7c7b\u6307\u6807\u7684\u6570\u636e\u6e90\u90fd\u4e3a photo_id \u7c92\u5ea6\uff0c\u5e76\u4e14\u4e94\u7c7b\u6570\u636e\u6e90\u7684 model \u90fd\u5fc5\u987b\u76f8\u540c\uff0c\u5e76\u4e14\u53ef\u4ee5\u505a\u5408\u5e76\u300d<\/strong><\/li>\n\n\n\n<li><strong>\u300c5.union \u7b97\u5b50\u53ef\u4ee5\u5bf9\u4e94\u7c7b\u6570\u636e\u6e90\u505a\u5408\u5e76\uff01\uff01\uff01\u300d<\/strong><\/li>\n<\/ul>\n\n\n\n<p>\u8bdd\u4e0d\u591a\u8bf4\u76f4\u63a5\u4e0a union \u65b9\u6848\u4ee3\u7801\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"union\"><\/span><strong>union<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Union {\n\n    public static void main(String&#91;] args) throws Exception {\n\n        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();\n\n        \/\/ Tuple2&lt;Long, String&gt; -&gt; photo_id + \"PLAY\"\u6807\u7b7e\n        DataStream&lt;Tuple2&lt;Long, String&gt;&gt; play = SourceFactory.getDataStream(xxx);\n        \/\/ Tuple2&lt;Long, String&gt; -&gt; photo_id + \"LIKE\"\u6807\u7b7e\n        DataStream&lt;Tuple2&lt;Long, String&gt;&gt; like = SourceFactory.getDataStream(xxx);\n        \/\/ Tuple2&lt;Long, String&gt; -&gt; photo_id + \"COMMENT\"\u6807\u7b7e\n        DataStream&lt;Tuple2&lt;Long, String&gt;&gt; comment = SourceFactory.getDataStream(xxx);\n        \/\/ Tuple2&lt;Long, String&gt; -&gt; photo_id + \"SHARE\"\u6807\u7b7e\n        DataStream&lt;Tuple2&lt;Long, String&gt;&gt; share = SourceFactory.getDataStream(xxx);\n        \/\/ Tuple2&lt;Long, String&gt; -&gt; photo_id + \"NEGATIVE\"\u6807\u7b7e\n        DataStream&lt;Tuple2&lt;Long, String&gt;&gt; negative = SourceFactory.getDataStream(xxx);\n\n        \/\/ Tuple5&lt;Long, Long, Long, Long&gt; -&gt; photo_id + play_cnt + like_cnt + comment_cnt + window_start_timestamp\n        DataStream&lt;Tuple3&lt;Long, Long, Long&gt;&gt; playAndLikeCnt = play\n            .union(like)\n            .union(comment)\n            .union(share)\n            .union(negative)\n            .keyBy(KeySelectorFactory.get(i -&gt; i.f0))\n            .timeWindow(Time.seconds(60))\n            .process(xxx);\n\n        env.execute();\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>\u53ef\u4ee5\u53d1\u73b0\uff0c\u65e0\u8bba\u4e0a\u6e38\u6570\u636e\u6e90\u600e\u6837\u8fdb\u884c\u53d8\u5316\uff0c\u4e0a\u8ff0 union \u65b9\u6848\u4e2d\u59cb\u7ec8\u53ef\u4ee5\u4fdd\u6301\u53ea\u6709\u4e00\u4e2a\u7a97\u53e3\u7b97\u5b50\u5904\u7406\u548c\u8ba1\u7b97\u6570\u636e\uff0c\u5219\u53ef\u4ee5\u89e3\u51b3\u4e4b\u524d\u5217\u4e3e\u7684\u6570\u636e\u5ef6\u8fdf\u4ee5\u53ca flink \u4efb\u52a1\u7b97\u5b50\u8fc7\u591a\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u5728\u6570\u636e\u6e90\u7684 schema \u76f8\u540c\uff08\u6216\u8005\u4e0d\u540c\u4f46\u7ecf\u8fc7\u5904\u7406\u4e4b\u540e\u53ef\u4ee5 format \u6210\u76f8\u540c\u683c\u5f0f\uff09\u7684\u60c5\u51b5\u4e0b\uff0c\u6216\u8005\u5904\u7406\u903b\u8f91\u76f8\u540c\u7684\u8bdd\uff0c\u53ef\u4ee5\u4f7f\u7528 union \u8fdb\u884c\u903b\u8f91\u7b80\u5316\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%80%BB%E7%BB%93\"><\/span><strong>\u603b\u7ed3<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u672c\u6587\u9996\u5148\u4ecb\u7ecd\u4e86\u6211\u4eec\u7684\u9700\u6c42\u573a\u666f\uff0c\u7b2c\u4e8c\u90e8\u5206\u5206\u6790\u4e86\u4f7f\u7528 cogroup\uff08\u6848\u4f8b\u4ee3\u7801\uff09\u662f\u5982\u4f55\u89e3\u51b3\u6b64\u9700\u6c42\u573a\u666f\uff0c\u518d\u5206\u6790\u4e86\u6b64\u5b9e\u73b0\u65b9\u6848\u53ef\u80fd\u4f1a\u5b58\u5728\u4e00\u4e9b\u95ee\u9898\uff0c\u5e76\u5f15\u51fa\u4e86 union \u89e3\u51b3\u65b9\u6848\u7684\u9006\u63a8\u548c\u8bbe\u8ba1\u601d\u8def\u3002 \u5728\u7b2c\u4e09\u90e8\u5206\u9488\u5bf9\u6b64\u573a\u666f\u4f7f\u7528 union \u4ee3\u66ff cogroup \u8fdb\u884c\u4e86\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u7684\u4f18\u5316\u3002\u5982\u679c\u9488\u5bf9\u6b64\u573a\u666f\uff0c\u5927\u4f6c\u4eec\u6709\u66f4\u597d\u7684\u4f18\u5316\u65b9\u6848\u7684\u8bdd\uff0c\u671f\u5f85\u7559\u8a00\u5594\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u6c42\u573a\u666f\u5206\u6790 \u9700\u6c42\u573a\u666f \u9700\u6c42\u8bf1\u8bf1\u8bf1\u6765\u4e86\u3002\u3002\u3002\u6570\u636e\u4ea7\u54c1\u59b9\u59b9\u60f3\u8981\u7edf\u8ba1\u5355\u4e2a\u77ed\u89c6\u9891\u7c92\u5ea6\u7684\u300c\u70b9\u8d5e\uff0c\u64ad\u653e\uff0c\u8bc4\u8bba\uff0c&hellip; <a href=\"http:\/\/viplao.com\/index.php\/2023\/03\/19\/%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91-flink-sql-%e4%bd%bf%e7%94%a8-union-%e4%bb%a3%e6%9b%bf-join%e3%80%81cogroup-%e7%bb%8f%e9%aa%8c\/\" class=\"more-link read-more\" rel=\"bookmark\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">\u3010\u8fd0\u7ef4\u5de5\u5177\u3011\u00a0Flink SQL \u4f7f\u7528 union \u4ee3\u66ff join\u3001cogroup \u7ecf\u9a8c<\/span><i class=\"fa fa-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[25],"views":912,"_links":{"self":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/1306"}],"collection":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/comments?post=1306"}],"version-history":[{"count":1,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/1306\/revisions"}],"predecessor-version":[{"id":1307,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/1306\/revisions\/1307"}],"wp:attachment":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/media?parent=1306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/categories?post=1306"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/tags?post=1306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}