sqoop导入hsqldb数据示例
$ cp -r examples/apps/sqoop* oozie-apps/$ ls oozie-apps/sqoop*oozie-apps/sqoop:db.hsqldb.properties db.hsqldb.script job.properties workflow.xmloozie-apps/sqoop-freeform:db.hsqldb.properties db.hsqldb.script job.properties workflow.xml
job.properties
nameNode=hdfs://192.168.32.130:8020jobTracker=192.168.32.130:8032queueName=defaultexamplesRoot=oozie-appsoozie.use.system.libpath=trueoozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}/sqoop-freeform
workflow.xml
<?xml version="1.0" encoding="UTF-8"?><!--Licensed to the Apache Software Foundation (ASF) under oneor more contributor license agreements. See the NOTICE filedistributed with this work for additional informationregarding copyright ownership. The ASF licenses this fileto you under the Apache License, Version 2.0 (the"License"); you may not use this file except in compliancewith the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.--><workflow-app xmlns="uri:oozie:workflow:0.2" name="sqoop-freeform-wf"><start to="sqoop-freeform-node"/><action name="sqoop-freeform-node"><sqoop xmlns="uri:oozie:sqoop-action:0.2"><job-tracker>${jobTracker}</job-tracker><name-node>${nameNode}</name-node><prepare><delete path="${nameNode}/user/${wf:user()}/${examplesRoot}/output-data/sqoop-freeform"/><mkdir path="${nameNode}/user/${wf:user()}/${examplesRoot}/output-data"/></prepare><configuration><property><name>mapred.job.queue.name</name><value>${queueName}</value></property></configuration><arg>import</arg><arg>--connect</arg><arg>jdbc:hsqldb:file:db.hsqldb</arg><arg>--username</arg><arg>sa</arg><arg>--password</arg><arg></arg><arg>--verbose</arg><arg>--query</arg><arg>select TT.I, TT.S from TT where $CONDITIONS</arg><arg>--target-dir</arg><arg>/user/${wf:user()}/${examplesRoot}/output-data/sqoop-freeform</arg><arg>-m</arg><arg>1</arg><file>db.hsqldb.properties#db.hsqldb.properties</file><file>db.hsqldb.script#db.hsqldb.script</file></sqoop><ok to="end"/><error to="fail"/></action><kill name="fail"><message>Sqoop free form failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message></kill><end name="end"/></workflow-app>
db.hsqldb.properties
#HSQL Database Engine 1.8.0.5#Tue Oct 05 11:20:19 SGT 2010hsqldb.script_format=0runtime.gc_interval=0sql.enforce_strict_size=falsehsqldb.cache_size_scale=8readonly=falsehsqldb.nio_data_file=truehsqldb.cache_scale=14version=1.8.0hsqldb.default_table_type=memoryhsqldb.cache_file_scale=1hsqldb.log_size=200modified=nohsqldb.cache_version=1.7.0hsqldb.original_version=1.8.0hsqldb.compatible_version=1.8.0
db.hsqldb.script
CREATE SCHEMA PUBLIC AUTHORIZATION DBACREATE MEMORY TABLE TT(I INTEGER NOT NULL PRIMARY KEY,S VARCHAR(256))CREATE USER SA PASSWORD ""GRANT DBA TO SASET WRITE_DELAY 10SET SCHEMA PUBLICINSERT INTO TT VALUES(1,'a')INSERT INTO TT VALUES(2,'a')INSERT INTO TT VALUES(3,'a')
执行
$ # 上传任务$ ~/Documents/hadoop/bin/hadoop fs -put oozie-apps/sqoop-freeform/ oozie-apps$ # 查看目录信息$ ~/Documents/hadoop/bin/hadoop fs -ls /user/jack/oozie-apps/sqoop-freeformFound 2 itemsFound 4 items-rw-r--r-- 1 jack supergroup 1208 2020-05-13 18:12 /user/jack/oozie-apps/sqoop-freeform/db.hsqldb.properties-rw-r--r-- 1 jack supergroup 1081 2020-05-13 18:12 /user/jack/oozie-apps/sqoop-freeform/db.hsqldb.script-rw-r--r-- 1 jack supergroup 1018 2020-05-13 18:12 /user/jack/oozie-apps/sqoop-freeform/job.properties-rw-r--r-- 1 jack supergroup 2508 2020-05-13 18:12 /user/jack/oozie-apps/sqoop-freeform/workflow.xml$ # 执行工作流任务$ bin/oozied.sh start$ export OOZIE_URL="http://192.168.32.130:11000/oozie"$ bin/oozie job -config oozie-apps/sqoop-freeform/job.properties -runjob: 0000000-200513181559469-oozie-jack-W$ # 检查工作流任务状态,也可以通过Oozie web控制台检查工作流作业状态,http://localhost:11000/oozie$ bin/oozie job -info 0000000-200513181559469-oozie-jack-WJob ID : 0000000-200513181559469-oozie-jack-W------------------------------------------------------------------------------------------------------------------------------------Workflow Name : sqoop-freeform-wfApp Path : hdfs://192.168.32.130:8020/user/jack/oozie-apps/sqoop-freeformStatus : RUNNINGRun : 0User : jackGroup : -Created : 2020-05-14 01:17 GMTStarted : 2020-05-14 01:17 GMTLast Modified : 2020-05-14 01:17 GMTEnded : -CoordAction ID: -Actions------------------------------------------------------------------------------------------------------------------------------------ID Status Ext ID Ext Status Err Code------------------------------------------------------------------------------------------------------------------------------------0000000-200513181559469-oozie-jack-W@:start: OK - OK -------------------------------------------------------------------------------------------------------------------------------------0000000-200513181559469-oozie-jack-W@sqoop-freeform-node RUNNING job_1588552715711_0025 RUNNING -------------------------------------------------------------------------------------------------------------------------------------··· ···Actions------------------------------------------------------------------------------------------------------------------------------------ID Status Ext ID Ext Status Err Code------------------------------------------------------------------------------------------------------------------------------------0000000-200513181559469-oozie-jack-W@:start: OK - OK -------------------------------------------------------------------------------------------------------------------------------------0000000-200513181559469-oozie-jack-W@sqoop-freeform-node OK job_1588552715711_0025 SUCCEEDED -------------------------------------------------------------------------------------------------------------------------------------0000000-200513181559469-oozie-jack-W@end OK - OK -------------------------------------------------------------------------------------------------------------------------------------$ # 查看输出内容$ ~/Documents/hadoop/bin/hadoop fs -ls /user/jack/oozie-apps/output-data/sqoop-freeformFound 2 items-rw-r--r-- 1 jack supergroup 0 2020-05-13 18:18 /user/jack/oozie-apps/output-data/sqoop-freeform/_SUCCESS-rw-r--r-- 1 jack supergroup 12 2020-05-13 18:18 /user/jack/oozie-apps/output-data/sqoop-freeform/part-m-00000$ ~/Documents/hadoop/bin/hadoop fs -cat /user/jack/oozie-apps/output-data/sqoop-freeform/part-m-000001,a2,a3,a
sqoop导入oracle数据
$ cp -r oozie-apps/sqoop-freeform/ oozie-apps/sqoop-freeform-oracle$ rm -rf oozie-apps/sqoop-freeform-oracle/db.hsqldb.*
job.properties
nameNode=hdfs://192.168.32.130:8020jobTracker=192.168.32.130:8032queueName=defaultexamplesRoot=oozie-appsoozie.use.system.libpath=trueoozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}/sqoop-freeform-oracle
workflow.xml
<?xml version="1.0" encoding="UTF-8"?><!--Licensed to the Apache Software Foundation (ASF) under oneor more contributor license agreements. See the NOTICE filedistributed with this work for additional informationregarding copyright ownership. The ASF licenses this fileto you under the Apache License, Version 2.0 (the"License"); you may not use this file except in compliancewith the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.--><workflow-app xmlns="uri:oozie:workflow:0.2" name="sqoop-freeform-wf"><start to="sqoop-freeform-node"/><action name="sqoop-freeform-node"><sqoop xmlns="uri:oozie:sqoop-action:0.2"><job-tracker>${jobTracker}</job-tracker><name-node>${nameNode}</name-node><prepare><delete path="${nameNode}/user/${wf:user()}/${examplesRoot}/output-data/sqoop-freeform-oracle/h_log_lotbase"/><mkdir path="${nameNode}/user/${wf:user()}/${examplesRoot}/output-data/sqoop-freeform-oracle/"/></prepare><configuration><property><name>mapred.job.queue.name</name><value>${queueName}</value></property></configuration><arg>import</arg><arg>--connect</arg><arg>jdbc:oracle:thin:@//192.168.1.38:1521/CMASPROD</arg><arg>--username</arg><arg>mes_bc</arg><arg>--password</arg><arg>mes_bc_real</arg><arg>--table</arg><arg>H_LOG_LOTBASE</arg><arg>--where</arg><arg><![CDATA[complete_time < to_date('2016:3:12 00:00:00', 'yyyy-mm-dd HH24:MI:SS')]]></arg><arg>--delete-target-dir</arg><arg>--target-dir</arg><arg>/user/${wf:user()}/${examplesRoot}/output-data/sqoop-freeform-oracle/h_log_lotbase</arg><arg>-m</arg><arg>1</arg><archive>ojdbc7.jar</archive></sqoop><ok to="end"/><error to="fail"/></action><kill name="fail"><message>Sqoop free form failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message></kill><end name="end"/></workflow-app>
执行
$ # 上传任务 -f 覆盖$ ~/Documents/hadoop/bin/hadoop fs -put oozie-apps/sqoop-freeform-oracle/ oozie-apps$ # 查看目录信息$ ~/Documents/hadoop/bin/hadoop fs -ls /user/jack/oozie-apps/sqoop-freeform-oracleFound 2 items-rw-r--r-- 1 jack supergroup 1025 2020-05-13 18:56 /user/jack/oozie-apps/sqoop-freeform-oracle/job.properties-rw-r--r-- 1 jack supergroup 2503 2020-05-13 18:56 /user/jack/oozie-apps/sqoop-freeform-oracle/workflow.xml$ bin/oozied.sh start$ export OOZIE_URL="http://192.168.32.130:11000/oozie"$ bin/oozie job -config oozie-apps/sqoop-freeform-oracle/job.properties -runjob: 0000015-200513181559469-oozie-jack-W$ bin/oozie job -info 0000015-200513181559469-oozie-jack-WJob ID : 0000015-200513181559469-oozie-jack-W------------------------------------------------------------------------------------------------------------------------------------Workflow Name : sqoop-freeform-wfApp Path : hdfs://192.168.32.130:8020/user/jack/oozie-apps/sqoop-freeform-oracleStatus : RUNNINGRun : 0User : jackGroup : -Created : 2020-05-14 05:23 GMTStarted : 2020-05-14 05:23 GMTLast Modified : 2020-05-14 05:23 GMTEnded : -CoordAction ID: -Actions------------------------------------------------------------------------------------------------------------------------------------ID Status Ext ID Ext Status Err Code------------------------------------------------------------------------------------------------------------------------------------0000015-200513181559469-oozie-jack-W@:start: OK - OK -------------------------------------------------------------------------------------------------------------------------------------0000015-200513181559469-oozie-jack-W@sqoop-freeform-node RUNNING job_1588552715711_0046 RUNNING -------------------------------------------------------------------------------------------------------------------------------------··· ···------------------------------------------------------------------------------------------------------------------------------------ID Status Ext ID Ext Status Err Code------------------------------------------------------------------------------------------------------------------------------------0000015-200513181559469-oozie-jack-W@:start: OK - OK -------------------------------------------------------------------------------------------------------------------------------------0000015-200513181559469-oozie-jack-W@sqoop-freeform-node OK job_1588552715711_0046 SUCCEEDED -------------------------------------------------------------------------------------------------------------------------------------0000015-200513181559469-oozie-jack-W@end OK - OK -------------------------------------------------------------------------------------------------------------------------------------# 默认逗号分隔field$ ~/Documents/hadoop/bin/hadoop fs -cat \oozie-apps/output-data/sqoop-freeform-oracle/h_log_lotbase/*914b7ee3-20c0-4289-8ca2-b883dad9b73a,2016-03-11 09:13:22.0,COMPLETE,11,3,2016,11,null,null,L216-1603040030,L216-1603040030,2310215012240,2,2016-03-11 09:13:22.0,A1301005,MACPRO_NORMAL_01,ROUTE_SET,ROUTE_SET-B01-01,FALSE,216-1600289,null,2,2,0,0,MACPRO_NORMAL_01,MACPRO_NORMAL_01,ROUTE_SET,PROGRAM,INITIAL,WAIT,null,2016-03-11 09:13:22.0,2016-03-11 09:13:22.0,null,RELEASED,ACTIVE,PCS,2016-03-21 00:00:00.0,null,null,null,null,null,null,null,null5667f1e5-999e-4b6a-9021-653320e28349,2016-03-11 09:13:24.0,COMPLETE,11,3,2016,11,null,null,L216-1603040035,L216-1603040035,2310215082321,2,2016-03-11 09:13:24.0,A1301005,MACPRO_NORMAL_01,ROUTE_SET,ROUTE_SET-B01-01,FALSE,216-1600289,null,2,2,0,0,MACPRO_NORMAL_01,MACPRO_NORMAL_01,ROUTE_SET,PROGRAM,INITIAL,WAIT,null,2016-03-11 09:13:24.0,2016-03-11 09:13:24.0,null,RELEASED,ACTIVE,PCS,2016-03-21 00:00:00.0,null,null,null,null,null,null,null,null
sqoop导入mysql数据
job.properties
nameNode=hdfs://192.168.32.130:8020jobTracker=192.168.32.130:8032queueName=defaultexamplesRoot=oozie-appsoozie.use.system.libpath=trueoozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}/sqoop-freeform-mysql
workflow.xml
<?xml version="1.0" encoding="UTF-8"?><!--Licensed to the Apache Software Foundation (ASF) under oneor more contributor license agreements. See the NOTICE filedistributed with this work for additional informationregarding copyright ownership. The ASF licenses this fileto you under the Apache License, Version 2.0 (the"License"); you may not use this file except in compliancewith the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.--><workflow-app xmlns="uri:oozie:workflow:0.2" name="sqoop-freeform-wf"><start to="sqoop-freeform-node"/><action name="sqoop-freeform-node"><sqoop xmlns="uri:oozie:sqoop-action:0.2"><job-tracker>${jobTracker}</job-tracker><name-node>${nameNode}</name-node><prepare><delete path="${nameNode}/user/${wf:user()}/${examplesRoot}/output-data/sqoop-freeform-mysql/roles"/><mkdir path="${nameNode}/user/${wf:user()}/${examplesRoot}/output-data/sqoop-freeform-mysql/"/></prepare><configuration><property><name>mapred.job.queue.name</name><value>${queueName}</value></property></configuration><arg>import</arg><arg>--connect</arg><arg>jdbc:mysql://192.168.32.130:3306/hive</arg><arg>--username</arg><arg>root</arg><arg>--password</arg><arg>123456</arg><arg>--table</arg><arg>ROLES</arg><arg>--delete-target-dir</arg><arg>--target-dir</arg><arg>/user/${wf:user()}/${examplesRoot}/output-data/sqoop-freeform-mysql/roles</arg><arg>-m</arg><arg>1</arg><archive>mysql-connector-java-5.1.27-bin.jar</archive></sqoop><ok to="end"/><error to="fail"/></action><kill name="fail"><message>Sqoop free form failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message></kill><end name="end"/></workflow-app>
执行
$ bin/oozied.sh start$ ~/Documents/hadoop/bin/hadoop fs -put -f \oozie-apps/sqoop-freeform-mysql/ oozie-apps$ bin/oozie job -config oozie-apps/sqoop-freeform-mysql/job.properties -run$ bin/oozie job -info 0000013-200513181559469-oozie-jack-W$ ~/Documents/hadoop/bin/hadoop fs -cat \/user/jack/oozie-apps/output-data/sqoop-freeform-mysql/roles/*20/05/13 22:14:47 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable1,1585619269,admin,admin2,1585619269,public,public
参考
启动Sqoop失败的问题
“Launcher ERROR, reason: Main class [org.apache.oozie.action.hadoop.SqoopMain], exit code [1]”,引发的原因,Sqoop无法加载访问数据库所需的数据库驱动程序。
