{"id":61431,"date":"2024-10-13T11:04:15","date_gmt":"2024-10-13T03:04:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/61431\/"},"modified":"2024-10-13T11:04:16","modified_gmt":"2024-10-13T03:04:16","slug":"flink-sql-%e7%9f%a5%e5%85%b6%e6%89%80%e4%bb%a5%e7%84%b6%ef%bc%9a%e5%85%a9%e8%90%ac%e5%ad%97%e8%a9%b3%e8%bf%b0-join-%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/61431\/","title":{"rendered":"Flink SQL \u77e5\u5176\u6240\u4ee5\u7136\uff1a\u5169\u842c\u5b57\u8a73\u8ff0 Join \u64cd\u4f5c"},"content":{"rendered":"<h1 id=\"flink-sql-%e7%9f%a5%e5%85%b6%e6%89%80%e4%bb%a5%e7%84%b6%ef%bc%9a%e5%85%a9%e8%90%ac%e5%ad%97%e8%a9%b3%e8%bf%b0-join-%e6%93%8d%e4%bd%9c-yENRitoBkQ\">Flink SQL \u77e5\u5176\u6240\u4ee5\u7136\uff1a\u5169\u842c\u5b57\u8a73\u8ff0 Join \u64cd\u4f5c<\/h1>\n<p>\u5728\u5927\u6578\u64da\u8655\u7406\u7684\u9818\u57df\u4e2d\uff0cApache Flink \u4f5c\u70ba\u4e00\u500b\u6d41\u8655\u7406\u6846\u67b6\uff0c\u8d8a\u4f86\u8d8a\u53d7\u5230\u958b\u767c\u8005\u7684\u9752\u775e\u3002Flink SQL \u662f Flink \u7684\u4e00\u500b\u91cd\u8981\u7d44\u4ef6\uff0c\u63d0\u4f9b\u4e86 SQL \u67e5\u8a62\u7684\u80fd\u529b\uff0c\u4f7f\u5f97\u7528\u6236\u80fd\u5920\u4ee5\u66f4\u76f4\u89c0\u7684\u65b9\u5f0f\u9032\u884c\u6578\u64da\u8655\u7406\u3002\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5c07\u6df1\u5165\u63a2\u8a0e Flink SQL \u4e2d\u7684 Join \u64cd\u4f5c\uff0c\u4e26\u5206\u6790\u5176\u80cc\u5f8c\u7684\u539f\u7406\u548c\u61c9\u7528\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-join-%e6%93%8d%e4%bd%9c%ef%bc%9f-yENRitoBkQ\">\u4ec0\u9ebc\u662f Join \u64cd\u4f5c\uff1f<\/h2>\n<p>Join \u64cd\u4f5c\u662f\u95dc\u806f\u6578\u64da\u5eab\u4e2d\u4e00\u7a2e\u5e38\u898b\u7684\u64cd\u4f5c\uff0c\u7528\u65bc\u5c07\u5169\u500b\u6216\u591a\u500b\u8868\u4e2d\u7684\u6578\u64da\u6839\u64da\u67d0\u4e9b\u689d\u4ef6\u9032\u884c\u5408\u4f75\u3002\u5728 Flink SQL \u4e2d\uff0cJoin \u64cd\u4f5c\u540c\u6a23\u626e\u6f14\u8457\u91cd\u8981\u7684\u89d2\u8272\uff0c\u7279\u5225\u662f\u5728\u8655\u7406\u6d41\u6578\u64da\u6642\u3002Flink \u652f\u6301\u591a\u7a2e Join \u985e\u578b\uff0c\u5305\u62ec Inner Join\u3001Left Join\u3001Right Join \u548c Full Join\u3002<\/p>\n<h2 id=\"join-%e7%9a%84%e9%a1%9e%e5%9e%8b-yENRitoBkQ\">Join \u7684\u985e\u578b<\/h2>\n<ul>\n<li><strong>Inner Join<\/strong>: \u53ea\u8fd4\u56de\u5169\u500b\u8868\u4e2d\u5339\u914d\u7684\u884c\u3002<\/li>\n<li><strong>Left Join<\/strong>: \u8fd4\u56de\u5de6\u8868\u7684\u6240\u6709\u884c\uff0c\u5373\u4f7f\u53f3\u8868\u4e2d\u6c92\u6709\u5339\u914d\u7684\u884c\u3002<\/li>\n<li><strong>Right Join<\/strong>: \u8fd4\u56de\u53f3\u8868\u7684\u6240\u6709\u884c\uff0c\u5373\u4f7f\u5de6\u8868\u4e2d\u6c92\u6709\u5339\u914d\u7684\u884c\u3002<\/li>\n<li><strong>Full Join<\/strong>: \u8fd4\u56de\u5169\u500b\u8868\u4e2d\u7684\u6240\u6709\u884c\uff0c\u7121\u8ad6\u662f\u5426\u6709\u5339\u914d\u3002<\/li>\n<\/ul>\n<h2 id=\"flink-sql-%e4%b8%ad%e7%9a%84-join-%e8%aa%9e%e6%b3%95-yENRitoBkQ\">Flink SQL \u4e2d\u7684 Join \u8a9e\u6cd5<\/h2>\n<p>\u5728 Flink SQL \u4e2d\uff0cJoin \u64cd\u4f5c\u7684\u8a9e\u6cd5\u8207\u6a19\u6e96 SQL \u985e\u4f3c\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5728 Flink SQL \u4e2d\u4f7f\u7528 Inner Join\uff1a<\/p>\n<pre><code>SELECT a.id, a.name, b.salary\nFROM employees AS a\nINNER JOIN salaries AS b\nON a.id = b.employee_id;<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6211\u5011\u5f9e\u5169\u500b\u8868\u4e2d\u9078\u64c7\u54e1\u5de5\u7684 ID\u3001\u59d3\u540d\u548c\u85aa\u6c34\uff0c\u4e26\u6839\u64da\u54e1\u5de5 ID \u9032\u884c\u5339\u914d\u3002<\/p>\n<h2 id=\"join-%e6%93%8d%e4%bd%9c%e7%9a%84%e6%80%a7%e8%83%bd%e8%80%83%e9%87%8f-yENRitoBkQ\">Join \u64cd\u4f5c\u7684\u6027\u80fd\u8003\u91cf<\/h2>\n<p>\u5728\u9032\u884c Join \u64cd\u4f5c\u6642\uff0c\u6027\u80fd\u662f\u4e00\u500b\u91cd\u8981\u7684\u8003\u91cf\u56e0\u7d20\u3002Flink \u63d0\u4f9b\u4e86\u591a\u7a2e\u512a\u5316\u7b56\u7565\u4f86\u63d0\u9ad8 Join \u64cd\u4f5c\u7684\u6548\u7387\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>Broadcast Join<\/strong>: \u5c0d\u65bc\u5c0f\u8868\uff0c\u53ef\u4ee5\u5c07\u5176\u5ee3\u64ad\u5230\u6240\u6709\u5de5\u4f5c\u7bc0\u9ede\uff0c\u5f9e\u800c\u6e1b\u5c11\u6578\u64da\u50b3\u8f38\u7684\u958b\u92b7\u3002<\/li>\n<li><strong>Shuffle Join<\/strong>: \u5c0d\u65bc\u5927\u8868\uff0cFlink \u6703\u6839\u64da Join \u689d\u4ef6\u9032\u884c\u6578\u64da\u7684\u91cd\u65b0\u5206\u914d\uff0c\u4ee5\u78ba\u4fdd\u76f8\u540c\u7684\u9375\u5728\u540c\u4e00\u500b\u7bc0\u9ede\u4e0a\u9032\u884c\u8655\u7406\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%af%a6%e9%9a%9b%e6%87%89%e7%94%a8%e6%a1%88%e4%be%8b-yENRitoBkQ\">\u5be6\u969b\u61c9\u7528\u6848\u4f8b<\/h2>\n<p>\u5728\u5be6\u969b\u61c9\u7528\u4e2d\uff0cJoin \u64cd\u4f5c\u5e38\u7528\u65bc\u6578\u64da\u6574\u5408\u548c\u5831\u544a\u751f\u6210\u3002\u4f8b\u5982\uff0c\u5728\u4e00\u500b\u96fb\u5546\u5e73\u53f0\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u5c07\u7528\u6236\u7684\u8cfc\u8cb7\u8a18\u9304\u8207\u7528\u6236\u4fe1\u606f\u9032\u884c Join\uff0c\u4ee5\u751f\u6210\u7528\u6236\u7684\u8cfc\u8cb7\u5831\u544a\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u793a\u4f8b\uff1a<\/p>\n<pre><code>SELECT u.user_id, u.name, COUNT(o.order_id) AS total_orders\nFROM users AS u\nLEFT JOIN orders AS o\nON u.user_id = o.user_id\nGROUP BY u.user_id, u.name;<\/code><\/pre>\n<p>\u9019\u6bb5 SQL \u67e5\u8a62\u5c07\u8fd4\u56de\u6bcf\u4f4d\u7528\u6236\u7684 ID\u3001\u59d3\u540d\u4ee5\u53ca\u4ed6\u5011\u7684\u7e3d\u8a02\u55ae\u6578\uff0c\u5373\u4f7f\u67d0\u4e9b\u7528\u6236\u6c92\u6709\u4e0b\u904e\u8a02\u55ae\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-yENRitoBkQ\">\u7d50\u8ad6<\/h2>\n<p>Flink SQL \u4e2d\u7684 Join \u64cd\u4f5c\u662f\u6578\u64da\u8655\u7406\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u901a\u904e\u7406\u89e3\u4e0d\u540c\u985e\u578b\u7684 Join \u53ca\u5176\u6027\u80fd\u512a\u5316\u7b56\u7565\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u8655\u7406\u548c\u5206\u6790\u6578\u64da\u3002\u7121\u8ad6\u662f\u5728\u5be6\u6642\u6578\u64da\u6d41\u8655\u7406\u9084\u662f\u6279\u91cf\u6578\u64da\u5206\u6790\u4e2d\uff0c\u638c\u63e1 Join \u64cd\u4f5c\u7684\u4f7f\u7528\u90fd\u662f\u63d0\u5347\u6578\u64da\u8655\u7406\u80fd\u529b\u7684\u95dc\u9375\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u95dc\u65bc <a href=\"https:\/\/server.hk\">VPS<\/a> \u53ca\u5176\u5728\u5927\u6578\u64da\u8655\u7406\u4e2d\u7684\u61c9\u7528\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6df1\u5165\u63a2\u8a0e Flink SQL \u4e2d\u7684 Join \u64cd\u4f5c\uff0c\u5169\u842c\u5b57\u8a73\u8ff0\u5176\u539f\u7406\u8207\u61c9\u7528\uff0c\u52a9\u4f60\u638c\u63e1\u6578\u64da\u8655\u7406\u7684\u7cbe\u9ad3\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-61431","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=61431"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61431\/revisions"}],"predecessor-version":[{"id":61432,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61431\/revisions\/61432"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=61431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=61431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=61431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}