{"id":12665,"date":"2024-07-09T14:15:52","date_gmt":"2024-07-09T06:15:52","guid":{"rendered":"https:\/\/nj.transwarp.cn:8180\/?p=12665"},"modified":"2024-07-10T16:13:44","modified_gmt":"2024-07-10T08:13:44","slug":"hyperdrive-%e8%a1%a8%e4%bd%bf%e7%94%a8-splitkey-%e9%a2%84%e5%88%86-region","status":"publish","type":"post","link":"https:\/\/kbwp.transwarp.cn\/?p=12665","title":{"rendered":"hyperdrive \u8868\u4f7f\u7528 splitkey \u9884\u5206 region"},"content":{"rendered":"<h3>\u6982\u8981\u63cf\u8ff0<\/h3>\n<hr \/>\n<blockquote>\n<p>\u672c\u6848\u4f8b\u8be6\u7ec6\u4ecb\u7ecd  hyperdrive \u8868\u4f7f\u7528 splitkey \u9884\u5206 region \u7684\u65b9\u6cd5\u3002<br \/>\nTDH 6.2.2 \u4ee5\u53ca\u4ee5\u4e0a\u7248\u672c\u3002<\/p>\n<\/blockquote>\n<h3>\u8be6\u7ec6\u8bf4\u660e<\/h3>\n<hr \/>\n<ol>\n<li>\u57fa\u4e8e\u539f\u59cb\u6570\u636e\u91c7\u6837\uff0c\u5e76\u5b58\u5165\u8868\u4e2d\uff1b<\/li>\n<li>\u57fa\u4e8e\u91c7\u6837\u8868\u751f\u6210 splitkey\uff1b<\/li>\n<li>\u4f7f\u7528 splitkey \u521b\u5efa\u8868\uff0c\u8fbe\u5230\u9884\u5206 region \u7684\u6548\u679c<\/li>\n<\/ol>\n<p>\u5047\u8bbe\u539f\u59cb\u6570\u636e\u8868\u662f store_people<\/p>\n<h4>1\u3001\u57fa\u4e8e\u539f\u59cb\u6570\u636e\u91c7\u6837\uff0c\u5e76\u5199\u5165\u8868\u4e2d<\/h4>\n<p>\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\u7684 rowkey\uff1a<\/p>\n<pre><code class=\"language-sql\">create table sample_table\n(idcard STRING)\nSTORED AS ORC;<\/code><\/pre>\n<p>\u6839\u636e\u539f\u59cb\u6570\u636e\u6536\u96c6\u91c7\u6837\u7ed3\u679c\uff0c\u5e76\u5199\u5165\u8868\u4e2d\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<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>2\u3001\u901a\u8fc7\u91c7\u6837\u751f\u6210 splitkey<\/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>3\u3001\u4f7f\u7528 Inceptor \u5efa\u7acb hyperdrive \u8868\u7684\u6620\u5c04\u8868<\/h4>\n<p>\u6839\u636e\u4e0a\u4e00\u6b65\u9aa4\u5f97\u5230\u7684 splitkey \u521b\u5efa hyperdrive \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)\nSTORED AS HYPERDRIVE\nTBLPROPERTIES(\n-- \u8fd9\u91cc\u4e00\u5b9a\u8981\u6ce8\u610f\uff0csplitkey \u662f\u7528 \"\" \u5305\u88f9\u7684\u5b57\u7b26\u4e32\uff0c\u4e0d\u80fd\u7701\u7565 \"\"\n'hyperdrive.table.splitkey'='\"230124199501014575\",\"362430200912311849\",\"432501200001010756\",\"522527199001014861\"',\n'COMPRESSION'='SNAPPY');<\/code><\/pre>\n<p>\u4f7f\u7528 bulkload \u7684\u65b9\u5f0f\u4ece\u6e90\u8868\u4e2d\u5c06\u6570\u636e\u5bfc\u5165\u76ee\u6807\u8868\uff0c\u6b64\u5904\u5fc5\u987b\u57fa\u4e8e serverkey \u6392\u5e8f\uff0c\u4e5f\u5c31\u662f sql \u4e2d\u8981\u52a0 order by key \u5b57\u6bb5<\/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","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981\u63cf\u8ff0 \u672c\u6848\u4f8b\u8be6\u7ec6\u4ecb\u7ecd hyperdrive \u8868\u4f7f\u7528 splitkey \u9884\u5206 region \u7684\u65b9\u6cd5\u3002 TDH ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/kbwp.transwarp.cn\/?p=12665\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12665","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"acf":[],"_links":{"self":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/12665","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\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12665"}],"version-history":[{"count":3,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/12665\/revisions"}],"predecessor-version":[{"id":13545,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/12665\/revisions\/13545"}],"wp:attachment":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}