{"id":1323,"date":"2023-03-19T08:32:29","date_gmt":"2023-03-19T00:32:29","guid":{"rendered":"http:\/\/viplao.com\/?p=1323"},"modified":"2023-03-19T08:32:31","modified_gmt":"2023-03-19T00:32:31","slug":"%e3%80%90%e8%bf%90%e7%bb%b4%e5%b7%a5%e5%85%b7%e3%80%91flink-sql-%e5%ae%9e%e8%b7%b55-%e8%87%aa%e5%ae%9a%e4%b9%89-protobuf-format","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%91flink-sql-%e5%ae%9e%e8%b7%b55-%e8%87%aa%e5%ae%9a%e4%b9%89-protobuf-format\/","title":{"rendered":"\u3010\u8fd0\u7ef4\u5de5\u5177\u3011Flink SQL\u00a0\u5b9e\u8df55 \u81ea\u5b9a\u4e49 protobuf format"},"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%91flink-sql-%e5%ae%9e%e8%b7%b55-%e8%87%aa%e5%ae%9a%e4%b9%89-protobuf-format\/#1%E5%BA%8F%E7%AF%87-%E6%9C%AC%E6%96%87%E7%BB%93%E6%9E%84\" title=\"1.\u5e8f\u7bc7-\u672c\u6587\u7ed3\u6784\">1.\u5e8f\u7bc7-\u672c\u6587\u7ed3\u6784<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><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%91flink-sql-%e5%ae%9e%e8%b7%b55-%e8%87%aa%e5%ae%9a%e4%b9%89-protobuf-format\/#2%E8%83%8C%E6%99%AF%E7%AF%87-%E4%B8%BA%E5%95%A5%E9%9C%80%E8%A6%81_protobuf_format\" title=\"2.\u80cc\u666f\u7bc7-\u4e3a\u5565\u9700\u8981 protobuf format\">2.\u80cc\u666f\u7bc7-\u4e3a\u5565\u9700\u8981 protobuf format<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><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%91flink-sql-%e5%ae%9e%e8%b7%b55-%e8%87%aa%e5%ae%9a%e4%b9%89-protobuf-format\/#3%E7%9B%AE%E6%A0%87%E7%AF%87-protobuf_format_%E9%A2%84%E6%9C%9F%E6%95%88%E6%9E%9C\" title=\"3.\u76ee\u6807\u7bc7-protobuf format \u9884\u671f\u6548\u679c\">3.\u76ee\u6807\u7bc7-protobuf format \u9884\u671f\u6548\u679c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><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%91flink-sql-%e5%ae%9e%e8%b7%b55-%e8%87%aa%e5%ae%9a%e4%b9%89-protobuf-format\/#4%E9%9A%BE%E7%82%B9%E5%89%96%E6%9E%90%E7%AF%87-%E7%9B%AE%E5%89%8D%E6%9C%89%E5%93%AA%E4%BA%9B%E5%AE%9E%E7%8E%B0\" title=\"4.\u96be\u70b9\u5256\u6790\u7bc7-\u76ee\u524d\u6709\u54ea\u4e9b\u5b9e\u73b0\">4.\u96be\u70b9\u5256\u6790\u7bc7-\u76ee\u524d\u6709\u54ea\u4e9b\u5b9e\u73b0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><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%91flink-sql-%e5%ae%9e%e8%b7%b55-%e8%87%aa%e5%ae%9a%e4%b9%89-protobuf-format\/#5%E5%AE%9E%E7%8E%B0%E7%AF%87-%E5%AE%9E%E7%8E%B0%E7%9A%84%E8%BF%87%E7%A8%8B\" title=\"5.\u5b9e\u73b0\u7bc7-\u5b9e\u73b0\u7684\u8fc7\u7a0b\">5.\u5b9e\u73b0\u7bc7-\u5b9e\u73b0\u7684\u8fc7\u7a0b<\/a><\/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%91flink-sql-%e5%ae%9e%e8%b7%b55-%e8%87%aa%e5%ae%9a%e4%b9%89-protobuf-format\/#51flink_format_%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86\" title=\"5.1.flink format \u5de5\u4f5c\u539f\u7406\">5.1.flink format \u5de5\u4f5c\u539f\u7406<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><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%91flink-sql-%e5%ae%9e%e8%b7%b55-%e8%87%aa%e5%ae%9a%e4%b9%89-protobuf-format\/#52flink_protobuf_format_%E5%AE%9E%E7%8E%B0\" title=\"5.2.flink protobuf format \u5b9e\u73b0\">5.2.flink protobuf format \u5b9e\u73b0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><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%91flink-sql-%e5%ae%9e%e8%b7%b55-%e8%87%aa%e5%ae%9a%e4%b9%89-protobuf-format\/#6%E6%80%BB%E7%BB%93%E4%B8%8E%E5%B1%95%E6%9C%9B%E7%AF%87\" title=\"6.\u603b\u7ed3\u4e0e\u5c55\u671b\u7bc7\">6.\u603b\u7ed3\u4e0e\u5c55\u671b\u7bc7<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><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%91flink-sql-%e5%ae%9e%e8%b7%b55-%e8%87%aa%e5%ae%9a%e4%b9%89-protobuf-format\/#61%E6%80%BB%E7%BB%93\" title=\"6.1.\u603b\u7ed3\">6.1.\u603b\u7ed3<\/a><\/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%91flink-sql-%e5%ae%9e%e8%b7%b55-%e8%87%aa%e5%ae%9a%e4%b9%89-protobuf-format\/#62%E5%B1%95%E6%9C%9B\" title=\"6.2.\u5c55\u671b\">6.2.\u5c55\u671b<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1%E5%BA%8F%E7%AF%87-%E6%9C%AC%E6%96%87%E7%BB%93%E6%9E%84\"><\/span>1.\u5e8f\u7bc7-\u672c\u6587\u7ed3\u6784<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><code>protobuf<\/code>&nbsp;\u4f5c\u4e3a\u76ee\u524d\u5404\u5927\u516c\u53f8\u4e2d\u6700\u5e7f\u6cdb\u4f7f\u7528\u7684\u9ad8\u6548\u7684\u534f\u8bae\u6570\u636e\u4ea4\u6362\u683c\u5f0f\u5de5\u5177\u5e93\uff0c\u4f1a\u5927\u91cf\u4f5c\u4e3a\u6d41\u5f0f\u6570\u636e\u4f20\u8f93\u7684\u5e8f\u5217\u5316\u65b9\u5f0f\uff0c\u6240\u4ee5\u5728 flink sql \u4e2d\u5982\u679c\u80fd\u5b9e\u73b0&nbsp;<code>protobuf<\/code>&nbsp;\u7684&nbsp;<code>format<\/code>&nbsp;\u4f1a\u975e\u5e38\u6709\u7528\uff08<strong>\u76ee\u524d\u793e\u533a\u5df2\u7ecf\u6709\u5bf9\u5e94\u7684\u5b9e\u73b0\uff0c\u4e0d\u8fc7\u76ee\u524d\u8fd8\u6ca1\u6709 merge\uff0c\u9884\u8ba1\u5728 1.14 \u7cfb\u5217\u7248\u672c\u4e2d\u80fd release<\/strong>\uff09\u3002<\/p>\n\n\n\n<p><code>issue<\/code>&nbsp;\u89c1\uff1a<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/issues.apache.org\/jira\/browse\/FLINK-18202%3Ffilter%3D-4%26jql%3Dproject%2520%253D%2520FLINK%2520AND%2520issuetype%2520%253D%2520%2522New%2520Feature%2522%2520AND%2520text%2520~%2520protobuf%2520order%2520by%2520created%2520DESC\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/issues.apache.org\/jira\/browse\/FLINK-18202?filter=-4&amp;jql=project%20%3D%20FLINK%20AND%20issuetype%20%3D%20%22New%20Feature%22%20AND%20text%20~%20protobuf%20order%20by%20created%20DESC<\/a><\/p>\n\n\n\n<p><code>pr<\/code>&nbsp;\u89c1\uff1a<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/github.com\/apache\/flink\/pull\/14376\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/apache\/flink\/pull\/14376<\/a><\/p>\n\n\n\n<p>\u8fd9\u4e00\u8282\u4e3b\u8981\u4ecb\u7ecd flink sql \u4e2d\u600e\u4e48\u81ea\u5b9a\u4e49\u5b9e\u73b0&nbsp;<code>format<\/code>\uff0c\u5176\u4e2d\u4ee5\u6700\u5e38\u4f7f\u7528\u7684&nbsp;<code>protobuf<\/code>&nbsp;\u4f5c\u4e3a\u6848\u4f8b\u6765\u4ecb\u7ecd\u3002<\/p>\n\n\n\n<ol>\n<li>\u80cc\u666f\u7bc7-\u4e3a\u5565\u9700\u8981 protobuf format<\/li>\n\n\n\n<li>\u76ee\u6807\u7bc7-protobuf format \u9884\u671f\u6548\u679c<\/li>\n\n\n\n<li>\u96be\u70b9\u5256\u6790\u7bc7-\u6b64\u6846\u67b6\u5efa\u8bbe\u7684\u96be\u70b9\u3001\u76ee\u524d\u6709\u54ea\u4e9b\u5b9e\u73b0<\/li>\n\n\n\n<li>\u7ef4\u8868\u5b9e\u73b0\u7bc7-\u5b9e\u73b0\u7684\u8fc7\u7a0b<\/li>\n\n\n\n<li>\u603b\u7ed3\u4e0e\u5c55\u671b\u7bc7<\/li>\n<\/ol>\n\n\n\n<p>\u5982\u679c\u60f3\u5728\u672c\u5730\u76f4\u63a5\u6d4b\u8bd5\u4e0b\uff1a<\/p>\n\n\n\n<ol>\n<li>\u5728\u516c\u4f17\u53f7\u540e\u53f0\u56de\u590d<\/li>\n<\/ol>\n\n\n\n<ul>\n<li><strong>flink sql \u77e5\u5176\u6240\u4ee5\u7136\uff08\u4e94\uff09| \u81ea\u5b9a\u4e49 protobuf format<\/strong>\u83b7\u53d6\u6e90\u7801\uff08\u6e90\u7801\u57fa\u4e8e 1.13.1 \u5b9e\u73b0\uff09<\/li>\n\n\n\n<li><strong>flink sql \u77e5\u5176\u6240\u4ee5\u7136\uff08\u4e94\uff09| \u81ea\u5b9a\u4e49 protobuf format<\/strong>\u83b7\u53d6\u6e90\u7801\uff08\u6e90\u7801\u57fa\u4e8e 1.13.1 \u5b9e\u73b0\uff09<\/li>\n\n\n\n<li><strong>flink sql \u77e5\u5176\u6240\u4ee5\u7136\uff08\u4e94\uff09| \u81ea\u5b9a\u4e49 protobuf format<\/strong>\u83b7\u53d6\u6e90\u7801\uff08\u6e90\u7801\u57fa\u4e8e 1.13.1 \u5b9e\u73b0\uff09<\/li>\n\n\n\n<li>\u6267\u884c\u6e90\u7801\u5305\u4e2d\u7684&nbsp;<code>flink.examples.sql._05.format.formats.SocketWriteTest<\/code>&nbsp;\u6d4b\u8bd5\u7c7b\u6765\u5236\u9020 protobuf \u6570\u636e<\/li>\n\n\n\n<li>\u7136\u540e\u6267\u884c\u6e90\u7801\u5305\u4e2d\u7684&nbsp;<code>flink.examples.sql._05.format.formats.ProtobufFormatTest<\/code>&nbsp;\u6d4b\u8bd5\u7c7b\u6765\u6d88\u8d39 protobuf \u6570\u636e\uff0c\u5e76\u4e14\u6253\u5370\u5728 console \u4e2d\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u5728 console \u4e2d\u770b\u5230\u7ed3\u679c\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2%E8%83%8C%E6%99%AF%E7%AF%87-%E4%B8%BA%E5%95%A5%E9%9C%80%E8%A6%81_protobuf_format\"><\/span>2.\u80cc\u666f\u7bc7-\u4e3a\u5565\u9700\u8981 protobuf format<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5173\u4e8e\u4e3a\u4ec0\u4e48\u9009\u62e9&nbsp;<code>protobuf<\/code>&nbsp;\u53ef\u4ee5\u770b\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5199\u7684\u5f88\u8be6\u7ec6\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/link.zhihu.com\/?target=http%3A\/\/hengyunabc.github.io\/thinking-about-grpc-protobuf\/%3Futm_source%3Dtuicool%26utm_medium%3Dreferral\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/hengyunabc.github.io\/thinking-about-grpc-protobuf\/?utm_source=tuicool&amp;utm_medium=referral<\/a><\/p>\n\n\n\n<p>\u5728\u5b9e\u65f6\u8ba1\u7b97\u7684\u9886\u57df\u4e2d\uff0c\u4e3a\u4e86\u53ef\u8bfb\u6027\u4f1a\u9009\u62e9&nbsp;<code>json<\/code>\uff0c\u4e3a\u4e86\u6548\u7387\u4ee5\u53ca\u4e00\u4e9b\u5df2\u7ecf\u4f9d\u8d56\u4e86&nbsp;<code>grpc<\/code>&nbsp;\u7684\u516c\u53f8\u4f1a\u9009\u62e9&nbsp;<code>protobuf<\/code>&nbsp;\u6765\u505a\u6570\u636e\u5e8f\u5217\u5316\uff0c\u90a3\u4e48\u81ea\u7136\u800c\u7136\uff0c\u65e5\u5fd7\u7684\u5e8f\u5217\u5316\u65b9\u5f0f\u4e5f\u4f1a\u9009\u62e9&nbsp;<code>protobuf<\/code>\u3002<\/p>\n\n\n\n<p>\u800c\u5b98\u65b9\u76ee\u524d\u5df2\u7ecf release \u7684\u7248\u672c\u4e2d\u662f\u6ca1\u6709\u63d0\u4f9b flink sql api \u7684&nbsp;<code>protobuf format<\/code>&nbsp;\u7684\u3002\u5982\u4e0b\u56fe\uff0c\u57fa\u4e8e 1.13 \u7248\u672c\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/ci.apache.org\/projects\/flink\/flink-docs-release-1.13\/docs\/connectors\/table\/overview\/\">https:\/\/ci.apache.org\/projects\/flink\/flink-docs-release-1.13\/docs\/connectors\/table\/overview\/<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic3.zhimg.com\/80\/v2-ac01bb5be4b65f7ce215bb3b48b5c8ea_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>1<\/p>\n\n\n\n<p>\u56e0\u6b64\u672c\u6587\u5728\u4ecb\u7ecd\u600e\u6837\u81ea\u5b9a\u4e49\u4e00\u4e2a format \u7684\u540c\u65f6\uff0c\u5b9e\u73b0\u4e00\u4e2a protobuf format \u6765\u7ed9\u5927\u5bb6\u4f7f\u7528\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3%E7%9B%AE%E6%A0%87%E7%AF%87-protobuf_format_%E9%A2%84%E6%9C%9F%E6%95%88%E6%9E%9C\"><\/span>3.\u76ee\u6807\u7bc7-protobuf format \u9884\u671f\u6548\u679c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u9884\u671f\u6548\u679c\u662f\u5148\u5b9e\u73b0\u51e0\u79cd\u6700\u57fa\u672c\u7684\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec protobuf \u4e2d\u7684&nbsp;<code>message<\/code>\uff08\u81ea\u5b9a\u4e49 model\uff09\u3001<code>map<\/code>\uff08\u6620\u5c04\uff09\u3001<code>repeated<\/code>\uff08\u5217\u8868\uff09\u3001\u5176\u4ed6\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7b49\uff0c\u8fd9\u4e9b\u90fd\u662f\u6211\u4eec\u6700\u5e38\u4f7f\u7528\u7684\u7c7b\u578b\u3002<\/p>\n\n\n\n<p>\u9884\u671f protobuf message \u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-b270c7cb2765a0dbb07da285e20d6728_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>2<\/p>\n\n\n\n<p>\u6d4b\u8bd5\u6570\u636e\u6e90\u6570\u636e\u5982\u4e0b\uff0c\u535a\u4e3b\u628a protobuf \u7684\u6570\u636e\u8f6c\u6362\u4e3a json\uff0c\u4ee5\u65b9\u4fbf\u5c55\u793a\uff0c\u5982\u4e0b\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic3.zhimg.com\/80\/v2-ba5d78af97687c8e55d0a0160a824cce_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>3<\/p>\n\n\n\n<p>\u9884\u671f flink sql\uff1a<\/p>\n\n\n\n<p>\u6570\u636e\u6e90\u8868 DDL\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE protobuf_source (\n    name STRING\n  , names ARRAY&lt;STRING&gt;\n  , si_map MAP&lt;STRING, INT&gt;\n)\nWITH (\n  'connector' = 'socket',\n  'hostname' = 'localhost',\n  'port' = '9999',\n  'format' = 'protobuf',\n  'protobuf.class-name' = 'flink.examples.sql._04.format.formats.protobuf.Test'\n)\n<\/code><\/pre>\n\n\n\n<p>\u6570\u636e\u6c47\u8868 DDL\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE print_sink (\n  name STRING\n  , names ARRAY&lt;STRING&gt;\n  , si_map MAP&lt;STRING, INT&gt;\n) WITH (\n  'connector' = 'print'\n)\n<\/code><\/pre>\n\n\n\n<p>Transform \u6267\u884c\u903b\u8f91\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO print_sink\nSELECT *\nFROM protobuf_source\n<\/code><\/pre>\n\n\n\n<p>\u4e0b\u9762\u662f\u6211\u5728\u672c\u5730\u8dd1\u7684\u7ed3\u679c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic4.zhimg.com\/80\/v2-5b70e33b5ede3580fbf7892971bf67eb_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic4.zhimg.com\/80\/v2-4c6dc47fa95f172bd124b840992af8c3_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\u6253\u5370\u7684\u7ed3\u679c\uff0c\u6570\u636e\u662f\u6b63\u786e\u7684\u88ab\u53cd\u5e8f\u5217\u5316\u8bfb\u5165\uff0c\u5e76\u4e14\u6700\u7ec8\u8f93\u51fa\u5230 console\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4%E9%9A%BE%E7%82%B9%E5%89%96%E6%9E%90%E7%AF%87-%E7%9B%AE%E5%89%8D%E6%9C%89%E5%93%AA%E4%BA%9B%E5%AE%9E%E7%8E%B0\"><\/span>4.\u96be\u70b9\u5256\u6790\u7bc7-\u76ee\u524d\u6709\u54ea\u4e9b\u5b9e\u73b0<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u76ee\u524d\u4e1a\u754c\u53ef\u4ee5\u53c2\u8003\u7684\u5b9e\u73b0\u5982\u4e0b\uff1a<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/github.com\/maosuhan\/flink-pb\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/maosuhan\/flink-pb<\/a>\uff0c \u4e5f\u5c31\u662f\u8fd9\u4f4d\u54e5\u4eec\u8d1f\u8d23\u76ee\u524d flink protobuf \u7684 format\u3002<\/p>\n\n\n\n<p>\u8fd9\u79cd\u5b9e\u73b0\u7684\u5177\u4f53\u4f7f\u7528\u65b9\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-56fe0dca9a9f9ffebc97be7f0d4901c8_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>7<\/p>\n\n\n\n<p>\u5176\u5b9e\u73b0\u6709\u51e0\u4e2a\u7279\u70b9\uff1a<\/p>\n\n\n\n<ol>\n<li><strong>\u590d\u6742\u6027<\/strong>\uff1a\u7528\u6237\u9700\u8981\u5728 flink sql \u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c\u5c06\u5bf9\u5e94\u7684 protobuf java \u6587\u4ef6\u5f15\u5165 classpath\uff0c\u8fd9\u4e2a\u7279\u70b9\u662f\u590d\u5408 flink \u8fd9\u6837\u7684\u901a\u7528\u6846\u67b6\u7684\u7279\u70b9\u7684\u3002\u4f46\u662f\u5982\u679c\u9700\u8981\u5728\u5404\u4e2a\u516c\u53f8\u573a\u666f\u8981\u505a\u4e00\u4e2a\u6d41\u5f0f\u5904\u7406\u5e73\u53f0\u7684\u573a\u666f\u4e0b\uff0c\u5404\u4e2a protobuf sdk \u53ef\u80fd\u90fd\u4f4d\u4e8e\u4e0d\u540c\u7684 jar \u5305\u4e2d\uff0c\u90a3\u4e48\u5176 jar \u5305\u7ba1\u7406\u53ef\u80fd\u662f\u4e00\u4e2a\u6bd4\u8f83\u5927\u7684\u95ee\u9898\u3002<\/li>\n\n\n\n<li><strong>\u9ad8\u6548 serde<\/strong>\uff1a\u4e00\u822c\u5f88\u591a\u573a\u666f\u4e0b\u4e3a\u4e86\u901a\u7528\u5316 serde protobuf message\uff0c\u53ef\u80fd\u4f1a\u9009\u62e9 DynamicMessage \u6765\u5904\u7406 protobuf message\uff0c\u4f46\u662f\u5176 serde \u6027\u80fd\u76f8\u6bd4\u539f\u751f java code \u7684\u6027\u80fd\u6bd4\u8f83\u5dee\u3002\u56e0\u4e3a\u7279\u70b9 1 \u5f15\u5165\u4e86 protobuf \u7684 java class\uff0c\u6240\u4ee5\u5176 serde function \u53ef\u4ee5\u57fa\u4e8e codegen \u5b9e\u73b0\uff0c\u800c\u8fd9\u5c06\u6781\u5927\u63d0\u9ad8 serde \u6548\u7387\uff0c\u6548\u7387\u63d0\u9ad8\u5c31\u4ee3\u8868\u7740\u7701\u94b1\u554a\uff0c\u53ef\u4ee5\u5439\u903c\u7684\u3002<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-ea58fef8fa69a09b313be0b359157f30_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>8<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>Notes\uff1a<br>\u5f53\u7136\u535a\u4e3b\u9488\u5bf9\u7b2c\u4e00\u70b9\u4e5f\u6709\u4e00\u4e9b\u60f3\u6cd5\uff0c\u6bd4\u5982\u600e\u6837\u505a\u5230\u4e0d\u4f9d\u8d56 protobuf java \u6587\u4ef6\uff0c\u53ea\u4f9d\u8d56 protobuf \u7684 message \u5b9a\u4e49\u5373\u53ef\u6216\u8005\u53ea\u4f9d\u8d56\u5176 descriptor\u3002\u76ee\u524d\u535a\u4e3b\u7684\u60f3\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/blockquote>\n\n\n\n<ol>\n<li><strong>flink \u7a0b\u5e8f\u5728\u5ba2\u6237\u7aef\u83b7\u53d6\u5230\u5bf9\u5e94\u7684 protobuf message \u5b9a\u4e49<\/strong><\/li>\n\n\n\n<li><strong>\u7136\u540e\u6839\u636e\u8fd9\u4e2a\u5b9a\u4e49\u6062\u590d\u51fa proto \u6587\u4ef6<\/strong><\/li>\n\n\n\n<li><strong>\u5ba2\u6237\u7aef\u672c\u5730\u6267\u884c protoc \u5c06\u6b64\u6587\u4ef6\u7f16\u8bd1\u4e3a java \u6587\u4ef6<\/strong><\/li>\n\n\n\n<li><strong>\u5ba2\u6237\u7aef\u672c\u5730\u52a8\u6001\u5c06\u6b64 java \u6587\u4ef6\u7f16\u8bd1\u5e76 load \u5230 jvm \u4e2d<\/strong><\/li>\n\n\n\n<li><strong>\u4f7f\u7528 codegen \u7136\u540e\u52a8\u6001\u751f\u6210\u6267\u884c\u4ee3\u7801<\/strong><\/li>\n<\/ol>\n\n\n\n<p>\u4e00\u6c14\u5475\u6210\uff01\uff01\uff01<br>\u5177\u4f53\u5b9e\u73b0\u5176\u5b9e\u53ef\u4ee5\u53c2\u8003\uff1a<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/stackoverflow.com\/questions\/28381659\/how-to-compile-protocol-buffers-schema-at-runtime\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/stackoverflow.com\/questions\/28381659\/how-to-compile-protocol-buffers-schema-at-runtime<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5%E5%AE%9E%E7%8E%B0%E7%AF%87-%E5%AE%9E%E7%8E%B0%E7%9A%84%E8%BF%87%E7%A8%8B\"><\/span>5.\u5b9e\u73b0\u7bc7-\u5b9e\u73b0\u7684\u8fc7\u7a0b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"51flink_format_%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86\"><\/span>5.1.flink format \u5de5\u4f5c\u539f\u7406<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5176\u5b9e\u4e0a\u8282\u5df2\u7ecf\u8be6\u7ec6\u63cf\u8ff0\u4e86 flink sql \u5bf9\u4e8e source\\sink\\format \u7684\u52a0\u8f7d\u673a\u5236\u3002<\/p>\n\n\n\n<ol>\n<li>\u901a\u8fc7 SPI \u673a\u5236\u52a0\u8f7d\u6240\u6709\u7684 source\\sink\\format \u5de5\u5382&nbsp;<code>Factory<\/code><\/li>\n\n\n\n<li>\u8fc7\u6ee4\u51fa DeserializationFormatFactory\\SerializationFormatFactory + format \u6807\u8bc6\u7684 format \u5de5\u5382\u7c7b<\/li>\n\n\n\n<li>\u901a\u8fc7 format \u5de5\u5382\u7c7b\u521b\u5efa\u51fa\u5bf9\u5e94\u7684 format<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic3.zhimg.com\/80\/v2-6de17db7934b0704a4ab3c8a22ce458e_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>12<\/p>\n\n\n\n<p><a href=\"https:\/\/link.zhihu.com\/?target=http%3A\/\/mp.weixin.qq.com\/s%3F__biz%3DMzkxNjA1MzM5OQ%3D%3D%26mid%3D2247488486%26idx%3D1%26sn%3Db9bdb56e44631145c8cc6354a093e7c0%26chksm%3Dc1549f1ef623160834e3c5661c155ec421699fc18c57f2c63ba14d33bab1d37c5930fdce016b%26scene%3D21%23wechat_redirect\" target=\"_blank\" rel=\"noreferrer noopener\">flink sql \u77e5\u5176\u6240\u4ee5\u7136\uff08\u4e00\uff09| source\\sink \u539f\u7406<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic2.zhimg.com\/80\/v2-598b6de539ea08b78def9ab24ed37385_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-ca03fceb44e7e7a0b64d9e314cc8e264_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>11<\/p>\n\n\n\n<p>\u5982\u56fe serde format \u662f\u901a\u8fc7&nbsp;<code>TableFactoryHelper.discoverDecodingFormat<\/code>&nbsp;\u548c&nbsp;<code>TableFactoryHelper.discoverEncodingFormat<\/code>&nbsp;\u521b\u5efa\u7684<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ either implement your custom validation logic here ...\n        \/\/ or use the provided helper utility\nfinal FactoryUtil.TableFactoryHelper helper = FactoryUtil.createTableFactoryHelper(this, context);\n\n\/\/ discover a suitable decoding format\nfinal DecodingFormat&lt;DeserializationSchema&lt;RowData&gt;&gt; decodingFormat = helper.discoverDecodingFormat(\n        DeserializationFormatFactory.class,\n        FactoryUtil.FORMAT);\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-36ed1ff9309ac6f5d78c93fc39eff95c_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>16<\/p>\n\n\n\n<p>\u6240\u6709\u901a\u8fc7 SPI \u7684 source\\sink\\formt \u63d2\u4ef6\u90fd\u7ee7\u627f\u81ea&nbsp;<code>Factory<\/code>\u3002<\/p>\n\n\n\n<p>\u6574\u4f53\u521b\u5efa format \u65b9\u6cd5\u7684\u8c03\u7528\u94fe\u5982\u4e0b\u56fe\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic2.zhimg.com\/80\/v2-575cc68df076e447460dac1380d71509_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>13<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"52flink_protobuf_format_%E5%AE%9E%E7%8E%B0\"><\/span>5.2.flink protobuf format \u5b9e\u73b0<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u6700\u7ec8\u5b9e\u73b0\u5982\u4e0b\uff0c\u6d89\u53ca\u5230\u4e86\u51e0\u4e2a\u5b9e\u73b0\u7c7b\uff1a<\/p>\n\n\n\n<ol>\n<li><code>ProtobufFormatFactory<\/code><\/li>\n\n\n\n<li><code>ProtobufOptions<\/code><\/li>\n\n\n\n<li><code>ProtobufRowDataDeserializationSchema<\/code><\/li>\n\n\n\n<li><code>ProtobufToRowDataConverters<\/code><\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic4.zhimg.com\/80\/v2-8d9f4fe7e1d12b24705ed07b2d6e9f3b_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>14<\/p>\n\n\n\n<p>\u5177\u4f53\u6d41\u7a0b\uff1a<\/p>\n\n\n\n<ol>\n<li><strong>\u5b9a\u4e49 SPI \u7684\u5de5\u5382\u7c7b&nbsp;<code>ProtobufFormatFactory implements DeserializationFormatFactory<\/code>\uff0c\u5e76\u4e14\u5728 resource\\META-INF \u4e0b\u521b\u5efa SPI \u7684\u63d2\u4ef6\u6587\u4ef6<\/strong><\/li>\n\n\n\n<li><strong>\u5b9e\u73b0&nbsp;<code>ProtobufFormatFactory#factoryIdentifier<\/code>&nbsp;\u6807\u8bc6&nbsp;<code>protobuf<\/code><\/strong><\/li>\n\n\n\n<li><strong>\u5b9e\u73b0&nbsp;<code>ProtobufFormatFactory#createDecodingFormat<\/code>&nbsp;\u6765\u521b\u5efa\u5bf9\u5e94\u7684&nbsp;<code>DecodingFormat&lt;DeserializationSchema&lt;RowData&gt;&gt;<\/code>\uff0c<code>DecodingFormat<\/code>&nbsp;\u662f\u7528\u6765\u5c01\u88c5\u5177\u4f53\u7684\u53cd\u5e8f\u5217\u5316\u5668\u7684\uff0c\u5b9e\u73b0&nbsp;<code>DecodingFormat&lt;DeserializationSchema&lt;RowData&gt;&gt;#createRuntimeDecoder<\/code>\uff0c\u8fd4\u56de&nbsp;<code>ProtobufRowDataDeserializationSchema<\/code><\/strong><\/li>\n\n\n\n<li><strong>\u5b9a\u4e49&nbsp;<code>ProtobufRowDataDeserializationSchema implements DeserializationSchema&lt;RowData&gt;<\/code>\uff0c\u8fd9\u4e2a\u5c31\u662f\u5177\u4f53\u7684\u53cd\u5e8f\u5217\u5316\u5668\uff0c\u5176\u5b9e\u4e0e datastream api \u76f8\u540c<\/strong><\/li>\n\n\n\n<li><strong>\u5b9e\u73b0&nbsp;<code>ProtobufRowDataDeserializationSchema#deserialize<\/code>&nbsp;\u65b9\u6cd5\uff0c\u4e0e datastream \u76f8\u540c\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u5c31\u662f\u5c06&nbsp;<code>byte[]<\/code>&nbsp;\u5e8f\u5217\u5316\u4e3a&nbsp;<code>RowData<\/code>&nbsp;\u7684\u5177\u4f53\u903b\u8f91<\/strong><\/li>\n\n\n\n<li><strong>\u6ce8\u610f\u8fd9\u91cc\u8fd8\u5b9e\u73b0\u4e86\u4e00\u4e2a\u7c7b&nbsp;<code>ProtobufToRowDataConverters<\/code>\uff0c\u5176\u4f5c\u7528\u5c31\u662f\u5728\u5ba2\u6237\u7aef\u521b\u5efa\u51fa\u5177\u4f53\u7684\u5c06&nbsp;<code>byte[]<\/code>&nbsp;\u5e8f\u5217\u5316\u4e3a&nbsp;<code>RowData<\/code>&nbsp;\u7684\u5177\u4f53\u5de5\u5177\u7c7b\uff0c\u5176\u4f1a\u6839\u636e\u7528\u6237\u5b9a\u4e49\u7684\u8868\u5b57\u6bb5\u7c7b\u578b\u52a8\u6001\u751f\u6210\u6570\u636e\u8f6c\u6362\u7684 converter \u7c7b\uff08\u7b56\u7565\u6a21\u5f0f\uff1a<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/www.runoob.com\/design-pattern\/strategy-pattern.html\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.runoob.com\/design-pattern\/strategy-pattern.html<\/a>\uff09\uff0c\u76f8\u5f53\u4e8e\u8868\u7684 schema \u786e\u5b9a\u4e4b\u540e\uff0c\u5176 converter \u4e5f\u4f1a\u786e\u5b9a<\/strong><\/li>\n<\/ol>\n\n\n\n<p>\u4e0a\u8ff0\u5b9e\u73b0\u7c7b\u7684\u5177\u4f53\u5173\u7cfb\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-d3c72a78a70c8a0b8a053b1b84c043f4_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>19<\/p>\n\n\n\n<p>\u4ecb\u7ecd\u5b8c\u6d41\u7a0b\uff0c\u8fdb\u5165\u5177\u4f53\u5b9e\u73b0\u65b9\u6848\u7ec6\u8282\uff1a<\/p>\n\n\n\n<p><code>ProtobufFormatFactory<\/code>&nbsp;\u4e3b\u8981\u521b\u5efa format \u7684\u903b\u8f91\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ProtobufFormatFactory implements DeserializationFormatFactory {\n\n    public static final String IDENTIFIER = \"protobuf\";\n\n    @Override\n    public DecodingFormat&lt;DeserializationSchema&lt;RowData&gt;&gt; createDecodingFormat(Context context,\n            ReadableConfig formatOptions) {\n\n        FactoryUtil.validateFactoryOptions(this, formatOptions);\n\n        \/\/ 1.\u83b7\u53d6\u5230 protobuf \u7684 class \u5168\u8def\u5f84\n        final String className = formatOptions.get(PROTOBUF_CLASS_NAME);\n\n        try {\n            \/\/ 2.load class\n            Class&lt;GeneratedMessageV3&gt; protobufV3 =\n                    (Class&lt;GeneratedMessageV3&gt;) this.getClass().getClassLoader().loadClass(className);\n\n            \/\/ 3.\u521b\u5efa DecodingFormat\n            return new DecodingFormat&lt;DeserializationSchema&lt;RowData&gt;&gt;() {\n                @Override\n                public DeserializationSchema&lt;RowData&gt; createRuntimeDecoder(DynamicTableSource.Context context,\n                        DataType physicalDataType) {\n                    \/\/ 4.\u83b7\u53d6\u5230 table schema rowtype\n                    final RowType rowType = (RowType) physicalDataType.getLogicalType();\n\n                    \/\/ 5.\u521b\u5efa\u5bf9\u5e94\u7684 DeserializationSchema \u4f5c\u4e3a\u53cd\u5e8f\u5217\u5316\u5668\n                    return new ProtobufRowDataDeserializationSchema(\n                            protobufV3\n                            , true\n                            , rowType);\n                }\n\n                @Override\n                public ChangelogMode getChangelogMode() {\n                    return ChangelogMode.insertOnly();\n                }\n            };\n        } catch (ClassNotFoundException e) {\n            throw new RuntimeException(e);\n        }\n    }\n\n    @Override\n    public String factoryIdentifier() {\n        return IDENTIFIER;\n    }\n\n    ...\n}\n<\/code><\/pre>\n\n\n\n<p>resources\\META-INF \u6587\u4ef6\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic4.zhimg.com\/80\/v2-9204e3e216d13b3d4f8624aa95074c3f_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>17<\/p>\n\n\n\n<p><code>ProtobufRowDataDeserializationSchema<\/code>&nbsp;\u4e3b\u8981\u5b9e\u73b0\u53cd\u5e8f\u5217\u5316\u7684\u903b\u8f91\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ProtobufRowDataDeserializationSchema extends AbstractDeserializationSchema&lt;RowData&gt; {\n\n    ...\n\n    private ProtobufToRowDataConverters.ProtobufToRowDataConverter runtimeConverter;\n\n    public ProtobufRowDataDeserializationSchema(\n            Class&lt;? extends GeneratedMessageV3&gt; messageClazz\n            , boolean ignoreParseErrors\n            , RowType expectedResultType) {\n        this.ignoreParseErrors = ignoreParseErrors;\n        Preconditions.checkNotNull(messageClazz, \"Protobuf message class must not be null.\");\n        this.messageClazz = messageClazz;\n        this.descriptorBytes = null;\n        this.descriptor = ProtobufUtils.getDescriptor(messageClazz);\n        this.defaultInstance = ProtobufUtils.getDefaultInstance(messageClazz);\n\n        \/\/ protobuf \u672c\u8eab\u7684 schema\n        this.protobufOriginalRowType = (RowType) ProtobufSchemaConverter.convertToRowDataTypeInfo(messageClazz);\n\n        this.expectedResultType = expectedResultType;\n\n        \/\/ 1.\u6839\u636e table schema \u52a8\u6001\u521b\u5efa\u51fa\u5bf9\u5e94\u7684\u53cd\u5e8f\u5217\u5316\u5668\n        this.runtimeConverter = new ProtobufToRowDataConverters(false)\n                .createRowDataConverterByLogicalType(this.descriptor, this.expectedResultType);\n    }\n\n    @Override\n    public RowData deserialize(byte&#91;] bytes) throws IOException {\n        if (bytes == null) {\n            return null;\n        }\n        try {\n\n            \/\/ 2.\u5c06 bytes \u53cd\u5e8f\u5217\u5316\u4e3a protobuf message\n            Message message = this.defaultInstance\n                    .newBuilderForType()\n                    .mergeFrom(bytes)\n                    .build();\n\n            \/\/ 3.\u53cd\u5e8f\u5217\u5316\u903b\u8f91\uff0c\u4ece protobuf message \u4e2d\u83b7\u53d6\u5b57\u6bb5\u8f6c\u6362\u4e3a RowData\n            return (RowData) runtimeConverter.convert(message);\n        } catch (Throwable t) {\n            if (ignoreParseErrors) {\n                return null;\n            }\n            throw new IOException(\n                    format(\"Failed to deserialize Protobuf '%s'.\", new String(bytes)), t);\n        }\n    }\n\n    ...\n<\/code><\/pre>\n\n\n\n<p>\u53ef\u4ee5\u6ce8\u610f\u5230\u4e0a\u8ff0\u53cd\u5e8f\u5217\u5316\u7684\u4e3b\u8981\u903b\u8f91\u5c31\u96c6\u4e2d\u5728&nbsp;<code>runtimeConverter<\/code>&nbsp;\u4e0a\uff0c\u5373&nbsp;<code>ProtobufToRowDataConverters.ProtobufToRowDataConverter<\/code>\u3002<\/p>\n\n\n\n<p><code>ProtobufToRowDataConverters.ProtobufToRowDataConverter<\/code>&nbsp;\u5c31\u662f\u5728&nbsp;<code>ProtobufToRowDataConverters<\/code>&nbsp;\u4e2d\u5b9a\u4e49\u7684\u3002<\/p>\n\n\n\n<p><code>ProtobufToRowDataConverters.ProtobufToRowDataConverter<\/code>&nbsp;\u5176\u5b9e\u5c31\u662f\u4e00\u4e2a convertor \u63a5\u53e3\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@FunctionalInterface\npublic interface ProtobufToRowDataConverter extends Serializable {\n    Object convert(Object object);\n}\n<\/code><\/pre>\n\n\n\n<p>\u5176\u4f5c\u7528\u5c31\u662f\u5c06 protobuf message \u4e2d\u7684\u6bcf\u4e00\u4e2a\u5b57\u6bb5\u8f6c\u6362\u6210\u4e3a&nbsp;<code>RowData<\/code>&nbsp;\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5b57\u6bb5\u3002<\/p>\n\n\n\n<p><code>ProtobufToRowDataConverters<\/code>&nbsp;\u4e2d\u5c31\u5b9a\u4e49\u4e86\u5177\u4f53\u8f6c\u6362\u903b\u8f91\uff0c\u5982\u622a\u56fe\u6240\u793a\uff0c\u6bcf\u4e00\u4e2a LogicalType \u90fd\u5b9a\u4e49\u4e86 protobuf message \u5b57\u6bb5\u8f6c\u6362\u4e3a flink \u6570\u636e\u7c7b\u578b\u7684\u903b\u8f91\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic2.zhimg.com\/80\/v2-a7730fb573d5afb7a5b65d26151ab569_720w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>18<\/p>\n\n\n\n<p>\u6e90\u7801\u516c\u4f17\u53f7\u540e\u53f0\u56de\u590d<strong>flink sql \u77e5\u5176\u6240\u4ee5\u7136\uff08\u4e94\uff09| \u81ea\u5b9a\u4e49 protobuf format<\/strong>\u83b7\u53d6\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6%E6%80%BB%E7%BB%93%E4%B8%8E%E5%B1%95%E6%9C%9B%E7%AF%87\"><\/span>6.\u603b\u7ed3\u4e0e\u5c55\u671b\u7bc7<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"61%E6%80%BB%E7%BB%93\"><\/span>6.1.\u603b\u7ed3<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u672c\u6587\u4e3b\u8981\u662f\u9488\u5bf9 flink sql protobuf format \u8fdb\u884c\u4e86\u539f\u7406\u89e3\u91ca\u4ee5\u53ca\u5bf9\u5e94\u7684\u5b9e\u73b0\u3002\u5982\u679c\u4f60\u6b63\u597d\u9700\u8981\u8fd9\u4e48\u4e00\u4e2a format\uff0c\u76f4\u63a5\u516c\u4f17\u53f7\u540e\u53f0\u56de\u590d<strong>flink sql \u77e5\u5176\u6240\u4ee5\u7136\uff08\u4e94\uff09| \u81ea\u5b9a\u4e49 protobuf format<\/strong>\u83b7\u53d6\u6e90\u7801\u5427\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"62%E5%B1%95%E6%9C%9B\"><\/span>6.2.\u5c55\u671b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5f53\u7136\u4e0a\u8ff0\u53ea\u662f protobuf format \u4e00\u4e2a\u57fa\u7840\u7684\u5b9e\u73b0\uff0c\u7528\u4e8e\u751f\u4ea7\u73af\u5883\u8fd8\u6709\u5f88\u591a\u65b9\u9762\u53ef\u4ee5\u53bb\u6269\u5c55\u7684\u3002<\/p>\n\n\n\n<ol>\n<li><strong>\u6027\u80fd\u4f18\u5316\u3001\u901a\u7528\u5316<\/strong>\uff1aprotobuf java class \u672c\u5730 codegen \u6765\u63d0\u9ad8\u4efb\u52a1\u6027\u80fd<\/li>\n\n\n\n<li><strong>\u6570\u636e\u8d28\u91cf<\/strong>\uff1a\u5f02\u5e38 AOP\uff0calert \u7b49<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>1.\u5e8f\u7bc7-\u672c\u6587\u7ed3\u6784 protobuf&nbsp;\u4f5c\u4e3a\u76ee\u524d\u5404\u5927\u516c\u53f8\u4e2d\u6700\u5e7f\u6cdb\u4f7f\u7528\u7684\u9ad8\u6548\u7684\u534f\u8bae\u6570\u636e\u4ea4\u6362\u683c\u5f0f&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%91flink-sql-%e5%ae%9e%e8%b7%b55-%e8%87%aa%e5%ae%9a%e4%b9%89-protobuf-format\/\" class=\"more-link read-more\" rel=\"bookmark\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">\u3010\u8fd0\u7ef4\u5de5\u5177\u3011Flink SQL\u00a0\u5b9e\u8df55 \u81ea\u5b9a\u4e49 protobuf format<\/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":899,"_links":{"self":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/1323"}],"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=1323"}],"version-history":[{"count":1,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/1323\/revisions"}],"predecessor-version":[{"id":1324,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/1323\/revisions\/1324"}],"wp:attachment":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/media?parent=1323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/categories?post=1323"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/tags?post=1323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}