{"id":10008020,"date":"2023-06-30T10:59:46","date_gmt":"2023-06-30T02:59:46","guid":{"rendered":"https:\/\/ityet.com\/?p=10008020"},"modified":"2023-06-30T10:59:46","modified_gmt":"2023-06-30T02:59:46","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-flink-sql-%e6%8e%a2%e7%b4%a2-github-%e6%95%b0%e6%8d%ae%e9%9b%86%ef%bd%9cflink-learning-%e5%ae%9e%e6%88%98%e8%90%a5","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10008020","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 Flink SQL \u63a2\u7d22 GitHub \u6570\u636e\u96c6\uff5cFlink-Learning \u5b9e\u6218\u8425"},"content":{"rendered":"<p>\u4f5c\u8005\uff5c\u738b\u6d2a\u987a\uff08\u5f18\u821c\uff09<\/p>\n<p>\u4e3a\u8fdb\u4e00\u6b65\u5e2e\u52a9\u5f00\u53d1\u8005\u5b66\u4e60\u4f7f\u7528 Flink\uff0cApache Flink \u4e2d\u6587\u793e\u533a\u8fd1\u671f\u53d1\u8d77 Flink-Learning \u5b9e\u6218\u8425\u9879\u76ee\u3002\u672c\u6b21\u5b9e\u6218\u8425\u901a\u8fc7\u771f\u5b9e\u6709\u8da3\u7684\u5b9e\u6218\u573a\u666f\u5e2e\u52a9\u5f00\u53d1\u8005\u5b9e\u64cd\u4f53\u9a8c Flink\uff0c\u8bfe\u7a0b\u5305\u62ec\u5b9e\u65f6\u6570\u636e\u63a5\u5165\u3001\u5b9e\u65f6\u6570\u636e\u5206\u6790\u3001\u5b9e\u65f6\u6570\u636e\u5e94\u7528\u7684\u573a\u666f\u5b9e\u3002\u5e76\u7ed3\u5408\u5c0f\u677e\u9f20\u52a9\u6559\u6a21\u5f0f\uff0c\u5168\u65b9\u4f4d\u5e2e\u52a9\u5165\u8425\u5f00\u53d1\u8005\u8f7b\u677e\u73a9\u8f6c Flink\uff0c<strong>\u70b9\u51fb\u4e0b\u65b9\u56fe\u7247\u626b\u7801\u5373\u523b\u5165\u8425<\/strong>\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043953866\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>\u672c\u671f\u5c06\u7ee7\u7eed\u8be6\u7ec6\u4ecb\u7ecd Flink- Learning \u5b9e\u6218\u8425\u3002<\/p>\n<hr>\n<p>\u60f3\u8981\u4e86\u89e3\u5982\u4f55\u4f7f\u7528 Flink \u5728 GitHub \u4e2d\u53d1\u73b0\u6700\u70ed\u95e8\u7684\u9879\u76ee\u5417\uff1f\u672c\u5b9e\u9a8c\u4f7f\u7528\u963f\u91cc\u4e91\u5b9e\u65f6\u8ba1\u7b97 Flink \u7248\u5185\u7f6e\u7684 GitHub \u516c\u5f00\u4e8b\u4ef6\u6570\u636e\u96c6\uff0c\u901a\u8fc7 Flink SQL \u5b9e\u65f6\u63a2\u7d22\u5206\u6790 Github \u516c\u5f00\u6570\u636e\u96c6\u4e2d\u9690\u85cf\u7684\u5f69\u86cb\uff01<\/p>\n<p>\u5b8c\u6210\u672c\u5b9e\u9a8c\u540e\uff0c\u60a8\u5c06\u638c\u63e1\u7684\u77e5\u8bc6\u6709\uff1a<\/p>\n<ul>\n<li>\u4e86\u89e3 Flink \u548c\u6d41\u5f0f\u8ba1\u7b97\u7684\u4f18\u52bf<\/li>\n<li>\u5bf9 Flink SQL \u57fa\u7840\u80fd\u529b\u548c Flink \u5b9e\u65f6\u5904\u7406\u7279\u6027\u6709\u521d\u6b65\u4f53\u9a8c<\/li>\n<\/ul>\n<h2>\u5b9e\u9a8c\u7b80\u4ecb<\/h2>\n<p>\u901a\u8fc7 Flink \u5bf9 GitHub \u7684\u5b9e\u65f6\u4e8b\u4ef6\u6d41\u8fdb\u884c\u5206\u6790\uff0c\u5e76\u901a\u8fc7\u62a5\u8868\u76f4\u89c2\u5c55\u793a\uff0c\u4e86\u89e3 GitHub \u7684\u6700\u65b0\u70ed\u95e8\u8d8b\u52bf\u3001\u7279\u5b9a\u4ed3\u5e93\u6216\u8005\u7ec4\u7ec7\u7684\u6d3b\u8dc3\u5ea6\u3002<\/p>\n<p>\u4f53\u9a8c\u6b64\u573a\u666f\u540e\uff0c\u53ef\u4ee5\u5bf9 Flink SQL \u57fa\u7840\u80fd\u529b\u548c Flink \u5b9e\u65f6\u5904\u7406\u7279\u6027\u6709\u76f4\u89c2\u7684\u521d\u6b65\u4f53\u9a8c\u3002<\/p>\n<p>\u25a0 \u4e3a\u56de\u9988\u5e7f\u5927\u5f00\u6e90\u5f00\u53d1\u8005\u5bf9\u793e\u533a\u7684\u652f\u6301\uff0c\u963f\u91cc\u4e91\u5b9e\u65f6\u8ba1\u7b97 Flink \u7248\u63d0\u4f9b\u4e91\u539f\u751f\u514d\u8d39\u8bd5\u7528\u8d44\u6e90<\/p>\n<h2>\u5b9e\u9a8c\u8d44\u6e90<\/h2>\n<p>\u672c\u573a\u666f\u4f7f\u7528\u5230\u7684\u5b9e\u9a8c\u8d44\u6e90\u548c\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n<p>\u963f\u91cc\u4e91\u5b9e\u65f6\u8ba1\u7b97 Flink \u7248<\/p>\n<table>\n<thead>\n<tr>\n<th><strong>\u914d\u7f6e\u9879<\/strong><\/th>\n<th><strong>\u89c4\u683c<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Task Manger \u4e2a\u6570<\/td>\n<td>4 \u4e2a<\/td>\n<\/tr>\n<tr>\n<td>Task Manager CPU<\/td>\n<td>2 \u6838\u5fc3<\/td>\n<\/tr>\n<tr>\n<td>Task Manager Memory<\/td>\n<td>8 GiB<\/td>\n<\/tr>\n<tr>\n<td>Job Manager CPU<\/td>\n<td>1 \u6838<\/td>\n<\/tr>\n<tr>\n<td>Job Manager Memory<\/td>\n<td>2 GiB<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u4f53\u9a8c\u76ee\u6807<\/h2>\n<p>\u5bf9 Flink SQL \u57fa\u7840\u80fd\u529b\u548c Flink \u5b9e\u65f6\u5904\u7406\u7279\u6027\u6709\u76f4\u89c2\u7684\u521d\u6b65\u4f53\u9a8c\u3002<\/p>\n<h2>\u80cc\u666f\u77e5\u8bc6<\/h2>\n<p>GitHub \u516c\u5f00\u6570\u636e\u96c6\uff08GitHub Archive\uff09\u662f GitHub \u63d0\u4f9b\u7684\u4e00\u4e2a\u5f00\u653e\u6570\u636e\u96c6\u5408\uff0c\u5b83\u5305\u542b\u4e86\u6bcf\u4e2a\u516c\u5171\u4ed3\u5e93\u7684\u4e8b\u4ef6\u6570\u636e\uff0c\u4f8b\u5982\u63d0\u4ea4\u3001\u62c9\u53d6\u8bf7\u6c42\u3001\u95ee\u9898\u548c\u8bc4\u8bba\u7b49\u3002GitHub \u516c\u5f00\u6570\u636e\u96c6\u7684\u6570\u636e\u53ef\u4ee5\u7528\u4e8e\u8fdb\u884c\u5404\u79cd\u7c7b\u578b\u7684\u7814\u7a76\u548c\u5206\u6790\uff0c\u4f8b\u5982\u5f00\u6e90\u793e\u533a\u7684\u534f\u4f5c\u60c5\u51b5\u3001\u5f00\u53d1\u8005\u7684\u884c\u4e3a\u7279\u5f81\u3001\u7f16\u7a0b\u8bed\u8a00\u7684\u53d1\u5c55\u8d8b\u52bf\u7b49\u3002\u4f7f\u5f00\u53d1\u8005\u4eec\u66f4\u597d\u5730\u4e86\u89e3 GitHub \u4e0a\u7684\u6d3b\u52a8\u548c\u8d8b\u52bf\uff0c\u5e76\u4ece\u4e2d\u83b7\u5f97\u6709\u4ef7\u503c\u7684\u4fe1\u606f\u548c\u6d1e\u5bdf\u3002<\/p>\n<p>\u672c\u5b9e\u9a8c\u5c06 GitHub \u516c\u5f00\u6570\u636e\u96c6\u5b9e\u65f6\u540c\u6b65\u5230 SLS \u4f5c\u4e3a\u6570\u636e\u6e90\uff0c\u6839\u636e Flink \u5bf9\u6570\u636e\u8fdb\u884c\u591a\u79cd\u7ef4\u5ea6\u7684\u5206\u6790\u5e76\u4e14\u901a\u8fc7\u62a5\u8868\u76f4\u89c2\u5c55\u793a\u3002<\/p>\n<h2>\u524d\u7f6e\u77e5\u8bc6<\/h2>\n<ul>\n<li>\u4e86\u89e3 Flink \u76f8\u5173\u7684\u57fa\u7840\u77e5\u8bc6\u3002<\/li>\n<li>\u4e86\u89e3 Flink SQL \u76f8\u5173\u7684\u57fa\u7840\u77e5\u8bc6\u3002<\/li>\n<\/ul>\n<h2>\u73af\u5883\u642d\u5efa<\/h2>\n<p>\u521b\u5efa Session \u96c6\u7fa4\u3002\u8fdb\u5165\u963f\u91cc\u4e91\u63a7\u5236\u53f0\uff0c\u9009\u62e9\u5b9e\u65f6\u8ba1\u7b97 Flink \u7248\u3002\u7136\u540e\u9009\u62e9\u5df2\u7ecf\u8d2d\u4e70\u7684\u5de5\u4f5c\u7a7a\u95f4\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043953867\" alt=\"1\" title=\"1\" loading=\"lazy\"><\/p>\n<p>\u5728\u5f00\u59cb\u963f\u91cc\u4e91\u5b9e\u65f6\u8ba1\u7b97 Flink \u7248\u4f5c\u4e1a\u7f16\u5199\u524d\uff0c\u9700\u8981\u5148\u521b\u5efa Session \u96c6\u7fa4\uff0c\u53ea\u6709\u521b\u5efa\u4e86 Flink \u96c6\u7fa4\uff0c\u624d\u80fd\u6267\u884c\u4efb\u52a1\u3002<\/p>\n<p>1.\u70b9\u51fb\u7cfb\u7edf\u7ba1\u7406 -&gt; Session \u96c6\u7fa4 -&gt;\u521b\u5efa Session<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043953868\" alt=\"2\" title=\"2\" loading=\"lazy\"><\/p>\n<p>2.\u521b\u5efa Session \u96c6\u7fa4\u65f6\u8bbe\u7f6e\u4e3a SQL Preview \u96c6\u7fa4\uff0c\u8fd9\u6837\u65e0\u9700\u8bbe\u7f6e Sink\uff0c \u5373\u53ef\u5c06 Select \u8bed\u53e5\u7684\u7ed3\u679c\u8f93\u51fa\u6210\u56fe\u8868\u7684\u683c\u5f0f\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043953869\" alt=\"3\" title=\"3\" loading=\"lazy\"><\/p>\n<h2>\u5b9e\u9a8c 1\uff1aGithub \u5173\u6ce8\u6570\u6392\u884c\u699c<\/h2>\n<p>\u672c\u5b9e\u9a8c\u7edf\u8ba1\u4ece\u4e00\u5468\u524d\u8d77\u7684 Github \u5173\u6ce8\u5ea6\u6392\u884c\u699c\u3002<\/p>\n<h3>\u64cd\u4f5c<\/h3>\n<p>1.\u4f5c\u4e1a SQL \u4ee3\u7801\u3002<strong>\u5176\u4e2d startTime \u5c3d\u91cf\u8bbe\u7f6e\u4e3a\u5f53\u524d\u6b64\u523b\u7684\u4e00\u5468\u524d\u9644\u8fd1<\/strong>\uff0c\u5982\u679c\u8bbe\u7f6e\u7684\u65f6\u95f4\u592a\u65e9\uff0c\u524d\u9762\u65e0\u6548\u8ba1\u7b97\u65f6\u95f4\u6bd4\u8f83\u957f\uff0c\u4e0d\u4ec5\u8017\u8d39\u8d44\u6e90\uff0c\u800c\u4e14\u5f88\u4e45\u624d\u80fd\u52a0\u8f7d\u51fa\u8ba1\u7b97\u7ed3\u679c\u3002<strong>\u6839\u636e\u4e0d\u540c\u7684\u5730\u57df\u8bbe\u7f6e\u76f8\u5e94\u7684 project \u548cendPoint<\/strong>\uff0c\u5982\u5b9e\u4f8b\u4e3a\u4e0a\u6d77\u7684\u670d\u52a1\u5e73\u53f0\uff0c\u56e0\u6b64\u8bbe\u7f6e&#8217;project&#8217; = &#8216;github-events-shanghai&#8217;\u548c&#8217;endPoint&#8217; = &#8216;<a href=\"https:\/\/link.segmentfault.com\/?enc=jXjowqqvZXN9DNbQG%2B4u%2BQ%3D%3D.%2FrZUYV5%2FW64ZNCT77JRvWr%2FnAXd8Y7p0WVGvW0pgp0K6uz%2FM0EybeLnlQ2rEhZ3f\" rel=\"nofollow\">https:\/\/cn-shanghai-intranet.log.aliyuncs.com<\/a>&#8216;\uff0c\u5176\u4ed6\u5730\u57df\u5982\u5317\u4eac\u3001\u676d\u5dde\u3001\u6df1\u5733\u66f4\u6539\u4e3a\u5bf9\u5e94\u503c\u5373\u53ef\u3002<\/p>\n<pre><code class=\"sql\">-- \u901a\u8fc7DDL\u8bed\u53e5\u521b\u5efaSLS\u6e90\u8868\uff0cSLS\u4e2d\u5b58\u653e\u4e86Github\u7684\u5b9e\u65f6\u6570\u636e\u3002\nCREATE TEMPORARY TABLE gh_event(\n  id STRING,                                        -- \u6bcf\u4e2a\u4e8b\u4ef6\u7684\u552f\u4e00ID\u3002\n  created_at BIGINT,                                -- \u4e8b\u4ef6\u65f6\u95f4\uff0c\u5355\u4f4d\u79d2\u3002\n  created_at_ts as TO_TIMESTAMP(created_at*1000),   -- \u4e8b\u4ef6\u65f6\u95f4\u6233\uff08\u5f53\u524d\u4f1a\u8bdd\u65f6\u533a\u4e0b\u7684\u65f6\u95f4\u6233\uff0c\u5982\uff1aAsia\/Shanghai\uff09\u3002\n  type STRING,                                      -- Github\u4e8b\u4ef6\u7c7b\u578b\uff0c\u5982\uff1a\u3002ForkEvent, WatchEvent, IssuesEvent, CommitCommentEvent\u7b49\u3002\n  actor_id STRING,                                  -- Github\u7528\u6237ID\u3002\n  actor_login STRING,                               -- Github\u7528\u6237\u540d\u3002\n  repo_id STRING,                                   -- Github\u4ed3\u5e93ID\u3002\n  repo_name STRING,                                 -- Github\u4ed3\u5e93\u540d\uff0c\u5982\uff1aapache\/flink, apache\/spark, alibaba\/fastjson\u7b49\u3002\n  org STRING,                                       -- Github\u7ec4\u7ec7ID\u3002\n  org_login STRING                                 -- Github\u7ec4\u7ec7\u540d\uff0c\u5982\uff1a apache,google,alibaba\u7b49\u3002\n) WITH (\n  'connector' = 'sls',                              -- \u5b9e\u65f6\u91c7\u96c6\u7684Github\u4e8b\u4ef6\u5b58\u653e\u5728\u963f\u91cc\u4e91SLS\u4e2d\u3002\n  'project' = 'github-events-shanghai',                     -- \u5b58\u653e\u516c\u5f00\u6570\u636e\u7684SLS\u9879\u76ee\u3002\u4f8b\u5982'github-events-hangzhou'\u3002\n  'endPoint' = 'https:\/\/cn-shanghai-intranet.log.aliyuncs.com',                   -- \u516c\u5f00\u6570\u636e\u4ec5\u9650\u963f\u91cc\u4e91\u5b9e\u65f6\u8ba1\u7b97 Flink \u7248\u901a\u8fc7\u79c1\u7f51\u5730\u5740\u8bbf\u95ee\u3002\u4f8b\u5982'https:\/\/cn-hangzhou-intranet.log.aliyuncs.com'\u3002\n  'logStore' = 'realtime-github-events',            -- \u5b58\u653e\u516c\u5f00\u6570\u636e\u7684SLS logStore\u3002\n  'accessId' =  ' ',         -- \u53ea\u8bfb\u8d26\u53f7\u7684AK\u3002\n  'accessKey' = ' ',   -- \u53ea\u8bfb\u8d26\u53f7\u7684SK\u3002\n  'batchGetSize' = '500',                           -- \u6279\u91cf\u8bfb\u53d6\u6570\u636e\uff0c\u6bcf\u6279\u6700\u591a\u62c9\u53d6500\u6761\u3002\n  'startTime' = '2023-06-01 14:00:00'              -- \u5f00\u59cb\u65f6\u95f4\uff0c\u5c3d\u91cf\u8bbe\u7f6e\u5230\u9700\u8981\u8ba1\u7b97\u7684\u65f6\u95f4\u9644\u8fd1\uff0c\u5426\u5219\u65e0\u6548\u8ba1\u7b97\u7684\u65f6\u95f4\u8f83\u957f\u3002\u9ed8\u8ba4\u503c\u4e3a\u5f53\u524d\u503c\n);\n\n-- \u914d\u7f6e\u5f00\u542fmini-batch, \u6bcf2s\u5904\u7406\u4e00\u6b21\u3002\nSET 'table.exec.mini-batch.enabled'='true'; \nSET 'table.exec.mini-batch.allow-latency'='2s'; \nSET 'table.exec.mini-batch.size'='4096'; \n\n-- \u4f5c\u4e1a\u8bbe\u7f6e4\u4e2a\u5e76\u53d1\uff0c\u805a\u5408\u66f4\u5feb\u3002\nSET 'parallelism.default' = '4';\n\n\n-- \u67e5\u770bGithub\u65b0\u589estar\u6570Top 5\u4ed3\u5e93\u3002\nSELECT DATE_FORMAT(created_at_ts, 'yyyy-MM-dd') as `date`, repo_name, COUNT(*) as num\nFROM gh_event WHERE type = 'WatchEvent' \nGROUP BY DATE_FORMAT(created_at_ts, 'yyyy-MM-dd'), repo_name\nORDER BY num DESC\nLIMIT 5;<\/code><\/pre>\n<p>2.\u9a8c\u8bc1 SQL \u662f\u5426\u6b63\u786e\u5e76\u4e14\u6267\u884c<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043953870\" alt=\"4\" title=\"4\" loading=\"lazy\"><\/p>\n<p>3.\u914d\u7f6e\u56fe\u8868<\/p>\n<p>\u200b    a. \u9009\u62e9 Y Bar \u5e76\u4e14\u7f16\u8f91\u6807\u9898\u680f\u4e3a Top 5<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043953871\" alt=\"5\" title=\"5\" loading=\"lazy\"><\/p>\n<p>\u200b    b. \u914d\u7f6e group by repo_name\uff0c order by num\uff0c\u5373\u6839\u636e repo_name \u5206\u7ec4\u6bd4\u8f83\u6570\u91cf<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043953872\" alt=\"6\" title=\"6\" loading=\"lazy\"><\/p>\n<p>\u200b    c. \u5b9e\u9a8c\u53ef\u4ee5\u4e00\u76f4\u8fd0\u884c\uff0c\u4e0d\u65ad\u6d88\u8d39\u6700\u65b0\u7684\u6570\u636e\u3002\u4f46\u662f\u5982\u679c\u5f53\u524d\u96c6\u7fa4\u7684 CPU \u6570\u914d\u7f6e\u7684\u8f83\u5c11\uff0c\u4e0d\u8db3\u4ee5\u6267\u884c\u4e24\u4e2a\u4efb\u52a1\uff0c\u53c8\u60f3\u6267\u884c\u4e0b\u4e00\u4e2a\u5b9e\u9a8c\u662f\uff0c\u53ef\u4ee5\u5c06\u672c\u5b9e\u9a8c\u505c\u6b62\u3002\u70b9\u51fb\u7ed3\u679c\u5de6\u4fa7\u7684\u7ea2\u8272\u65b9\u6846\u5373\u53ef\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043953873\" alt=\"7\" title=\"7\" loading=\"lazy\"><\/p>\n<h3>\u7ed3\u679c<\/h3>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043953874\" alt=\"8\" title=\"8\" loading=\"lazy\"><\/p>\n<p>\u7b2c\u4e00\u540d\uff1a<strong>s0md3v\/roop<\/strong> \u89c6\u9891\u6362\u8138\uff08\u6700\u8fd1\u6211\u5728b\u7ad9\u4e5f\u7ecf\u5e38\u7ffb\u5230\uff09<\/p>\n<p>\u7b2c\u4e8c\u540d\uff1a<strong>pengzhile\/pandora<\/strong> \u6f58\u591a\u62c9\u5b9e\u73b0\u4e86\u7f51\u9875\u7248 ChatGPT \u7684\u4e3b\u8981\u64cd\u4f5c<\/p>\n<p>\u7b2c\u4e09\u540d\uff1a<strong>ClassmateLin\/dm-ticket<\/strong> \u5927\u9ea6\u7f51\u62a2\u7968\uff08\u75ab\u60c5\u653e\u5f00\uff0c\u4f30\u8ba1\u4e0a\u5468\u6f14\u5531\u4f1a\u5f88\u591a\uff09<\/p>\n<p>\u7b2c\u56db\u540d\uff1a<strong>ShishirPatil\/gorilla<\/strong> \u8fde\u63a5\u6d77\u91cf API \u7684\u5927\u578b\u8bed\u8a00\u6a21\u578b<\/p>\n<p>\u7b2c\u4e94\u540d\uff1a <strong>iperov\/DeepFaceLive<\/strong> \u6362\u8138<\/p>\n<p>\u7531\u6b64\u53ef\u89c1\u6700\u8fd1\u4e00\u5468\u6700\u6d41\u884c\u7684 repo \u5c31\u662f ai \u89c6\u9891\u6362\u8138\u548c\u5927\u6a21\u578b\uff0c\u6700\u6d41\u884c\u7684\u9886\u57df\u5c31\u662f ai<\/p>\n<h2>\u5b9e\u9a8c 2\uff1a\u7edf\u8ba1\u7ec4\u7ec7\u6d3b\u8dc3\u5ea6\u53d8\u5316<\/h2>\n<p>\u672c\u5b9e\u9a8c\u7edf\u8ba1 apache \u548c alibaba \u7ec4\u7ec7\u5f00\u6e90\u5728\u4ece 24 \u5c0f\u65f6\u524d\u5f00\u59cb\u7684\u6d3b\u8dc3\u5ea6\u8d8b\u52bf\u53d8\u5316\u3002<\/p>\n<h3>\u64cd\u4f5c<\/h3>\n<p>1.SQL \u4ee3\u7801\u5982\u4e0b\u3002\u5176\u4e2d <strong>startTime \u5c3d\u91cf\u8bbe\u7f6e\u4e3a\u5f53\u524d\u6b64\u523b\u7684 24 \u5c0f\u65f6\u524d\u9644\u8fd1<\/strong>\uff0c\u5982\u679c\u8bbe\u7f6e\u7684\u65f6\u95f4\u592a\u65e9\uff0c\u524d\u9762\u65e0\u6548\u8ba1\u7b97\u65f6\u95f4\u6bd4\u8f83\u957f\uff0c\u4e0d\u4ec5\u8017\u8d39\u8d44\u6e90\uff0c\u800c\u4e14\u5f88\u4e45\u624d\u80fd\u52a0\u8f7d\u51fa\u8ba1\u7b97\u7ed3\u679c\u3002\u5982\u679c\u60f3\u8981\u7edf\u8ba1 alibaba, \u6539\u6210 org_login =&#8217;alibaba&#8217; \u5373\u53ef<\/p>\n<pre><code class=\"sql\">CREATE TEMPORARY TABLE gh_event(\n  id STRING,                                        -- \u6bcf\u4e2a\u4e8b\u4ef6\u7684\u552f\u4e00ID\u3002\n  created_at BIGINT,                                -- \u4e8b\u4ef6\u65f6\u95f4\uff0c\u5355\u4f4d\u79d2\u3002\n  created_at_ts as TO_TIMESTAMP(created_at*1000),   -- \u4e8b\u4ef6\u65f6\u95f4\u6233\uff08\u5f53\u524d\u4f1a\u8bdd\u65f6\u533a\u4e0b\u7684\u65f6\u95f4\u6233\uff0c\u5982\uff1aAsia\/Shanghai\uff09\u3002\n  type STRING,                                      -- Github\u4e8b\u4ef6\u7c7b\u578b\uff0c\u5982\uff1a\u3002ForkEvent, WatchEvent, IssuesEvent, CommitCommentEvent\u7b49\u3002\n  actor_id STRING,                                  -- Github\u7528\u6237ID\u3002\n  actor_login STRING,                               -- Github\u7528\u6237\u540d\u3002\n  repo_id STRING,                                   -- Github\u4ed3\u5e93ID\u3002\n  repo_name STRING,                                 -- Github\u4ed3\u5e93\u540d\uff0c\u5982\uff1aapache\/flink, apache\/spark, alibaba\/fastjson\u7b49\u3002\n  org STRING,                                       -- Github\u7ec4\u7ec7ID\u3002\n  org_login STRING                                 -- Github\u7ec4\u7ec7\u540d\uff0c\u5982\uff1a apache,google,alibaba\u7b49\u3002\n) WITH (\n  'connector' = 'sls',                              -- \u5b9e\u65f6\u91c7\u96c6\u7684Github\u4e8b\u4ef6\u5b58\u653e\u5728\u963f\u91cc\u4e91SLS\u4e2d\u3002\n  'project' = 'github-events-shanghai',                     -- \u5b58\u653e\u516c\u5f00\u6570\u636e\u7684SLS\u9879\u76ee\u3002\u4f8b\u5982'github-events-hangzhou'\u3002\n  'endPoint' = 'https:\/\/cn-shanghai-intranet.log.aliyuncs.com',                   -- \u516c\u5f00\u6570\u636e\u4ec5\u9650\u963f\u91cc\u4e91\u5b9e\u65f6\u8ba1\u7b97 Flink \u7248\u901a\u8fc7\u79c1\u7f51\u5730\u5740\u8bbf\u95ee\u3002\u4f8b\u5982'https:\/\/cn-hangzhou-intranet.log.aliyuncs.com'\u3002\n  'logStore' = 'realtime-github-events',            -- \u5b58\u653e\u516c\u5f00\u6570\u636e\u7684SLS logStore\u3002\n  'accessId' =  ' ',         -- \u53ea\u8bfb\u8d26\u53f7\u7684AK\u3002\n  'accessKey' = ' ',   -- \u53ea\u8bfb\u8d26\u53f7\u7684SK\u3002\n  'batchGetSize' = '500',                           -- \u6279\u91cf\u8bfb\u53d6\u6570\u636e\uff0c\u6bcf\u6279\u6700\u591a\u62c9\u53d6500\u6761\u3002\n  'startTime' = '2023-06-07 14:00:00'               -- \u5f00\u59cb\u65f6\u95f4\uff0c\u5c3d\u91cf\u8bbe\u7f6e\u5230\u9700\u8981\u8ba1\u7b97\u7684\u65f6\u95f4\u9644\u8fd1\uff0c\u5426\u5219\u65e0\u6548\u8ba1\u7b97\u7684\u65f6\u95f4\u8f83\u957f\n);\n\n-- \u914d\u7f6e\u5f00\u542fmini-batch, \u6bcf2s\u5904\u7406\u4e00\u6b21\u3002\nSET 'table.exec.mini-batch.enabled'='true';\nSET 'table.exec.mini-batch.allow-latency'='2s';\nSET 'table.exec.mini-batch.size'='4096';\n\n-- \u4f5c\u4e1a\u8bbe\u7f6e4\u4e2a\u5e76\u53d1\uff0c\u805a\u5408\u66f4\u5feb\u3002\nSET 'parallelism.default' = '4';\n\n\n-- \u4ece\u4e00\u5929\u524d\u5f00\u59cb\u7edf\u8ba1\u4e8b\u4ef6\u603b\u91cf\nSELECT NOW(), max(created_at_ts) as created_ts, COUNT(*) as event_count\nFROM gh_event \nWHERE  org_login ='apache' and\ncreated_at_ts &gt;= NOW() - INTERVAL '1' DAY;<\/code><\/pre>\n<p>2.\u70b9\u51fb\u6267\u884c\uff0c\u5e76\u4e14\u914d\u7f6e\u56fe\u8868<\/p>\n<p>\u200b    a. \u70b9\u51fb\u56fe\u8868\u914d\u7f6e<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043953875\" alt=\"9\" title=\"9\" loading=\"lazy\"><\/p>\n<p>\u200b    b. \u7f16\u8f91\u6807\u9898\u4e3a&#8221;apache&#8221;\uff0c\u5e76\u4e14\u9009\u62e9 X\/Y Line<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043953876\" alt=\"10\" title=\"10\" loading=\"lazy\"><\/p>\n<p>\u200b    c. \u914d\u7f6e X \u8f74\u4e3a create_ts, y \u8f74\u4e3a event_count<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043953877\" alt=\"11\" title=\"11\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043953878\" alt=\"12\" title=\"12\" loading=\"lazy\"><\/p>\n<h3>\u7ed3\u679c<\/h3>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043953879\" alt=\"13\" title=\"13\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043953880\" alt=\"14\" title=\"14\" loading=\"lazy\"><\/p>\n<p>apache \u4f5c\u4e3a\u5168\u7403\u6027\u7684\u5f00\u6e90\u7ec4\u7ec7\uff0c\u4e00\u5929\u5185\u7684\u6d3b\u8dc3\u5ea6\u6bd4\u8f83\u5747\u5300\uff0c\u800c\u963f\u91cc\u5df4\u5df4\u5f00\u6e90\u57fa\u672c\u7531\u56fd\u5185\u5f00\u53d1\u8005\u5173\u6ce8\u548c\u8d21\u732e\uff0c\u591c\u95f4\u589e\u52a0\u6bd4\u8f83\u5e73\u7f13\uff0c\u5728 9 \u70b9\u4e4b\u540e\u660e\u663e\u63d0\u5347\u3002<\/p>\n<h2>\u5b9e\u9a8c 3: \u7edf\u8ba1\u4ed3\u5e93\u8d21\u732e\u65f6\u95f4\u5206\u5e03\u60c5\u51b5<\/h2>\n<p>\u672c\u5b9e\u9a8c\u7edf\u8ba1 flink \u548c spark \u5f00\u6e90\u4ed3\u5e93\u5728\u4ece\u4e00\u5468\u524d\u524d\u5f00\u59cb\u7684\u8d21\u732e\u5206\u5e03\u60c5\u51b5\u3002\u8d21\u732e\u5305\u62ec\u4ee3\u7801\u63d0\u4ea4\u3001commit \u8bc4\u8bba\u3001issue \u8bc4\u8bba\u3001\u63d0\u4ea4 PR \u8bf7\u6c42\u3001PR \u8bf7\u6c42\u7684\u5ba1\u67e5\u8bc4\u8bba\u7b49\u4e0e\u5f00\u53d1\u8005\u76f8\u5173\u7684\u4e8b\u4ef6\u3002<\/p>\n<p>1.\u4f5c\u4e1a SQL \u4ee3\u7801\u3002<strong>\u5176\u4e2d startTime \u5c3d\u91cf\u8bbe\u7f6e\u4e3a\u5f53\u524d\u6b64\u523b\u7684\u4e00\u5468\u524d\u9644\u8fd1<\/strong>\uff0c\u5982\u679c\u8bbe\u7f6e\u7684\u65f6\u95f4\u592a\u65e9\uff0c\u524d\u9762\u65e0\u6548\u8ba1\u7b97\u65f6\u95f4\u6bd4\u8f83\u957f\uff0c\u4e0d\u4ec5\u8017\u8d39\u8d44\u6e90\uff0c\u800c\u4e14\u5f88\u4e45\u624d\u80fd\u52a0\u8f7d\u51fa\u8ba1\u7b97\u7ed3\u679c\u3002\u5982\u679c\u60f3\u8981\u7edf\u8ba1 spark, \u6539\u6210 repo_name = &#8216;apache\/flink&#8221; \u5373\u53ef\u3002<\/p>\n<pre><code class=\"sql\">CREATE TEMPORARY TABLE gh_event(\n    id STRING,                                        -- \u6bcf\u4e2a\u4e8b\u4ef6\u7684\u552f\u4e00ID\u3002\n    created_at BIGINT,                                -- \u4e8b\u4ef6\u65f6\u95f4\uff0c\u5355\u4f4d\u79d2\u3002\n    created_at_ts as TO_TIMESTAMP(created_at*1000),   -- \u4e8b\u4ef6\u65f6\u95f4\u6233\uff08\u5f53\u524d\u4f1a\u8bdd\u65f6\u533a\u4e0b\u7684\u65f6\u95f4\u6233\uff0c\u5982\uff1aAsia\/Shanghai\uff09\u3002\n    type STRING,                                      -- Github\u4e8b\u4ef6\u7c7b\u578b\uff0c\u5982\uff1a\u3002ForkEvent, WatchEvent, IssuesEvent, CommitCommentEvent\u7b49\u3002\n    actor_id STRING,                                  -- Github\u7528\u6237ID\u3002\n    actor_login STRING,                               -- Github\u7528\u6237\u540d\u3002\n    repo_id STRING,                                   -- Github\u4ed3\u5e93ID\u3002\n    repo_name STRING,                                 -- Github\u4ed3\u5e93\u540d\uff0c\u5982\uff1aapache\/flink, apache\/spark, alibaba\/fastjson\u7b49\u3002\n    org STRING,                                       -- Github\u7ec4\u7ec7ID\u3002\n    org_login STRING                                 -- Github\u7ec4\u7ec7\u540d\uff0c\u5982\uff1a apache,google,alibaba\u7b49\u3002\n) WITH (\n  'connector' = 'sls',                              -- \u5b9e\u65f6\u91c7\u96c6\u7684Github\u4e8b\u4ef6\u5b58\u653e\u5728\u963f\u91cc\u4e91SLS\u4e2d\u3002\n  'project' = 'github-events-shanghai',                     -- \u5b58\u653e\u516c\u5f00\u6570\u636e\u7684SLS\u9879\u76ee\u3002\u4f8b\u5982'github-events-hangzhou'\u3002\n  'endPoint' = 'https:\/\/cn-shanghai-intranet.log.aliyuncs.com',                   -- \u516c\u5f00\u6570\u636e\u4ec5\u9650\u963f\u91cc\u4e91\u5b9e\u65f6\u8ba1\u7b97 Flink \u7248\u901a\u8fc7\u79c1\u7f51\u5730\u5740\u8bbf\u95ee\u3002\u4f8b\u5982'https:\/\/cn-hangzhou-intranet.log.aliyuncs.com'\u3002\n  'logStore' = 'realtime-github-events',            -- \u5b58\u653e\u516c\u5f00\u6570\u636e\u7684SLS logStore\u3002\n  'accessId' =  ' ',         -- \u53ea\u8bfb\u8d26\u53f7\u7684AK\u3002\n  'accessKey' = ' ',   -- \u53ea\u8bfb\u8d26\u53f7\u7684SK\u3002\n  'batchGetSize' = '500',                           -- \u6279\u91cf\u8bfb\u53d6\u6570\u636e\uff0c\u6bcf\u6279\u6700\u591a\u62c9\u53d6500\u6761\u3002\n  'startTime' = '2023-06-01 14:00:00'              -- \u5f00\u59cb\u65f6\u95f4\uff0c\u5c3d\u91cf\u8bbe\u7f6e\u5230\u9700\u8981\u8ba1\u7b97\u7684\u65f6\u95f4\u9644\u8fd1\uff0c\u5426\u5219\u65e0\u6548\u8ba1\u7b97\u7684\u65f6\u95f4\u8f83\u957f\n);\n\n-- \u914d\u7f6e\u5f00\u542fmini-batch, \u6bcf2s\u5904\u7406\u4e00\u6b21\u3002\nSET 'table.exec.mini-batch.enabled'='true';\nSET 'table.exec.mini-batch.allow-latency'='2s';\nSET 'table.exec.mini-batch.size'='4096';\n\n-- \u4f5c\u4e1a\u8bbe\u7f6e4\u4e2a\u5e76\u53d1\uff0c\u805a\u5408\u66f4\u5feb\u3002\nSET 'parallelism.default' = '4';\n\n\n-- \u914d\u7f6e\u5f00\u542fmini-batch, \u6bcf2s\u5904\u7406\u4e00\u6b21\u3002\nSET 'table.exec.mini-batch.enabled'='true'; \nSET 'table.exec.mini-batch.allow-latency'='2s'; \nSET 'table.exec.mini-batch.size'='4096'; \n\n-- \u4f5c\u4e1a\u8bbe\u7f6e4\u4e2a\u5e76\u53d1\uff0c\u805a\u5408\u66f4\u5feb\u3002\nSET 'parallelism.default' = '4';\n\n-- \u7edf\u8ba1\u4ece\u4e0a\u5468\u8d77\u7684\u8d21\u732e\u91cf\nSELECT  DATE_FORMAT(created_at_ts, 'yyyy-MM-dd') as comment_date, HOUR(created_at_ts) AS comment_hour ,COUNT(*) AS comment_count\nFROM gh_event\nWHERE created_at_ts &gt;= NOW() - INTERVAL '7' DAY \n        AND repo_name = 'apache\/flink'\n       AND (type ='CommitCommentEvent' OR \n            type='IssueCommentEvent' or \n            type = 'PullRequestReviewCommentEvent'or \n            type = 'PushEvent' or \n            type = 'PullRequestEvent' or \n            type = 'PullRequestReviewEvent')\nGROUP BY DATE_FORMAT(created_at_ts, 'yyyy-MM-dd'), HOUR(created_at_ts) ;<\/code><\/pre>\n<p>2.\u70b9\u51fb\u6267\u884c\uff0c\u5e76\u4e14\u914d\u7f6e\u56fe\u8868\u3002\u9009\u62e9 Heatmap, \u8bbe\u7f6e Group by comment_date, Spli By comment_hour\uff0cColor\u4e3a Sum(comment_count)\uff0c \u5373 X \u8f74\u4e3a\u5929\uff0cY \u5468\u4e3a\u5c0f\u65f6\uff0c\u6839\u636e\u603b\u6570\u91cf\u663e\u793a\u989c\u8272\u6df1\u6d45\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043953881\" alt=\"15\" title=\"15\" loading=\"lazy\"><\/p>\n<p><strong>\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u5982\u4f55\u5728 GitHub \u4e2d\u53d1\u73b0\u6700\u70ed\u95e8\u7684\u9879\u76ee\u7684\u77e5\u8bc6\u5417\uff1f\u5feb\u6765\u5c1d\u8bd5\u4e00\u4e0b\u5427\uff01<\/strong><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043953882\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=I%2FeoyiDkUKqw5nRn%2BsHXmg%3D%3D.206XuSmmvZzPSfEJGDl%2FaKPHGxg2oyBuamzkJ0ig8p7%2BcqRZ5RNw0p9KrV1gyKB53P7O0fwKds8kuhg9Q5VAFeq74j4U5DJR4%2BOJZ%2Fz62ZTHCjsGg6TmjC2fqkpAGwoy\" rel=\"nofollow\">\u70b9\u51fb\u5373\u523b\u5165\u8425<\/a><\/p>\n<hr>\n<p>\u66f4\u591a\u5185\u5bb9<br \/><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043814703\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><br \/>\u6d3b\u52a8\u63a8\u8350\u963f\u91cc\u4e91\u57fa\u4e8e Apache Flink \u6784\u5efa\u7684\u4f01\u4e1a\u7ea7\u4ea7\u54c1-\u5b9e\u65f6\u8ba1\u7b97 Flink \u7248\u73b0\u5f00\u542f\u6d3b\u52a8\uff1a0 \u5143\u8bd5\u7528\u00a0\u5b9e\u65f6\u8ba1\u7b97 Flink \u7248\uff085000CU*\u5c0f\u65f6\uff0c3 \u4e2a\u6708\u5185\uff09\u4e86\u89e3\u6d3b\u52a8\u8be6\u60c5\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=3irXgVizgbmK21P55B3rwg%3D%3D.vKZiVWGDQfNgeo5nJgENIgT6CRpcx3Xs5Dfx87FO6o2NqIHQ2Y%2BLzS0NDCW7iz4K\" rel=\"nofollow\">https:\/\/click.aliyun.com\/m\/1000372333\/<\/a><br \/><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc8sP8\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000043953864\">https:\/\/segmentfault.com\/a\/1190000043953864<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005\uff5c\u738b\u6d2a\u987a\uff08\u5f18\u821c\uff09 \u4e3a\u8fdb\u4e00\u6b65\u5e2e\u52a9\u5f00\u53d1\u8005\u5b66\u4e60\u4f7f\u7528 Flink\uff0cApache Flink \u4e2d\u6587\u793e\u533a\u8fd1\u671f\u53d1\u8d77 Fl [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10008020","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008020","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10008020"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008020\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10008020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10008020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10008020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}