{"id":1821,"date":"2019-12-31T10:41:47","date_gmt":"2019-12-31T02:41:47","guid":{"rendered":"https:\/\/nj.transwarp.cn:8180\/?p=1821"},"modified":"2025-03-04T15:58:01","modified_gmt":"2025-03-04T07:58:01","slug":"%e3%80%90inceptor%e3%80%91%e5%af%bc%e5%87%ba%e6%95%b0%e6%8d%ae%e5%ba%93%e5%af%b9%e8%b1%a1%e7%9a%84ddl%e8%af%ad%e5%8f%a5","status":"publish","type":"post","link":"https:\/\/kbwp.transwarp.cn\/?p=1821","title":{"rendered":"\u3010Inceptor\u3011\u5bfc\u51fa\u6570\u636e\u5e93\u5bf9\u8c61\u7684DDL\u8bed\u53e5"},"content":{"rendered":"<h3>\u6982\u8981\u63cf\u8ff0<\/h3>\n<hr \/>\n<p>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecdInceptor \u5982\u4f55\u901a\u8fc7\u6570\u636e\u5b57\u5178 \u6279\u91cf\u5bfc\u51fa\u5982\u4e0b\u6570\u636e\u5bf9\u8c61\u7684DDL\u8bed\u53e5<\/p>\n<ul>\n<li>\u89c6\u56fe\u548c\u8868<\/li>\n<li>\u51fd\u6570<\/li>\n<li>\u5b58\u50a8\u8fc7\u7a0b<\/li>\n<li>\u5305<\/li>\n<li>\u5e8f\u5217<\/li>\n<\/ul>\n<h3>\u8be6\u7ec6\u8bf4\u660e<\/h3>\n<hr \/>\n<h4>1. \u5bfc\u51fa\u8868\u548c\u89c6\u56fe\u7684DDL\u8bed\u53e5<\/h4>\n<p>\u4ee5\u4e0b\u811a\u672c\u53ef\u4ee5\u7528\u6765\u5bfc\u51fa\u8868\u548c\u89c6\u56fe\u7684DDL\uff0c\u6ce8\u610f\u6267\u884c\u524d\u9700\u8981\u521d\u59cb\u5316TDH Client\uff0c\u4fdd\u8bc1beeline\u547d\u4ee4\u53ef\u7528<\/p>\n<p><font color=red> <strong>\u6ce8\u610f\uff1a \u8be5\u65b9\u5f0f\u4f1a\u4fdd\u7559location\u548c\u4e00\u4e9b\u65e0\u7528\u7684tblproperties\uff0c\u5efa\u8bae\u5254\u9664<\/strong><\/font><br \/>\n<font color=red> <strong>\u6ce8\u610f\uff1a \u8be5\u65b9\u5f0f\u4e3a\u5355\u7ebf\u7a0b\u5bfc\u51fa\uff0c\u903b\u8f91\u4f9b\u53c2\u8003\uff0c\u6027\u80fd\u8f83\u6162\uff0c\u5982\u5ba2\u6237\u73af\u5883\u8868\u6570\u91cf\u8f83\u591a\uff0c\u9700\u81ea\u884c\u5f00\u53d1\u591a\u7ebf\u7a0b\u5bfc\u51fa\u7a0b\u5e8f<\/strong><\/font><\/p>\n<pre><code class=\"language-sql\">#\u5982\u679c\u4f7f\u7528show tables\u5217\u51fa\u6240\u6709\u8868\u548c\u89c6\u56fe\u6570\u636e\uff0c\u751f\u6210\u7684\u6570\u636e\uff0c\u9ed8\u8ba4\u662f\u4ee5\u5f00\u5934\u5b57\u6bcd\u6392\u5e8f\u7684\uff0c\u6240\u4ee5\u5982\u679c\u89c6\u56fe\u4f9d\u8d56\u7684\u8868\u5728\u89c6\u56fe\u7684DDL\u540e\u9762\uff0c\u5c31\u4f1a\u62a5\u8868\u4e0d\u5b58\u5728\u7684\u9519\u8bef\uff0c\u6240\u4ee5\u8fd9\u91cc\u4e0d\u5efa\u8bae\u4f7f\u7528show tables ,\u6539\u7528\u6570\u636e\u5b57\u5178tables_v,views_v \u9650\u5b9a\u8868\u7c7b\u578b\u6570\u636e\uff0c\u5c06\u8868\u548c\u89c6\u56feDDL\u6587\u4ef6\u5206\u5f00\n#export.sh\n\n#!\/bin\/bash\n########################################\n#\u4f7f\u7528\u65b9\u6cd5:\n##\u5bfc\u51fa\u6240\u6709\u5e93\u7684\u8868\/\u89c6\u56fe              sh export.sh all\n##\u5bfc\u51fa\u6307\u5b9a\u5e93\u7684\u8868\/\u89c6\u56fe              sh export.sh {\u6570\u636e\u5e93\u540d}\n########################################\ndatabase=$1\n\n#source \/root\/TDH-Client\/init.sh\n\nv_table=tables_${database}\nv_view=views_${database}\ndst_tables=ddl_tables_${database}\ndst_views=ddl_views_${database}\n\n#\u5bfc\u51fatable & view \u5217\u8868\nif [ \"${database}\" == \"all\" ]; then\n        beeline -u jdbc:hive2:\/\/localhost:10000\/default --showHeader=false --outputformat=csv -e \"select database_name||'.'||table_name from system.tables_v where database_name<>'system'\" |sed 's\/\\\"\/\/g' > ${v_table}.txt\n        beeline -u jdbc:hive2:\/\/localhost:10000\/default --showHeader=false --outputformat=csv -e \"select database_name||'.'||view_name from system.views_v where database_name<>'system'\" |sed 's\/\\\"\/\/g' > ${v_view}.txt\nelse\n        beeline -u jdbc:hive2:\/\/localhost:10000\/default --showHeader=false --outputformat=csv -e \"select database_name||'.'||table_name from system.tables_v where database_name='${database}'\" |sed 's\/\\\"\/\/g' > ${v_table}.txt\n        beeline -u jdbc:hive2:\/\/localhost:10000\/default --showHeader=false --outputformat=csv -e \"select database_name||'.'||view_name from system.views_v where database_name='${database}'\" |sed 's\/\\\"\/\/g' > ${v_view}.txt\nfi\n\n#sleep\u65f6\u95f4\u6839\u636e\u8868\u548c\u89c6\u56fe\u7684\u6570\u91cf\u9884\u7559\necho sleep start\nsleep 3\necho sleep end\n\n#\u5bfc\u51fa\u8868ddl\u8bed\u53e5\ncat ${v_table}.txt|while read eachline01\ndo\nbeeline -u jdbc:hive2:\/\/localhost:10000\/default --showHeader=false --outputformat=csv -e \"show create table $eachline01\"|sed 's\/\\\"\/\/g' |sed '$a;' >>${dst_tables}.sql\ndone\n\n#\u5bfc\u51fa\u89c6\u56feddl\u8bed\u53e5\ncat ${v_view}.txt|while read eachline02\ndo\nbeeline -u jdbc:hive2:\/\/localhost:10000\/default --showHeader=false --outputformat=csv -e \"show create table $eachline02\"|sed 's\/\\\"\/\/g' |sed '$a;'>>${dst_views}.sql\ndone<\/code><\/pre>\n<p><strong>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/strong><\/p>\n<pre><code class=\"language-shell\">#\u5bfc\u51fadefault\u6570\u636e\u5e93\u4e0b\u6240\u6709\u7684\u8868\u548c\u89c6\u56fe\n[root@tdh522-183 lkw]# .\/export.sh default\n#\u5bfc\u51fa\u6240\u6709\u6570\u636e\u5e93\u4e0b\u7684\u8868\u548c\u89c6\u56fe\n[root@tdh522-183 lkw]# .\/export.sh all<\/code><\/pre>\n<h4>2. \u5bfc\u51fa\u51fd\u6570\u7684DDL\u8bed\u53e5<\/h4>\n<pre><code class=\"language-sql\">--\u6240\u6709\u51fd\u6570DDL\u8bed\u53e5\u90fd\u53ef\u4ee5\u5728system.FUNCTIONSS_V\u8868\u7684full_text\u5217\u62ff\u5230\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762SQL\u8bed\u53e5\u62ff\u5230\u6240\u6709PL\/SQL\u51fd\u6570\u7684DDL\uff1a\n\nINSERT OVERWRITE DIRECTORY '\/tmp\/function\/' SELECT \"use \" ||database_name||\"\\;\" || \"\\n\" ||\"!set plsqlUseSlash true\"||\"\\n\"||full_text||\"\\n\"||\"\\\/\"||\"\\n\"||\"!set plsqlUseSlash false\" from system.functions_v ;<\/code><\/pre>\n<pre><code class=\"language-shell\">root@kevin1 ~# hadoop fs -get \/tmp\/function\/000000_0 .<\/code><\/pre>\n<h4>3. \u5bfc\u51fa\u5b58\u50a8\u8fc7\u7a0b\u7684DDL\u8bed\u53e5<\/h4>\n<pre><code class=\"language-sql\">--\u6240\u6709\u5b58\u50a8\u8fc7\u7a0b\u7684DDL\u8bed\u53e5\u90fd\u53ef\u4ee5\u5728system.PROCEDURES_V\u8868\u7684full_text\u5217\u62ff\u5230\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762SQL\u8bed\u53e5\u62ff\u5230\u6240\u6709\u5b58\u50a8\u8fc7\u7a0b\u7684DDL\uff1a\n\nINSERT OVERWRITE DIRECTORY '\/tmp\/procedure\/' SELECT \"use \" ||database_name||\"\\;\" || \"\\n\" ||\"!set plsqlUseSlash true\"||\"\\n\"||full_text||\"\\n\"||\"\\\/\"||\"\\n\"||\"!set plsqlUseSlash false\" from system.procedures_v ;\n\n--\u5982\u679c\u9700\u8981\u989d\u5916\u6253\u5370\u51fa\u5373\u5c06\u7f16\u8bd1\u7684\u5b58\u50a8\u8fc7\u7a0b\u540d\u79f0\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0bsql\nINSERT OVERWRITE DIRECTORY '\/tmp\/procedure\/' SELECT \"SET plsql.compile.dml.check.semantic=false;\"||\"\\n\" ||  \"use \" ||database_name||\"\\;\" || \"\\n\" ||\"!set plsqlUseSlash true\"||\"\\n\" || \"SELECT '\" || \"Begin to parse \" || <code>database_name<\/code> || \".\" || <code>procedure_name<\/code> || \"(\"|| <code>parameters<\/code>  || \")\" || \"' from system.dual;\" ||\"\\n\"||full_text||\"\\n\"||\"\\\/\"||\"\\n\"||\"!set plsqlUseSlash false\" from system.procedures_v;<\/code><\/pre>\n<pre><code class=\"language-shell\">root@kevin1 ~# hadoop fs -get \/tmp\/procedure\/000000_0 .<\/code><\/pre>\n<h4>4. \u5bfc\u51faPackage\u7684DDL\u8bed\u53e5<\/h4>\n<p>\u6ce8\u610f\uff1a\u8fd9\u91cc\u65e0\u6cd5\u907f\u514d\u4f1a\u51fa\u73b0plsql\u4f9d\u8d56\u7684\u95ee\u9898\uff0c\u6bd4\u5982\u5b58\u50a8\u8fc7\u7a0b\u4f9d\u8d56package\uff0c\u9700\u8981\u624b\u52a8\u8c03\u6574\u6267\u884c\u987a\u5e8f<\/p>\n<pre><code class=\"language-sql\">--system.PACKAGES_V\/full_text  \u5305\u5934\n--system.PACKAGES_V\/package_body \u5305\u4f53\n\nINSERT OVERWRITE DIRECTORY '\/tmp\/package' select  \"use \" ||database_name||\"\\;\" || \"\\n\" ||\"!set plsqlUseSlash  true\"||\"\\n\" || full_text || \"\\n\"  ||\"\/\" || \"\\n\" ||package_body||\"\\n\"||\"\\\/\"||\"\\n\"||\"!set plsqlUseSlash false\"\nfrom system.packages_v;<\/code><\/pre>\n<pre><code class=\"language-shell\">root@kevin1 ~# hadoop fs -get \/tmp\/package\/000000_0 .<\/code><\/pre>\n<h4>5. \u5bfc\u51faSequence\u7684DDL\u8bed\u53e5<\/h4>\n<p>\u901a\u8fc7dblink\u67e5\u8be2\u5143\u6570\u636e\uff0c<\/p>\n<pre><code class=\"language-sql\">SELECT\n    SEQ_NAME,\n    concat(\n        'CREATE SEQUENCE ', t2.name,'.',SEQ_NAME,\n        ' INCREMENT BY ',INCRE_BY,\n        ' START WITH ',START_WITH,\n        if(MAX_VAL='9223372036854775807',' NOMAXVALUE ',concat(' MAXVALUE  ',MAX_VAL)),\n        if(MIN_VAL='1',' NOMINVALUE ',concat(' MINVALUE ',MIN_VAL)),\n        if(CYCLE='0',' NOCYCLE ',' CYCLE '),\n        if(CACHE_SIZE='0',' NOCACHE ',concat(' CACHE ',CACHE_SIZE)),';') as  seq_ddl\nFROM SEQS@system_dblink t1\nJOIN DBS@system_dblink t2\nON t1.db_id=t2.db_id;<\/code><\/pre>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2019\/12\/image-1710405305295.png\" alt=\"file\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981\u63cf\u8ff0 \u672c\u6587\u4e3b\u8981\u4ecb\u7ecdInceptor \u5982\u4f55\u901a\u8fc7\u6570\u636e\u5b57\u5178 \u6279\u91cf\u5bfc\u51fa\u5982\u4e0b\u6570\u636e\u5bf9\u8c61\u7684DDL\u8bed\u53e5 \u89c6\u56fe\u548c\u8868 \u51fd\u6570 \u5b58 ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/kbwp.transwarp.cn\/?p=1821\" 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":[36],"tags":[157,159],"class_list":["post-1821","post","type-post","status-publish","format-standard","hentry","category-migration","tag--ddl","tag-ddl"],"acf":[],"_links":{"self":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/1821","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=1821"}],"version-history":[{"count":5,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/1821\/revisions"}],"predecessor-version":[{"id":16002,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/1821\/revisions\/16002"}],"wp:attachment":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}