最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

sqoop如何指定pg庫的模式(方法詳解)

 更新時(shí)間:2022年01月22日 11:47:58   作者:華為云開發(fā)者社區(qū)  
sqoop是一個(gè)用來將hadoop中hdfs和關(guān)系型數(shù)據(jù)庫中的數(shù)據(jù)相互遷移的工具,可以將一個(gè)關(guān)系型數(shù)據(jù)庫(mysql、oracle等)中的數(shù)據(jù)導(dǎo)入到hadoop的hdfs中,也可以將hdfs的數(shù)據(jù)導(dǎo)入到關(guān)系型數(shù)據(jù)庫中,本文給大家介紹sqoop如何指定pg庫的模式,一起看看吧

sqoop是一款用于hadoop和關(guān)系型數(shù)據(jù)庫之間數(shù)據(jù)導(dǎo)入導(dǎo)出的工具。你可以通過sqoop把數(shù)據(jù)從數(shù)據(jù)庫(比如mysql,oracle)導(dǎo)入到hdfs中;也可以把數(shù)據(jù)從hdfs中導(dǎo)出到關(guān)系型數(shù)據(jù)庫中。sqoop通過Hadoop的MapReduce導(dǎo)入導(dǎo)出,因此提供了很高的并行性能以及良好的容錯(cuò)性。

sqoop適合以下的人群使用:

  • 系統(tǒng)和應(yīng)用開發(fā)者
  • 系統(tǒng)管理員
  • 數(shù)據(jù)庫管理員
  • 數(shù)據(jù)分析師
  • 數(shù)據(jù)工程師

說明

使用sqoop導(dǎo)出導(dǎo)入數(shù)據(jù)非常的方便,但是對(duì)于postgresql(簡(jiǎn)稱PG庫)時(shí)就碰到了一個(gè)問題,pg庫是三層結(jié)構(gòu)的database——schema——table。如果想導(dǎo)入到某一個(gè)模式下,那就需要指定模式才可以。但是sqoop如何指定pg庫的模式?

解決辦法

碰到問題首先要看文檔才對(duì)的。文檔這里已經(jīng)指出如何指定pg庫的schema了。官方文檔地址
文檔已經(jīng)說了,如果向指定schema需要添加-- --schema <name> 但是要注意的是必須在命令行的?。。?!最后?。?!添加才會(huì)生效。

但是,這是命令行的解決辦法,如果我們使用的是java呢?在沒解決之前,我的java代碼是這樣寫的:

public static boolean ExportCmdInPg(Configuration conf, String tableName, List<String> columns, String hdfsDir,Map<String, String> dbMap) {
        try {
            LogUtils.logInfoPrint("開始任務(wù)",logger);
            List<String> list = new ArrayList<>();
            list.add("--connect");
            list.add(dbMap.get(Constant.DRIVERURL));
            list.add("--username");
            list.add(dbMap.get(Constant.USER));
            list.add("--password");
            list.add(dbMap.get(Constant.PASSWORD));
            list.add("--table");
            list.add(tableName);
            list.add("--columns");
            list.add(StringUtils.join(columns, ','));
            list.add("--fields-terminated-by");
            list.add("\t");
            list.add("--export-dir");
            list.add(hdfsDir);
            list.add("-m");
            list.add("1");
            ExportTool exporter = new ExportTool();
            Sqoop sqoop = new Sqoop(exporter);
            String[] data = list.toArray(new String[0]);
            if (0 == data.length) {
                LogUtils.logErrorPrint("sqoop參數(shù)為空,請(qǐng)檢查ExportCmd方法!",logger);
                return false;
            }
            if (0 == Sqoop.runSqoop(sqoop, data)){
                return true;
            }
        }catch (Exception e){
            LogUtils.logErrorPrint("ExportCmd 導(dǎo)入到HDFS出現(xiàn)錯(cuò)誤",logger,e);
        }
        return false;
    }

結(jié)果當(dāng)然是不成功。那我哦添加-- --schema 參數(shù)試一下

public static boolean ExportCmdInPg(Configuration conf, String tableName, List<String> columns, String hdfsDir,Map<String, String> dbMap) {
        try {
            LogUtils.logInfoPrint("開始任務(wù)",logger);
            List<String> list = new ArrayList<>();
            list.add("--connect");
            list.add(dbMap.get(Constant.DRIVERURL));
            list.add("--username");
            list.add(dbMap.get(Constant.USER));
            list.add("--password");
            list.add(dbMap.get(Constant.PASSWORD));
            list.add("--table");
            list.add(tableName);
            list.add("--columns");
            list.add(StringUtils.join(columns, ','));
            list.add("--fields-terminated-by");
            list.add("\t");
            list.add("--export-dir");
            list.add(hdfsDir);
            list.add("-m");
            list.add("1");
            list.add("-- --schema");
            list.add("HERO");
            ExportTool exporter = new ExportTool();
            Sqoop sqoop = new Sqoop(exporter);
            String[] data = list.toArray(new String[0]);
            if (0 == data.length) {
                LogUtils.logErrorPrint("sqoop參數(shù)為空,請(qǐng)檢查ExportCmd方法!",logger);
                return false;
            }
            if (0 == Sqoop.runSqoop(sqoop, data)){
                return true;
            }
        }catch (Exception e){
            LogUtils.logErrorPrint("ExportCmd 導(dǎo)入到HDFS出現(xiàn)錯(cuò)誤",logger,e);
        }
        return false;
    }

結(jié)果也是不成功,顯示報(bào)錯(cuò)不識(shí)別-- --schema 。。。為了能夠使schema參數(shù)生效,廢了我不少勁。。。也查了不少資料,但是查到的資料都沒有關(guān)于java的schema的設(shè)置。所以。。。最終正確的解決辦法是:

public static boolean ExportCmdInPg(Configuration conf, String tableName, List<String> columns, String hdfsDir,Map<String, String> dbMap) {
        try {
            LogUtils.logInfoPrint("開始sqoop將oracle的數(shù)據(jù)導(dǎo)出到HDFS目錄",logger);
            List<String> list = new ArrayList<>();
            list.add("--connect");
            list.add(dbMap.get(Constant.DRIVERURL));
            list.add("--username");
            list.add(dbMap.get(Constant.USER));
            list.add("--password");
            list.add(dbMap.get(Constant.PASSWORD));
            list.add("--table");
            list.add(tableName);
            list.add("--columns");
            list.add(StringUtils.join(columns, ','));
            list.add("--fields-terminated-by");
            list.add("\t");
            list.add("--export-dir");
            list.add(hdfsDir);
            list.add("-m");
            list.add("1");
            // 注意這里是--是分開的,源碼這里是通過--做判斷的
            list.add("--");
            list.add("--schema");
            list.add("HERO");
            ExportTool exporter = new ExportTool();
            Sqoop sqoop = new Sqoop(exporter);
            String[] data = list.toArray(new String[0]);
            if (0 == data.length) {
                LogUtils.logErrorPrint("sqoop參數(shù)為空,請(qǐng)檢查ExportCmd方法!",logger);
                return false;
            }
            if (0 == Sqoop.runSqoop(sqoop, data)){
                return true;
            }
        }catch (Exception e){
            LogUtils.logErrorPrint("ExportCmd 導(dǎo)入到HDFS出現(xiàn)錯(cuò)誤",logger,e);
        }
        return false;
    }

當(dāng)然你也可能會(huì)使用字符串?dāng)?shù)組,數(shù)組方式就要這樣寫了

// 這里只是舉個(gè)示例
String[] string = new String[]{"--","--schema","HERO"}

so 問題解決,心情愉快。如果問題不解決,可能會(huì)憋一天。。。。

本文分享自華為云社區(qū)《【Hadoop】關(guān)于Sqoop導(dǎo)出數(shù)據(jù)到postgresql時(shí)schema的設(shè)置問題》,作者:Copy工程師 。

到此這篇關(guān)于sqoop如何指定pg庫的模式的文章就介紹到這了,更多相關(guān)sqoop指定pg庫的模式內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 如何正確使用開源項(xiàng)目?

    如何正確使用開源項(xiàng)目?

    開源項(xiàng)目廣受大家喜愛,其實(shí)我們?cè)谑褂瞄_源項(xiàng)目的過程中有不少注意的事項(xiàng),今天就來給大家介紹下如何正確的使用開源項(xiàng)目。需要的朋友可以參考一下
    2018-09-09
  • VScode內(nèi)接入deepseek包過程記錄

    VScode內(nèi)接入deepseek包過程記錄

    在VSCode中集成本地部署的DeepSeek-R1模型,通過擴(kuò)展商店下載并配置Continue插件,實(shí)現(xiàn)模型的添加、連接和使用,過程中包括配置文件的修改、模型的刪除以及注意事項(xiàng)的處理,本文介紹VScode內(nèi)接入deepseek包過程,感興趣的朋友一起看看吧
    2025-02-02
  • 45個(gè)GIT經(jīng)典操作場(chǎng)景使用詳解

    45個(gè)GIT經(jīng)典操作場(chǎng)景使用詳解

    這篇文章主要介紹了45個(gè)GIT經(jīng)典操作場(chǎng)景使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-07-07
  • Win10下為VSCode配置LaTex編輯器的方法

    Win10下為VSCode配置LaTex編輯器的方法

    這篇文章主要介紹了Win10下為VSCode配置LaTex編輯器的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • Git里多種撤銷操作的最佳方法

    Git里多種撤銷操作的最佳方法

    這篇文章我們會(huì)給大家介紹關(guān)于Git里的多種撤銷操作,我會(huì)講解某些你需要“撤銷”已做出的修改的常見場(chǎng)景,以及利用 Git 進(jìn)行這些操作的最佳方法。下面來一起看看吧。
    2016-09-09
  • 解決IDEA中g(shù)it拉取代碼時(shí)出現(xiàn)Update canceled問題

    解決IDEA中g(shù)it拉取代碼時(shí)出現(xiàn)Update canceled問題

    這篇文章主要介紹了解決IDEA中g(shù)it拉取代碼時(shí)出現(xiàn)Update canceled問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • git工具常用命令及ssh操作方法

    git工具常用命令及ssh操作方法

    這篇文章主要介紹了git工具常用到的命令以及非常詳細(xì)的ssh操作方法,有需要的朋友可以借鑒參考下,希望可以有所幫助,祝大家能夠多多進(jìn)步,早日升職加薪
    2021-09-09
  • 如何讓vsCode顯示中文界面

    如何讓vsCode顯示中文界面

    vscode默認(rèn)的語言是英文,這給使用者帶來了一定的挑戰(zhàn),現(xiàn)在小編就來告訴你如何將vscode設(shè)置成中文。
    2020-01-01
  • 使用SSH快速下載Git項(xiàng)目的實(shí)現(xiàn)方法

    使用SSH快速下載Git項(xiàng)目的實(shí)現(xiàn)方法

    下面小編就為大家分享一篇使用SSH快速下載Git項(xiàng)目的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2017-12-12
  • Git如何實(shí)現(xiàn)撤銷提交(命令行+IDEA)

    Git如何實(shí)現(xiàn)撤銷提交(命令行+IDEA)

    這篇文章主要介紹了Git如何實(shí)現(xiàn)撤銷提交(命令行+IDEA)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-12-12

最新評(píng)論

教育| 合阳县| 花莲县| 和政县| 丰镇市| 澄城县| 天峨县| 墨竹工卡县| 炎陵县| 二手房| 法库县| 桂平市| 太保市| 万安县| 丘北县| 东方市| 彭州市| 双鸭山市| 汤原县| 凤山县| 沙洋县| 新龙县| 巴青县| 枝江市| 阿城市| 汉沽区| 丹凤县| 琼海市| 永康市| 称多县| 西畴县| 宁安市| 车险| 丹阳市| 武威市| 荥阳市| 齐河县| 龙里县| 固阳县| 嵊州市| 龙川县|