{"id":2824,"date":"2022-03-31T19:10:42","date_gmt":"2022-03-31T11:10:42","guid":{"rendered":"https:\/\/nj.transwarp.cn:8180\/?p=2824"},"modified":"2024-10-29T15:17:41","modified_gmt":"2024-10-29T07:17:41","slug":"hbase%e7%9a%84sql-bulkload","status":"publish","type":"post","link":"https:\/\/kbwp.transwarp.cn\/?p=2824","title":{"rendered":"hyperbase \u7684 SQL bulkload"},"content":{"rendered":"<h3>\u6982\u8981\u63cf\u8ff0<\/h3>\n<hr \/>\n<blockquote>\n<p>\u672c\u6848\u4f8b\u8be6\u7ec6\u4ecb\u7ecdhbase\u7684SQL Bulkload\u64cd\u4f5c\u6d41\u7a0b\uff0c\u4ee5\u53ca\u6ce8\u610f\u4e8b\u9879\uff1b<\/p>\n<\/blockquote>\n<h3>\u8be6\u7ec6\u8bf4\u660e<\/h3>\n<hr \/>\n<blockquote>\n<p>Bulkload\u662f\u4e00\u79cd\u5feb\u901f\u5411Hbase\u5bfc\u5165\u5927\u91cf\u6570\u636e\u7684\u65b9\u6cd5\uff1b<br \/>\nSQL BulkLoad\u7684\u9002\u7528\u573a\u666f\u4e3a\uff1a<\/p>\n<ul>\n<li>\u521d\u6b21\u539f\u59cb\u6570\u636e\u5bfc\u5165<\/li>\n<li>\u589e\u91cf\u6570\u636e\u5bfc\u5165<\/li>\n<\/ul>\n<\/blockquote>\n<h4>1\u3001\u64cd\u4f5c\u524d\u51c6\u5907\u5de5\u4f5c<\/h4>\n<ul>\n<li>\u51c6\u5907\u6570\u636e\u96c6\uff0c\u5e76\u4e0a\u4f20\u81f3HDFS<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2020\/04\/image-1586761242417.png\" alt=\"file\" \/><\/p>\n<h4>2\u3001\u6839\u636ehdfs\u6570\u636e\u5efa\u7acbInceptor\u5916\u8868<\/h4>\n<p>\u8bf7\u786e\u4fdd\u6e90\u8868\u4e2d\u7684\u6570\u636e\u662f\u6309\u7167splikey\u5747\u5300\u5206\u5e03\u7684\uff0c\u5426\u5219bulkload\u5bfc\u5165\u6570\u636e\u540e\u5404region\u53ef\u80fd\u4f1a\u51fa\u73b0\u6570\u636e\u503e\u659c\u7684\u72b6\u51b5\uff0c\u540e\u7eed\u4f7f\u7528\u4f1a\u5f15\u53d1\u8d1f\u8f7d\u4e0d\u5747\u8861\u7684\u95ee\u9898\uff1b<\/p>\n<pre><code class=\"language-sql\">create external table store_people\n(name string, sex string\n , nation STRING\n , idcard STRING\n , b_date STRING\n , phone STRING\n , email STRING\n , addr STRING) \n ROW FORMAT delimited fields TERMINATED BY ','  location    '\/tmp\/hbase\/';<\/code><\/pre>\n<h4>3\u3001\u91c7\u6837\u751f\u6210SplitKey<\/h4>\n<p>\u5728\u5bfc\u5165\u6570\u636e\u4e4b\u524d\uff0c\u7528\u6237\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u91c7\u6837\uff0c\u6839\u636e\u91c7\u6837\u7ed3\u679c\u53ef\u4ee5\u751f\u6210splitkey\uff0c\u4f5c\u4e3a\u9884\u5206region\u7684\u4f9d\u636e\uff1b<br \/>\n\u91c7\u6837\u8868\u5373\u7528\u6765\u4fdd\u5b58\u91c7\u6837\u7684\u7ed3\u679c\uff0c\u91c7\u6837\u8868\u5217\u4e2d\u5fc5\u987b\u5305\u542b <strong>\u6240\u6709<\/strong> \u7528\u6765\u751f\u6210rowkey\u7684\u6e90\u8868\u5b57\u6bb5\uff1b<br \/>\n\u4f8b\u5982\uff0c\u6e90\u8868\u4e2d\u7684 <strong>idcard<\/strong> \u5b57\u6bb5\u4f1a\u7528\u6765\u751f\u6210\u76ee\u6807\u8868\u7684rowkey\uff1a<\/p>\n<pre><code class=\"language-sql\">create table sample_table\n(idcard STRING) \nROW FORMAT delimited FIELDS TERMINATED BY ',' \nCOLLECTION ITEMS TERMINATED BY '\\001' \nMAP KEYS TERMINATED BY '\\003' \nLINES TERMINATED BY '\\n' \nSTORED AS TEXTFILE;<\/code><\/pre>\n<h5>3.1\u3001\u5b58\u653e\u91c7\u6837\u7ed3\u679c<\/h5>\n<p>\u6839\u636e\u539f\u59cb\u6570\u636e\u6536\u96c6\u91c7\u6837\u7ed3\u679c\uff1a<\/p>\n<pre><code class=\"language-sql\">INSERT INTO TABLE sample_table SELECT sample(20618,idcard) FROM store_people;<\/code><\/pre>\n<p>&#8212; \u8bf4\u660e\uff1a<br \/>\n&#8212; Inceptor\u63d0\u4f9b\u4e86sample\u51fd\u6570\u7528\u6765\u751f\u6210splitkey\uff1b<br \/>\n&#8212; sample\u51fd\u6570\u63a5\u53d7\u81f3\u5c112\u4e2a\u53c2\u6570\uff0c\u7b2c1\u4e2a\u53c2\u6570\u662f\u91c7\u6837\u7387\uff0c\u91c7\u6837\u7387=\u6570\u636e\u6761\u6570\/97\/\u9884\u5206region\u6570\uff0c\u5176\u4e2d\u7684 97 \u662f\u56fa\u5b9a\u503c\uff0c\u662f\u56e0\u4e3asample \u51fd\u6570\u626b\u63cf hdfs \u6570\u636e\u65f6\u6bcf\u9694 97 \u884c\u53d6\u4e00\u884c\u3002<br \/>\n&#8212; \u6837\u4f8b\u6570\u636e\u670910000000\u6761\uff0c\u9884\u52065\u4e2aregion\uff0c\u56e0\u6b64\u91c7\u6837\u7387=10000000\/97\/5\uff0c\u5373\u91c7\u6837\u7387\u4e3a20618\uff1b<br \/>\n&#8212; \u540e\u9762\u7684\u53c2\u6570\u4e3a\u91c7\u6837\u8868\u4e2d\u7684\u5217\u540d\uff1b<br \/>\n&#8212; \u7528\u6237\u9700\u8981\u6839\u636e\u81ea\u8eab\u4e1a\u52a1\u573a\u666f\u548c\u5b9e\u9645\u6570\u636e\u91cf\uff0c\u786e\u5b9a\u5bfc\u5165\u540e\u76ee\u6807\u8868\u7684rowkey\uff0cregion\u6570\u91cf\uff1b<\/p>\n<h5>3.2\u3001\u901a\u8fc7\u91c7\u6837\u83b7\u53d6splitkey<\/h5>\n<p>\u5c06\u67e5\u8be2\u7ed3\u679c\u8bb0\u5f55\u4e0b\u6765\uff0c\u4e0b\u4e00\u6b65\u9700\u8981\u4f7f\u7528\u8fd9\u4e9bsplitkey\u521b\u5efa\u76ee\u6807\u8868\uff1a<\/p>\n<pre><code class=\"language-sql\">select splitkey from ( \nselect max(c) as splitkey from (\nselect idcard c, ntile(5) over (order by idcard) nt from sample_table ) group by nt\n) order by splitkey LIMIT 4;<\/code><\/pre>\n<ul>\n<li>\u8bf4\u660e\uff1a<\/li>\n<li>ntile\u51fd\u6570\u7684\u53c2\u6570\u5373\u4e3a\u9884\u5206region\u7684\u6570\u91cf\uff1b<\/li>\n<li>limit\u7684\u6570\u91cf\u662f\u9884\u5206region\u6570\u91cf\u51cf\u4e00\uff1b<\/li>\n<\/ul>\n<p>\u6700\u7ec8\u83b7\u53d6\u5230\u7684splitkey\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2020\/04\/image-1587287888995.png\" alt=\"file\" \/><\/p>\n<h4>4\u3001\u4f7f\u7528Inceptor\u5efa\u7acbhbase\u8868\u7684\u6620\u5c04\u8868<\/h4>\n<p>\u6839\u636e\u4e0a\u4e00\u6b65\u9aa4\u5f97\u5230\u7684splitkey\u521b\u5efahbase\u8868\uff1a<\/p>\n<pre><code class=\"language-sql\">DROP TABLE sqlbulkload_test;\nCREATE TABLE sqlbulkload_test\n(key STRING\n  , name STRING\n  , sex STRING\n  , nation STRING\n  , b_date BIGINT\n  , phone STRING\n  , email STRING\n  , addr STRING)\nROW FORMAT DELIMITED FIELDS TERMINATED BY ',' \nCOLLECTION ITEMS TERMINATED BY '\\001' \nMAP KEYS TERMINATED BY '\\003' \nLINES TERMINATED BY '\\N'\nSTORED by org.apache.hadoop.hive.hbase.HBaseStorageHandler\nTBLPROPERTIES(\n'hbase.table.splitkey'='230124199501014575,362430200912311849,432501200001010756,522527199001014861',\n'COMPRESSION'='SNAPPY',\n'hbase.table.name'='sqlbulkload_test');<\/code><\/pre>\n<h4>5\u3001\u4f7f\u7528SQL Bulkload\u5bfc\u5165\u6570\u636e<\/h4>\n<p>\u4f7f\u7528bulkload\u7684\u65b9\u5f0f\u4ece\u6e90\u8868\u4e2d\u5c06\u6570\u636e\u5bfc\u5165\u76ee\u6807\u8868<\/p>\n<pre><code class=\"language-sql\">insert into table sqlbulkload_test \nselect \/*+USE_BULKLOAD*\/ \nidcard key,name STRING,sex STRING,nation STRING,\nb_date BIGINT,phone STRING,email STRING,addr STRING \nfrom store_people order by key;<\/code><\/pre>\n<h4>6\u3001\u5728hbase shell\u4e2d\u67e5\u770b\u6570\u636e\u5df2\u7ecf\u6210\u529f\u63d2\u5165<\/h4>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2020\/04\/image-1587288082678.png\" alt=\"file\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981\u63cf\u8ff0 \u672c\u6848\u4f8b\u8be6\u7ec6\u4ecb\u7ecdhbase\u7684SQL Bulkload\u64cd\u4f5c\u6d41\u7a0b\uff0c\u4ee5\u53ca\u6ce8\u610f\u4e8b\u9879\uff1b \u8be6\u7ec6\u8bf4\u660e Bulkloa ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/kbwp.transwarp.cn\/?p=2824\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,1],"tags":[],"class_list":["post-2824","post","type-post","status-publish","format-standard","hentry","category-configuration","category-uncategorized"],"acf":[],"_links":{"self":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/2824","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2824"}],"version-history":[{"count":5,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/2824\/revisions"}],"predecessor-version":[{"id":14587,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/2824\/revisions\/14587"}],"wp:attachment":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}