{"id":61569,"date":"2024-10-13T12:04:16","date_gmt":"2024-10-13T04:04:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/61569\/"},"modified":"2024-10-13T12:04:16","modified_gmt":"2024-10-13T04:04:16","slug":"hive-%e5%85%a7%e7%bd%ae%e7%9a%84-json-%e8%a7%a3%e6%9e%90%e5%87%bd%e6%95%b8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/61569\/","title":{"rendered":"Hive \u5167\u7f6e\u7684 Json \u89e3\u6790\u51fd\u6578"},"content":{"rendered":"<h1 id=\"hive-%e5%85%a7%e7%bd%ae%e7%9a%84-json-%e8%a7%a3%e6%9e%90%e5%87%bd%e6%95%b8-CvFjWnbkPA\">Hive \u5167\u7f6e\u7684 JSON \u89e3\u6790\u51fd\u6578<\/h1>\n<p>\u5728\u5927\u6578\u64da\u8655\u7406\u7684\u9818\u57df\u4e2d\uff0cApache Hive \u4f5c\u70ba\u4e00\u500b\u6578\u64da\u5009\u5eab\u57fa\u790e\u8a2d\u65bd\uff0c\u63d0\u4f9b\u4e86\u5f37\u5927\u7684\u67e5\u8a62\u529f\u80fd\uff0c\u7279\u5225\u662f\u5728\u8655\u7406\u7d50\u69cb\u5316\u548c\u534a\u7d50\u69cb\u5316\u6578\u64da\u65b9\u9762\u3002\u96a8\u8457 JSON \u683c\u5f0f\u7684\u5ee3\u6cdb\u61c9\u7528\uff0cHive \u5167\u7f6e\u7684 JSON \u89e3\u6790\u51fd\u6578\u6210\u70ba\u4e86\u6578\u64da\u5206\u6790\u5e2b\u548c\u5de5\u7a0b\u5e2b\u7684\u91cd\u8981\u5de5\u5177\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e Hive \u4e2d\u7684 JSON \u89e3\u6790\u51fd\u6578\uff0c\u5305\u62ec\u5176\u529f\u80fd\u3001\u4f7f\u7528\u65b9\u6cd5\u53ca\u5be6\u969b\u61c9\u7528\u793a\u4f8b\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-json%ef%bc%9f-CvFjWnbkPA\">\u4ec0\u9ebc\u662f JSON\uff1f<\/h2>\n<p>JSON\uff08JavaScript Object Notation\uff09\u662f\u4e00\u7a2e\u8f15\u91cf\u7d1a\u7684\u6578\u64da\u4ea4\u63db\u683c\u5f0f\uff0c\u6613\u65bc\u4eba\u985e\u95b1\u8b80\u548c\u7de8\u5beb\uff0c\u540c\u6642\u4e5f\u6613\u65bc\u6a5f\u5668\u89e3\u6790\u548c\u751f\u6210\u3002\u7531\u65bc\u5176\u7d50\u69cb\u7c21\u55ae\uff0cJSON \u88ab\u5ee3\u6cdb\u61c9\u7528\u65bc Web \u61c9\u7528\u7a0b\u5e8f\u4e2d\uff0c\u7279\u5225\u662f\u5728 API \u6578\u64da\u50b3\u8f38\u4e2d\u3002<\/p>\n<h2 id=\"hive-%e4%b8%ad%e7%9a%84-json-%e8%a7%a3%e6%9e%90%e5%87%bd%e6%95%b8-CvFjWnbkPA\">Hive \u4e2d\u7684 JSON \u89e3\u6790\u51fd\u6578<\/h2>\n<p>Hive \u63d0\u4f9b\u4e86\u5e7e\u500b\u5167\u7f6e\u51fd\u6578\u4f86\u89e3\u6790 JSON \u6578\u64da\uff0c\u4e3b\u8981\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><code>get_json_object<\/code><\/li>\n<li><code>json_tuple<\/code><\/li>\n<\/ul>\n<h3 id=\"1-get_json_object-CvFjWnbkPA\">1. get_json_object<\/h3>\n<p><code>get_json_object<\/code> \u51fd\u6578\u7528\u65bc\u5f9e JSON \u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u6307\u5b9a\u7684\u5b57\u6bb5\u3002\u5176\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>get_json_object(json_string, json_path)<\/code><\/pre>\n<p>\u5176\u4e2d\uff0c<code>json_string<\/code> \u662f\u8981\u89e3\u6790\u7684 JSON \u5b57\u7b26\u4e32\uff0c<code>json_path<\/code> \u662f\u6307\u5b9a\u8981\u63d0\u53d6\u7684\u5b57\u6bb5\u8def\u5f91\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u793a\u4f8b\uff1a<\/p>\n<pre><code>SELECT get_json_object('{\"name\":\"John\", \"age\":30}', '$.name') AS name;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\u7d50\u679c\uff1a<\/p>\n<pre><code>name\n-----\nJohn<\/code><\/pre>\n<h3 id=\"2-json_tuple-CvFjWnbkPA\">2. json_tuple<\/h3>\n<p><code>json_tuple<\/code> \u51fd\u6578\u7528\u65bc\u5f9e JSON \u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u591a\u500b\u5b57\u6bb5\u3002\u5176\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>json_tuple(json_string, field1, field2, ...)<\/code><\/pre>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u793a\u4f8b\uff1a<\/p>\n<pre><code>SELECT json_tuple('{\"name\":\"John\", \"age\":30}', 'name', 'age') AS (name, age);<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\u7d50\u679c\uff1a<\/p>\n<pre><code>name   | age\n-------|-----\nJohn   | 30<\/code><\/pre>\n<h2 id=\"%e5%af%a6%e9%9a%9b%e6%87%89%e7%94%a8%e7%a4%ba%e4%be%8b-CvFjWnbkPA\">\u5be6\u969b\u61c9\u7528\u793a\u4f8b<\/h2>\n<p>\u5728\u5be6\u969b\u61c9\u7528\u4e2d\uff0cJSON \u89e3\u6790\u51fd\u6578\u53ef\u4ee5\u7528\u65bc\u8655\u7406\u4f86\u81ea API \u7684\u6578\u64da\uff0c\u6216\u662f\u5f9e\u65e5\u8a8c\u6587\u4ef6\u4e2d\u63d0\u53d6\u4fe1\u606f\u3002\u4f8b\u5982\uff0c\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u5305\u542b\u7528\u6236\u4fe1\u606f\u7684 JSON \u6578\u64da\u96c6\uff0c\u4e26\u5e0c\u671b\u63d0\u53d6\u7528\u6236\u7684\u96fb\u5b50\u90f5\u4ef6\u5730\u5740\u548c\u8a3b\u518a\u65e5\u671f\uff1a<\/p>\n<pre><code>SELECT get_json_object(user_info, '$.email') AS email,\n       get_json_object(user_info, '$.registration_date') AS registration_date\nFROM users;<\/code><\/pre>\n<p>\u9019\u6a23\u7684\u67e5\u8a62\u53ef\u4ee5\u5e6b\u52a9\u6211\u5011\u5feb\u901f\u7372\u53d6\u6240\u9700\u7684\u4fe1\u606f\uff0c\u4e26\u9032\u884c\u9032\u4e00\u6b65\u7684\u6578\u64da\u5206\u6790\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-CvFjWnbkPA\">\u7e3d\u7d50<\/h2>\n<p>Hive \u5167\u7f6e\u7684 JSON \u89e3\u6790\u51fd\u6578\u70ba\u6578\u64da\u5206\u6790\u63d0\u4f9b\u4e86\u5f37\u5927\u7684\u652f\u6301\uff0c\u4f7f\u5f97\u8655\u7406 JSON \u683c\u5f0f\u7684\u6578\u64da\u8b8a\u5f97\u66f4\u52a0\u9ad8\u6548\u3002\u901a\u904e\u4f7f\u7528 <code>get_json_object<\/code> \u548c <code>json_tuple<\/code> \u51fd\u6578\uff0c\u6578\u64da\u5206\u6790\u5e2b\u53ef\u4ee5\u8f15\u9b06\u63d0\u53d6\u6240\u9700\u7684\u5b57\u6bb5\uff0c\u9032\u884c\u6df1\u5165\u7684\u6578\u64da\u5206\u6790\u3002\u5c0d\u65bc\u9700\u8981\u8655\u7406\u5927\u91cf JSON \u6578\u64da\u7684\u4f01\u696d\u4f86\u8aaa\uff0c\u9019\u4e9b\u51fd\u6578\u7121\u7591\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u5de5\u5177\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684\u6578\u64da\u5206\u6790\u9700\u6c42\uff0cServer.HK \u63d0\u4f9b\u4e86\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u8f15\u9b06\u7ba1\u7406\u548c\u8655\u7406\u6578\u64da\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22 Hive \u5167\u7f6e\u7684 JSON \u89e3\u6790\u51fd\u6578\uff0c\u8f15\u9b06\u8655\u7406\u548c\u5206\u6790 JSON \u6578\u64da\uff0c\u63d0\u5347\u6578\u64da\u67e5\u8a62\u6548\u7387\u8207\u9748\u6d3b\u6027\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-61569","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61569","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=61569"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61569\/revisions"}],"predecessor-version":[{"id":61570,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61569\/revisions\/61570"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=61569"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=61569"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=61569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}