{"id":988,"date":"2018-10-08T21:30:49","date_gmt":"2018-10-08T13:30:49","guid":{"rendered":"http:\/\/www.rain1024.com\/?p=988"},"modified":"2023-08-07T20:57:25","modified_gmt":"2023-08-07T12:57:25","slug":"article135","status":"publish","type":"post","link":"http:\/\/rain1024.com\/index.php\/2018\/10\/08\/article135\/","title":{"rendered":"HIVE\u51fd\u6570\u5927\u5168"},"content":{"rendered":"<h3>\u4e00\u3001\u7b80\u5355\u63cf\u8ff0\u8868\u7ed3\u6784\uff0c\u5b57\u6bb5\u7c7b\u578b<\/h3>\n<p>hive>desc tabl_name;<\/p>\n<h3>\u4e8c\uff0c\u5173\u7cfb\u8fd0\u7b97\uff0c\u7b49\u4e8e\uff0c\u4e0d\u7b49\u4e8e\uff0c\u5c0f\u4e8e\uff0c\u5927\u4e8e\uff0c\u5c0f\u4e8e\u7b49\u4e8e\uff0c\u5927\u4e8e\u7b49\u4e8e<\/h3>\n<p>\u63cf\u8ff0:\u5982\u679c\u8868\u8fbe\u5f0fA\u4e3aNULL,\u6216\u8005\u8868\u8fbe\u5f0fB\u4e3aNULL,\u8fd4\u56deNULL;<\/p>\n<p>hive>select year from record where temperature=0;<\/p>\n<p>hive>select year from record where temperature&lt;>0;<\/p>\n<p>hive>select year from record where temperature&lt;0;<\/p>\n<p>hive>select year from record where temperature>0;<\/p>\n<h3>\u4e09\uff0c\u7a7a\u503c\u5224\u65ad: IS NULL<\/h3>\n<p>\u8bed\u6cd5:A IS NULL<br \/>\n\u64cd\u4f5c\u7c7b\u578b:\u6240\u6709\u7c7b\u578b<br \/>\n\u63cf\u8ff0:\u5982\u679c\u8868\u8fbe\u5f0fA\u7684\u503c\u4e3aNULL\uff0c\u5219\u4e3aTRUE;\u5426\u5219\u4e3aFALSE<br \/>\n\u4e3e\u4f8b:<br \/>\nhive> select 1 from lxw_ dual where null is null;<\/p>\n<h3>\u56db\uff0c\u975e\u7a7a\u5224\u65ad: IS NOT NULL<\/h3>\n<p>\u8bed\u6cd5:A IS NOT NULL<br \/>\n\u64cd\u4f5c\u7c7b\u578b:\u6240\u6709\u7c7b\u578b<br \/>\n\u63cf\u8ff0:\u5982\u679c\u8868\u8fbe\u5f0fA\u7684\u503c\u4e3aNULL\uff0c\u5219\u4e3aFALSE;\u5426\u5219\u4e3aTRUE<br \/>\n\u4e3e\u4f8b:<br \/>\nhive> select 1 from lxw_ dual where 1 is not null;<\/p>\n<h3>\u4e94\uff0cLIKE\u67e5\u8be2<\/h3>\n<p>\u8bed\u6cd5:A LKE B<br \/>\n\u64cd\u4f5c\u7c7b\u578b: strings<br \/>\n\u63cf\u8ff0:\u5982\u679c\u5b57\u7b26\u4e32A\u6216\u8005\u5b57\u7b26\u4e32B\u4e3aNULL\uff0c\u5219\u8fd4\u56deNULL;\u5982\u679c\u5b57\u7b26\u4e32A\u7b26\u5408\u8868\u8fbe\u5f0fB<br \/>\n\u7684\u6b63\u5219\u8bed\u6cd5\uff0c\u5219\u4e3aTRUE;\u5426\u5219\u4e3aFALSE\u3002B\u4e2d\u5b57\u7b26\u201d<em>\u201d\u8868\u793a\u4efb\u610f\u5355\u4e2a\u5b57\u7b26\uff0c\u800c\u5b57\u7b26\u201d%\u201d\u8868\u793a\u4efb\u610f\u6570\u91cf\u7684\u5b57\u7b26\u3002<br \/>\n\u4e3e\u4f8b:<br \/>\nhive> select 1 from lxw<\/em> dual where 'football' like 'foot%';<br \/>\n1<br \/>\nhive> select 1 from lxw_ dual where 'football' like 'foot<br \/>\n1<\/p>\n<p>hive> select * from record where 'temperature' like '%%';<\/p>\n<p>\u6ce8\u610f:<br \/>\n\u5426\u5b9a\u6bd4\u8f83\u65f6\u5019\u7528NOTA LIKE B<br \/>\nhive> select 1 from lxw_ dual where NOT 'football' like 'ff%';<\/p>\n<p>\u6ce8\u610f:<br \/>\n\u5224\u65ad-\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u5168\u4e3a\u6570\u5b57:<br \/>\nhive>select 1 from bxw_ dual where '123456'  rlike  '^&#92;\\d+$';<br \/>\n1<\/p>\n<h3>\u516d\uff0c\u6570\u5b66\u8fd0\u7b97<\/h3>\n<p>\u5728select\u540e\u5199\u5165\u6570\u5b66\u8868\u8fbe\u5f0f\uff0c\u5305\u542b+-*\/,\u53d6\u4f59%\uff0c\u4f4d\u4e0e&amp;\uff0c\u4f4d\u6216|\uff0c\u4f4d\u5f02\u6216\u2026\u2026\uff0c\u4f4d\u53d6\u53cd~\uff0c\u8fd9\u4e9b\u8868\u8fbe\u5f0f\u5728\u904d\u5386\u6bcf\u4e00\u5217\u65f6\u90fd\u4f1a\u8fd0\u7b97\u4e00\u904d\u3002<\/p>\n<p>hive> select 10 - 5 from record;<\/p>\n<p>OK<\/p>\n<p>5<\/p>\n<p>Time taken: 0.132 seconds, Fetched: 5 row(s)<\/p>\n<h3>\u4e03\uff0c\u903b\u8f91\u8fd0\u7b97<\/h3>\n<p>\u903b\u8f91\u4e0e \uff1aAND\uff0c\u903b\u8f91\u6216\uff1aOR\uff0c\u903b\u8f91\u975e\uff1aNOT<\/p>\n<p>hive> select * from record where temperature>0 and year=1950<\/p>\n<h2>\u4e00\u3001\u5173\u7cfb\u8fd0\u7b97\uff1a<\/h2>\n<h3>1. \u7b49\u503c\u6bd4\u8f83: =<\/h3>\n<pre><code>     \u8bed\u6cd5\uff1aA=B\n\n     \u64cd\u4f5c\u7c7b\u578b\uff1a\u6240\u6709\u57fa\u672c\u7c7b\u578b\n\n     \u63cf\u8ff0:\u5982\u679c\u8868\u8fbe\u5f0fA\u4e0e\u8868\u8fbe\u5f0fB\u76f8\u7b49\uff0c\u5219\u4e3aTRUE\uff1b\u5426\u5219\u4e3aFALSE\n\n     \u4e3e\u4f8b\uff1a\n\n     hive&gt;select 1 from lxw_dual where 1=1;\n\n     1\n<\/code><\/pre>\n<h3>2. \u4e0d\u7b49\u503c\u6bd4\u8f83: &lt;><\/h3>\n<pre><code>     \u8bed\u6cd5: A &lt;&gt; B\n<\/code><\/pre>\n<p>\u64cd\u4f5c\u7c7b\u578b:\u6240\u6709\u57fa\u672c\u7c7b\u578b<\/p>\n<p>\u63cf\u8ff0:\u5982\u679c\u8868\u8fbe\u5f0fA\u4e3aNULL\uff0c\u6216\u8005\u8868\u8fbe\u5f0fB\u4e3aNULL\uff0c\u8fd4\u56deNULL\uff1b\u5982\u679c\u8868\u8fbe\u5f0fA\u4e0e\u8868\u8fbe\u5f0fB\u4e0d\u76f8\u7b49\uff0c\u5219\u4e3aTRUE\uff1b\u5426\u5219\u4e3aFALSE<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select1 from lxw_dual where 1 &lt;> 2;<\/p>\n<p>1<\/p>\n<h3>3.\u5c0f\u4e8e\u6bd4\u8f83: &lt;<\/h3>\n<pre><code>     \u8bed\u6cd5: A &lt; B\n<\/code><\/pre>\n<p>\u64cd\u4f5c\u7c7b\u578b:\u6240\u6709\u57fa\u672c\u7c7b\u578b<\/p>\n<p>\u63cf\u8ff0:\u5982\u679c\u8868\u8fbe\u5f0fA\u4e3aNULL\uff0c\u6216\u8005\u8868\u8fbe\u5f0fB\u4e3aNULL\uff0c\u8fd4\u56deNULL\uff1b\u5982\u679c\u8868\u8fbe\u5f0fA\u5c0f\u4e8e\u8868\u8fbe\u5f0fB\uff0c\u5219\u4e3aTRUE\uff1b\u5426\u5219\u4e3aFALSE<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select1 from lxw_dual where 1 &lt; 2;<\/p>\n<p>1<\/p>\n<h3>4. \u5c0f\u4e8e\u7b49\u4e8e\u6bd4\u8f83: &lt;=<\/h3>\n<p>\u8bed\u6cd5: A &lt;= B<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b:\u6240\u6709\u57fa\u672c\u7c7b\u578b<\/p>\n<p>\u63cf\u8ff0:\u5982\u679c\u8868\u8fbe\u5f0fA\u4e3aNULL\uff0c\u6216\u8005\u8868\u8fbe\u5f0fB\u4e3aNULL\uff0c\u8fd4\u56deNULL\uff1b\u5982\u679c\u8868\u8fbe\u5f0fA\u5c0f\u4e8e\u6216\u8005\u7b49\u4e8e\u8868\u8fbe\u5f0fB\uff0c\u5219\u4e3aTRUE\uff1b\u5426\u5219\u4e3aFALSE<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select1 from lxw_dual where 1 &lt;= 1;<\/p>\n<p>1<\/p>\n<h3>5. \u5927\u4e8e\u6bd4\u8f83: ><\/h3>\n<p>\u8bed\u6cd5: A > B<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b:\u6240\u6709\u57fa\u672c\u7c7b\u578b<\/p>\n<p>\u63cf\u8ff0:\u5982\u679c\u8868\u8fbe\u5f0fA\u4e3aNULL\uff0c\u6216\u8005\u8868\u8fbe\u5f0fB\u4e3aNULL\uff0c\u8fd4\u56deNULL\uff1b\u5982\u679c\u8868\u8fbe\u5f0fA\u5927\u4e8e\u8868\u8fbe\u5f0fB\uff0c\u5219\u4e3aTRUE\uff1b\u5426\u5219\u4e3aFALSE<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select1 from lxw_dual where 2 > 1;<\/p>\n<p>1<\/p>\n<h3>6. \u5927\u4e8e\u7b49\u4e8e\u6bd4\u8f83: >=<\/h3>\n<p>\u8bed\u6cd5: A >= B<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b:\u6240\u6709\u57fa\u672c\u7c7b\u578b<\/p>\n<p>\u63cf\u8ff0:\u5982\u679c\u8868\u8fbe\u5f0fA\u4e3aNULL\uff0c\u6216\u8005\u8868\u8fbe\u5f0fB\u4e3aNULL\uff0c\u8fd4\u56deNULL\uff1b\u5982\u679c\u8868\u8fbe\u5f0fA\u5927\u4e8e\u6216\u8005\u7b49\u4e8e\u8868\u8fbe\u5f0fB\uff0c\u5219\u4e3aTRUE\uff1b\u5426\u5219\u4e3aFALSE<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select1 from lxw_dual where 1 >= 1;<\/p>\n<p>1<\/p>\n<p><strong>\u6ce8\u610f\uff1aString\u7684\u6bd4\u8f83\u8981\u6ce8\u610f(\u5e38\u7528\u7684\u65f6\u95f4\u6bd4\u8f83\u53ef\u4ee5\u5148to_date\u4e4b\u540e\u518d\u6bd4\u8f83)<\/strong><\/p>\n<p>hive> select* from lxw_dual;<\/p>\n<p>201111120900:00:00    2011111209<\/p>\n<p>hive> selecta,b,a&lt;b,a>b,a=b from lxw_dual;<\/p>\n<p>201111120900:00:00    2011111209      false   true    false<\/p>\n<h3>7. \u7a7a\u503c\u5224\u65ad: IS NULL<\/h3>\n<p>\u8bed\u6cd5: A IS NULL<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b:\u6240\u6709\u7c7b\u578b<\/p>\n<p>\u63cf\u8ff0:\u5982\u679c\u8868\u8fbe\u5f0fA\u7684\u503c\u4e3aNULL\uff0c\u5219\u4e3aTRUE\uff1b\u5426\u5219\u4e3aFALSE<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select1 from lxw_dual where null is null;<\/p>\n<p>1<\/p>\n<h3>8. \u975e\u7a7a\u5224\u65ad: IS NOTNULL<\/h3>\n<p>\u8bed\u6cd5: A IS NOT NULL<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b:\u6240\u6709\u7c7b\u578b<\/p>\n<p>\u63cf\u8ff0:\u5982\u679c\u8868\u8fbe\u5f0fA\u7684\u503c\u4e3aNULL\uff0c\u5219\u4e3aFALSE\uff1b\u5426\u5219\u4e3aTRUE<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select1 from lxw_dual where 1 is not null;<\/p>\n<p>1<\/p>\n<h3>9. LIKE\u6bd4\u8f83: LIKE<\/h3>\n<p>\u8bed\u6cd5: A LIKE B<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b: strings<\/p>\n<p>\u63cf\u8ff0:\u5982\u679c\u5b57\u7b26\u4e32A\u6216\u8005\u5b57\u7b26\u4e32B\u4e3aNULL\uff0c\u5219\u8fd4\u56deNULL\uff1b\u5982\u679c\u5b57\u7b26\u4e32A\u7b26\u5408\u8868\u8fbe\u5f0fB  \u7684\u6b63\u5219\u8bed\u6cd5\uff0c\u5219\u4e3aTRUE\uff1b\u5426\u5219\u4e3aFALSE\u3002B\u4e2d\u5b57\u7b26\u201d_\u201d\u8868\u793a\u4efb\u610f\u5355\u4e2a\u5b57\u7b26\uff0c\u800c\u5b57\u7b26\u201d%\u201d\u8868\u793a\u4efb\u610f\u6570\u91cf\u7684\u5b57\u7b26\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select1 from lxw_dual where 'football' like 'foot%';<\/p>\n<p>1<\/p>\n<p>hive> select1 from lxw_dual where 'football' like 'foot____';<\/p>\n<p>1<\/p>\n<p><strong>\u6ce8\u610f\uff1a\u5426\u5b9a\u6bd4\u8f83\u65f6\u5019\u7528NOT ALIKE B<\/strong><\/p>\n<p>hive> select1 from lxw_dual where NOT 'football' like 'fff%';<\/p>\n<p>1<\/p>\n<h3>10. JAVA\u7684LIKE\u64cd\u4f5c: RLIKE<\/h3>\n<p>\u8bed\u6cd5: A RLIKE B<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b: strings<\/p>\n<p>\u63cf\u8ff0:\u5982\u679c\u5b57\u7b26\u4e32A\u6216\u8005\u5b57\u7b26\u4e32B\u4e3aNULL\uff0c\u5219\u8fd4\u56deNULL\uff1b\u5982\u679c\u5b57\u7b26\u4e32A\u7b26\u5408JAVA\u6b63\u5219\u8868\u8fbe\u5f0fB\u7684\u6b63\u5219\u8bed\u6cd5\uff0c\u5219\u4e3aTRUE\uff1b\u5426\u5219\u4e3aFALSE\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select1 from lxw_dual where 'footbar\u2019 rlike '^f.*r$\u2019;<\/p>\n<p>1<\/p>\n<p><strong>\u6ce8\u610f\uff1a\u5224\u65ad\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u5168\u4e3a\u6570\u5b57\uff1a<\/strong><\/p>\n<p>hive>select 1from lxw_dual where '123456' rlike '^&#92;d+$';<\/p>\n<p>1<\/p>\n<p>hive> select1 from lxw_dual where '123456aa' rlike '^&#92;d+$';<\/p>\n<h3>11. REGEXP\u64cd\u4f5c: REGEXP<\/h3>\n<p>\u8bed\u6cd5: A REGEXP B<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b: strings<\/p>\n<p>\u63cf\u8ff0:\u529f\u80fd\u4e0eRLIKE\u76f8\u540c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select1 from lxw_dual where 'footbar' REGEXP '^f.*r$';<\/p>\n<p>1<\/p>\n<h2>\u4e8c\u3001\u6570\u5b66\u8fd0\u7b97\uff1a<\/h2>\n<h3>1. \u52a0\u6cd5\u64cd\u4f5c: +<\/h3>\n<p>\u8bed\u6cd5: A + B<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b\uff1a\u6240\u6709\u6570\u503c\u7c7b\u578b<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56deA\u4e0eB\u76f8\u52a0\u7684\u7ed3\u679c\u3002\u7ed3\u679c\u7684\u6570\u503c\u7c7b\u578b\u7b49\u4e8eA\u7684\u7c7b\u578b\u548cB\u7684\u7c7b\u578b\u7684\u6700\u5c0f\u7236\u7c7b\u578b\uff08\u8be6\u89c1\u6570\u636e\u7c7b\u578b\u7684\u7ee7\u627f\u5173\u7cfb\uff09\u3002\u6bd4\u5982\uff0cint  + int \u4e00\u822c\u7ed3\u679c\u4e3aint\u7c7b\u578b\uff0c\u800cint + double\u4e00\u822c\u7ed3\u679c\u4e3adouble\u7c7b\u578b<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select1 + 9 from lxw_dual;<\/p>\n<p>10<\/p>\n<p>hive> createtable lxw_dual as select 1 + 1.2 from lxw_dual;<\/p>\n<p>hive> describelxw_dual;<\/p>\n<p>_c0     double<\/p>\n<h3>2. \u51cf\u6cd5\u64cd\u4f5c: -<\/h3>\n<p>\u8bed\u6cd5: A\u2013 B<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b\uff1a\u6240\u6709\u6570\u503c\u7c7b\u578b<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56deA\u4e0eB\u76f8\u51cf\u7684\u7ed3\u679c\u3002\u7ed3\u679c\u7684\u6570\u503c\u7c7b\u578b\u7b49\u4e8eA\u7684\u7c7b\u578b\u548cB\u7684\u7c7b\u578b\u7684\u6700\u5c0f\u7236\u7c7b\u578b\uff08\u8be6\u89c1\u6570\u636e\u7c7b\u578b\u7684\u7ee7\u627f\u5173\u7cfb\uff09\u3002\u6bd4\u5982\uff0cint\u2013  int \u4e00\u822c\u7ed3\u679c\u4e3aint\u7c7b\u578b\uff0c\u800cint\u2013 double \u4e00\u822c\u7ed3\u679c\u4e3adouble\u7c7b\u578b<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select10 \u2013 5 from lxw_dual;<\/p>\n<p>5<\/p>\n<p>hive> createtable lxw_dual as select 5.6 \u2013 4 from lxw_dual;<\/p>\n<p>hive>describe lxw_dual;<\/p>\n<p>_c0     double<\/p>\n<h3>3. \u4e58\u6cd5\u64cd\u4f5c: *<\/h3>\n<p>\u8bed\u6cd5: A * B<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b\uff1a\u6240\u6709\u6570\u503c\u7c7b\u578b<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56deA\u4e0eB\u76f8\u4e58\u7684\u7ed3\u679c\u3002\u7ed3\u679c\u7684\u6570\u503c\u7c7b\u578b\u7b49\u4e8eA\u7684\u7c7b\u578b\u548cB\u7684\u7c7b\u578b\u7684\u6700\u5c0f\u7236\u7c7b\u578b\uff08\u8be6\u89c1\u6570\u636e\u7c7b\u578b\u7684\u7ee7\u627f\u5173\u7cfb\uff09\u3002\u6ce8\u610f\uff0c\u5982\u679cA\u4e58\u4ee5B\u7684\u7ed3\u679c\u8d85\u8fc7\u9ed8\u8ba4\u7ed3\u679c\u7c7b\u578b\u7684\u6570\u503c\u8303\u56f4\uff0c\u5219\u9700\u8981\u901a\u8fc7cast\u5c06\u7ed3\u679c\u8f6c\u6362\u6210\u8303\u56f4\u66f4\u5927\u7684\u6570\u503c\u7c7b\u578b<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select40 * 5 from lxw_dual;<\/p>\n<p>200<\/p>\n<h3>4. \u9664\u6cd5\u64cd\u4f5c: \/<\/h3>\n<p>\u8bed\u6cd5: A \/ B<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b\uff1a\u6240\u6709\u6570\u503c\u7c7b\u578b<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56deA\u9664\u4ee5B\u7684\u7ed3\u679c\u3002\u7ed3\u679c\u7684\u6570\u503c\u7c7b\u578b\u4e3adouble<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select40 \/ 5 from lxw_dual;<\/p>\n<p>8.0<\/p>\n<p><strong>\u6ce8\u610f\uff1ahive\u4e2d\u6700\u9ad8\u7cbe\u5ea6\u7684\u6570\u636e\u7c7b\u578b\u662fdouble,\u53ea\u7cbe\u786e\u5230\u5c0f\u6570\u70b9\u540e16\u4f4d\uff0c\u5728\u505a\u9664\u6cd5\u8fd0\u7b97\u7684\u65f6\u5019\u8981\u7279\u522b\u6ce8\u610f<\/strong><\/p>\n<p>hive>select ceil(28.0\/6.999999999999999999999) from lxw_duallimit 1;<\/p>\n<p>\u7ed3\u679c\u4e3a4<\/p>\n<p>hive>select ceil(28.0\/6.99999999999999) from lxw_dual limit1;<\/p>\n<p>\u7ed3\u679c\u4e3a5<\/p>\n<h3>5. \u53d6\u4f59\u64cd\u4f5c: %<\/h3>\n<p>\u8bed\u6cd5: A % B<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b\uff1a\u6240\u6709\u6570\u503c\u7c7b\u578b<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56deA\u9664\u4ee5B\u7684\u4f59\u6570\u3002\u7ed3\u679c\u7684\u6570\u503c\u7c7b\u578b\u7b49\u4e8eA\u7684\u7c7b\u578b\u548cB\u7684\u7c7b\u578b\u7684\u6700\u5c0f\u7236\u7c7b\u578b\uff08\u8be6\u89c1\u6570\u636e\u7c7b\u578b\u7684\u7ee7\u627f\u5173\u7cfb\uff09\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select 41 % 5 from lxw_dual;<\/p>\n<p>1<\/p>\n<p>hive> select 8.4 % 4 from lxw_dual;<\/p>\n<p>0.40000000000000036<\/p>\n<p><strong>\u6ce8\u610f\uff1a\u7cbe\u5ea6\u5728hive\u4e2d\u662f\u4e2a\u5f88\u5927\u7684\u95ee\u9898\uff0c\u7c7b\u4f3c\u8fd9\u6837\u7684\u64cd\u4f5c\u6700\u597d\u901a\u8fc7round\u6307\u5b9a\u7cbe\u5ea6<\/strong><\/p>\n<p>hive> select round(8.4 % 4 , 2) from lxw_dual;<\/p>\n<p>0.4<\/p>\n<h3>6. \u4f4d\u4e0e\u64cd\u4f5c: &amp;<\/h3>\n<p>\u8bed\u6cd5: A &amp; B<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b\uff1a\u6240\u6709\u6570\u503c\u7c7b\u578b<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56deA\u548cB\u6309\u4f4d\u8fdb\u884c\u4e0e\u64cd\u4f5c\u7684\u7ed3\u679c\u3002\u7ed3\u679c\u7684\u6570\u503c\u7c7b\u578b\u7b49\u4e8eA\u7684\u7c7b\u578b\u548cB\u7684\u7c7b\u578b\u7684\u6700\u5c0f\u7236\u7c7b\u578b\uff08\u8be6\u89c1\u6570\u636e\u7c7b\u578b\u7684\u7ee7\u627f\u5173\u7cfb\uff09\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select 4 &amp; 8 from lxw_dual;<\/p>\n<p>0<\/p>\n<p>hive> select 6 &amp; 4 from lxw_dual;<\/p>\n<p>4<\/p>\n<h3>7. \u4f4d\u6216\u64cd\u4f5c: |<\/h3>\n<p>\u8bed\u6cd5: A | B<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b\uff1a\u6240\u6709\u6570\u503c\u7c7b\u578b<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56deA\u548cB\u6309\u4f4d\u8fdb\u884c\u6216\u64cd\u4f5c\u7684\u7ed3\u679c\u3002\u7ed3\u679c\u7684\u6570\u503c\u7c7b\u578b\u7b49\u4e8eA\u7684\u7c7b\u578b\u548cB\u7684\u7c7b\u578b\u7684\u6700\u5c0f\u7236\u7c7b\u578b\uff08\u8be6\u89c1\u6570\u636e\u7c7b\u578b\u7684\u7ee7\u627f\u5173\u7cfb\uff09\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select 4 | 8 from lxw_dual;<\/p>\n<p>12<\/p>\n<p>hive> select 6 | 8 from lxw_dual;<\/p>\n<p>14<\/p>\n<h3>8. \u4f4d\u5f02\u6216\u64cd\u4f5c: ^<\/h3>\n<p>\u8bed\u6cd5: A ^ B<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b\uff1a\u6240\u6709\u6570\u503c\u7c7b\u578b<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56deA\u548cB\u6309\u4f4d\u8fdb\u884c\u5f02\u6216\u64cd\u4f5c\u7684\u7ed3\u679c\u3002\u7ed3\u679c\u7684\u6570\u503c\u7c7b\u578b\u7b49\u4e8eA\u7684\u7c7b\u578b\u548cB\u7684\u7c7b\u578b\u7684\u6700\u5c0f\u7236\u7c7b\u578b\uff08\u8be6\u89c1\u6570\u636e\u7c7b\u578b\u7684\u7ee7\u627f\u5173\u7cfb\uff09\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select 4 ^ 8 from lxw_dual;<\/p>\n<p>12<\/p>\n<p>hive> select 6 ^ 4 from lxw_dual;<\/p>\n<p>2<\/p>\n<h3>9\uff0e\u4f4d\u53d6\u53cd\u64cd\u4f5c: ~<\/h3>\n<p>\u8bed\u6cd5: ~A<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b\uff1a\u6240\u6709\u6570\u503c\u7c7b\u578b<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56deA\u6309\u4f4d\u53d6\u53cd\u64cd\u4f5c\u7684\u7ed3\u679c\u3002\u7ed3\u679c\u7684\u6570\u503c\u7c7b\u578b\u7b49\u4e8eA\u7684\u7c7b\u578b\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select ~6 from lxw_dual;<\/p>\n<p>-7<\/p>\n<p>hive> select ~4 from lxw_dual;<\/p>\n<p>-5<\/p>\n<h2>\u4e09\u3001\u903b\u8f91\u8fd0\u7b97\uff1a<\/h2>\n<h3>1. \u903b\u8f91\u4e0e\u64cd\u4f5c: AND<\/h3>\n<p>\u8bed\u6cd5: A AND B<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b\uff1aboolean<\/p>\n<p>\u8bf4\u660e\uff1a\u5982\u679cA\u548cB\u5747\u4e3aTRUE\uff0c\u5219\u4e3aTRUE\uff1b\u5426\u5219\u4e3aFALSE\u3002\u5982\u679cA\u4e3aNULL\u6216B\u4e3aNULL\uff0c\u5219\u4e3aNULL<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select 1 from lxw_dual where 1=1 and 2=2;<\/p>\n<p>1<\/p>\n<h3>2. \u903b\u8f91\u6216\u64cd\u4f5c: OR<\/h3>\n<p>\u8bed\u6cd5: A OR B<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b\uff1aboolean<\/p>\n<p>\u8bf4\u660e\uff1a\u5982\u679cA\u4e3aTRUE\uff0c\u6216\u8005B\u4e3aTRUE\uff0c\u6216\u8005A\u548cB\u5747\u4e3aTRUE\uff0c\u5219\u4e3aTRUE\uff1b\u5426\u5219\u4e3aFALSE<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select 1 from lxw_dual where 1=2 or 2=2;<\/p>\n<p>1<\/p>\n<h3>3. \u903b\u8f91\u975e\u64cd\u4f5c: NOT<\/h3>\n<p>\u8bed\u6cd5: NOT A<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b\uff1aboolean<\/p>\n<p>\u8bf4\u660e\uff1a\u5982\u679cA\u4e3aFALSE\uff0c\u6216\u8005A\u4e3aNULL\uff0c\u5219\u4e3aTRUE\uff1b\u5426\u5219\u4e3aFALSE<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select 1 from lxw_dual where not 1=2;<\/p>\n<p>1<\/p>\n<h2>\u56db\u3001\u6570\u503c\u8ba1\u7b97<\/h2>\n<h3>1. \u53d6\u6574\u51fd\u6570: round<\/h3>\n<p>\u8bed\u6cd5: round(double a)<\/p>\n<p>\u8fd4\u56de\u503c: BIGINT<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56dedouble\u7c7b\u578b\u7684\u6574\u6570\u503c\u90e8\u5206\uff08\u9075\u5faa\u56db\u820d\u4e94\u5165\uff09<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select round(3.1415926) from lxw_dual;<\/p>\n<p>3<\/p>\n<p>hive> select round(3.5) from lxw_dual;<\/p>\n<p>4<\/p>\n<p>hive> create table lxw_dual as select round(9542.158) fromlxw_dual;<\/p>\n<p>hive> describe lxw_dual;<\/p>\n<p>_c0     bigint<\/p>\n<h3>2. \u6307\u5b9a\u7cbe\u5ea6\u53d6\u6574\u51fd\u6570: round<\/h3>\n<p>\u8bed\u6cd5: round(double a, int d)<\/p>\n<p>\u8fd4\u56de\u503c: DOUBLE<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u6307\u5b9a\u7cbe\u5ea6d\u7684double\u7c7b\u578b<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select round(3.1415926,4) from lxw_dual;<\/p>\n<p>3.1416<\/p>\n<h3>3. \u5411\u4e0b\u53d6\u6574\u51fd\u6570: floor<\/h3>\n<p>\u8bed\u6cd5: floor(double a)<\/p>\n<p>\u8fd4\u56de\u503c: BIGINT<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u7b49\u4e8e\u6216\u8005\u5c0f\u4e8e\u8be5double\u53d8\u91cf\u7684\u6700\u5927\u7684\u6574\u6570<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select floor(3.1415926) from lxw_dual;<\/p>\n<p>3<\/p>\n<p>hive> select floor(25) from lxw_dual;<\/p>\n<p>25<\/p>\n<h3>4. \u5411\u4e0a\u53d6\u6574\u51fd\u6570: ceil<\/h3>\n<p>\u8bed\u6cd5: ceil(double a)<\/p>\n<p>\u8fd4\u56de\u503c: BIGINT<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u7b49\u4e8e\u6216\u8005\u5927\u4e8e\u8be5double\u53d8\u91cf\u7684\u6700\u5c0f\u7684\u6574\u6570<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select ceil(3.1415926) from lxw_dual;<\/p>\n<p>4<\/p>\n<p>hive> select ceil(46) from lxw_dual;<\/p>\n<p>46<\/p>\n<h3>5. \u5411\u4e0a\u53d6\u6574\u51fd\u6570: ceiling<\/h3>\n<p>\u8bed\u6cd5: ceiling(double a)<\/p>\n<p>\u8fd4\u56de\u503c: BIGINT<\/p>\n<p>\u8bf4\u660e:\u4e0eceil\u529f\u80fd\u76f8\u540c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select ceiling(3.1415926) from lxw_dual;<\/p>\n<p>4<\/p>\n<p>hive> select ceiling(46) from lxw_dual;<\/p>\n<p>46<\/p>\n<h3>6. \u53d6\u968f\u673a\u6570\u51fd\u6570: rand<\/h3>\n<p>\u8bed\u6cd5: rand(),rand(int seed)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u4e00\u4e2a0\u52301\u8303\u56f4\u5185\u7684\u968f\u673a\u6570\u3002\u5982\u679c\u6307\u5b9a\u79cd\u5b50seed\uff0c\u5219\u4f1a\u7b49\u5230\u4e00\u4e2a\u7a33\u5b9a\u7684\u968f\u673a\u6570\u5e8f\u5217<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select rand() from lxw_dual;<\/p>\n<p>0.5577432776034763<\/p>\n<p>hive> select rand() from lxw_dual;<\/p>\n<p>0.6638336467363424<\/p>\n<p>hive> select rand(100) from lxw_dual;<\/p>\n<p>0.7220096548596434<\/p>\n<p>hive> select rand(100) from lxw_dual;<\/p>\n<p>0.7220096548596434<\/p>\n<h3>7. \u81ea\u7136\u6307\u6570\u51fd\u6570: exp<\/h3>\n<p>\u8bed\u6cd5: exp(double a)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u81ea\u7136\u5bf9\u6570e\u7684a\u6b21\u65b9<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select exp(2) from lxw_dual;<\/p>\n<p>7.38905609893065<\/p>\n<p>\u81ea\u7136\u5bf9\u6570\u51fd\u6570: ln<\/p>\n<p>\u8bed\u6cd5: ln(double a)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56dea\u7684\u81ea\u7136\u5bf9\u6570<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select ln(7.38905609893065) from lxw_dual;<\/p>\n<p>2.0<\/p>\n<h3>8. \u4ee510\u4e3a\u5e95\u5bf9\u6570\u51fd\u6570: log10<\/h3>\n<p>\u8bed\u6cd5: log10(double a)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u4ee510\u4e3a\u5e95\u7684a\u7684\u5bf9\u6570<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select log10(100) from lxw_dual;<\/p>\n<p>2.0<\/p>\n<h3>9. \u4ee52\u4e3a\u5e95\u5bf9\u6570\u51fd\u6570: log2<\/h3>\n<p>\u8bed\u6cd5: log2(double a)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u4ee52\u4e3a\u5e95\u7684a\u7684\u5bf9\u6570<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select log2(8) from lxw_dual;<\/p>\n<p>3.0<\/p>\n<h3>10.  \u5bf9\u6570\u51fd\u6570: log<\/h3>\n<p>\u8bed\u6cd5: log(double base, double a)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u4ee5base\u4e3a\u5e95\u7684a\u7684\u5bf9\u6570<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select log(4,256) from lxw_dual;<\/p>\n<p>4.0<\/p>\n<h3>11.  \u5e42\u8fd0\u7b97\u51fd\u6570: pow<\/h3>\n<p>\u8bed\u6cd5: pow(double a, double p)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56dea\u7684p\u6b21\u5e42<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select pow(2,4) from lxw_dual;<\/p>\n<p>16.0<\/p>\n<h3>12.  \u5e42\u8fd0\u7b97\u51fd\u6570: power<\/h3>\n<p>\u8bed\u6cd5: power(double a, double p)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56dea\u7684p\u6b21\u5e42,\u4e0epow\u529f\u80fd\u76f8\u540c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select power(2,4) from lxw_dual;<\/p>\n<p>16.0<\/p>\n<h3>13.  \u5f00\u5e73\u65b9\u51fd\u6570: sqrt<\/h3>\n<p>\u8bed\u6cd5: sqrt(double a)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56dea\u7684\u5e73\u65b9\u6839<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select sqrt(16) from lxw_dual;<\/p>\n<p>4.0<\/p>\n<h3>14.  \u4e8c\u8fdb\u5236\u51fd\u6570: bin<\/h3>\n<p>\u8bed\u6cd5: bin(BIGINT a)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56dea\u7684\u4e8c\u8fdb\u5236\u4ee3\u7801\u8868\u793a<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select bin(7) from lxw_dual;<\/p>\n<p>111<\/p>\n<h3>15.  \u5341\u516d\u8fdb\u5236\u51fd\u6570: hex<\/h3>\n<p>\u8bed\u6cd5: hex(BIGINT a)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e:\u5982\u679c\u53d8\u91cf\u662fint\u7c7b\u578b\uff0c\u90a3\u4e48\u8fd4\u56dea\u7684\u5341\u516d\u8fdb\u5236\u8868\u793a\uff1b\u5982\u679c\u53d8\u91cf\u662fstring\u7c7b\u578b\uff0c\u5219\u8fd4\u56de\u8be5\u5b57\u7b26\u4e32\u7684\u5341\u516d\u8fdb\u5236\u8868\u793a<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select hex(17) from lxw_dual;<\/p>\n<p>11<\/p>\n<p>hive> select hex(\u2018abc\u2019) from lxw_dual;<\/p>\n<p>616263<\/p>\n<h3>16.  \u53cd\u8f6c\u5341\u516d\u8fdb\u5236\u51fd\u6570: unhex<\/h3>\n<p>\u8bed\u6cd5: unhex(string a)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u8be5\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u6240\u4ee3\u7801\u7684\u5b57\u7b26\u4e32<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select unhex(\u2018616263\u2019) from lxw_dual;<\/p>\n<p>abc<\/p>\n<p>hive> select unhex(\u201811\u2019) from lxw_dual;<\/p>\n<p>&#45;<\/p>\n<p>hive> select unhex(616263) from lxw_dual;<\/p>\n<p>abc<\/p>\n<h3>17.  \u8fdb\u5236\u8f6c\u6362\u51fd\u6570: conv<\/h3>\n<p>\u8bed\u6cd5: conv(BIGINT num, int from_base, int to_base)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e:\u5c06\u6570\u503cnum\u4ecefrom_base\u8fdb\u5236\u8f6c\u5316\u5230to_base\u8fdb\u5236<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select conv(17,10,16) from lxw_dual;<\/p>\n<p>11<\/p>\n<p>hive> select conv(17,10,2) from lxw_dual;<\/p>\n<p>10001<\/p>\n<h3>18.  \u7edd\u5bf9\u503c\u51fd\u6570: abs<\/h3>\n<p>\u8bed\u6cd5: abs(double a)  abs(int a)<\/p>\n<p>\u8fd4\u56de\u503c: double       int<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u6570\u503ca\u7684\u7edd\u5bf9\u503c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select abs(-3.9) from lxw_dual;<\/p>\n<p>3.9<\/p>\n<p>hive> select abs(10.9) from lxw_dual;<\/p>\n<p>10.9<\/p>\n<h3>19.  \u6b63\u53d6\u4f59\u51fd\u6570: pmod<\/h3>\n<p>\u8bed\u6cd5: pmod(int a, int b),pmod(double a, double b)<\/p>\n<p>\u8fd4\u56de\u503c: int double<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u6b63\u7684a\u9664\u4ee5b\u7684\u4f59\u6570<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select pmod(9,4) from lxw_dual;<\/p>\n<p>1<\/p>\n<p>hive> select pmod(-9,4) from lxw_dual;<\/p>\n<p>3<\/p>\n<h3>20.  \u6b63\u5f26\u51fd\u6570: sin<\/h3>\n<p>\u8bed\u6cd5: sin(double a)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56dea\u7684\u6b63\u5f26\u503c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select sin(0.8) from lxw_dual;<\/p>\n<p>0.7173560908995228<\/p>\n<h3>21.  \u53cd\u6b63\u5f26\u51fd\u6570: asin<\/h3>\n<p>\u8bed\u6cd5: asin(double a)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56dea\u7684\u53cd\u6b63\u5f26\u503c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select asin(0.7173560908995228) from lxw_dual;<\/p>\n<p>0.8<\/p>\n<h3>22.  \u4f59\u5f26\u51fd\u6570: cos<\/h3>\n<p>\u8bed\u6cd5: cos(double a)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56dea\u7684\u4f59\u5f26\u503c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select cos(0.9) from lxw_dual;<\/p>\n<p>0.6216099682706644<\/p>\n<h3>23.  \u53cd\u4f59\u5f26\u51fd\u6570: acos<\/h3>\n<p>\u8bed\u6cd5: acos(double a)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56dea\u7684\u53cd\u4f59\u5f26\u503c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select acos(0.6216099682706644) from lxw_dual;<\/p>\n<p>0.9<\/p>\n<h3>24. positive\u51fd\u6570: positive<\/h3>\n<p>\u8bed\u6cd5: positive(int a), positive(double a)<\/p>\n<p>\u8fd4\u56de\u503c: int double<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56dea<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select positive(-10) from lxw_dual;<\/p>\n<p>-10<\/p>\n<p>hive> select positive(12) from lxw_dual;<\/p>\n<p>12<\/p>\n<h3>25. negative\u51fd\u6570: negative<\/h3>\n<p>\u8bed\u6cd5: negative(int a), negative(double a)<\/p>\n<p>\u8fd4\u56de\u503c: int double<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de-a<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select negative(-5) from lxw_dual;<\/p>\n<p>5<\/p>\n<p>hive> select negative(8) from lxw_dual;<\/p>\n<p>-8<\/p>\n<h2>\u4e94\u3001\u65e5\u671f\u51fd\u6570<\/h2>\n<h3>1. UNIX\u65f6\u95f4\u6233\u8f6c\u65e5\u671f\u51fd\u6570:from_unixtime<\/h3>\n<p>\u8bed\u6cd5: from_unixtime(bigint unixtime[, string format])<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e:\u8f6c\u5316UNIX\u65f6\u95f4\u6233\uff08\u4ece1970-01-01 00:00:00 UTC\u5230\u6307\u5b9a\u65f6\u95f4\u7684\u79d2\u6570\uff09\u5230\u5f53\u524d\u65f6\u533a\u7684\u65f6\u95f4\u683c\u5f0f<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select from_unixtime(1323308943,'yyyyMMdd')  fromlxw_dual;<\/p>\n<p>20111208<\/p>\n<h3>2. \u83b7\u53d6\u5f53\u524dUNIX\u65f6\u95f4\u6233\u51fd\u6570:unix_timestamp<\/h3>\n<p>\u8bed\u6cd5: unix_timestamp()<\/p>\n<p>\u8fd4\u56de\u503c: bigint<\/p>\n<p>\u8bf4\u660e:\u83b7\u5f97\u5f53\u524d\u65f6\u533a\u7684UNIX\u65f6\u95f4\u6233<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select unix_timestamp() from lxw_dual;<\/p>\n<p>1323309615<\/p>\n<h3>3. \u65e5\u671f\u8f6cUNIX\u65f6\u95f4\u6233\u51fd\u6570:unix_timestamp<\/h3>\n<p>\u8bed\u6cd5: unix_timestamp(string date)<\/p>\n<p>\u8fd4\u56de\u503c: bigint<\/p>\n<p>\u8bf4\u660e:\u8f6c\u6362\u683c\u5f0f\u4e3a\"yyyy-MM-ddHH:mm:ss\"\u7684\u65e5\u671f\u5230UNIX\u65f6\u95f4\u6233\u3002\u5982\u679c\u8f6c\u5316\u5931\u8d25\uff0c\u5219\u8fd4\u56de0\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select unix_timestamp('2011-12-07 13:01:03') from lxw_dual;<\/p>\n<p>1323234063<\/p>\n<h3>4. \u6307\u5b9a\u683c\u5f0f\u65e5\u671f\u8f6cUNIX\u65f6\u95f4\u6233\u51fd\u6570:unix_timestamp<\/h3>\n<p>\u8bed\u6cd5: unix_timestamp(string date, string pattern)<\/p>\n<p>\u8fd4\u56de\u503c: bigint<\/p>\n<p>\u8bf4\u660e:\u8f6c\u6362pattern\u683c\u5f0f\u7684\u65e5\u671f\u5230UNIX\u65f6\u95f4\u6233\u3002\u5982\u679c\u8f6c\u5316\u5931\u8d25\uff0c\u5219\u8fd4\u56de0\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select unix_timestamp('20111207 13:01:03','yyyyMMddHH:mm:ss') from lxw_dual;<\/p>\n<p>1323234063<\/p>\n<h3>5. \u65e5\u671f\u65f6\u95f4\u8f6c\u65e5\u671f\u51fd\u6570:to_date<\/h3>\n<p>\u8bed\u6cd5: to_date(string timestamp)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u65e5\u671f\u65f6\u95f4\u5b57\u6bb5\u4e2d\u7684\u65e5\u671f\u90e8\u5206\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select to_date('2011-12-08 10:03:01') from lxw_dual;<\/p>\n<p>2011-12-08<\/p>\n<h3>6. \u65e5\u671f\u8f6c\u5e74\u51fd\u6570: year<\/h3>\n<p>\u8bed\u6cd5: year(string date)<\/p>\n<p>\u8fd4\u56de\u503c: int<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u65e5\u671f\u4e2d\u7684\u5e74\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select year('2011-12-08 10:03:01') from lxw_dual;<\/p>\n<p>2011<\/p>\n<p>hive> select year('2012-12-08') from lxw_dual;<\/p>\n<p>2012<\/p>\n<h3>7. \u65e5\u671f\u8f6c\u6708\u51fd\u6570: month<\/h3>\n<p>\u8bed\u6cd5: month (string date)<\/p>\n<p>\u8fd4\u56de\u503c: int<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u65e5\u671f\u4e2d\u7684\u6708\u4efd\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select month('2011-12-08 10:03:01') from lxw_dual;<\/p>\n<p>12<\/p>\n<p>hive> select month('2011-08-08') from lxw_dual;<\/p>\n<p>8<\/p>\n<h3>8. \u65e5\u671f\u8f6c\u5929\u51fd\u6570: day<\/h3>\n<p>\u8bed\u6cd5: day (string date)<\/p>\n<p>\u8fd4\u56de\u503c: int<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u65e5\u671f\u4e2d\u7684\u5929\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select day('2011-12-08 10:03:01') from lxw_dual;<\/p>\n<p>8<\/p>\n<p>hive> select day('2011-12-24') from lxw_dual;<\/p>\n<p>24<\/p>\n<h3>9. \u65e5\u671f\u8f6c\u5c0f\u65f6\u51fd\u6570: hour<\/h3>\n<p>\u8bed\u6cd5: hour (string date)<\/p>\n<p>\u8fd4\u56de\u503c: int<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u65e5\u671f\u4e2d\u7684\u5c0f\u65f6\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select hour('2011-12-08 10:03:01') from lxw_dual;<\/p>\n<p>10<\/p>\n<h3>10.  \u65e5\u671f\u8f6c\u5206\u949f\u51fd\u6570: minute<\/h3>\n<p>\u8bed\u6cd5: minute (string date)<\/p>\n<p>\u8fd4\u56de\u503c: int<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u65e5\u671f\u4e2d\u7684\u5206\u949f\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select minute('2011-12-08 10:03:01') from lxw_dual;<\/p>\n<p>3<\/p>\n<h3>11.  \u65e5\u671f\u8f6c\u79d2\u51fd\u6570: second<\/h3>\n<p>\u8bed\u6cd5: second (string date)<\/p>\n<p>\u8fd4\u56de\u503c: int<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u65e5\u671f\u4e2d\u7684\u79d2\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select second('2011-12-08 10:03:01') from lxw_dual;<\/p>\n<p>1<\/p>\n<h3>12.  \u65e5\u671f\u8f6c\u5468\u51fd\u6570:weekofyear<\/h3>\n<p>\u8bed\u6cd5: weekofyear (string date)<\/p>\n<p>\u8fd4\u56de\u503c: int<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u65e5\u671f\u5728\u5f53\u524d\u7684\u5468\u6570\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select weekofyear('2011-12-08 10:03:01') from lxw_dual;<\/p>\n<p>49<\/p>\n<h3>13.  \u65e5\u671f\u6bd4\u8f83\u51fd\u6570: datediff<\/h3>\n<p>\u8bed\u6cd5: datediff(string enddate, string startdate)<\/p>\n<p>\u8fd4\u56de\u503c: int<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u7ed3\u675f\u65e5\u671f\u51cf\u53bb\u5f00\u59cb\u65e5\u671f\u7684\u5929\u6570\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select datediff('2012-12-08','2012-05-09') from lxw_dual;<\/p>\n<p>213<\/p>\n<h3>14.  \u65e5\u671f\u589e\u52a0\u51fd\u6570: date_add<\/h3>\n<p>\u8bed\u6cd5: date_add(string startdate, int days)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u5f00\u59cb\u65e5\u671fstartdate\u589e\u52a0days\u5929\u540e\u7684\u65e5\u671f\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select date_add('2012-12-08',10) from lxw_dual;<\/p>\n<p>2012-12-18<\/p>\n<h3>15.  \u65e5\u671f\u51cf\u5c11\u51fd\u6570: date_sub<\/h3>\n<p>\u8bed\u6cd5: date_sub (string startdate, int days)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56de\u5f00\u59cb\u65e5\u671fstartdate\u51cf\u5c11days\u5929\u540e\u7684\u65e5\u671f\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select date_sub('2012-12-08',10) from lxw_dual;<\/p>\n<p>2012-11-28<\/p>\n<h2>\u516d\u3001\u6761\u4ef6\u51fd\u6570<\/h2>\n<h3>1. If\u51fd\u6570: if<\/h3>\n<p>\u8bed\u6cd5: if(boolean testCondition, T valueTrue, T valueFalseOrNull)<\/p>\n<p>\u8fd4\u56de\u503c: T<\/p>\n<p>\u8bf4\u660e: \u5f53\u6761\u4ef6testCondition\u4e3aTRUE\u65f6\uff0c\u8fd4\u56devalueTrue\uff1b\u5426\u5219\u8fd4\u56devalueFalseOrNull<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select if(1=2,100,200) from lxw_dual;<\/p>\n<p>200<\/p>\n<p>hive> select if(1=1,100,200) from lxw_dual;<\/p>\n<p>100<\/p>\n<h3>2. \u975e\u7a7a\u67e5\u627e\u51fd\u6570: COALESCE<\/h3>\n<p>\u8bed\u6cd5: COALESCE(T v1, T v2,\u2026)<\/p>\n<p>\u8fd4\u56de\u503c: T<\/p>\n<p>\u8bf4\u660e: \u8fd4\u56de\u53c2\u6570\u4e2d\u7684\u7b2c\u4e00\u4e2a\u975e\u7a7a\u503c\uff1b\u5982\u679c\u6240\u6709\u503c\u90fd\u4e3aNULL\uff0c\u90a3\u4e48\u8fd4\u56deNULL<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select COALESCE(null,'100','50\u2032) from lxw_dual;<\/p>\n<p>100<\/p>\n<h3>3. \u6761\u4ef6\u5224\u65ad\u51fd\u6570\uff1aCASE<\/h3>\n<p>\u8bed\u6cd5: CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END<\/p>\n<p>\u8fd4\u56de\u503c: T<\/p>\n<p>\u8bf4\u660e\uff1a\u5982\u679ca\u7b49\u4e8eb\uff0c\u90a3\u4e48\u8fd4\u56dec\uff1b\u5982\u679ca\u7b49\u4e8ed\uff0c\u90a3\u4e48\u8fd4\u56dee\uff1b\u5426\u5219\u8fd4\u56def<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> Select case 100 when 50 then 'tom' when 100 then 'mary'else 'tim' end from lxw_dual;<\/p>\n<p>mary<\/p>\n<p>hive> Select case 200 when 50 then 'tom' when 100 then 'mary'else 'tim' end from lxw_dual;<\/p>\n<p>tim<\/p>\n<h3>4. \u6761\u4ef6\u5224\u65ad\u51fd\u6570\uff1aCASE<\/h3>\n<p>\u8bed\u6cd5: CASE WHEN a THEN b [WHEN c THEN d]* [ELSE e] END<\/p>\n<p>\u8fd4\u56de\u503c: T<\/p>\n<p>\u8bf4\u660e\uff1a\u5982\u679ca\u4e3aTRUE,\u5219\u8fd4\u56deb\uff1b\u5982\u679cc\u4e3aTRUE\uff0c\u5219\u8fd4\u56ded\uff1b\u5426\u5219\u8fd4\u56dee<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select case when 1=2 then 'tom' when 2=2 then 'mary' else'tim' end from lxw_dual;<\/p>\n<p>mary<\/p>\n<p>hive> select case when 1=1 then 'tom' when 2=2 then 'mary' else'tim' end from lxw_dual;<\/p>\n<p>tom<\/p>\n<h2>\u4e03\u3001\u5b57\u7b26\u4e32\u51fd\u6570<\/h2>\n<h3>1. \u5b57\u7b26\u4e32\u957f\u5ea6\u51fd\u6570\uff1alength<\/h3>\n<p>\u8bed\u6cd5: length(string A)<\/p>\n<p>\u8fd4\u56de\u503c: int<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56de\u5b57\u7b26\u4e32A\u7684\u957f\u5ea6<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select length('abcedfg') from lxw_dual;<\/p>\n<p>7<\/p>\n<h3>2. \u5b57\u7b26\u4e32\u53cd\u8f6c\u51fd\u6570\uff1areverse<\/h3>\n<p>\u8bed\u6cd5: reverse(string A)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56de\u5b57\u7b26\u4e32A\u7684\u53cd\u8f6c\u7ed3\u679c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select reverse(abcedfg\u2019) from lxw_dual;<\/p>\n<p>gfdecba<\/p>\n<h3>3. \u5b57\u7b26\u4e32\u8fde\u63a5\u51fd\u6570\uff1aconcat<\/h3>\n<p>\u8bed\u6cd5: concat(string A, string B\u2026)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56de\u8f93\u5165\u5b57\u7b26\u4e32\u8fde\u63a5\u540e\u7684\u7ed3\u679c\uff0c\u652f\u6301\u4efb\u610f\u4e2a\u8f93\u5165\u5b57\u7b26\u4e32<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select concat(\u2018abc\u2019,'def\u2019,'gh\u2019) from lxw_dual;<\/p>\n<p>abcdefgh<\/p>\n<h3>4. \u5e26\u5206\u9694\u7b26\u5b57\u7b26\u4e32\u8fde\u63a5\u51fd\u6570\uff1aconcat_ws<\/h3>\n<p>\u8bed\u6cd5: concat_ws(string SEP, string A, string B\u2026)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56de\u8f93\u5165\u5b57\u7b26\u4e32\u8fde\u63a5\u540e\u7684\u7ed3\u679c\uff0cSEP\u8868\u793a\u5404\u4e2a\u5b57\u7b26\u4e32\u95f4\u7684\u5206\u9694\u7b26<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select concat_ws(',','abc','def','gh') from lxw_dual;<\/p>\n<p>abc,def,gh<\/p>\n<h3>5. \u5b57\u7b26\u4e32\u622a\u53d6\u51fd\u6570\uff1asubstr,substring<\/h3>\n<p>\u8bed\u6cd5: substr(string A, int start),substring(string A, int start)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56de\u5b57\u7b26\u4e32A\u4ecestart\u4f4d\u7f6e\u5230\u7ed3\u5c3e\u7684\u5b57\u7b26\u4e32<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select substr('abcde',3) from lxw_dual;<\/p>\n<p>cde<\/p>\n<p>hive> select substring('abcde',3) from lxw_dual;<\/p>\n<p>cde<\/p>\n<p>hive>  selectsubstr('abcde',-1) from lxw_dual; \uff08\u548cORACLE\u76f8\u540c\uff09<\/p>\n<p>e<\/p>\n<h3>6. \u5b57\u7b26\u4e32\u622a\u53d6\u51fd\u6570\uff1asubstr,substring<\/h3>\n<p>\u8bed\u6cd5: substr(string A, int start, int len),substring(string A, intstart, int len)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56de\u5b57\u7b26\u4e32A\u4ecestart\u4f4d\u7f6e\u5f00\u59cb\uff0c\u957f\u5ea6\u4e3alen\u7684\u5b57\u7b26\u4e32<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select substr('abcde',3,2) from lxw_dual;<\/p>\n<p>cd<\/p>\n<p>hive> select substring('abcde',3,2) from lxw_dual;<\/p>\n<p>cd<\/p>\n<p>hive>select substring('abcde',-2,2) from lxw_dual;<\/p>\n<p>de<\/p>\n<h3>7. \u5b57\u7b26\u4e32\u8f6c\u5927\u5199\u51fd\u6570\uff1aupper,ucase<\/h3>\n<p>\u8bed\u6cd5: upper(string A) ucase(string A)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56de\u5b57\u7b26\u4e32A\u7684\u5927\u5199\u683c\u5f0f<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select upper('abSEd') from lxw_dual;<\/p>\n<p>hive> select ucase('abSEd') from lxw_dual;<\/p>\n<h3>8. \u5b57\u7b26\u4e32\u8f6c\u5c0f\u5199\u51fd\u6570\uff1alower,lcase<\/h3>\n<p>\u8bed\u6cd5: lower(string A) lcase(string A)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56de\u5b57\u7b26\u4e32A\u7684\u5c0f\u5199\u683c\u5f0f<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select lower('abSEd') from lxw_dual;<\/p>\n<p>absed<\/p>\n<p>hive> select lcase('abSEd') from lxw_dual;<\/p>\n<p>absed<\/p>\n<h3>9. \u53bb\u7a7a\u683c\u51fd\u6570\uff1atrim<\/h3>\n<p>\u8bed\u6cd5: trim(string A)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u53bb\u9664\u5b57\u7b26\u4e32\u4e24\u8fb9\u7684\u7a7a\u683c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select trim(' abc ') from lxw_dual;<\/p>\n<p>abc<\/p>\n<h3>10.  \u5de6\u8fb9\u53bb\u7a7a\u683c\u51fd\u6570\uff1altrim<\/h3>\n<p>\u8bed\u6cd5: ltrim(string A)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u53bb\u9664\u5b57\u7b26\u4e32\u5de6\u8fb9\u7684\u7a7a\u683c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select ltrim(' abc ') from lxw_dual;<\/p>\n<p>abc<\/p>\n<h3>11.  \u53f3\u8fb9\u53bb\u7a7a\u683c\u51fd\u6570\uff1artrim<\/h3>\n<p>\u8bed\u6cd5: rtrim(string A)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u53bb\u9664\u5b57\u7b26\u4e32\u53f3\u8fb9\u7684\u7a7a\u683c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select rtrim(' abc ') from lxw_dual;<\/p>\n<p>abc<\/p>\n<h3>12.  \u6b63\u5219\u8868\u8fbe\u5f0f\u66ff\u6362\u51fd\u6570\uff1aregexp_replace<\/h3>\n<p>\u8bed\u6cd5: regexp_replace(string A, string B, string C)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u5c06\u5b57\u7b26\u4e32A\u4e2d\u7684\u7b26\u5408java\u6b63\u5219\u8868\u8fbe\u5f0fB\u7684\u90e8\u5206\u66ff\u6362\u4e3aC\u3002\u6ce8\u610f\uff0c\u5728\u6709\u4e9b\u60c5\u51b5\u4e0b\u8981\u4f7f\u7528\u8f6c\u4e49\u5b57\u7b26,\u7c7b\u4f3coracle\u4e2d\u7684regexp_replace\u51fd\u6570\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select regexp_replace('foobar', 'oo|ar', '') from lxw_dual;<\/p>\n<p>fb<\/p>\n<h3>13.  \u6b63\u5219\u8868\u8fbe\u5f0f\u89e3\u6790\u51fd\u6570\uff1aregexp_extract<\/h3>\n<p>\u8bed\u6cd5: regexp_extract(string subject, string pattern, int index)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u5c06\u5b57\u7b26\u4e32subject\u6309\u7167pattern\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u89c4\u5219\u62c6\u5206\uff0c\u8fd4\u56deindex\u6307\u5b9a\u7684\u5b57\u7b26\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select regexp_extract('foothebar', 'foo(.*?)(bar)', 1) fromlxw_dual;<\/p>\n<p>the<\/p>\n<p>hive> select regexp_extract('foothebar', 'foo(.*?)(bar)', 2) fromlxw_dual;<\/p>\n<p>bar<\/p>\n<p>hive> select regexp_extract('foothebar', 'foo(.*?)(bar)', 0) fromlxw_dual;<\/p>\n<p>foothebar<\/p>\n<p><strong>\u6ce8\u610f\uff0c\u5728\u6709\u4e9b\u60c5\u51b5\u4e0b\u8981\u4f7f\u7528\u8f6c\u4e49\u5b57\u7b26\uff0c\u4e0b\u9762\u7684\u7b49\u53f7\u8981\u7528\u53cc\u7ad6\u7ebf\u8f6c\u4e49\uff0c\u8fd9\u662fjava\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u89c4\u5219\u3002<\/strong><\/p>\n<p>select data_field,<\/p>\n<pre><code> regexp_extract(data_field,'.*?bgStart\\\\=([^&amp;]+)',1) as aaa,\n\n regexp_extract(data_field,'.*?contentLoaded_headStart\\\\=([^&amp;]+)',1) as bbb,\n\n regexp_extract(data_field,'.*?AppLoad2Req\\\\=([^&amp;]+)',1) as ccc\n\n from pt_nginx_loginlog_st\n\n where pt = '2012-03-26'limit 2;\n<\/code><\/pre>\n<h3>14. URL\u89e3\u6790\u51fd\u6570\uff1aparse_url<\/h3>\n<p>\u8bed\u6cd5: parse_url(string urlString, string partToExtract [, stringkeyToExtract])<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56deURL\u4e2d\u6307\u5b9a\u7684\u90e8\u5206\u3002partToExtract\u7684\u6709\u6548\u503c\u4e3a\uff1aHOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY,  FILE, and USERINFO.<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> selectparse_url('http:\/\/facebook.com\/path1\/p.php?k1=v1&amp;k2=v2#Ref1', 'HOST') fromlxw_dual;<\/p>\n<p>facebook.com<\/p>\n<p>hive> selectparse_url('http:\/\/facebook.com\/path1\/p.php?k1=v1&amp;k2=v2#Ref1', 'QUERY','k1') from lxw_dual;<\/p>\n<p>v1<\/p>\n<h3>15. json\u89e3\u6790\u51fd\u6570\uff1aget_json_object<\/h3>\n<p>\u8bed\u6cd5: get_json_object(string json_string, string path)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u89e3\u6790json\u7684\u5b57\u7b26\u4e32json_string,\u8fd4\u56depath\u6307\u5b9a\u7684\u5185\u5bb9\u3002\u5982\u679c\u8f93\u5165\u7684json\u5b57\u7b26\u4e32\u65e0\u6548\uff0c\u90a3\u4e48\u8fd4\u56deNULL\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select   get_json_object('{\"store\":<\/p>\n<p>&#62;   {\"fruit\":&#91;{\"weight\":8,\"type\":\"apple\"},{\"weight\":9,\"type\":\"pear\"}],<\/p>\n<p>&#62;    \"bicycle\":{\"price\":19.95,\"color\":\"red\"}<\/p>\n<p>&#62;   },<\/p>\n<p>&#62;  \"email\":\"amy@only_for_json_udf_test.net\",<\/p>\n<p>&#62;  \"owner\":\"amy\"<\/p>\n<p>&#62; }<\/p>\n<p>&#62; ','$.owner') from lxw_dual;<\/p>\n<p>amy<\/p>\n<h3>16.  \u7a7a\u683c\u5b57\u7b26\u4e32\u51fd\u6570\uff1aspace<\/h3>\n<p>\u8bed\u6cd5: space(int n)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56de\u957f\u5ea6\u4e3an\u7684\u5b57\u7b26\u4e32<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select space(10) from lxw_dual;<\/p>\n<p>hive> select length(space(10)) from lxw_dual;<\/p>\n<p>10<\/p>\n<h3>17.  \u91cd\u590d\u5b57\u7b26\u4e32\u51fd\u6570\uff1arepeat<\/h3>\n<p>\u8bed\u6cd5: repeat(string str, int n)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56de\u91cd\u590dn\u6b21\u540e\u7684str\u5b57\u7b26\u4e32<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select repeat('abc',5) from lxw_dual;<\/p>\n<p>abcabcabcabcabc<\/p>\n<h3>18.  \u9996\u5b57\u7b26ascii\u51fd\u6570\uff1aascii<\/h3>\n<p>\u8bed\u6cd5: ascii(string str)<\/p>\n<p>\u8fd4\u56de\u503c: int<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56de\u5b57\u7b26\u4e32str\u7b2c\u4e00\u4e2a\u5b57\u7b26\u7684ascii\u7801<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select ascii('abcde') from lxw_dual;<\/p>\n<p>97<\/p>\n<h3>19.  \u5de6\u8865\u8db3\u51fd\u6570\uff1alpad<\/h3>\n<p>\u8bed\u6cd5: lpad(string str, int len, string pad)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u5c06str\u8fdb\u884c\u7528pad\u8fdb\u884c\u5de6\u8865\u8db3\u5230len\u4f4d<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select lpad('abc',10,'td') from lxw_dual;<\/p>\n<p>tdtdtdtabc<\/p>\n<p><strong>\u6ce8\u610f\uff1a\u4e0eGP\uff0cORACLE\u4e0d\u540c\uff0cpad\u4e0d\u80fd\u9ed8\u8ba4<\/strong><\/p>\n<h3>20.  \u53f3\u8865\u8db3\u51fd\u6570\uff1arpad<\/h3>\n<p>\u8bed\u6cd5: rpad(string str, int len, string pad)<\/p>\n<p>\u8fd4\u56de\u503c: string<\/p>\n<p>\u8bf4\u660e\uff1a\u5c06str\u8fdb\u884c\u7528pad\u8fdb\u884c\u53f3\u8865\u8db3\u5230len\u4f4d<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select rpad('abc',10,'td') from lxw_dual;<\/p>\n<p>abctdtdtdt<\/p>\n<h3>21.  \u5206\u5272\u5b57\u7b26\u4e32\u51fd\u6570: split<\/h3>\n<p>\u8bed\u6cd5: split(string str, stringpat)<\/p>\n<p>\u8fd4\u56de\u503c: array<\/p>\n<p>\u8bf4\u660e:\u6309\u7167pat\u5b57\u7b26\u4e32\u5206\u5272str\uff0c\u4f1a\u8fd4\u56de\u5206\u5272\u540e\u7684\u5b57\u7b26\u4e32\u6570\u7ec4<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select split('abtcdtef','t') from lxw_dual;<\/p>\n<p>[\"ab\",\"cd\",\"ef\"]<\/p>\n<h3>22.  \u96c6\u5408\u67e5\u627e\u51fd\u6570:find_in_set<\/h3>\n<p>\u8bed\u6cd5: find_in_set(string str, string strList)<\/p>\n<p>\u8fd4\u56de\u503c: int<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56destr\u5728strlist\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e\uff0cstrlist\u662f\u7528\u9017\u53f7\u5206\u5272\u7684\u5b57\u7b26\u4e32\u3002\u5982\u679c\u6ca1\u6709\u627e\u8be5str\u5b57\u7b26\uff0c\u5219\u8fd4\u56de0<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select find_in_set('ab','ef,ab,de') from lxw_dual;<\/p>\n<p>2<\/p>\n<p>hive> select find_in_set('at','ef,ab,de') from lxw_dual;<\/p>\n<p>0<\/p>\n<h2>\u516b\u3001\u96c6\u5408\u7edf\u8ba1\u51fd\u6570<\/h2>\n<h3>1. \u4e2a\u6570\u7edf\u8ba1\u51fd\u6570: count<\/h3>\n<p>\u8bed\u6cd5: count(*), count(expr), count(DISTINCT expr[, expr_.])<\/p>\n<p>\u8fd4\u56de\u503c: int<\/p>\n<p>\u8bf4\u660e: count(*)\u7edf\u8ba1\u68c0\u7d22\u51fa\u7684\u884c\u7684\u4e2a\u6570\uff0c\u5305\u62ecNULL\u503c\u7684\u884c\uff1bcount(expr)\u8fd4\u56de\u6307\u5b9a\u5b57\u6bb5\u7684\u975e\u7a7a\u503c\u7684\u4e2a\u6570\uff1bcount(DISTINCTexpr[,  expr_.])\u8fd4\u56de\u6307\u5b9a\u5b57\u6bb5\u7684\u4e0d\u540c\u7684\u975e\u7a7a\u503c\u7684\u4e2a\u6570<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select count(*) from lxw_dual;<\/p>\n<p>20<\/p>\n<p>hive> select count(distinct t) from lxw_dual;<\/p>\n<p>10<\/p>\n<h3>2. \u603b\u548c\u7edf\u8ba1\u51fd\u6570: sum<\/h3>\n<p>\u8bed\u6cd5: sum(col), sum(DISTINCT col)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e: sum(col)\u7edf\u8ba1\u7ed3\u679c\u96c6\u4e2dcol\u7684\u76f8\u52a0\u7684\u7ed3\u679c\uff1bsum(DISTINCT col)\u7edf\u8ba1\u7ed3\u679c\u4e2dcol\u4e0d\u540c\u503c\u76f8\u52a0\u7684\u7ed3\u679c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select sum(t) from lxw_dual;<\/p>\n<p>100<\/p>\n<p>hive> select sum(distinct t) from lxw_dual;<\/p>\n<p>70<\/p>\n<h3>3. \u5e73\u5747\u503c\u7edf\u8ba1\u51fd\u6570: avg<\/h3>\n<p>\u8bed\u6cd5: avg(col), avg(DISTINCT col)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e: avg(col)\u7edf\u8ba1\u7ed3\u679c\u96c6\u4e2dcol\u7684\u5e73\u5747\u503c\uff1bavg(DISTINCT col)\u7edf\u8ba1\u7ed3\u679c\u4e2dcol\u4e0d\u540c\u503c\u76f8\u52a0\u7684\u5e73\u5747\u503c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select avg(t) from lxw_dual;<\/p>\n<p>50<\/p>\n<p>hive> select avg (distinct t) from lxw_dual;<\/p>\n<p>30<\/p>\n<h3>4. \u6700\u5c0f\u503c\u7edf\u8ba1\u51fd\u6570: min<\/h3>\n<p>\u8bed\u6cd5: min(col)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u7edf\u8ba1\u7ed3\u679c\u96c6\u4e2dcol\u5b57\u6bb5\u7684\u6700\u5c0f\u503c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select min(t) from lxw_dual;<\/p>\n<p>20<\/p>\n<h3>5. \u6700\u5927\u503c\u7edf\u8ba1\u51fd\u6570: max<\/h3>\n<p>\u8bed\u6cd5: maxcol)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u7edf\u8ba1\u7ed3\u679c\u96c6\u4e2dcol\u5b57\u6bb5\u7684\u6700\u5927\u503c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select max(t) from lxw_dual;<\/p>\n<p>120<\/p>\n<h3>6. \u975e\u7a7a\u96c6\u5408\u603b\u4f53\u53d8\u91cf\u51fd\u6570:var_pop<\/h3>\n<p>\u8bed\u6cd5: var_pop(col)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u7edf\u8ba1\u7ed3\u679c\u96c6\u4e2dcol\u975e\u7a7a\u96c6\u5408\u7684\u603b\u4f53\u53d8\u91cf\uff08\u5ffd\u7565null\uff09<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<h3>7. \u975e\u7a7a\u96c6\u5408\u6837\u672c\u53d8\u91cf\u51fd\u6570:var_samp<\/h3>\n<p>\u8bed\u6cd5: var_samp (col)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u7edf\u8ba1\u7ed3\u679c\u96c6\u4e2dcol\u975e\u7a7a\u96c6\u5408\u7684\u6837\u672c\u53d8\u91cf\uff08\u5ffd\u7565null\uff09<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<h3>8. \u603b\u4f53\u6807\u51c6\u504f\u79bb\u51fd\u6570:stddev_pop<\/h3>\n<p>\u8bed\u6cd5: stddev_pop(col)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u8be5\u51fd\u6570\u8ba1\u7b97\u603b\u4f53\u6807\u51c6\u504f\u79bb\uff0c\u5e76\u8fd4\u56de\u603b\u4f53\u53d8\u91cf\u7684\u5e73\u65b9\u6839\uff0c\u5176\u8fd4\u56de\u503c\u4e0eVAR_POP\u51fd\u6570\u7684\u5e73\u65b9\u6839\u76f8\u540c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<h3>9. \u6837\u672c\u6807\u51c6\u504f\u79bb\u51fd\u6570:stddev_samp<\/h3>\n<p>\u8bed\u6cd5: stddev_samp (col)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u8be5\u51fd\u6570\u8ba1\u7b97\u6837\u672c\u6807\u51c6\u504f\u79bb<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<h3>10\uff0e\u4e2d\u4f4d\u6570\u51fd\u6570:percentile<\/h3>\n<p>\u8bed\u6cd5: percentile(BIGINT col, p)<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u6c42\u51c6\u786e\u7684\u7b2cpth\u4e2a\u767e\u5206\u4f4d\u6570\uff0cp\u5fc5\u987b\u4ecb\u4e8e0\u548c1\u4e4b\u95f4\uff0c\u4f46\u662fcol\u5b57\u6bb5\u76ee\u524d\u53ea\u652f\u6301\u6574\u6570\uff0c\u4e0d\u652f\u6301\u6d6e\u70b9\u6570\u7c7b\u578b<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<h3>11.  \u4e2d\u4f4d\u6570\u51fd\u6570:percentile<\/h3>\n<p>\u8bed\u6cd5: percentile(BIGINT col, array(p1 [, p2]\u2026))<\/p>\n<p>\u8fd4\u56de\u503c: array<double><\/p>\n<p>\u8bf4\u660e:\u529f\u80fd\u548c\u4e0a\u8ff0\u7c7b\u4f3c\uff0c\u4e4b\u540e\u540e\u9762\u53ef\u4ee5\u8f93\u5165\u591a\u4e2a\u767e\u5206\u4f4d\u6570\uff0c\u8fd4\u56de\u7c7b\u578b\u4e5f\u4e3aarray<double>\uff0c\u5176\u4e2d\u4e3a\u5bf9\u5e94\u7684\u767e\u5206\u4f4d\u6570\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>select percentile(score,&lt;0.2,0.4>) from lxw_dual\uff1b\u53d60.2\uff0c0.4\u4f4d\u7f6e\u7684\u6570\u636e<\/p>\n<h3>12.  \u8fd1\u4f3c\u4e2d\u4f4d\u6570\u51fd\u6570:percentile_approx<\/h3>\n<p>\u8bed\u6cd5: percentile_approx(DOUBLE col, p [, B])<\/p>\n<p>\u8fd4\u56de\u503c: double<\/p>\n<p>\u8bf4\u660e:\u6c42\u8fd1\u4f3c\u7684\u7b2cpth\u4e2a\u767e\u5206\u4f4d\u6570\uff0cp\u5fc5\u987b\u4ecb\u4e8e0\u548c1\u4e4b\u95f4\uff0c\u8fd4\u56de\u7c7b\u578b\u4e3adouble\uff0c\u4f46\u662fcol\u5b57\u6bb5\u652f\u6301\u6d6e\u70b9\u7c7b\u578b\u3002\u53c2\u6570B\u63a7\u5236\u5185\u5b58\u6d88\u8017\u7684\u8fd1\u4f3c\u7cbe\u5ea6\uff0cB\u8d8a\u5927\uff0c\u7ed3\u679c\u7684\u51c6\u786e\u5ea6\u8d8a\u9ad8\u3002\u9ed8\u8ba4\u4e3a10,000\u3002\u5f53col\u5b57\u6bb5\u4e2d\u7684distinct\u503c\u7684\u4e2a\u6570\u5c0f\u4e8eB\u65f6\uff0c\u7ed3\u679c\u4e3a\u51c6\u786e\u7684\u767e\u5206\u4f4d\u6570<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<h3>13.  \u8fd1\u4f3c\u4e2d\u4f4d\u6570\u51fd\u6570:percentile_approx<\/h3>\n<p>\u8bed\u6cd5: percentile_approx(DOUBLE col, array(p1 [, p2]\u2026) [, B])<\/p>\n<p>\u8fd4\u56de\u503c: array<double><\/p>\n<p>\u8bf4\u660e:\u529f\u80fd\u548c\u4e0a\u8ff0\u7c7b\u4f3c\uff0c\u4e4b\u540e\u540e\u9762\u53ef\u4ee5\u8f93\u5165\u591a\u4e2a\u767e\u5206\u4f4d\u6570\uff0c\u8fd4\u56de\u7c7b\u578b\u4e5f\u4e3aarray<double>\uff0c\u5176\u4e2d\u4e3a\u5bf9\u5e94\u7684\u767e\u5206\u4f4d\u6570\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<h3>14.  \u76f4\u65b9\u56fe:histogram_numeric<\/h3>\n<p>\u8bed\u6cd5: histogram_numeric(col, b)<\/p>\n<p>\u8fd4\u56de\u503c: array<struct {\u2018x\u2019,\u2018y\u2019}><\/p>\n<p>\u8bf4\u660e:\u4ee5b\u4e3a\u57fa\u51c6\u8ba1\u7b97col\u7684\u76f4\u65b9\u56fe\u4fe1\u606f\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select histogram_numeric(100,5) from lxw_dual;<\/p>\n<p>[{\"x\":100.0,\"y\":1.0}]<\/p>\n<h2>\u4e5d\u3001\u590d\u5408\u7c7b\u578b\u6784\u5efa\u64cd\u4f5c<\/h2>\n<h3>1. Map\u7c7b\u578b\u6784\u5efa: map<\/h3>\n<p>\u8bed\u6cd5: map (key1, value1, key2, value2,\u2026)<\/p>\n<p>\u8bf4\u660e\uff1a\u6839\u636e\u8f93\u5165\u7684key\u548cvalue\u5bf9\u6784\u5efamap\u7c7b\u578b<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> Create table lxw_test as select map('100','tom','200','mary')as t from lxw_dual;<\/p>\n<p>hive> describe lxw_test;<\/p>\n<p>t       map&lt;string,string><\/p>\n<p>hive> select t from lxw_test;<\/p>\n<p>{\"100\":\"tom\",\"200\":\"mary\"}<\/p>\n<h3>2. Struct\u7c7b\u578b\u6784\u5efa: struct<\/h3>\n<p>\u8bed\u6cd5: struct(val1, val2, val3,\u2026)<\/p>\n<p>\u8bf4\u660e\uff1a\u6839\u636e\u8f93\u5165\u7684\u53c2\u6570\u6784\u5efa\u7ed3\u6784\u4f53struct\u7c7b\u578b<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> create table lxw_test as select struct('tom','mary','tim')as t from lxw_dual;<\/p>\n<p>hive> describe lxw_test;<\/p>\n<p>t       struct&lt;col1:string,col2:string,col3:string><\/p>\n<p>hive> select t from lxw_test;<\/p>\n<p>{\"col1\":\"tom\",\"col2\":\"mary\",\"col3\":\"tim\"}<\/p>\n<h3>3. array\u7c7b\u578b\u6784\u5efa: array<\/h3>\n<p>\u8bed\u6cd5: array(val1, val2,\u2026)<\/p>\n<p>\u8bf4\u660e\uff1a\u6839\u636e\u8f93\u5165\u7684\u53c2\u6570\u6784\u5efa\u6570\u7ec4array\u7c7b\u578b<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> create table lxw_test as selectarray(\"tom\",\"mary\",\"tim\") as t from lxw_dual;<\/p>\n<p>hive> describe lxw_test;<\/p>\n<p>t       array<string><\/p>\n<p>hive> select t from lxw_test;<\/p>\n<p>[\"tom\",\"mary\",\"tim\"]<\/p>\n<h2>\u5341\u3001\u590d\u6742\u7c7b\u578b\u8bbf\u95ee\u64cd\u4f5c<\/h2>\n<h3>1. array\u7c7b\u578b\u8bbf\u95ee: A[n]<\/h3>\n<p>\u8bed\u6cd5: A[n]<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b: A\u4e3aarray\u7c7b\u578b\uff0cn\u4e3aint\u7c7b\u578b<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56de\u6570\u7ec4A\u4e2d\u7684\u7b2cn\u4e2a\u53d8\u91cf\u503c\u3002\u6570\u7ec4\u7684\u8d77\u59cb\u4e0b\u6807\u4e3a0\u3002\u6bd4\u5982\uff0cA\u662f\u4e2a\u503c\u4e3a['foo',  'bar']\u7684\u6570\u7ec4\u7c7b\u578b\uff0c\u90a3\u4e48A[0]\u5c06\u8fd4\u56de'foo',\u800cA[1]\u5c06\u8fd4\u56de'bar'<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> create table lxw_test as selectarray(\"tom\",\"mary\",\"tim\") as t from lxw_dual;<\/p>\n<p>hive> select t[0],t[1],t[2] from lxw_test;<\/p>\n<p>tom     mary   tim<\/p>\n<h3>2. map\u7c7b\u578b\u8bbf\u95ee: M[key]<\/h3>\n<p>\u8bed\u6cd5: M[key]<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b: M\u4e3amap\u7c7b\u578b\uff0ckey\u4e3amap\u4e2d\u7684key\u503c<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56demap\u7c7b\u578bM\u4e2d\uff0ckey\u503c\u4e3a\u6307\u5b9a\u503c\u7684value\u503c\u3002\u6bd4\u5982\uff0cM\u662f\u503c\u4e3a{'f'  -> 'foo', 'b'-> 'bar', 'all' -> 'foobar'}\u7684map\u7c7b\u578b\uff0c\u90a3\u4e48M['all']\u5c06\u4f1a\u8fd4\u56de'foobar'<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> Create table lxw_test as selectmap('100','tom','200','mary') as t from lxw_dual;<\/p>\n<p>hive> select t['200'],t['100'] from lxw_test;<\/p>\n<p>mary    tom<\/p>\n<h3>3. struct\u7c7b\u578b\u8bbf\u95ee: S.x<\/h3>\n<p>\u8bed\u6cd5: S.x<\/p>\n<p>\u64cd\u4f5c\u7c7b\u578b: S\u4e3astruct\u7c7b\u578b<\/p>\n<p>\u8bf4\u660e\uff1a\u8fd4\u56de\u7ed3\u6784\u4f53S\u4e2d\u7684x\u5b57\u6bb5\u3002\u6bd4\u5982\uff0c\u5bf9\u4e8e\u7ed3\u6784\u4f53struct foobar {int foo, int bar}\uff0cfoobar.foo\u8fd4\u56de\u7ed3\u6784\u4f53\u4e2d\u7684foo\u5b57\u6bb5<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> create table lxw_test as select struct('tom','mary','tim')as t from lxw_dual;<\/p>\n<p>hive> describe lxw_test;<\/p>\n<p>t       struct&lt;col1:string,col2:string,col3:string><\/p>\n<p>hive> select t.col1,t.col3 from lxw_test;<\/p>\n<p>tom     tim<\/p>\n<h2>\u5341\u4e00\u3001\u590d\u6742\u7c7b\u578b\u957f\u5ea6\u7edf\u8ba1\u51fd\u6570<\/h2>\n<h3>1.   Map\u7c7b\u578b\u957f\u5ea6\u51fd\u6570: size(Map&lt;K.V>)<\/h3>\n<p>\u8bed\u6cd5: size(Map&lt;K.V>)<\/p>\n<p>\u8fd4\u56de\u503c: int<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56demap\u7c7b\u578b\u7684\u957f\u5ea6<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select size(map('100','tom','101','mary')) from lxw_dual;<\/p>\n<p>2<\/p>\n<h3>2.   array\u7c7b\u578b\u957f\u5ea6\u51fd\u6570: size(Array<T>)<\/h3>\n<p>\u8bed\u6cd5: size(Array<T>)<\/p>\n<p>\u8fd4\u56de\u503c: int<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56dearray\u7c7b\u578b\u7684\u957f\u5ea6<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select size(array('100','101','102','103')) from lxw_dual;<\/p>\n<p>4<\/p>\n<h3>3.   \u7c7b\u578b\u8f6c\u6362\u51fd\u6570<\/h3>\n<p>\u7c7b\u578b\u8f6c\u6362\u51fd\u6570: cast<\/p>\n<p>\u8bed\u6cd5: cast(expr as <type>)<\/p>\n<p>\u8fd4\u56de\u503c: Expected \"=\" to follow \"type\"<\/p>\n<p>\u8bf4\u660e:\u8fd4\u56dearray\u7c7b\u578b\u7684\u957f\u5ea6<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<p>hive> select cast(1 as bigint) from lxw_dual;<\/p>\n<p>1<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u7b80\u5355\u63cf\u8ff0\u8868\u7ed3\u6784\uff0c\u5b57\u6bb5\u7c7b\u578b hive>desc tabl_name; \u4e8c\uff0c\u5173\u7cfb\u8fd0\u7b97\uff0c\u7b49\u4e8e\uff0c\u4e0d\u7b49\u4e8e\uff0c\u5c0f\u4e8e\uff0c\u5927\u4e8e\u2026 <span class=\"read-more\"><a href=\"http:\/\/rain1024.com\/index.php\/2018\/10\/08\/article135\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,21],"tags":[44],"class_list":["post-988","post","type-post","status-publish","format-standard","hentry","category-hive","category-21","tag-hive"],"_links":{"self":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/988","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/comments?post=988"}],"version-history":[{"count":1,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/988\/revisions"}],"predecessor-version":[{"id":1397,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/988\/revisions\/1397"}],"wp:attachment":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media?parent=988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/categories?post=988"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/tags?post=988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}