{"id":2214,"date":"2023-07-27T23:14:24","date_gmt":"2023-07-27T15:14:24","guid":{"rendered":"http:\/\/viplao.com\/?p=2214"},"modified":"2023-07-27T23:18:13","modified_gmt":"2023-07-27T15:18:13","slug":"hive-sql%ef%bc%9a%e5%b7%a5%e4%bd%9c%e4%b8%ad%e5%b8%b8%e7%94%a8hsql%e8%af%ad%e5%8f%a5%e5%a4%a7%e5%85%a8-%e4%ba%8c","status":"publish","type":"post","link":"http:\/\/viplao.com\/index.php\/2023\/07\/27\/hive-sql%ef%bc%9a%e5%b7%a5%e4%bd%9c%e4%b8%ad%e5%b8%b8%e7%94%a8hsql%e8%af%ad%e5%8f%a5%e5%a4%a7%e5%85%a8-%e4%ba%8c\/","title":{"rendered":"HIVE SQL\uff1a\u5de5\u4f5c\u4e2d\u5e38\u7528HSQL\u8bed\u53e5\u5927\u5168 \u4e8c"},"content":{"rendered":"\n<p><strong>1\u3001 hive\u4e66\u5199\u987a\u5e8f<\/strong>&nbsp; &#8212; 1\uff09hive\u4e66\u5199\u987a\u5e8f<\/p>\n\n\n\n<ul>\n<li><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>select \u2026\u2026from \u2026\u2026where \u2026\u2026group by\u2026\u2026having\u2026\u2026order by\u2026\u2026limit<\/code><\/pre>\n\n\n\n<p>&nbsp;&#8212; 2\uff09sql\u6267\u884c\u987a\u5e8f\uff08having &#8211;\u8fc7\u6ee4\u5206\u7ec4\uff09<\/p>\n\n\n\n<ul>\n<li><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from \u2026\u2026where \u2026\u2026group by \u2026\u2026having \u2026\u2026select \u2026\u2026order by\u2026\u2026limit<\/code><\/pre>\n\n\n\n<p><strong>2\u3001\u8fde\u8868\uff0c\u6761\u4ef6\u653e\u5728on\u540e\u8fb9\u8fd8\u662f\u653e\u5728where\u540e\u8fb9\u7684\uff1f<\/strong>&nbsp; \u5bf9\u4e8eleft join\uff0c\u4e0d\u7ba1on\u540e\u9762\u8ddf\u4ec0\u4e48\u6761\u4ef6\uff0c\u5de6\u8868\u7684\u6570\u636e\u5168\u90e8\u67e5\u51fa\u6765\uff0c\u56e0\u6b64\u8981\u60f3\u8fc7\u6ee4\u9700\u628a\u6761\u4ef6\u653e\u5230where\u540e\u9762\u3002&nbsp; \u5bf9\u4e8einner join\uff0c\u6ee1\u8db3on\u540e\u9762\u7684\u6761\u4ef6\u8868\u7684\u6570\u636e\u624d\u80fd\u67e5\u51fa\uff0c\u53ef\u4ee5\u8d77\u5230\u8fc7\u6ee4\u4f5c\u7528\uff0c\u4e5f\u53ef\u4ee5\u628a\u6761\u4ef6\u653e\u5230where\u540e\u9762\u3002&nbsp;&nbsp;&#8211;\u8fde\u8868\u67e5\u8be2\uff0c\u628a\u6761\u4ef6\u653e\u5728where\u540e\u9762\u6700\u7a33\u59a5<strong>3\u3001\u5904\u7406\u65e5\u671f\u6570\u636e\u548c\u65f6\u95f4\u6233<\/strong>&nbsp;\u79d2\u7ea7\u522b &nbsp;10\u4f4d\u6b63\u6574\u6570\uff1b\u6beb\u79d2\u7ea7\u522b 13\u4f4d\u6b63\u6574\u6570\uff081\uff0910\u4f4d\u6b63\u6574\u6570\u79d2\u7ea7\u522b -\u8f6c\u65e5\u671f\u51fd\u6570\uff1afrom_unixtime(bigint unixtime[, string format]) &nbsp;&#8212; \u8fd4\u56de\u503c: string<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>from_unixtime(create_time,'yyyy\/MM\/dd'), -- create_time \u662f10\u4f4d\u6beb\u79d2\u7ea7\u522b\uff0c\u83b7\u53d6\u5e74\u6708\u65e5<\/code>\n<code>from_unixtime(create_time,'yyyy\/MM\/dd HH:mm:ss'), -- \u83b7\u53d6\u5e74\u6708\u65e5\u65f6\u5206\u79d2from_unixtime(create_time,'yyyy') -- \u83b7\u53d6\u5e74<\/code>\n<code>from_unixtime(1614157840,'MM') -- \u83b7\u53d6\u6708from_unixtime(create_time,'HH'), -- \u83b7\u53d6\u5c0f\u65f6<\/code>\n<code>from_unixtime(create_time,'yyyy-MM-dd\u00a0HH:mm:ss'),\u00a0--\u83b7\u53d6\u5e74\u6708\u65e5\u65f6\u5206\u79d2\uff0c\u53ea\u662f\u5c55\u793a\u683c\u5f0f\u6709\u53d8\u5316hour(from_unixtime(create_time,'yyyy-MM-dd\u00a0HH:mm:ss'))\u00a0--\u00a0\u65e5\u671f\u51fd\u6570hour\u7b49\u8981\u6c42\u65e5\u671f\u683c\u5f0f\u662f\u2018-\u2019\u5206\u5272<\/code><\/pre>\n\n\n\n<p>\uff082\uff0913\u4f4d\u6b63\u6574\u6570\u6beb\u79d2\u7ea7\u522b\u65f6\u95f4\u6233&nbsp; &#8212; time\u662f13\u4f4d\u6beb\u79d2\u7ea7\u522b\u65f6\u95f4\u6233\u683c\u5f0f\uff0c\u5148\u622a\u53d6\u523010\u4f4d\u79d2\u7ea7\u522b\u7136\u540e\u518d\u8f6c\u5316\u6210\u65e5\u671f\u65f6\u95f4\u683c\u5f0f&nbsp;&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>from_unixtime(cast(substring(time,1,10) as bigint),'yyyy-MM-dd HH:mm:ss'),<\/code><code>from_unixtime(cast(substring(time,1,10) as bigint),'HH'),<\/code><code>from_unixtime(cast(substring(time,1,10) as bigint),'yyyyMMdd') ,<\/code><\/pre>\n\n\n\n<p>&nbsp; &nbsp; &#8212; \u5224\u65ad\u5de5\u4f5c\u65e5\u548c\u5468\u672b\u201c&nbsp; &nbsp; &#8211;0\u5468\u65e5\u30011\u5468\u4e00\u30012\u5468\u4e8c\u30013\u5468\u4e09\u30014\u5468\u56db\u30015\u5468\u4e94\u30016\u5468\u516d\uff1bpmod\u53d6\u4f59<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>case <\/code><code>when pmod(datediff(from_unixtime(cast(substring(time,1,10) as bigint),'yyyy-MM-dd'), '2018-01-07'), 7) in(6,0) then '\u5468\u672b'<\/code><code>else '\u5de5\u4f5c\u65e5'<\/code><code>end as weekday_num<\/code><\/pre>\n\n\n\n<p>\uff083\uff09\u6c42\u65e5\u671f\u5dee-\u8fd4\u56de\u5929\u5dee\u5f02\uff1adatediff(\u7ed3\u675f\u65e5\u671f\uff0c\u5f00\u59cb\u65e5\u671f)&nbsp;&#8211;date_p\u5206\u533a\u5b57\u6bb5\uff0c\u683c\u5f0fbigint\uff0c\u6bd4\u598220230615<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>datediff(from_unixtime(unix_timestamp(CAST(b.date_p AS string), 'yyyyMMdd')), from_unixtime(unix_timestamp(CAST(a.date_p AS string), 'yyyyMMdd'))) AS diff_date<\/code><\/pre>\n\n\n\n<p>&nbsp;&#8212; UNIX_TIMESTAMP takes only string\/date\/timestamp types&nbsp;&#8212; \u8fd4\u56de\u503c: bigint<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> select datediff(from_unixtime(unix_timestamp('20210919', 'yyyyMMdd')), from_unixtime(unix_timestamp('20210909', 'yyyyMMdd')))<\/code><\/pre>\n\n\n\n<p>&nbsp; &nbsp; &#8212; &nbsp;\u8ba1\u7b97\u7ed3\u679c\u4e3a10\uff0c\u4e0d\u5305\u542b\u5f53\u5929&nbsp; &nbsp; &#8212; 20210909 20210909 \u8ba1\u7b97\u7ed3\u679c\u4e3a0\uff084\uff09\u65e5\u671f\u65f6\u95f4\u8f6c\u65e5\u671f\u51fd\u6570: &nbsp;to_date(string timestamp) &nbsp;&#8212; \u8fd4\u56de\u503c: &nbsp; string<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  to_date('2016-02-16 14:02:03') -- \u8fd4\u56de\u503c2016-02-16<\/code><\/pre>\n\n\n\n<p>\uff085\uff09\u65e5\u671f\u65f6\u95f4\u548cdate_p\u5bf9\u6bd4&nbsp; &nbsp; \u65e5\u671f\u65f6\u95f4\u8f6c\u65f6\u95f4\u6233unix_timestamp(&#8216;2020-03-14 14:29:24&#8217;)&#8212;1584167364 &#8212;\u8fd4\u56de\u503cbigint<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> cast(from_unixtime(unix_timestamp('2020-03-14 14:29:24'),'yyyyMMdd') as bigint)&gt;=${date_s}<\/code><\/pre>\n\n\n\n<p>\uff086\uff09bigint\u683c\u5f0f\u65e5\u671f\u7b97\u5468\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>weekofyear(to_date(from_unixtime(unix_timestamp(CAST(feed_create_time AS string),'yyyymmdd'),'yyyy-mm-dd'))) as week<\/code><\/pre>\n\n\n\n<p>\uff087\uff09date_p\u83b7\u53d6\u6708\u4efd<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>substr(date_p,5,2) as month1<\/code><\/pre>\n\n\n\n<p>\uff088\uff09date_p\u83b7\u53d6\u5468\uff0c\u4ece\u5468\u4e00\u5f00\u59cb\u7b97<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>weekofyear(from_unixtime(unix_timestamp(cast(date_p as string), 'yyyyMMdd')))<\/code><\/pre>\n\n\n\n<p>\uff089\uff09\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>current_date()  -- 2023-06-10<\/code><\/pre>\n\n\n\n<p><strong>4\u3001\u5b57\u7b26\u4e32\u5904\u7406\u51fd\u6570<\/strong>\u00a0 \u622a\u53d6\uff1asubstring(\u5b57\u7b26\u4e32m,\u7b2c\u51e0\u4f4d\u5f00\u59cb\u622a\u53d6\uff0c\u622a\u53d6\u51e0\u4e2a\u5b57\u7b26)\u00a0 \u53bb\u6389\u9996\u4f4d\u7a7a\u683c\uff1atrim()<\/p>\n\n\n\n<p><strong>5\u3001\u8f6c\u4e49\u5b57\u7b26\\\uff1a<\/strong>&#8212; trim(regexp_replace(feed_id,&#8217;\\&#8221;&#8216;,&#8221;)) &#8212; \u66ff\u6362&#8221;\u4e3a\u7a7a&#8211;\u00a0\u00a0+\u3001*\u3001|\u3001\\\u7b49\u7b26\u53f7\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u6709\u76f8\u5e94\u7684\u4e0d\u540c\u610f\u4e49\uff0c\u6240\u4ee5\u5728\u4f7f\u7528\u65f6\u8981\u8fdb\u884c\u8f6c\u4e49\u5904\u7406\uff0c\u00a0\u7528\\\\+ \u00a0\u6216\u8005[+]\u90fd\u53ef\u8fdb\u884c\u8f6c\u4e49\u3002<\/p>\n\n\n\n<p><strong>6\u3001null\u8ba1\u7b97\u89c4\u5219<\/strong>\u4e4b\u524d\u8be6\u7ec6\u4ecb\u7ecd\u8fc7null\u548c\u7a7a\u5b57\u7b26\u4e32\u7684\u533a\u522b\uff0c\u4f20\u9001\u95e8\uff1a<a rel=\"noreferrer noopener\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=MzIyNzMxOTEyNw==&amp;mid=2247483740&amp;idx=1&amp;sn=a91550d645aec98b4bf38d9198be78e6&amp;chksm=e8624d64df15c472f690d9a2119b0c41016e7b0f0763eb54e2729cc218aa7f1c3b2e7568acc6&amp;scene=21#wechat_redirect\" target=\"_blank\">HSQL\uff1aHive\u4e2d\u7a7aNULL\u548c\u7a7a\u5b57\u7b26\u4e32\u7684\u533a\u522b\uff1f<\/a>\u00a0<\/p>\n\n\n\n<p> hive \u2018\u4e0d\u7b49\u4e8e\u2019\u4e0d\u7ba1\u662f\u7528\uff01\u6216\u8005&lt;>\u7b26\u53f7\u5b9e\u73b0\uff0c\u90fd\u4f1a\u5c06\u7a7a\u503c\u5373null\u8fc7\u6ee4\u6389\uff0c\u6b64\u65f6\u8981\u7528\u00a0 where \uff08white_level&lt;>&#8217;3&#8242; or \u00a0white_level is null)\u00a0 \u6216\u8005 where (white_level!=&#8217;3&#8242; or white_level is null ) \u00a0\u6765\u4fdd\u7559null \u7684\u60c5\u51b5\u3002<\/p>\n\n\n\n<p><strong>7\u3001count(1) \u548ccount(\u5b57\u6bb5)\u533a\u522b\uff1a<\/strong>\u00a0 count(1)\u4e0ecount(*)\u5f97\u5230\u7684\u7ed3\u679c\u4e00\u81f4\uff0c\u5305\u542bnull\u503c\u00a0 count(\u5b57\u6bb5)\u4e0d\u8ba1\u7b97null\u503c\u00a0 count(null)\u7ed3\u679c\u6052\u4e3a0<\/p>\n\n\n\n<p><strong>8\u3001\u6392\u540d\u51fd\u6570<\/strong>\u00a0\u00a0\uff081\uff09ROW_NUMBER\uff1a\u6bcf\u4e00\u884c\u8bb0\u5f55\u751f\u6210\u4e00\u4e2a\u5e8f\u53f7\uff0c\u4f9d\u6b21\u6392\u5e8f\u4e14\u4e0d\u4f1a\u91cd\u590d,1,2,3(\u548c2\u4e00\u6837),4,5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>row_number() over(PARTITION BY orderid ORDER BY datachange_lasttime desc) as rank<\/code><\/pre>\n\n\n\n<p>\u00a0\u00a0\uff082\uff09rank() over()\uff1aover\u5b50\u53e5\u4e2d\u6392\u5e8f\u5b57\u6bb5\u503c\u76f8\u540c\u7684\u5e8f\u53f7\u662f\u4e00\u6837\u7684\uff0c\u540e\u9762\u5b57\u6bb5\u503c\u4e0d\u76f8\u540c\u7684\u5e8f\u53f7\u5c06\u8df3\u8fc7\u76f8\u540c\u7684\u6392\u540d\u53f7\u6392\u4e0b\u4e00\u4e2a1,2,2,4\u00a0\u00a0\uff083\uff09dense_rank() over()\uff1adense_rank\u51fd\u6570\u51fa\u73b0\u76f8\u540c\u6392\u540d\u65f6\uff0c\u5c06\u4e0d\u8df3\u8fc7\u76f8\u540c\u6392\u540d\u53f7\uff0crank\u503c\u7d27\u63a5\u4e0a\u4e00\u6b21\u7684rank\u503c,1,2,2,3<\/p>\n\n\n\n<p><strong>9\u3001uinoin\u548cunion all<\/strong>\u00a0 union\u4f1a\u81ea\u52a8\u538b\u7f29\u591a\u4e2a\u7ed3\u679c\u96c6\u5408\u4e2d\u7684\u91cd\u590d\u7ed3\u679c\uff0c\u800cunion all\u5219\u5c06\u6240\u6709\u7684\u7ed3\u679c\u5168\u90e8\u663e\u793a\u51fa\u6765\uff0c\u4e0d\u7ba1\u662f\u4e0d\u662f\u91cd\u590d<\/p>\n\n\n\n<p><strong>10\u3001\u5206\u7ec4\u805a\u5408<\/strong>\u00a0\uff081\uff09with cube\u7684\u5206\u7ec4\u7ec4\u5408\u6700\u5168\uff0c\u662f\u5404\u4e2a\u7ef4\u5ea6\u503c\u7684\u7b1b\u5361\u5c14\uff08\u5305\u542bnull)\u7ec4\u5408\uff0c\u00a0\uff082\uff09\u00a0grouping sets\u5219\u4e3a\u81ea\u5b9a\u4e49\u7ef4\u5ea6\uff0c\u6839\u636e\u9700\u8981\u5206\u7ec4\u5373\u53ef\u3002\u00a0 ps\uff1a\u901a\u8fc7grouping sets\u7684\u4f7f\u7528\u53ef\u4ee5\u7b80\u5316SQL\uff0c\u6bd4group by\u5355\u7ef4\u5ea6\u8fdb\u884cunion\u6027\u80fd\u66f4\u597d\u3002\u00a0\uff083\uff09hive grouping sets\u591a\u7ef4\u5ea6\u62a5\u9519\u00a0 \u5982\u679c\u4f60\u7684 grouping sets\u5927\u4e8e\u7b49\u4e8e5\u4e2a\u7ef4\u5ea6\uff0c\u5c06\u4f1a\u62a5\u5982\u4e0a\u7684\u9519\u8bef\uff1b\u89e3\u51b3\u529e\u6cd5\uff1a\u00a0\u5728\u4f60\u7684hql\u8bed\u53e5\u524d\u9762\u52a0\u4e0a set hive.new.job.grouping.set.cardinality=xx;\uff08\u4f8b\u5982\u6211\u8fd9\u91cc\u662f5\u4e2a\u7ef4\u5ea6\uff0c\u4e00\u517132\u4e2agrouping sets\uff0cxx\u53ef\u5199\u4e3a64 )\u6ce8\u610f\uff1agroup by\u4e2d\u5b57\u6bb5\u4e0eGrouping sets\u4e2d\u5b57\u6bb5\uff0c\u4e24\u8005\u5fc5\u987b\u4fdd\u6301\u5b8c\u5168\u4e00\u81f4\u3002<\/p>\n\n\n\n<p><strong>11\u3001\u884c\u5217\u8f6c\u6362<\/strong>\uff081\uff09\u884c\u8f6c\u5217\u00a0 \u6570\u636e\u8868\u7684\u8bb0\u5f55\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>&nbsp; \u5bf9promotion_id\u8fdb\u884c\u5408\u5e76\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>select product_id, concat_ws('_',collect_set(promotion_id)) as promotion_ids<\/code><code>from product_promotion<\/code><code>group by product_id<\/code><\/pre>\n\n\n\n<p>&nbsp; \u6267\u884c\u7ed3\u679c\uff1a&nbsp; 5112 960024_960025_960026_960027\uff082\uff09\u5217\u8f6c\u884c<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>select product_id,promotion_id<\/code><code>from&nbsp;product_promotion&nbsp;LATERAL&nbsp;VIEW&nbsp;EXPLODE(split(promotion_ids,&nbsp;','))&nbsp;f&nbsp;as&nbsp;promotion_id<\/code><\/pre>\n\n\n\n<p><strong>12\u3001\u4e0d\u5e38\u7528\u7684\u5e38\u7528\u51fd\u6570<\/strong>\u00a0 \u00a0 (1\uff09\u00a0\/: \u4e3a\u5b9e\u6570\u9664\uff0c\u5176\u8fd0\u7b97\u7ed3\u679c\u4e3a\u5b9e\u578b\u3002\u00a0 \u00a0 \u00a0\u5982: 5 \/ 2 = 2.5\uff0c5.0 \/ 2.0 = 2.5\uff0c\u6ce8\u610f\uff0c4 \/ 2 = 2.0\uff0c\u800c\u4e0d\u7b49\u4e8e2\u3002\u00a0 \u00a0 (2\uff09Div :\u4e3a\u6574\u9664\uff0cdiv \u8fd0\u7b97\u53ea\u53d6\u5546\u7684\u6574\u6570\u90e8\u5206\uff0c\u5b83\u8981\u6c42\u9664\u6570\u548c\u88ab\u9664\u6570\u5747\u4e3a\u6574\u578b\uff0c\u5176\u8fd0\u7b97\u7ed3\u679c\u4e5f\u4e3a\u6574\u578b\u3002\u00a0 \u00a0 \u5982\uff1a10 div 2 = 5\uff0c10 div 3 = 3\uff0c-15 div 4 = -3\u3002\u00a0 \u00a0 (3\uff09\u00a0mod: \u4e3a\u6c42\u4f59\uff0c\u53ea\u80fd\u7528\u4e8e\u6574\u6570\u8fd0\u7b97\uff0c\u7ed3\u679c\u4e5f\u4e3a\u6574\u6570\u3002\u00a0 \u00a0 \u5982\uff1a10 mod 4 = 2\uff0c-17 mod 4 = -1\uff0c4 mod (-3) = 1\uff0c\u5373 a mod b = a &#8211; (a div b) * b\u3002\u00a0 \u00a0 (4\uff09foor() \u5c0f\u6570\u53d6\u6574(8.6&#8212;->8;8.2&#8212;->8)\u00a0 \u00a0 (5\uff09stddev(c.pv) \u8ba1\u7b97\u6807\u51c6\u5dee\u00a0 \u00a0&#8211;\u6bd4\u5982\uff1a\u8ba1\u7b97\u4e24\u7ec4\u5b9e\u9a8c\u7528\u6237\u7684\u4eba\u5747\u53d1\u6587\u91cf\u662f\u5426\u6709\u5dee\u5f02\u00a0 \u00a0&#8211;\u9700\u8981\u8ba1\u7b97 \u4e24\u7ec4\u5b9e\u9a8c\u7528\u6237\u7684\u53d1\u6587\u91cf\u6807\u51c6\u5dee\u3002\u6ce8\u610f\uff1a\u672a\u53d1\u5e03\u7528\u6237\u7684\u53d1\u5e03\u6b21\u6570\u7f6e\u4e3a0\uff0c\u518d\u8ba1\u7b97\u6807\u51c6\u5dee\u3002<\/p>\n\n\n\n<p><strong>13\u3001\u805a\u5408\u51fd\u6570\u8054\u5408\u6761\u4ef6\u4f7f\u7528\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>nvl(sum(if(event_id='open_click',1,0)),0) as openclick_num<\/code><code>nvl(sum(case when event_id='open_click'then 1 else 0 end),0) as openclick_num<\/code><\/pre>\n\n\n\n<p><strong>14\u3001\u5b57\u5178\u7c7b\u578b\u63d0\u53d6\u4fe1\u606f\uff1aget_json_object(\u5b57\u6bb5\u540d,&#8217;$.\u5b57\u6bb5\u4e2d\u7684\u952e&#8217;)<\/strong>&#8212; level\u662f\u5b57\u5178dict\u7c7b\u578b{&#8220;value&#8221;:5, &#8220;reason&#8221;: 8, &#8220;level_reason&#8221;:&#8221;\u56fe\u7247\u5e7f\u544a-OCR\u6587\u672c#\u6587\u672c\u5e7f\u544a#\u654f\u611f\u4fe1\u606f#\u91cd\u5ea6\u8272\u60c5#\u4fe1\u606f\u8fc7\u5c11&#8221;}&#8211;&nbsp;\u60f3\u83b7\u53d6\u8bc4\u7ea7\u539f\u56e0\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>get_json_object(level,'$.level_reason') as level_reason  --\u8bc4\u7ea7\u539f\u56e0<\/code><\/pre>\n\n\n\n<p><strong>15\u3001map\u7c7b\u578b<\/strong>&nbsp; \u5b57\u6bb5\u540d\uff1aparams &nbsp;\u7c7b\u578b\uff1amap&lt;string,string&gt;{&#8220;last_upload_time&#8221;:&#8221;1584694386724&#8243;,&#8221;first_start&#8221;:&#8221;1&#8243;,&#8221;first_launch&#8221;:&#8221;0&#8243;,&#8221;launch_type&#8221;:&#8221;0&#8243;,&#8221;$launch_source&#8221;:&#8221;-1\\u0007normal\\u00070\\u00070&#8243;}&nbsp; \u63d0\u53d6\u89c4\u5219\uff1asplit(\u5b57\u6bb5\u540d,&#8217;\u5206\u9694\u7b26&#8217;\uff09\u6309\u7167\u5206\u5272\u7b26\u6253\u6563\u6210\u6570\u7ec4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> split(params&#91;'$launch_source'],'\\u0007')&#91;0] --\u63d0\u53d6\u7ed3\u679c-1<\/code><\/pre>\n\n\n\n<p><strong>16\u3001array\u7c7b\u578b<\/strong>\u00a0 \u5b57\u6bb5\u540d\uff1aresident_location_id \u00a0\u7c7b\u578b\uff1aarray&lt;struct&lt;id:string,value:int>>[{&#8220;id&#8221;:&#8221;1007&#8243;,&#8221;value&#8221;:0},{&#8220;id&#8221;:&#8221;1006&#8243;,&#8221;value&#8221;:0},{&#8220;id&#8221;:&#8221;1005&#8243;,&#8221;value&#8221;:0},{&#8220;id&#8221;:&#8221;1015&#8243;,&#8221;value&#8221;:0}]\u00a0 <\/p>\n\n\n\n<p>\u63d0\u53d6\u89c4\u5219\uff1aresident_location_id[3].value<\/p>\n\n\n\n<p><strong>17\u3001lead()over()\u548clag()over\u7a97\u53e3\u51fd\u6570<\/strong>\u00a0 &#8212; lag() over()\u51fd\u6570\uff1a\u5206\u7ec4\u6392\u5e8f\u540e \uff0c\u7ec4\u5185\u540e\u9762\u4e00\u6761\u8bb0\u5f55\u51cf\u524d\u9762\u4e00\u6761\u8bb0\u5f55\u7684\u5dee\uff0c\u7b2c\u4e00\u6761\u53ef\u8fd4\u56de NULL\u00a0 &#8212; lead(date_p,6,0)over() \uff1a\u8fd4\u56de\u5f53\u524ddate_p\u65e5\u671f\u540e\u9762\u7b2c6\u884c\u7684date_p\u5bf9\u5e94\u7684\u503c<strong>18\u3001\u7248\u672c\u9650\u5236<\/strong>\u00a0 app_version&lt;&#8216;8.3.0.0&#8242;\u00a0 cast(replace(app_version,&#8217;.&#8217;,&#8221;) as bigint)&lt;8300<\/p>\n\n\n\n<p><strong>19\u3001\u5982\u679cV1\u4e3a\u7a7a\u5c31\u7528v2\u8865\u5145\u8bed\u53e5\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>COALESCE(T v1, T v2, ...)<\/code><\/pre>\n\n\n\n<p><strong>20\u3001\u5efa\u8868\uff1a\u8bbe\u7f6e\u52a8\u6001\u5206\u533a<\/strong>&nbsp; &#8212; \u5f53\u5bf9hive\u5206\u533a\u672a\u505a\u8bbe\u7f6e\u65f6\uff0c\u53ef\u80fd\u4f1a\u62a5\u9519\uff1a\u8d85\u8fc7\u4e86\u6700\u5927\u7684\u5206\u533a\u6570\u8bbe\u7f6e&nbsp; &#8212; \u52a8\u6001\u5206\u533a\u5728insert\u6570\u636e\u7684\u65f6\u5019,\u5206\u533a\u5b57\u6bb5\u8981\u653e\u5728\u63d2\u5165\u5b57\u6bb5\u7684\u6700\u540e\u9762,\u540c\u65f6\u8981\u548c\u6307\u5b9a\u7684\u5206\u533a\u5b57\u6bb5\u7684\u987a\u5e8f\u4e00\u81f4.&nbsp; &#8212; \u8bf4\u660e\uff1a\u5206\u533a\u5185\u5bb9\u4e0d\u8981\u7528\u4e2d\u6587<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>set hive.exec.dynamic.partition=true;\u00a0<\/code>\n<code>set\u00a0hive.exec.dynamic.partition.mode=nonstrict;\u00a0<em>--\u00a0\u8bbe\u7f6e\u52a8\u6001\u5206\u533a\u7684\u6a21\u5f0f\uff1anonstrict\u6a21\u5f0f\u8868\u793a\u5141\u8bb8\u6240\u6709\u7684\u5206\u533a\u5b57\u6bb5\u90fd\u53ef\u4ee5\u4f7f\u7528\u52a8\u6001\u5206\u533a\u3002<\/em>\u00a0<\/code>\n<code>set\u00a0hive.stats.reliable=false;\u00a0<em>--\u00a0\u5982\u679c\u4e0d\u80fd\u591f\u53ef\u9760\u7684\u6536\u96c6\u7edf\u8ba1\u4fe1\u606f\uff0c\u5219\u67e5\u8be2\u5931\u8d25\uff0c\u7f3a\u7701\u662ffalse<\/em>\u00a0<\/code>\n<code>set\u00a0hive.exec.max.dynamic.partitions.pernode=1000;\u00a0<em>--\u00a0\u5728\u6bcf\u4e2a\u6267\u884cMR\u7684\u8282\u70b9\u4e0a\uff0c\u6700\u5927\u53ef\u4ee5\u521b\u5efa\u591a\u5c11\u4e2a\u52a8\u6001\u5206\u533a<\/em>\u00a0<\/code>\n<code>insert\u00a0overwrite\u00a0table\u00a0A\u8868\u00a0partition(date_p)\u00a0<em>--\u00a0\u6309\u7167<\/em><\/code>\u5206\u533a\u8986\u76d6\u5199\u5165\n\n\u53c2\u8003\u8d44\u6599\uff1a\nhttps:\/\/blog.51cto.com\/u_15105906\/5621807\nhttps:\/\/blog.csdn.net\/weixin_49582454\/article\/details\/110533283<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001 hive\u4e66\u5199\u987a\u5e8f&nbsp; &#8212; 1\uff09hive\u4e66\u5199\u987a\u5e8f &nbsp;&#8212;&hellip; <a href=\"http:\/\/viplao.com\/index.php\/2023\/07\/27\/hive-sql%ef%bc%9a%e5%b7%a5%e4%bd%9c%e4%b8%ad%e5%b8%b8%e7%94%a8hsql%e8%af%ad%e5%8f%a5%e5%a4%a7%e5%85%a8-%e4%ba%8c\/\" class=\"more-link read-more\" rel=\"bookmark\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">HIVE SQL\uff1a\u5de5\u4f5c\u4e2d\u5e38\u7528HSQL\u8bed\u53e5\u5927\u5168 \u4e8c<\/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":[26],"views":1356,"_links":{"self":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/2214"}],"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=2214"}],"version-history":[{"count":3,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/2214\/revisions"}],"predecessor-version":[{"id":2217,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/2214\/revisions\/2217"}],"wp:attachment":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/media?parent=2214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/categories?post=2214"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/tags?post=2214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}