{"id":18287,"date":"2026-04-29T16:18:06","date_gmt":"2026-04-29T08:18:06","guid":{"rendered":"https:\/\/kbwp.transwarp.cn\/?p=18287"},"modified":"2026-04-29T16:18:06","modified_gmt":"2026-04-29T08:18:06","slug":"python%e8%84%9a%e6%9c%ac%e5%bf%ab%e9%80%9f%e7%bb%9f%e8%ae%a1argodb%e9%9b%86%e7%be%a4%e6%af%8f%e5%bc%a0%e8%a1%a8%e7%9a%84%e6%9d%a1%e6%95%b0","status":"publish","type":"post","link":"https:\/\/kbwp.transwarp.cn\/?p=18287","title":{"rendered":"python\u811a\u672c\u5feb\u901f\u7edf\u8ba1Argodb\u96c6\u7fa4\u6bcf\u5f20\u8868\u7684\u6761\u6570"},"content":{"rendered":"<h2>\u6982\u8ff0<\/h2>\n<p><code>count_all_tables.py<\/code> \u662f\u4e00\u4e2a\u7528\u4e8e\u7edf\u8ba1 Quark\uff08ArgoDB \/ Inceptor\uff09\u96c6\u7fa4\u4e2d<strong>\u6240\u6709\u6570\u636e\u5e93\u3001\u6240\u6709\u8868\u8bb0\u5f55\u6761\u6570<\/strong>\u7684\u811a\u672c\u3002\u811a\u672c\u901a\u8fc7 Beeline \u8fde\u63a5\u96c6\u7fa4\uff0c\u5229\u7528 <code>system.tables_v<\/code> \u4e00\u6b21\u6027\u83b7\u53d6\u5e93\u8868\u5217\u8868\uff0c\u518d 10 \u5e76\u53d1\u6267\u884c <code>SELECT COUNT(*)<\/code> \u9010\u8868\u7edf\u8ba1\uff0c\u6700\u7ec8\u5c06\u7ed3\u679c\u8f93\u51fa\u5230\u6587\u672c\u6587\u4ef6\u3002<\/p>\n<p><strong>\u9002\u7528\u573a\u666f<\/strong>\uff1a<\/p>\n<ul>\n<li>\u6570\u636e\u76d8\u70b9\uff1a\u5feb\u901f\u4e86\u89e3\u5168\u5e93\u5404\u8868\u7684\u6570\u636e\u91cf\u5206\u5e03<\/li>\n<li>\u8fd0\u7ef4\u5de1\u68c0\uff1a\u5b9a\u671f\u7edf\u8ba1\u8868\u6761\u6570\uff0c\u76d1\u63a7\u6570\u636e\u589e\u957f\u8d8b\u52bf<\/li>\n<li>\u8fc1\u79fb\u6821\u9a8c\uff1a\u6570\u636e\u8fc1\u79fb\u524d\u540e\u5bf9\u6bd4\u5404\u8868\u6761\u6570\uff0c\u786e\u8ba4\u6570\u636e\u5b8c\u6574\u6027<\/li>\n<\/ul>\n<h2>\u73af\u5883\u8981\u6c42<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u9879\u76ee<\/th>\n<th>\u8981\u6c42<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u96c6\u7fa4\u8282\u70b9<\/td>\n<td>\u9700\u80fd SSH \u767b\u5f55\u5230\u5b89\u88c5\u4e86 TDH Client \u7684\u8282\u70b9<\/td>\n<\/tr>\n<tr>\n<td>TDH Client<\/td>\n<td>\u5df2\u5b89\u88c5\u5e76\u4f4d\u4e8e <code>\/root\/TDH-Client\/<\/code><\/td>\n<\/tr>\n<tr>\n<td>Python<\/td>\n<td>2.7\uff08TDH\u96c6\u7fa4\u81ea\u5e26\u7248\u672c\uff0c\u811a\u672c\u5df2\u505a\u517c\u5bb9\u5904\u7406\uff09<\/td>\n<\/tr>\n<tr>\n<td>Beeline<\/td>\n<td><code>\/root\/TDH-Client\/inceptor\/bin\/beeline<\/code> \u53ef\u7528<\/td>\n<\/tr>\n<tr>\n<td>\u7f51\u7edc<\/td>\n<td>\u6267\u884c\u8282\u70b9\u9700\u80fd\u8bbf\u95ee JDBC \u5730\u5740<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u5feb\u901f\u4f7f\u7528<\/h2>\n<h3>1. \u4e0a\u4f20\u811a\u672c\u5230\u670d\u52a1\u5668<\/h3>\n<p>\u5c06  <a href=\"https:\/\/fs.transwarp.cn\/?download&weblink=058c55823fa0f373b8ff6215fa82358f&realfilename=count_all_tables.py\" title=\"&lt;code&gt;count_all_tables.py&lt;\/code&gt;\">count_all_tables.py<\/a> \u4e0a\u4f20\u5230\u76ee\u6807\u8282\u70b9\u7684 <code>\/root\/<\/code> \u76ee\u5f55\uff1a<\/p>\n<h3>2. \u6267\u884c\u811a\u672c<\/h3>\n<p>SSH \u767b\u5f55\u5230\u670d\u52a1\u5668\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6267\u884c\uff1a<\/p>\n<pre><code class=\"language-bash\">source \/root\/TDH-Client\/init.sh n n \npython -u \/root\/count_all_tables.py<\/code><\/pre>\n<blockquote>\n<p><strong>\u4e3a\u4ec0\u4e48\u8981\u5148 <code>source \/root\/TDH-Client\/init.sh<\/code>\uff1f<\/strong><\/p>\n<p><code>source \/root\/TDH-Client\/init.sh<\/code> \u7528\u4e8e\u521d\u59cb\u5316 TDH \u73af\u5883\u53d8\u91cf\uff08\u5305\u62ec JAVA_HOME\u3001Hadoop \u914d\u7f6e\u7b49\uff09\u3002\u5355\u72ec\u6267\u884c <code>python<\/code> \u4e0d\u4f1a\u7ee7\u627f <code>source<\/code> \u8bbe\u7f6e\u7684\u73af\u5883\u53d8\u91cf\uff0c\u56e0\u6b64\u5fc5\u987b\u5728\u540c\u4e00\u4e2a <code>bash -c<\/code> \u4e2d\u5148 source \u518d\u6267\u884c\u3002<\/p>\n<\/blockquote>\n<h3>3. \u67e5\u770b\u7ed3\u679c<\/h3>\n<p>\u811a\u672c\u6267\u884c\u5b8c\u6210\u540e\uff0c\u7ed3\u679c\u6587\u4ef6\u4f4d\u4e8e\uff1a<\/p>\n<pre><code>\/root\/all_table_counts.txt<\/code><\/pre>\n<p>\u8f93\u51fa\u683c\u5f0f\u793a\u4f8b\uff1a<\/p>\n<pre><code>\u6570\u636e\u5e93                      \u8868\u540d                                           \u6761\u6570\n-------------------------------------------------------------------------------------\ndefault                  emp_holo                                       1\n-------------------------------------------------------------------------------------\ntest_db                  orders                                         150000\ntest_db                  users                                          28000\n-------------------------------------------------------------------------------------\n                                                                 \u603b\u8ba1: 3 \u5f20\u8868<\/code><\/pre>\n<h2>\u8fd0\u884c\u8fc7\u7a0b\u8bf4\u660e<\/h2>\n<p>\u811a\u672c\u8fd0\u884c\u65f6\u4f1a\u4f9d\u6b21\u8f93\u51fa\u4ee5\u4e0b\u4fe1\u606f\uff1a<\/p>\n<pre><code>[*] beeline \u5df2\u5c31\u7eea: \/root\/TDH-Client\/inceptor\/bin\/beeline\n[*] \u901a\u8fc7 system.tables_v \u83b7\u53d6\u6240\u6709\u5e93\/\u8868\u5217\u8868 ...\n[*] \u5171\u53d1\u73b0 156 \u5f20\u8868\n    default: 3 \u5f20\u8868\n    test_db: 45 \u5f20\u8868\n    dw_prod: 108 \u5f20\u8868\n[*] \u5f00\u59cb\u5e76\u53d1\u7edf\u8ba1\uff0810 \u5e76\u53d1\uff09...\n    \u8fdb\u5ea6: 5\/156\n    \u8fdb\u5ea6: 10\/156\n    ...\n[*] \u6e05\u7406\u6b8b\u7559\u8fdb\u7a0b ...\n\n[*] \u7edf\u8ba1\u5b8c\u6210\uff01\u8017\u65f6 342.5 \u79d2\n[*] \u7ed3\u679c\u5df2\u5199\u5165 \/root\/all_table_counts.txt<\/code><\/pre>\n<p><strong>\u6267\u884c\u8017\u65f6\u53c2\u8003<\/strong>\uff1a\u5355\u8868 <code>COUNT(*)<\/code> \u7ea6 2-5 \u79d2\uff0c100 \u5f20\u8868 10 \u5e76\u53d1\u7ea6\u9700 3-6 \u5206\u949f\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u8868\u5927\u5c0f\u548c\u96c6\u7fa4\u8d1f\u8f7d\u3002<\/p>\n<h2>\u81ea\u5b9a\u4e49\u914d\u7f6e<\/h2>\n<p>\u5982\u9700\u8c03\u6574\u811a\u672c\u884c\u4e3a\uff0c\u7f16\u8f91 <code>count_all_tables.py<\/code> \u9876\u90e8\u7684\u914d\u7f6e\u6bb5\uff1a<\/p>\n<pre><code class=\"language-python\"># ============ \u914d\u7f6e ============\nBEELINE = \"\/root\/TDH-Client\/inceptor\/bin\/beeline\"   # Beeline \u8def\u5f84\nJDBC = \"jdbc:hive2:\/\/172.18.131.171:10000\/default?ngmr.session.name=session-test1\"  # JDBC \u8fde\u63a5\u5730\u5740\uff0cngmr.session.name\u53c2\u6570\u900f\u4f20\uff0c\u65b9\u4fbfDBAService\u5b9a\u4f4d\nUSER = \"hive\"                                        # \u6570\u636e\u5e93LDAP\u7528\u6237\u540d\nPASS = \"123456\"                                      # \u6570\u636e\u5e93LDAP\u5bc6\u7801\nWORKERS = 10                                         # \u5e76\u53d1\u7ebf\u7a0b\u6570\nOUTPUT = \"\/root\/all_table_counts.txt\"                # \u7ed3\u679c\u8f93\u51fa\u8def\u5f84\nBEEELINE_TIMEOUT = 300                               # \u5355\u6761 SQL \u8d85\u65f6\uff08\u79d2\uff09\n# ==============================<\/code><\/pre>\n<h2>\u5e38\u89c1\u95ee\u9898<\/h2>\n<h3>Q1\uff1a\u6267\u884c\u62a5\u9519 &quot;beeline \u4e0d\u5b58\u5728&quot;<\/h3>\n<p><strong>\u539f\u56e0<\/strong>\uff1a<code>init.sh<\/code> \u672a\u6b63\u786e\u521d\u59cb\u5316\uff0c\u6216 TDH Client \u5b89\u88c5\u8def\u5f84\u4e0d\u662f\u9ed8\u8ba4\u7684 <code>\/root\/TDH-Client\/<\/code>\u3002<\/p>\n<p><strong>\u89e3\u51b3<\/strong>\uff1a\u786e\u8ba4\u6b63\u786e\u7684TDH-Client beeline \u8def\u5f84\u5e76\u4fee\u6539\u811a\u672c\u4e2d\u7684 <code>BEELINE<\/code> \u914d\u7f6e\u9879\uff1a<\/p>\n<h3>Q2\uff1a\u7edf\u8ba1\u67d0\u5f20\u8868\u65f6\u8fd4\u56de ERROR<\/h3>\n<p><strong>\u539f\u56e0<\/strong>\uff1a\u53ef\u80fd\u8868\u5df2\u635f\u574f\u3001\u6743\u9650\u4e0d\u8db3\u3001\u6216\u8d85\u65f6\u3002<\/p>\n<p><strong>\u89e3\u51b3<\/strong>\uff1a<\/p>\n<ol>\n<li>\u624b\u52a8\u9a8c\u8bc1\u8be5\u8868\u662f\u5426\u53ef\u67e5\uff1a<code>SELECT COUNT(*) FROM \u5e93\u540d.\u8868\u540d;<\/code><\/li>\n<li>\u5982\u8d85\u65f6\uff0c\u589e\u5927 <code>BEEELINE_TIMEOUT<\/code> \u503c\uff08\u5982 <code>600<\/code>\uff09<\/li>\n<li>\u5982\u6743\u9650\u95ee\u9898\uff0c\u786e\u8ba4 <code>USER<\/code> \/ <code>PASS<\/code> \u914d\u7f6e\u7684\u8d26\u53f7\u662f\u5426\u6709\u8be5\u5e93\u7684\u8bfb\u6743\u9650<\/li>\n<\/ol>\n<h3>Q3\uff1a\u811a\u672c\u8fd0\u884c\u4e2d\u5361\u4f4f\u4e0d\u52a8<\/h3>\n<p><strong>\u539f\u56e0<\/strong>\uff1a\u67d0\u5f20\u8868\u7279\u522b\u5927\u5bfc\u81f4 COUNT \u8017\u65f6\u5f88\u957f\uff0c\u6216 beeline \u8fdb\u7a0b\u6302\u8d77\u3002<\/p>\n<p><strong>\u89e3\u51b3<\/strong>\uff1a<\/p>\n<ol>\n<li>\u7b49\u5f85\u8d85\u65f6\uff08\u9ed8\u8ba4 300 \u79d2\uff09\u540e\u811a\u672c\u4f1a\u81ea\u52a8\u8df3\u8fc7\u8be5\u8868<\/li>\n<li>\u5982\u9700\u63d0\u524d\u7ec8\u6b62\uff0c\u6309 <code>Ctrl+C<\/code>\uff0c\u811a\u672c\u4f1a\u81ea\u52a8\u6e05\u7406\u6b8b\u7559\u7684 beeline \u8fdb\u7a0b<\/li>\n<li>\u53ef\u964d\u4f4e <code>WORKERS<\/code> \u51cf\u5c11\u5e76\u53d1\u538b\u529b<\/li>\n<\/ol>\n<h3>Q4\uff1a\u5982\u4f55\u53ea\u7edf\u8ba1\u6307\u5b9a\u6570\u636e\u5e93\u7684\u8868\uff1f<\/h3>\n<p><strong>\u89e3\u51b3<\/strong>\uff1a\u4fee\u6539\u811a\u672c\u4e2d <code>get_all_tables()<\/code> \u51fd\u6570\u7684 SQL\uff0c\u6dfb\u52a0\u6570\u636e\u5e93\u8fc7\u6ee4\u6761\u4ef6\uff1a<\/p>\n<pre><code class=\"language-python\"># \u5c06\u539f\u6765\u7684 SQL\uff1a\n\"SELECT database_name, table_name FROM system.tables_v;\"\n\n# \u6539\u4e3a\uff08\u4ee5\u7edf\u8ba1 test_db \u4e3a\u4f8b\uff09\uff1a\n\"SELECT database_name, table_name FROM system.tables_v WHERE database_name = 'test_db';\"<\/code><\/pre>\n<h3>Q5\uff1a\u7ed3\u679c\u6587\u4ef6\u7f16\u7801\u4e71\u7801<\/h3>\n<p><strong>\u539f\u56e0<\/strong>\uff1a\u811a\u672c\u8f93\u51fa\u4e3a UTF-8\uff0c\u90e8\u5206\u7ec8\u7aef\u9ed8\u8ba4\u7f16\u7801\u53ef\u80fd\u4e0d\u5339\u914d\u3002<\/p>\n<p><strong>\u89e3\u51b3<\/strong>\uff1a<\/p>\n<pre><code class=\"language-bash\"># \u67e5\u770b\/\u8f6c\u6362\u7f16\u7801\niconv -f UTF-8 -t GBK \/root\/all_table_counts.txt > \/root\/all_table_counts_gbk.txt\n\n# \u6216\u76f4\u63a5\u5728\u652f\u6301 UTF-8 \u7684\u5de5\u5177\u4e2d\u6253\u5f00\uff08\u5982 Notepad++\u3001VS Code\uff09<\/code><\/pre>\n<h2>\u6280\u672f\u539f\u7406<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u6b65\u9aa4<\/th>\n<th>\u5b9e\u73b0\u65b9\u5f0f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u83b7\u53d6\u5e93\u8868\u5217\u8868<\/td>\n<td><code>SELECT database_name, table_name FROM system.tables_v<\/code>\uff0c\u4e00\u6b21\u67e5\u8be2\u83b7\u53d6\u5168\u91cf\uff0c\u907f\u514d\u9010\u5e93 <code>SHOW TABLES<\/code> \u7684\u4f4e\u6548<\/td>\n<\/tr>\n<tr>\n<td>\u7edf\u8ba1\u8868\u6761\u6570<\/td>\n<td>\u5bf9\u6bcf\u5f20\u8868\u6267\u884c <code>SELECT COUNT(*) FROM \u5e93\u540d.\u8868\u540d<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u5e76\u53d1\u63a7\u5236<\/td>\n<td>\u4f7f\u7528 <code>Queue<\/code> + <code>threading<\/code> \u5b9e\u73b0 10 \u5e76\u53d1\u5de5\u4f5c\u7ebf\u7a0b<\/td>\n<\/tr>\n<tr>\n<td>\u8d85\u65f6\u5904\u7406<\/td>\n<td>\u6bcf\u4e2a beeline \u8fdb\u7a0b\u542f\u52a8\u72ec\u7acb\u7ebf\u7a0b\u7b49\u5f85\uff0c\u8d85\u65f6\u540e kill \u6574\u4e2a\u8fdb\u7a0b\u7ec4<\/td>\n<\/tr>\n<tr>\n<td>\u8fdb\u7a0b\u6e05\u7406<\/td>\n<td>\u811a\u672c\u9000\u51fa\u65f6\uff08\u6b63\u5e38\u6216\u5f02\u5e38\uff09\u81ea\u52a8 <code>pkill<\/code> \u6b8b\u7559 beeline \u8fdb\u7a0b\uff0c\u907f\u514d\u8d44\u6e90\u6cc4\u6f0f<\/td>\n<\/tr>\n<tr>\n<td>Python 2.7 \u517c\u5bb9<\/td>\n<td>\u4f7f\u7528 <code>%<\/code> \u683c\u5f0f\u5316\u3001<code>Queue<\/code>\uff08\u975e <code>queue<\/code>\uff09\u3001<code>threading<\/code>\uff08\u975e <code>concurrent.futures<\/code>\uff09\u7b49<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8ff0 count_all_tables.py \u662f\u4e00\u4e2a\u7528\u4e8e\u7edf\u8ba1 Quark\uff08ArgoDB \/ Inceptor\uff09 ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/kbwp.transwarp.cn\/?p=18287\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-18287","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\/18287","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\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=18287"}],"version-history":[{"count":3,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/18287\/revisions"}],"predecessor-version":[{"id":18336,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/18287\/revisions\/18336"}],"wp:attachment":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}