{"id":7041,"date":"2023-08-28T09:41:26","date_gmt":"2023-08-28T01:41:26","guid":{"rendered":"https:\/\/i007.vip:15443\/wordpress\/?p=7041"},"modified":"2023-08-28T09:41:26","modified_gmt":"2023-08-28T01:41:26","slug":"avro%e6%a0%bc%e5%bc%8f%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/7041","title":{"rendered":"avro\u683c\u5f0f\u8be6\u89e3"},"content":{"rendered":"<p><a href=\"https:\/\/blog.csdn.net\/hncscwc\/article\/details\/129210946\">cc from<\/a><\/p>\n<p>\u3010Avro\u4ecb\u7ecd\u3011<\/p>\n<p>Apache Avro\u662fhadoop\u4e2d\u7684\u4e00\u4e2a\u5b50\u9879\u76ee\uff0c\u4e5f\u662f\u4e00\u4e2a\u6570\u636e\u5e8f\u5217\u5316\u7cfb\u7edf\uff0c\u5176\u6570\u636e\u6700\u7ec8\u4ee5\u4e8c\u8fdb\u5236\u683c\u5f0f\uff0c\u91c7\u7528\u884c\u5f0f\u5b58\u50a8\u7684\u65b9\u5f0f\u8fdb\u884c\u5b58\u50a8\u3002<\/p>\n<p>Avro\u63d0\u4f9b\u4e86\uff1a<\/p>\n<p>\u4e30\u5bcc\u7684\u6570\u636e\u7ed3\u6784<\/p>\n<p>\u53ef\u538b\u7f29\u3001\u5feb\u901f\u7684\u4e8c\u8fdb\u5236\u6570\u636e\u683c\u5f0f<\/p>\n<p>\u4e00\u4e2a\u7528\u6765\u5b58\u50a8\u6301\u4e45\u5316\u6570\u636e\u7684\u5bb9\u5668\u6587\u4ef6<\/p>\n<p>\u8fdc\u7a0b\u8fc7\u7a0b\u8c03\u7528<\/p>\n<p>\u4e0e\u52a8\u6001\u8bed\u8a00\u7684\u7b80\u5355\u96c6\u6210\uff0c\u4ee3\u7801\u751f\u6210\u4e0d\u9700\u8981\u8bfb\u53d6\u6216\u5199\u5165\u6570\u636e\u6587\u4ef6\uff0c\u4e5f\u4e0d\u9700\u8981\u4f7f\u7528\u6216\u5b9e\u73b0RPC\u534f\u8bae\u3002\u4ee3\u7801\u751f\u6210\u662f\u4e00\u79cd\u53ef\u9009\u7684\u4f18\u5316\uff0c\u53ea\u503c\u5f97\u5728\u9759\u6001\u7c7b\u578b\u8bed\u8a00\u4e2d\u5b9e\u73b0\u3002<\/p>\n<p>\u57fa\u4e8e\u4ee5\u4e0a\u8fd9\u4e9b\u4f18\u70b9\uff0cavro\u5728hadoop\u4f53\u7cfb\u4e2d\u88ab\u5e7f\u6cdb\u4f7f\u7528\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u5728hudi\u3001iceberg\u4e2d\u4e5f\u90fd\u6709\u7528\u5230avro\u4f5c\u4e3a\u5143\u6570\u636e\u4fe1\u606f\u7684\u5b58\u50a8\u683c\u5f0f\u3002<\/p>\n<p>\u3010schema\u3011<\/p>\n<p>Avro\u4f9d\u8d56&#8221;schema&#8221;\uff08\u6a21\u5f0f\uff09\u6765\u5b9e\u73b0\u6570\u636e\u7ed3\u6784\u7684\u5b9a\u4e49\uff0cschema\u901a\u8fc7json\u5bf9\u8c61\u6765\u8fdb\u884c\u63cf\u8ff0\u8868\u793a\uff0c\u5177\u4f53\u8868\u73b0\u4e3a\uff1a<\/p>\n<p>\u4e00\u4e2ajson\u5b57\u7b26\u4e32\u547d\u540d\u4e00\u4e2a\u5b9a\u4e49\u7684\u7c7b\u578b<\/p>\n<p>\u4e00\u4e2ajson\u5bf9\u8c61\uff0c\u5176\u683c\u5f0f\u4e3a`{&#8220;type&#8221;:&#8221;typeName&#8221; &#8230;attributes&#8230;}`\uff0c\u5176\u4e2d`typeName`\u4e3a\u539f\u59cb\u7c7b\u578b\u540d\u79f0\u6216\u590d\u6742\u7c7b\u578b\u540d\u79f0\u3002<\/p>\n<p>\u4e00\u4e2ajson\u6570\u7ec4\uff0c\u8868\u793a\u5d4c\u5165\u7c7b\u578b\u7684\u8054\u5408<\/p>\n<p>schema\u4e2d\u7684\u7c7b\u578b\u7531\u539f\u59cb\u7c7b\u578b\uff08\u4e5f\u5c31\u662f\u57fa\u672c\u7c7b\u578b\uff09\uff08null\u3001boolean\u3001int\u3001long\u3001float\u3001double\u3001bytes\u548cstring\uff09\u548c\u590d\u6742\u7c7b\u578b\uff08record\u3001enum\u3001array\u3001map\u3001union\u548cfixed\uff09\u7ec4\u6210\u3002<\/p>\n<p>1\u3001\u539f\u59cb\u7c7b\u578b<\/p>\n<p>\u539f\u59cb\u7c7b\u578b\u5305\u62ec\u5982\u4e0b\u51e0\u79cd\uff1a<\/p>\n<p>null\uff1a\u6ca1\u6709\u503c<\/p>\n<p>boolean\uff1a\u5e03\u5c14\u7c7b\u578b\u7684\u503c<\/p>\n<p>int\uff1a32\u4f4d\u6574\u5f62<\/p>\n<p>long\uff1a64\u4f4d\u6574\u5f62<\/p>\n<p>float\uff1a32\u4f4d\u6d6e\u70b9<\/p>\n<p>double\uff1a64\u4f4d\u6d6e\u70b9<\/p>\n<p>bytes\uff1a8\u4f4d\u65e0\u7b26\u53f7\u7c7b\u578b<\/p>\n<p>string\uff1aunicode\u5b57\u7b26\u96c6\u5e8f\u5217<\/p>\n<p>\u539f\u59cb\u7c7b\u578b\u6ca1\u6709\u6307\u5b9a\u7684\u5c5e\u6027\u503c\uff0c\u539f\u59cb\u7c7b\u578b\u7684\u540d\u79f0\u4e5f\u5c31\u662f\u5b9a\u4e49\u7684\u7c7b\u578b\u7684\u540d\u79f0\uff0c\u56e0\u6b64\uff0cschema\u4e2d\u7684&#8221;string&#8221;\u7b49\u4ef7\u4e8e{&#8220;type&#8221;:&#8221;string&#8221;}\u3002<\/p>\n<p>2\u3001\u590d\u6742\u7c7b\u578b<\/p>\n<p>Avro\u652f\u63016\u79cd\u590d\u6742\u7c7b\u578b\uff1arecords\u3001enums\u3001arrays\u3001maps\u3001unions\u548cfixed\u3002<\/p>\n<p>1\uff09Records<\/p>\n<p>reocrds\u4f7f\u7528\u7c7b\u578b\u540d\u79f0&#8221;record&#8221;\uff0c\u5e76\u652f\u6301\u4ee5\u4e0b\u5c5e\u6027<\/p>\n<p>name\uff1a\u63d0\u4f9b\u8bb0\u5f55\u540d\u79f0\u7684json\u5b57\u7b26\u4e32\uff08\u5fc5\u9009\uff09<\/p>\n<p>namespace\uff1a\u9650\u5b9a\u540d\u79f0\u7684json\u5b57\u7b26\u4e32<\/p>\n<p>doc\uff1a\u4e00\u4e2ajson\u5b57\u7b26\u4e32\uff0c\u4e3a\u7528\u6237\u63d0\u4f9b\u8be5\u6a21\u5f0f\u7684\u8bf4\u660e\uff08\u53ef\u9009\uff09<\/p>\n<p>aliases\uff1a\u5b57\u7b26\u4e32\u7684json\u6570\u7ec4\uff0c\u4e3a\u8be5\u8bb0\u5f55\u63d0\u4f9b\u5907\u7528\u540d\u79f0<\/p>\n<p>fields\uff1a\u4e00\u4e2ajson\u6570\u7ec4\uff0c\u7f57\u5217\u6240\u6709\u5b57\u6bb5\uff08\u5fc5\u9009\uff09\uff0c\u6bcf\u4e2a\u5b57\u6bb5\u53c8\u90fd\u662f\u4e00\u4e2ajson\u5bf9\u8c61\uff0c\u5e76\u5305\u542b\u5982\u4e0b\u5c5e\u6027\uff1a<\/p>\n<p>name\uff1a\u5b57\u6bb5\u7684\u540d\u79f0\uff08\u5fc5\u9009\uff09<\/p>\n<p>doc\uff1a\u5b57\u6bb5\u7684\u63cf\u8ff0\uff08\u53ef\u9009\uff09<\/p>\n<p>type\uff1a\u4e00\u4e2aschema\uff0c\u5b9a\u4e49\u5982\u4e0a<\/p>\n<p>default\uff1a\u5b57\u6bb5\u7684\u9ed8\u8ba4\u503c<\/p>\n<p>order\uff1a\u6307\u5b9a\u5b57\u6bb5\u5982\u4f55\u5f71\u54cd\u8bb0\u5f55\u7684\u6392\u5e8f\u987a\u5e8f\uff0c\u6709\u6548\u503c\u4e3a`&#8221;ascending&#8221;`\uff08\u9ed8\u8ba4\u503c\uff09\u3001&#8221;descending&#8221;\u548c&#8221;ignore&#8221;\u3002<\/p>\n<p>aliases\uff1a\u522b\u540d<\/p>\n<p>\u4e00\u4e2a\u7b80\u5355\u793a\u4f8b\uff1a<\/p>\n<p>{<br \/>\n&#8220;type&#8221;: &#8220;record&#8221;,<br \/>\n&#8220;name&#8221;: &#8220;LongList&#8221;,<br \/>\n&#8220;aliases&#8221;: [&#8220;LinkedLongs&#8221;],<br \/>\n&#8220;fields&#8221;, [<br \/>\n{&#8220;name&#8221;: &#8220;value&#8221;, &#8220;type&#8221;: &#8220;long&#8221;},<br \/>\n{&#8220;name&#8221;: &#8220;next&#8221;, &#8220;type&#8221;: [&#8220;null&#8221;, &#8220;LongList&#8221;]}<br \/>\n]<br \/>\n}<br \/>\n2\uff09Enums<\/p>\n<p>Enum\u4f7f\u7528\u7c7b\u578b\u540d\u79f0&#8221;enum&#8221;\uff0c\u5e76\u652f\u6301\u4ee5\u4e0b\u5c5e\u6027<\/p>\n<p>name\uff1a\u63d0\u4f9b\u8bb0\u5f55\u540d\u79f0\u7684json\u5b57\u7b26\u4e32\uff08\u5fc5\u9009\uff09<\/p>\n<p>namespace\uff1a\u9650\u5b9a\u540d\u79f0\u7684json\u5b57\u7b26\u4e32<\/p>\n<p>aliases\uff1a\u5b57\u7b26\u4e32\u7684json\u6570\u7ec4\uff0c\u4e3a\u8be5\u8bb0\u5f55\u63d0\u4f9b\u5907\u7528\u540d\u79f0<\/p>\n<p>doc\uff1a\u4e00\u4e2ajson\u5b57\u7b26\u4e32\uff0c\u4e3a\u7528\u6237\u63d0\u4f9b\u8be5\u6a21\u5f0f\u7684\u8bf4\u660e\uff08\u53ef\u9009\uff09<\/p>\n<p>symbols\uff1a\u4e00\u4e2ajson\u6570\u7ec4\uff0c\u4ee5json\u5b57\u7b26\u4e32\u7684\u5f62\u5f0f\u5217\u51fa\u7b26\u53f7\u3002\u5728\u679a\u4e3e\u4e2d\u6bcf\u4e2a\u7b26\u53f7\u5fc5\u987b\u552f\u4e00\uff0c\u4e0d\u80fd\u91cd\u590d\uff0c\u6bcf\u4e2a\u7b26\u53f7\u90fd\u5fc5\u987b\u5339\u914d\u6b63\u5219\u8868\u8fbe\u5f0f&#8221;[A-Za-z_][A-Za-z0-9_]*&#8221;\u3002<\/p>\n<p>default\uff1a\u8be5\u679a\u4e3e\u7684\u9ed8\u8ba4\u503c\u3002<\/p>\n<p>\u793a\u4f8b\uff1a<\/p>\n<p>{<br \/>\n&#8220;type&#8221;: &#8220;enum&#8221;,<br \/>\n&#8220;name&#8221;: &#8220;Suit&#8221;,<br \/>\n&#8220;symbols&#8221;: [&#8220;SPADES&#8221;, &#8220;HEARTS&#8221;, &#8220;DIAMONDS&#8221;, &#8220;CLUBS&#8221;]<br \/>\n}<br \/>\n3\uff09 Arrays<\/p>\n<p>item\uff1a\u6570\u7ec4\u4e2d\u5143\u7d20\u7684schema<\/p>\n<p>\u4e00\u4e2a\u4f8b\u5b50\uff1a\u58f0\u660e\u4e00\u4e2avalue\u4e3astring\u7684array<\/p>\n<p>{<br \/>\n&#8220;type&#8221;: &#8220;array&#8221;,<br \/>\n&#8220;items&#8221;: &#8220;string&#8221;,<br \/>\n&#8220;default&#8221;: []<br \/>\n}<br \/>\n4\uff09Maps<\/p>\n<p>values\uff1amap\u7684\u503c\uff08value\uff09\u7684schema\uff0c\u5176key\u88ab\u5047\u5b9a\u4e3a\u5b57\u7b26\u4e32<\/p>\n<p>\u4e00\u4e2a\u4f8b\u5b50\uff1a\u58f0\u660e\u4e00\u4e2avalue\u4e3along\u7c7b\u578b\uff0c\uff08key\u7c7b\u578b\u4e3astring\uff09\u7684map<\/p>\n<p>{<br \/>\n&#8220;type&#8221;: &#8220;map&#8221;,<br \/>\n&#8220;values&#8221;: &#8220;long&#8221;,<br \/>\n&#8220;default&#8221;: {}<br \/>\n}<br \/>\n5\uff09Unions<\/p>\n<p>\u8054\u5408\u4f7f\u7528json\u6570\u7ec4\u8868\u793a\uff0c\u4f8b\u5982[null, &#8220;test&#8221;]\u58f0\u660e\u4e00\u4e2a\u6a21\u5f0f\uff0c\u5b83\u53ef\u4ee5\u662f\u7a7a\u503c\u6216\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff1a\u5f53\u4e3aunion\u7c7b\u578b\u7684\u5b57\u6bb5\u6307\u5b9a\u9ed8\u8ba4\u503c\u65f6\uff0c\u9ed8\u8ba4\u503c\u7684\u7c7b\u578b\u5fc5\u987b\u4e0eunion\u7b2c\u4e00\u4e2a\u5143\u7d20\u5339\u914d\uff0c\u56e0\u6b64\uff0c\u5bf9\u4e8e\u5305\u542b&#8221;null&#8221;\u7684union\uff0c\u901a\u5e38\u5148\u5217\u51fa&#8221;null&#8221;\uff0c\u56e0\u4e3a\u6b64\u7c7b\u578b\u7684union\u7684\u9ed8\u8ba4\u503c\u901a\u5e38\u4e3a\u7a7a\u3002<\/p>\n<p>\u53e6\u5916\uff0c union\u4e0d\u80fd\u5305\u542b\u591a\u4e2a\u76f8\u540c\u7c7b\u578b\u7684schema\uff0c\u7c7b\u578b\u4e3arecord\u3001fixed\u548ceum\u9664\u5916\u3002<\/p>\n<p>6\uff09Fixed<\/p>\n<p>Fixed\u4f7f\u7528\u7c7b\u578b\u540d\u79f0&#8221;fixed&#8221;\u5e76\u652f\u6301\u4ee5\u4e0b\u5c5e\u6027\uff1a<\/p>\n<p>name\uff1a\u63d0\u4f9b\u8bb0\u5f55\u540d\u79f0\u7684json\u5b57\u7b26\u4e32\uff08\u5fc5\u9009\uff09<\/p>\n<p>namespace\uff1a\u9650\u5b9a\u540d\u79f0\u7684json\u5b57\u7b26\u4e32<\/p>\n<p>aliases\uff1a\u5b57\u7b26\u4e32\u7684json\u6570\u7ec4\uff0c\u4e3a\u8be5\u8bb0\u5f55\u63d0\u4f9b\u5907\u7528\u540d\u79f0<\/p>\n<p>doc\uff1a\u4e00\u4e2ajson\u5b57\u7b26\u4e32\uff0c\u4e3a\u7528\u6237\u63d0\u4f9b\u8be5\u6a21\u5f0f\u7684\u8bf4\u660e\uff08\u53ef\u9009\uff09<\/p>\n<p>size\uff1a\u4e00\u4e2a\u6574\u6570\uff0c\u6307\u5b9a\u6bcf\u4e2a\u503c\u7684\u5b57\u8282\u6570\uff08\u5fc5\u987b\uff09<\/p>\n<p>\u4f8b\u5982\uff0c16\u5b57\u8282\u7684\u6570\u53ef\u4ee5\u58f0\u660e\u4e3a\uff1a<\/p>\n<p>{<br \/>\n&#8220;type&#8221;: &#8220;fixed&#8221;,<br \/>\n&#8220;name&#8221;: &#8220;md5&#8221;,<br \/>\n&#8220;size&#8221;: 16<br \/>\n}<br \/>\n\u3010Avro\u7684\u6587\u4ef6\u5b58\u50a8\u683c\u5f0f\u3011<\/p>\n<p>1\u3001\u6570\u636e\u7f16\u7801<\/p>\n<p>1\uff09\u539f\u59cb\u7c7b\u578b<\/p>\n<p>\u5bf9\u4e8enull\u7c7b\u578b\uff1a\u4e0d\u5199\u5165\u5185\u5bb9\uff0c\u53730\u5b57\u8282\u957f\u5ea6\u7684\u5185\u5bb9\u8868\u793a\uff1b<\/p>\n<p>\u5bf9\u4e8eboolean\u7c7b\u578b\uff1a\u4ee51\u5b57\u8282\u76840\u62161\u6765\u8868\u793afalse\u6216true\uff1b<\/p>\n<p>\u5bf9\u4e8eint\u3001long\uff1a\u4ee5zigzag\u7684\u65b9\u5f0f\u7f16\u7801\u5199\u5165<\/p>\n<p>\u5bf9\u4e8efloat\uff1a\u56fa\u5b9a4\u5b57\u8282\u957f\u5ea6\uff0c\u5148\u901a\u8fc7floatToIntBits\u8f6c\u6362\u4e3a32\u4f4d\u6574\u6570\uff0c\u7136\u540e\u6309\u5c0f\u7aef\u7f16\u7801\u5199\u5165\u3002<\/p>\n<p>\u5bf9\u4e8edouble\uff1a\u56fa\u5b9a8\u5b57\u8282\u957f\u5ea6\uff0c\u5148\u901a\u8fc7doubleToLongBits\u8f6c\u6362\u4e3a64\u4f4d\u6574\u578b\uff0c\u7136\u540e\u6309\u5c0f\u7aef\u7f16\u7801\u5199\u5165\u3002<\/p>\n<p>\u5bf9\u4e8ebytes\uff1a\u5148\u5199\u5165\u957f\u5ea6\uff08\u91c7\u7528zigzag\u7f16\u7801\u5199\u5165\uff09\uff0c\u7136\u540e\u662f\u5bf9\u5e94\u957f\u5ea6\u7684\u4e8c\u8fdb\u5236\u6570\u636e\u5185\u5bb9<\/p>\n<p>\u5bf9\u4e8estring\uff1a\u540c\u6837\u5148\u5199\u5165\u957f\u5ea6\uff08\u91c7\u7528zigzag\u7f16\u7801\u5199\u5165\uff09\uff0c\u7136\u540e\u518d\u5199\u5165\u5b57\u7b26\u4e32\u5bf9\u5e94utf8\u7684\u4e8c\u8fdb\u5236\u6570\u636e\u3002<\/p>\n<p>2\uff09\u590d\u6742\u7c7b\u578b<\/p>\n<p>\u5bf9\u4e8eenums\uff1a\u53ea\u9700\u8981\u5c06enum\u7684\u503c\u6240\u5728\u7684Index\u4f5c\u4e3a\u7ed3\u679c\u8fdb\u884c\u7f16\u7801\u5373\u53ef\uff0c\u4f8b\u5982\uff0c\u679a\u4e3e\u503c\u4e3a[&#8220;A&#8221;,&#8221;B&#8221;,&#8221;C&#8221;,&#8221;D&#8221;]\uff0c\u90a3\u4e480\u5c31\u8868\u793a\u201dA\u201c\uff0c3\u8868\u793a&#8221;D&#8221;\u3002<\/p>\n<p>\u5bf9\u4e8emaps\uff1a\u88ab\u7f16\u7801\u4e3a\u4e00\u7cfb\u5217\u7684\u5757\u3002\u6bcf\u4e2a\u5757\u7531\u4e00\u4e2a\u957f\u6574\u6570\u7684\u8ba1\u6570\u8868\u793a\u952e\u503c\u5bf9\u7684\u4e2a\u6570\uff08\u91c7\u7528zigzag\u7f16\u7801\u5199\u5165\uff09\uff0c\u5176\u540e\u662f\u591a\u4e2a\u952e\u503c\u5bf9\uff0c\u8ba1\u6570\u4e3a0\u7684\u5757\u8868\u793amap\u7684\u7ed3\u675f\u3002\u6bcf\u4e2a\u5143\u7d20\u6309\u7167\u5404\u81ea\u7684schema\u7c7b\u578b\u8fdb\u884c\u7f16\u7801\u3002<\/p>\n<p>\u5bf9\u4e8earrays\uff1a\u4e0emap\u7c7b\u4f3c\uff0c\u540c\u6837\u88ab\u7f16\u7801\u4e3a\u4e00\u7cfb\u5217\u7684\u5757\uff0c\u6bcf\u4e2a\u5757\u5305\u542b\u4e00\u4e2a\u957f\u6574\u6570\u7684\u8ba1\u6570\uff0c\u8ba1\u6570\u540e\u8ddf\u5177\u4f53\u7684\u6570\u7ec4\u9879\u5185\u5bb9\uff0c\u6700\u540e\u4ee50\u8ba1\u6570\u7684\u5757\u8868\u793a\u7ed3\u675f\u3002\u6570\u7ec4\u9879\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u6309\u7167\u5404\u81ea\u7684schema\u7c7b\u578b\u8fdb\u884c\u7f16\u7801\u3002<\/p>\n<p>\u5bf9\u4e8eunions\uff1a\u5148\u5199\u5165long\u7c7b\u578b\u7684\u8ba1\u6570\u8868\u793a\u6bcf\u4e2avalue\u503c\u7684\u4f4d\u7f6e\u5e8f\u53f7\uff08\u4ece\u96f6\u5f00\u59cb\uff09\uff0c\u7136\u540e\u518d\u5bf9\u503c\u6309\u5bf9\u5e94schema\u8fdb\u884c\u7f16\u7801\u3002<\/p>\n<p>\u5bf9\u4e8erecords\uff1a\u76f4\u63a5\u6309\u7167schema\u4e2d\u7684\u5b57\u6bb5\u987a\u5e8f\u6765\u8fdb\u884c\u7f16\u7801\u3002<\/p>\n<p>\u5bf9\u4e8efixed\uff1a\u4f7f\u7528schema\u4e2d\u5b9a\u4e49\u7684\u5b57\u8282\u6570\u5bf9\u5b9e\u4f8b\u8fdb\u884c\u7f16\u7801\u3002<\/p>\n<p>2\u3001\u5b58\u50a8\u683c\u5f0f<\/p>\n<p>\u5728\u4e00\u4e2a\u6807\u51c6\u7684avro\u6587\u4ef6\u4e2d\uff0c\u540c\u65f6\u5b58\u50a8\u4e86schema\u7684\u4fe1\u606f\uff0c\u4ee5\u53ca\u5bf9\u5e94\u7684\u6570\u636e\u5185\u5bb9\u3002\u5177\u4f53\u683c\u5f0f\u7531\u4e09\u90e8\u5206\u7ec4\u6210\uff1a<\/p>\n<p>\u9b54\u6570<\/p>\n<p>\u56fa\u5b9a4\u5b57\u8282\u957f\u5ea6\uff0c\u5185\u5bb9\u4e3a\u5b57\u7b26&#8217;O&#8217;\uff0c&#8217;b&#8217;\uff0c&#8217;j&#8217;\uff0c\u4ee5\u53ca\u7248\u672c\u53f7\u6807\u8bc6\uff0c\u901a\u5e38\u4e3a1\u3002<\/p>\n<p>\u5143\u6570\u636e\u4fe1\u606f<\/p>\n<p>\u6587\u4ef6\u7684\u5143\u6570\u636e\u5c5e\u6027\uff0c\u5305\u62ecschema\u3001\u6570\u636e\u538b\u7f29\u7f16\u7801\u65b9\u5f0f\u7b49\u3002\u6574\u4e2a\u5143\u6570\u636e\u5c5e\u6027\u4ee5\u4e00\u4e2amap\u7684\u5f62\u5f0f\u7f16\u7801\u5b58\u50a8\uff0c\u6bcf\u4e2a\u5c5e\u6027\u90fd\u4ee5\u4e00\u4e2aKV\u7684\u5f62\u5f0f\u5b58\u50a8\uff0c\u5c5e\u6027\u540d\u5bf9\u5e94key\uff0c\u5c5e\u6027\u503c\u5bf9\u5e94value\uff0c\u5e76\u4ee5\u5b57\u8282\u6570\u7ec4\u7684\u5f62\u5f0f\u5b58\u50a8\u3002\u6700\u540e\u4ee5\u4e00\u4e2a\u56fa\u5b9a16\u5b57\u8282\u957f\u5ea6\u7684\u968f\u673a\u5b57\u7b26\u4e32\u6807\u8bc6\u5143\u6570\u636e\u7684\u7ed3\u675f\u3002<\/p>\n<p>\u6570\u636e\u5185\u5bb9<\/p>\n<p>\u800c\u6570\u636e\u5185\u5bb9\u5219\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u6570\u636e\u5757\u6784\u6210\u3002\u6bcf\u4e2a\u6570\u636e\u5757\u7684\u6700\u524d\u9762\u662f\u4e00\u4e2along\u578b\uff08\u6309\u7167zigzag\u7f16\u7801\u5b58\u50a8\uff09\u7684\u8ba1\u6570\u8868\u793a\u8be5\u6570\u636e\u5757\u4e2d\u5b9e\u9645\u6709\u591a\u5c11\u6761\u6570\u636e\uff0c\u540e\u9762\u518d\u8ddf\u4e00\u4e2along\u578b\u7684\u8ba1\u6570\u8868\u793a\u7f16\u7801\u540e\u7684\uff08N\u6761\uff09\u6570\u636e\u7684\u957f\u5ea6\uff0c\u968f\u540e\u5c31\u662f\u6309\u7167\u7f16\u7801\u8fdb\u884c\u5b58\u50a8\u7684\u4e00\u6761\u6761\u6570\u636e\uff0c\u5728\u6bcf\u4e2a\u6570\u636e\u5757\u7684\u6700\u540e\u90fd\u6709\u4e00\u4e2a16\u5b57\u8282\u957f\u5ea6\u7684\u968f\u673a\u5b57\u7b26\u4e32\u6807\u8bc6\u5757\u7684\u7ed3\u675f\u3002<\/p>\n<p>\u6574\u4f53\u5b58\u50a8\u5185\u5bb9\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p>&nbsp;<\/p>\n<p>3\u3001\u5b58\u50a8\u683c\u5f0f<\/p>\n<p>\u6211\u4eec\u901a\u8fc7\u4e00\u4e2a\u5b9e\u9645\u4f8b\u5b50\u6765\u5bf9\u7167\u5206\u6790\u4e0b\u3002<\/p>\n<p>\u9996\u5148\u5b9a\u4e49schema\u7684\u5185\u5bb9\uff0c\u5177\u4f53\u4e3a4\u4e2a\u5b57\u6bb5\u7684\u8868\uff0c\u540d\u79f0\uff08\u5b57\u7b26\u4e32\uff09\u3001\u5e74\u9f84\uff08\u6574\u578b\uff09\u3001\u6280\u80fd\uff08\u6570\u7ec4\uff09\u3001\u5176\u4ed6\uff08map\u7c7b\u578b\uff09\uff0c\u8be6\u7ec6\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p>{<br \/>\n&#8220;type&#8221;:&#8221;record&#8221;,<br \/>\n&#8220;name&#8221;:&#8221;person&#8221;,<br \/>\n&#8220;fields&#8221;: [<br \/>\n{<br \/>\n&#8220;name&#8221;: &#8220;name&#8221;,<br \/>\n&#8220;type&#8221;: &#8220;string&#8221;<br \/>\n},<br \/>\n{<br \/>\n&#8220;name&#8221;: &#8220;age&#8221;,<br \/>\n&#8220;type&#8221;: &#8220;int&#8221;<br \/>\n},<br \/>\n{<br \/>\n&#8220;name&#8221;: &#8220;skill&#8221;,<br \/>\n&#8220;type&#8221;: {<br \/>\n&#8220;type&#8221;:&#8221;array&#8221;,<br \/>\n&#8220;items&#8221;: &#8220;string&#8221;<br \/>\n}<br \/>\n},<br \/>\n{<br \/>\n&#8220;name&#8221;: &#8220;other&#8221;,<br \/>\n&#8220;type&#8221;: {<br \/>\n&#8220;type&#8221;: &#8220;map&#8221;,<br \/>\n&#8220;values&#8221;: &#8220;string&#8221;<br \/>\n}<br \/>\n}<br \/>\n]<br \/>\n}<br \/>\n\u518d\u6309\u7167\u4e0a\u9762\u7684schema\u5b9a\u4e49\u4e24\u6761\u6570\u636e\uff08person.json\uff09\uff1a<\/p>\n<p>{&#8220;name&#8221;:&#8221;hncscwc&#8221;,&#8221;age&#8221;:20,&#8221;skill&#8221;:[&#8220;hadoop&#8221;,&#8221;flink&#8221;,&#8221;spark&#8221;,&#8221;kafka&#8221;],&#8221;other&#8221;:{&#8220;interests&#8221;:&#8221;basketball&#8221;}}<br \/>\n{&#8220;name&#8221;:&#8221;tom&#8221;,&#8221;age&#8221;:18, &#8220;skill&#8221;:[&#8220;java&#8221;,&#8221;scala&#8221;],&#8221;other&#8221;:{}}<br \/>\n\u901a\u8fc7avro-tools\u53ef\u4ee5\u751f\u6210\u4e00\u4e2aavro\u6587\u4ef6\uff1a<\/p>\n<p>java -jar avro-tools-1.7.4.jar fromjson &#8211;schema-file person.avsc person.json &gt; person.avro<br \/>\n\u901a\u8fc7\u4e8c\u8fdb\u5236\u7684\u65b9\u5f0f\u67e5\u770b\u751f\u6210\u7684avro\u6587\u4ef6\u5185\u5bb9\uff1a<\/p>\n<p>&nbsp;<\/p>\n<p>\u53e6\u5916\uff0c\u5bf9\u4e8e\u4e00\u4e2a\u5df2\u5b58\u5728\u7684\u6587\u4ef6\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7avro-tools\u5de5\u5177\u67e5\u770bschema\u5185\u5bb9\u3001\u6570\u636e\u5185\u5bb9\u3002<\/p>\n<p>[root@localhost avro]$ java -jar avro-tools-1.7.4.jar getschema .\/person.avro<br \/>\n{<br \/>\n&#8220;type&#8221; : &#8220;record&#8221;,<br \/>\n&#8220;name&#8221; : &#8220;person&#8221;,<br \/>\n&#8220;fields&#8221; : [ {<br \/>\n&#8220;name&#8221; : &#8220;name&#8221;,<br \/>\n&#8220;type&#8221; : &#8220;string&#8221;<br \/>\n}, {<br \/>\n&#8220;name&#8221; : &#8220;age&#8221;,<br \/>\n&#8220;type&#8221; : &#8220;int&#8221;<br \/>\n}, {<br \/>\n&#8220;name&#8221; : &#8220;skill&#8221;,<br \/>\n&#8220;type&#8221; : {<br \/>\n&#8220;type&#8221; : &#8220;array&#8221;,<br \/>\n&#8220;items&#8221; : &#8220;string&#8221;<br \/>\n}<br \/>\n}, {<br \/>\n&#8220;name&#8221; : &#8220;other&#8221;,<br \/>\n&#8220;type&#8221; : {<br \/>\n&#8220;type&#8221; : &#8220;map&#8221;,<br \/>\n&#8220;values&#8221; : &#8220;string&#8221;<br \/>\n}<br \/>\n} ]<br \/>\n}<br \/>\n[root@localhost avro]$ java -jar avro-tools-1.7.4.jar tojson .\/person.avro<br \/>\n{&#8220;name&#8221;:&#8221;hncscwc&#8221;,&#8221;age&#8221;:20,&#8221;skill&#8221;:[&#8220;hadoop&#8221;,&#8221;flink&#8221;,&#8221;spark&#8221;,&#8221;kafka&#8221;],&#8221;other&#8221;:{&#8220;interests&#8221;:&#8221;basketball&#8221;}}<br \/>\n{&#8220;name&#8221;:&#8221;tom&#8221;,&#8221;age&#8221;:18,&#8221;skill&#8221;:[&#8220;java&#8221;,&#8221;scala&#8221;],&#8221;other&#8221;:{}}<br \/>\n\u3010\u5c0f\u7ed3\u3011<\/p>\n<p>\u672c\u6587\u5bf9avro\u7684\u683c\u5f0f\u5b9a\u4e49\u3001\u7f16\u7801\u65b9\u5f0f\u3001\u4ee5\u53ca\u5b9e\u9645\u5b58\u50a8\u7684\u6587\u4ef6\u683c\u5f0f\u8fdb\u884c\u4e86\u8be6\u7ec6\u8bf4\u660e\uff0c\u6700\u540e\u4e5f\u4ee5\u4e00\u4e2a\u5b9e\u9645\u4f8b\u5b50\u8fdb\u884c\u4e86\u5bf9\u7167\u8bf4\u660e\u3002\u53e6\u5916\uff0c \u5728\u5b98\u7f51\u4e2d\u8fd8\u6d89\u53carpc\u7684\u4f7f\u7528\u3001mapreduce\u7684\u4f7f\u7528\uff0c\u8fd9\u91cc\u5c31\u6ca1\u6709\u5c55\u5f00\u8bf4\u660e\uff0c\u6709\u5174\u8da3\u7684\u53ef\u79fb\u6b65\u5b98\u7f51\u8fdb\u884c\u67e5\u9605\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u8fd9\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\uff0c\u5982\u679c\u89c9\u5f97\u672c\u6587\u5bf9\u60a8\u6709\u5e2e\u52a9\uff0c\u8bf7\u70b9\u8d5e+\u8f6c\u53d1\uff0c\u5982\u679c\u89c9\u5f97\u6709\u4e0d\u6b63\u786e\u7684\u5730\u65b9\uff0c\u4e5f\u53ef\u4ee5\u62cd\u7816\u6307\u70b9\uff0c\u6700\u540e\uff0c\u6b22\u8fce\u52a0\u6211\u5fae\u4fe1\u4ea4\u6d41\uff5e<\/p>\n<p>\u6587\u7ae0\u77e5\u8bc6\u70b9\u4e0e\u5b98\u65b9\u77e5\u8bc6\u6863\u6848\u5339\u914d\uff0c\u53ef\u8fdb\u4e00\u6b65\u5b66\u4e60\u76f8\u5173\u77e5\u8bc6<\/p>\n","protected":false},"excerpt":{"rendered":"<p>cc from \u3010Avro\u4ecb\u7ecd\u3011 Apa<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[24],"tags":[121],"class_list":["post-7041","post","type-post","status-publish","format-standard","hentry","category-value_docs","tag-05-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/7041","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=7041"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/7041\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=7041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=7041"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=7041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}