MegaBytes
MegaBytes

Reputation: 6385

Is there any alternative for SqoopOptions class

I am trying to import data from MySQL to Hive using Java code using SqoopOptions class, but it says this class(com.cloudera.sqoop.SqoopOptions) is deprecated, Class SqoopOptions. I google out alternative for this but not found anything, Can anyone suggest me what is the alternative to do this. I want to use the sqoop command through my java program.

Upvotes: 3

Views: 1225

Answers (2)

generalpiston
generalpiston

Reputation: 891

When Sqoop entered Apache, a lot of the com.cloudera.sqoop.* code has been renamed/migrated to org.apache.sqoop.*. The class you are looking for is org.apache.sqoop.SqoopOptions I believe.

I highly recommend not using Sqoop from a Java program. Instead, try Sqoop2 for that. I believe you can import into HDFS using the Kite connector in Avro or Parquet formats. Then you should be able to load that data into Hive.

Upvotes: 2

Prasad Khode
Prasad Khode

Reputation: 6739

One option is you can execute your sqoop import command using sshxcute

Following is the snippet that you can use

import net.neoremind.sshxcute.core.ConnBean;
import net.neoremind.sshxcute.core.Result;
import net.neoremind.sshxcute.core.SSHExec;
import net.neoremind.sshxcute.task.CustomTask;
import net.neoremind.sshxcute.task.impl.ExecCommand;

public static void main(String[] args) {
    ConnBean connBean = new ConnBean("<SYSTEM_IP>", "<USERNAME>","<PASSWORD>");

    SSHExec sshExec = SSHExec.getInstance(connBean); 

    StringBuilder sqoopImportCommand = new StringBuilder("sqoop import --connect jdbc:mysql://<IP_ADDRESS>:<PORT>/<DATABASE> ")
            .append("--username <USERNAME> --password <PASSWORD> --table <TABLE_NAME> --target-dir <HDFS_PATH>");

    try {
        sshExec.connect();

        CustomTask sqoopImportTask = new ExecCommand(sqoopImportCommand.toString());
        Result crres = sshExec.exec(sqoopImportTask);

        if(crres.isSuccess){
            System.out.println("Data imported successfully");
        }
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    } finally {
        sshExec.disconnect();
    }
}

Upvotes: 1

Related Questions