sqoop sample code

本文使用的数据库是mysql的sample database employees.

download url:https://launchpad.net/test-db/employees-db-1/1.0.6

然后根据ReadMe安装到自己的mysql数据库中。

sqoop的安装:

下载地址:http://apache.dataguru.cn/sqoop/1.4.6/

sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz 
sqoop-1.4.6.tar.gz                 
我的hadoop版本是2.6,所以我下载的是这两个版本。
sqoop-1.4.6.tar.gz不能直接使用,需要编译。编译后把生成的

sqoop-1.4.6.jar 复制到 sqoop_home/lib下面即可。

复制jdbc connector
mysql-connector-java-5.1.32-bin.jar 或版本更高的mysql jdbc connector.
否则会出现某些bug.
 
sqoop  list-tables --connect jdbc:mysql://namenode01:3306/employees --username hive --password hive
mysqlurl=jdbc:mysql://namenode01:3306/employees 

sqoop import --connect $mysqlurl --username hive --password hive --table departments --target-dir /etl/input/departments 

hdfs dfs -cat /etl/input/departments/* 

insert into departments values(‘d9999‘,‘Evan,Test‘);
Overriding Type Mapping
--map-column-java c1=Float,c2=String,c3=String ...
Sqoop by default uses four concurrent map tasks to transfer data to Hadoop. 

mysqlurl=jdbc:mysql://namenode01:3306/employees
sqoop import --connect $mysqlurl --username hive --password hive --query ‘select d.dept_no,d.dept_name,de.from_date, de.to_date, e.* from employees e join dept_emp de on e.emp_no=de.emp_no join departments d on de.dept_no=d.dept_no WHERE $CONDITIONS‘ --split-by d.dept_no --target-dir /etl/input/employees 

--compare the result count from mysql and hdfs file
hdfs dfs -cat /etl/input/employees/* | wc -l
if you want to overwrite the data type, you can specify the column=type
--map-column-hive id=STRING,price=DECIMAL 

mysqlurl=jdbc:mysql://namenode01:3306/employees
sqoop import --connect $mysqlurl --username hive --password hive --query ‘select d.dept_no,d.dept_name,de.from_date, de.to_date, e.* from employees e join dept_emp de on e.emp_no=de.emp_no join departments d on de.dept_no=d.dept_no WHERE $CONDITIONS‘ --split-by d.dept_no --hive-import --hive-table test.employees --hive-drop-import-delims --null-string ‘\\N‘ --null-non-string ‘\\N‘ --target-dir /tmp/employees
时间: 2024-10-10 04:28:10

sqoop sample code的相关文章

如何将经纬度利用Google Map API显示C# VS2005 Sample Code

原文 如何将经纬度利用Google Map API显示C# VS2005 Sample Code 日前写了一篇如何用GPS抓取目前所在,并回传至资料库储存,这篇将会利用这些回报的资料,将它显示在地图上,这个做法有两种,最简单的就是直接传值到Google Maps上. 举例来说,当我们知道经纬度后,只要将数据套到以下网址即可. http://maps.google.com/maps?q=25.048346%2c121.516396 在参数q=后面,就可以加上经纬度了. 25.048346是Lati

Compilation of OpenGL Redbook sample code

http://download.csdn.net/detail/gflytu/4110817#comment [email protected]:~/Downloads/redbook$ gcc -lglut -lGL -lGLU aaindex.c aaindex.c:(.text+0x2f7): undefined reference to `glutInit'aaindex.c:(.text+0x303): undefined reference to `glutInitDisplayMo

sample code /calculate PI (转)

using System; using System.Math; namespace PiWithMonteCarlo { /// <summary> /// Trivial, synchronous calculation algorithm /// </summary> public static class TrivialPiCalculator { public static double Calculate(int iterations) { int inCircle =

lua sample code analysis

What is a meta table a meta table has a __name attr whose value is name of metatable a meta table is stored in LUA_REGISTRYINDEX whose key is its name Code analysis Appl DUMP_STACK(L); /*{ "foo", "C:\\jshe\\codes\\mylualib\\test\\../build/v

使用MD5將字串加密 C# VS2005 Sample Code

MD5的加密已經出來很長一段時間了,也不是什麼特別的新技術,寫這篇的用意也有點像是給自己的一個Note,畢竟加密的功能不常用,最多寫成一個Class,未來去呼叫就好,怕自己也會忘記,所以把這個寫下來. 初步的UI設定如下: H執行是單純加密,而Salt執行則是跑Salted Hash的動作. 單純加密比較不好,如果被人猜到加密方法是採MD5,也沒有Salted,那會風險會高一點,而Salt的效果,因為多了一個Value去加密,除了前面的都要猜到外,還要知道Salted Value才可以.而Sal

python参数Sample Code

import time import datetime import getopt import sys try: opts, args = getopt.getopt(sys.argv[1:], "ho:", ["inputOCR=", "inputSpeech="]) except getopt.GetoptError: print ('Getopt Error!') sys.exit(1) for name, value in opts:

Stylecop code sample

StyleCopanalyzes C# source code to enforce a set of style and consistency rules. It can be run from inside of Visual Studio or integrated into an MSBuild project. StyleCop has also been integrated into many third-party development tools. StyleCop inc

solrcloud sample

在solrcloud出来之前,如果通过solrj连接solrserver,需要程序自己实现一致性hash.新版本的solr支持cloud的部署方式,可以自动实现lb和sharding的功能(通过CloudSolrServer类连接cloud),可以用下面代码做测试需要的jar包如下: apache-solr-solrj.jar apache-solr-core.jar zookeeper.jar    commons-logging.jar  apache-logging-log4j.jar 

Don’t Put View Code Into Your View Controller别把View创建的代码放在VC中(swift)

Don't Put Into Your View Controller别把View创建的代码放在VC中html, body {overflow-x: initial !important;}.CodeMirror { height: auto; } .CodeMirror-scroll { overflow-y: hidden; overflow-x: auto; } .CodeMirror-lines { padding: 4px 0px; } .CodeMirror pre { paddin