sqoop - Sqoop Codegen - apache sqoop - sqoop tutorial - sqoop hadoop



What is ‘Sqoop codegen’?

  • ‘Codegen’ tool creates the DAO class automatically. To run every object-oriented application, it is must to have one DAO class for each database table that contains ‘getter’ and ‘setter’ methods to initialize objects.
  • Codegen creates DAO class in Java, based on the Table Schema structure. The Java definition is instantiated as a part of the import process.
  • The main objective of this tool is to check if Java lost the Java code. If so, it will create a new version of Java with the default delimiter between fields.

Purpose

  • The Codegen tool generates Java classes which encapsulate and interpret imported records. The Java definition of a record is instantiated as part of the import process, but can also be performed separately.
  • For example, if Java source is lost, it can be recreated. New versions of a class can be created which use different delimiters between fields, and so on.

Syntax

$ sqoop codegen (generic-args) (codegen-args)
$ sqoop-codegen (generic-args) (codegen-args)
Click "Copy code" button to copy into clipboard - By wikitechy - sqoop tutorial - team
  • Although the Hadoop generic arguments must preceed any codegen arguments, the codegen arguments can be entered in any order with respect to one another.

Sqoop Codegen Command With Example

  • Although the Hadoop generic arguments must preceed any codegen arguments, the codegen arguments can be entered in any order with respect to one another.
  • The sqoop codegen command defines the importance of 'codegen' tool. From the viewpoint of object-oriented application, every database table has one DAO class that contains 'getter' and 'setter' methods.
  • It generates DAO class in Java, based on the Table Schema structure. The Java definition is instantiated as a part of the import process. The main usage of this tool is to check if Java lost the Java code.
  • If so, it will create a new version of Java with the default delimiter between fields.

Step 1 - Change the directory to /usr/local/hadoop/sbin

$ cd /usr/local/hadoop/sbin
Click "Copy code" button to copy into clipboard - By wikitechy - sqoop tutorial - team

Step 2 - Start all hadoop daemons.

 $ start-all.sh
Click "Copy code" button to copy into clipboard - By wikitechy - sqoop tutorial - team

Step 3 - The JPS (Java Virtual Machine Process Status Tool) tool is limited to reporting information on JVMs for which it has the access permissions.

$ jps
Click "Copy code" button to copy into clipboard - By wikitechy - sqoop tutorial - team

Step 4 - Change the directory to /usr/local/sqoop/bin

$ cd /usr/local/sqoop/bin
Click "Copy code" button to copy into clipboard - By wikitechy - sqoop tutorial - team

Example

  • Let’s take an example which creates Java code for the emp table in the user db database.
  • The following command is used to execute the given example.
$ sqoop codegen \
--connect jdbc:mysql://localhost/userdb \
--username root \
--table emp
Click "Copy code" button to copy into clipboard - By wikitechy - sqoop tutorial - team

Output

  • If the execution of the command is successful, below output will be produced.
14/12/23 02:34:40 INFO sqoop.Sqoop: Running Sqoop version: 1.4.5
14/12/23 02:34:41 INFO tool.CodeGenTool: Beginning code generatio
………….
14/12/23 02:34:42 INFO orm.CompilationManager: HADOOP_MAPRED_HOME is /usr/local/hadoop
Note: /tmp/sqoop-hadoop/compile/9a300a1f94899df4a9b10f9935ed9f91/emp.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
14/12/23 02:34:47 INFO orm.CompilationManager: Writing jar file: /tmp/sqoop-hadoop/compile/9a300a1f94899df4a9b10f9935ed9f91/emp.jar

Verification

  • The following command is to verify the output.
$ cd /tmp/sqoop-hadoop/compile/9a300a1f94899df4a9b10f9935ed9f91/
$ ls
emp.class
emp.jar
emp.java
  • To verify the in depth, compare the emp table in the user db database and emp.java in the following directory
/tmp/sqoop-hadoop/compile/9a300a1f94899df4a9b10f9935ed9f91/.
Click "Copy code" button to copy into clipboard - By wikitechy - sqoop tutorial - team


Related Searches to Sqoop - Codegen