I have problem when executing this java code to import table from mysql into hive :
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.*;
import com.cloudera.sqoop.Sqoop;
import com.cloudera.sqoop.SqoopOptions;
import com.cloudera.sqoop.SqoopOptions.FileLayout;
import com.cloudera.sqoop.tool.ImportTool;
import com.mysql.jdbc.*;
public class SqoopExample {
public static void main(String[] args) throws Exception {
String driver = "com.mysql.jdbc.Driver";
Class.forName(driver).newInstance();
Configuration config = new Configuration();
config.addResource(new Path("/home/socio/hadoop/etc/hadoop/core-site.xml"));
config.addResource(new Path("/home/socio/hadoop/etc/hadoop/hdfs-site.xml"));
FileSystem dfs = FileSystem.get(config);
SqoopOptions options = new SqoopOptions();
options.setDriverClassName(driver);
options.setConf(config);
options.setHiveTableName("tlinesuccess");
options.setConnManagerClassName("org.apache.sqoop.manager.GenericJdbcManager");
options.setConnectString("jdbc:mysql://dba-virtual-machine/test");
options.setHadoopMapRedHome("/home/socio/hadoop");
options.setHiveHome("/home/socio/hive");
options.setTableName("textlines");
options.setColumns(new String[] {"line"});
options.setUsername("socio");
options.setNumMappers(1);
options.setJobName("Test Import");
options.setOverwriteHiveTable(true);
options.setHiveImport(true);
options.setFileLayout(FileLayout.TextFile);
int ret = new ImportTool().run(options);
}
}
result :
Exception in thread "main" java.io.IOException: No FileSystem for scheme: hdfs
at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:2385)
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2392)
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:89)
at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:2431)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2413)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:368)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:167)
at SqoopExample.main(SqoopExample.java:22)
I specify that this command works sqoop import --connect jdbc:mysql://dba-virtual-machine/test \--username socio --table textlines \--columns line --hive-import
.
I can import from mysql with the shell using the command, the problem is with the java code.
Any help/ideas would be greatly appreciated.
Thanks