Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqoop code #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions sqoop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Sqoop

This code accompanies [this article which walks through Sqoop][blog-post].

## Compile

```
mvn compile
```

## Build
```
mvn assembly:single
```

## Run

```
java -jar /path/to/assembled.jar

[blog-post]:
121 changes: 121 additions & 0 deletions sqoop/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.matthewrathbone.example.DataImporter</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

<modelVersion>4.0.0</modelVersion>
<groupId>com.matthewrathbone.example</groupId>
<artifactId>sqoop-1</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>sqoop-1</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.apache.sqoop</groupId>
<artifactId>sqoop</artifactId>
<version>1.4.2</version>
<classifier>hadoop20</classifier>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.5.3</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro-mapred</artifactId>
<version>1.5.3</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>0.20.2</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>my-internal-site</id>
<url>https://repo1.maven.org/maven2/org/apache/sqoop/sqoop/1.4.2/</url>
</repository>
</repositories>
</project>
40 changes: 40 additions & 0 deletions sqoop/src/main/java/com/matthewrathbone/example/DataImporter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.matthewrathbone.example;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.sqoop.tool.ImportTool;
import com.cloudera.sqoop.SqoopOptions;

public class DataImporter {

public static void main(String[] args){
System.out.println(export());
}

public static int export(){
SqoopOptions options = new SqoopOptions();
options.setConnectString("jdbc:mysql://localhost/test");

//options.setTableName("TABLE_NAME");
//options.setWhereClause("id>10"); // this where clause works when importing whole table, ie when setTableName() is used

options.setUsername("root");
options.setPassword("");
options.setNumMappers(2);
options.setSqlQuery("select id, location from m_users WHERE $CONDITIONS");
options.setSplitByCol("id");

Configuration config = new Configuration();
config.addResource(new Path("/Users/elena/apache/hadoop-0.20.2/conf/core-site.xml"));
config.addResource(new Path("/Users/elena/apache/hadoop-0.20.2/conf/hdfs-site.xml"));

options.setConf(config);
options.setTargetDir("users_java_10");
options.setHadoopHome("/Users/elena/apache/hadoop-0.20.2");
options.setExplicitDelims(true);
options.setFieldsTerminatedBy('\t');
options.setLinesTerminatedBy('\n');
int ret = new ImportTool().run(options);
return ret;
}
}
22 changes: 22 additions & 0 deletions sqoop2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Sqoop

This code accompanies [this article which walks through Sqoop][blog-post].

## Compile

```
mvn compile
```

## Build
```
mvn assembly:single
```

## Run

```
java -jar /path/to/assembled.jar

[blog-post]:
```
Loading