通过java运行Sqoop Export时出错

时间:2015-06-12 14:25:04

标签: java sqoop

我有一个java程序来运行export命令。在执行导出时,它会尝试在本地计算机中查找导出目录而不是Hdfs。相同的程序适用于导入。我检查了hdfs上存在的文件。

请帮忙。

以下是我正在执行的代码:

public void executeSqoopLoad() throws UnsupportedEncodingException{
    SqoopOptions options = new SqoopOptions();

    String driver = "oracle.jdbc.driver.OracleDriver";
    //options.setDriverClassName(driver);
    options.setUsername(“user");
    options.setPassword(“pass");
    options.setConnectString("jdbc:oracle:thin:@host:1522:rptdev");

    Configuration configuration = new Configuration(false);
    Resource configResource;
    try {
        configResource = FileUtils.getFileResource("/Users/Moiz/git/jef/hadoop/hdfs-site.xml");
        configuration.addResource(configResource.getInputStream());
        configResource = FileUtils.getFileResource("/Users/Moiz/git/jef/hadoop/core-site.xml");
        configuration.addResource(configResource.getInputStream());
        FileSystem dfs = FileSystem.get(configuration); 

        String[] uriSplit = dfs.getUri().toString().split(":");
        String newUri = uriSplit[0]+":"+uriSplit[1];
        dfs.setWorkingDirectory(new Path(newUri+"/tmp"));
        System.out.println(dfs.getWorkingDirectory());

        System.out.println("Exists = " + dfs.exists(dfs.getWorkingDirectory()));

        DateTime dt =  new DateTime();
        options.setCodeOutputDir("/tmp");
        options.setClassName("SqoopLoad_"+null+dt.getYear()+dt.getMonthOfYear()+dt.getDayOfMonth()+dt.getMillisOfDay());
        options.setVerbose(true);
        // HDFS options
        options.setExportDir(dfs.getWorkingDirectory()+"/TestDirectory");

        System.out.println("Exists = " + dfs.exists(new Path(options.getExportDir())));
        options.setInputFieldsTerminatedBy('\u0005');
        options.setTableName(“SCHEMA.TEST_SQP");
        options.setNumMappers(1);
        options.setDirectMode(true);
        System.setProperty(Sqoop.SQOOP_RETHROW_PROPERTY, "rethrow");

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    int ret = 100;
    try{
        ret = new ExportTool().run(options);
    }catch (Exception e) {
        System.out.println("Debug");
        e.printStackTrace();
    }
    System.out.println("return code "+ ret);
}
  

java.lang.RuntimeException:java.io.FileNotFoundException:File   / tmp / TestDirectory / part-m-00000不存在

1 个答案:

答案 0 :(得分:0)

我得到了它的工作。不得不通过maven重新导入sqoop罐子。