存入HDFS有好幾種隱滾滑數據格式,我這里給備胡你列出一種格式的存儲,灶臘sequence的 public class SeqWrite {private static final String[] data = { "a,b,c,d,e,f,g", "h,i,j,k,l,m,n", "o,p,q,r,s,t", "u,v,w,x,y,z", "0,1,2,3,4", "5,6,7,8,9" };public
⑵ sqoop導入到HDFS怎麼都是java文件總結
運行一個maprece作業,該隱州作業會連接mysql資料庫並讀取歲禪表中的數據灶雀蔽,默認該作業會運行4個map任務來加速導入過程,每個任務都會將其導入的數據寫到一個單獨的文件,但所有4個文件都位於同一個目錄中。
codegen:生成源代碼,但並不執行導入操作
⑶ Sqoop工作原理是什麼
Sqoop是一款用於把關系型資料庫中的數據導入到hdfs中或者hive中的工具,當然也支持把數據從hdfs或者hive導入到關系型資料庫中。
Sqoop也是基於Maprece來做的數據導入。
關於sqoop的原理
sqoop的原理比較簡單,就是根據用戶指定的sql或者欄位參數,從資料庫中讀取數據導入到hive或者hdfs中。也支持基於資料庫導出工具導出,不陵槐御過受限於資料庫的版本。
在導出的過程中,sqoop會自動切分maprece任務。比如某個欄位的主鍵是從1到1000,那麼當設置num-mappers為2時,第一個mr任務會讀取1-500的數據,第二個mr任務會讀取500-1000的尺岩數據。如果是字元串還有其他的劃分方法.
關明沖於架構
sqoop目前有兩個大版本,第一個版本比較簡單,只能使用命令行
第二個版本引入了sqoop server,統一處理連接等信息,並提供多種連接方式,還引入了許可權控制,另外規范了連接的各項配置。
⑷ Sqoop的簡單使用案例
(配置sqoop家目錄環境變數,略)
  
 驗證Sqoop連接MySQL:
  
  bin/sqoop list-databases --connect jdbc:mysql://hadoop01:3306/ --username root --password root
1 導入數據
  
 在Sqoop中,「導入」概念指:從非大數據集群(RDBMS)向大數據集群(HDFS,HIVE,HBASE)中傳輸數據,叫做:導入,即使用import關鍵字。
  
    1.1 RDBMS到HDFS
  
 1) 確定Mysql服務開啟正常
  
 2) 在Mysql中新建一張表並插入一些數據
  
 $ mysql -uroot -proot
  
  create database company;
  
  create table company.staff(id int(4) primary key not null auto_increment, name varchar(255), sex varchar(255));
  
  insert into company.staff(name, sex) values('Thomas', 'Male');
  
  insert into company.staff(name, sex) values('Catalina', 'FeMale');
  
  select * from company;
  
 3) 導入數據
  
  (1)全部導入
  
 $ bin/sqoop import \
  
 --connect jdbc:mysql://hadoop01:3306/company \
  
 --username root \
  
 --password root \
  
 --table staff \
  
 --target-dir /user/company \
  
 --delete-target-dir \
  
 --num-mappers 1 \
  
 --fields-terminated-by "\t"
  
  (2)查詢導入
  
 $ bin/sqoop import \
  
 --connect jdbc:mysql://hadoop01:3306/衡配褲company \
  
 --username root \
  
 --password root \
  
 --target-dir /user/company \
  
 --delete-target-dir \
  
 --num-mappers 1 \
  
 --fields-terminated-by "\t" \
  
 --query 'select name,sex from staff where id <=1 and $CONDITIONS;'
  
 提示:must contain '$CONDITIONS'咐簡 in WHERE clause.
  
 如果query後使用的是雙引號,則$CONDITIONS前必須加轉移符,防止shell識別為自己的變數。
  
  (3)導入指定列
  
 $ bin/sqoop import \
  
 --connect jdbc:mysql://hadoop01:3306/company \
  
 --username root \
  
 --password root \
  
 --target-dir /user/company \
  
 --delete-target-dir \
  
 --num-mappers 1 \
  
 --fields-terminated-by "\t" \
  
 --columns id,sex \
  
 --table staff
  
 提示:columns中如果涉及到多列,用逗號分隔,分隔時不要添加空格
  
  (4)使用sqoop關鍵賣州字篩選查詢導入數據
  
 $ bin/sqoop import \
  
 --connect jdbc:mysql://hadoop01:3306/company \
  
 --username root \
  
 --password root \
  
 --target-dir /user/company \
  
 --delete-target-dir \
  
 --num-mappers 1 \
  
 --fields-terminated-by "\t" \
  
 --table staff \
  
 --where "id=1"
  
    1.2 RDBMS到Hive
  
 $ bin/sqoop import \
  
 --connect jdbc:mysql://hadoop01:3306/company \
  
 --username root \
  
 --password root \
  
 --table staff \
  
 --num-mappers 1 \
  
 --hive-import \
  
 --fields-terminated-by "\t" \
  
 --hive-overwrite \
  
 --hive-table staff_hive
  
 提示:該過程分為兩步,第一步將數據導入到HDFS,第二步將導入到HDFS的數據遷移到Hive倉庫,第一步默認的臨時目錄是/user/atguigu/表名
  
    1.3 RDBMS到Hbase
  
 $ bin/sqoop import \
  
 --connect jdbc:mysql://hadoop01:3306/company \
  
 --username root \
  
 --password root \
  
 --table company \
  
 --columns "id,name,sex" \
  
 --column-family "info" \
  
 --hbase-create-table \
  
 --hbase-row-key "id" \
  
 --hbase-table "hbase_company" \
  
 --num-mappers 1 \
  
 --split-by id
  
 提示:sqoop1.   6隻支持HBase1.0.1之前的版本的自動創建HBase表的功能
  
 解決方案:手動創建HBase表
  
 hbase> create 'hbase_company,'info'
  
 (5) 在HBase中scan這張表得到如下內容
  
 hbase> scan 『hbase_company』
  
    2、導出數據
  
 在Sqoop中,「導出」概念指:從大數據集群(HDFS,HIVE,HBASE)向非大數據集群(RDBMS)中傳輸數據,叫做:導出,即使用export關鍵字。
  
    2.1 HIVE/HDFS到RDBMS
  
 $ bin/sqoop export \
  
 --connect jdbc:mysql://hadoop01:3306/company \
  
 --username root \
  
 --password root \
  
 --table staff \
  
 --num-mappers 1 \
  
 --export-dir /user/hive/warehouse/staff_hive \
  
 --input-fields-terminated-by "\t"
  
 提示:Mysql中如果表不存在,不會自動創建
  
    3 腳本打包
  
 使用opt格式的文件打包sqoop命令,然後執行
  
 1) 創建一個.opt文件
  
 $ mkdir opt
  
 $ touch opt/job_HDFS2RDBMS.opt
  
 2) 編寫sqoop腳本
  
 $ vi opt/job_HDFS2RDBMS.opt
  
 export
  
 --connect
  
 jdbc:mysql://hadoop01:3306/company
  
 --username
  
 root
  
 --password
  
 root
  
 --table
  
 staff
  
 --num-mappers
  
 1
  
 --export-dir
  
 /user/hive/warehouse/staff_hive
  
 --input-fields-terminated-by
  
 "\t"
  
 3) 執行該腳本
  
 $ bin/sqoop --options-file opt/job_HDFS2RDBMS.opt
sqoop 配合集群使用: 
  
 創建連接MySQL密碼存放文件 並傳到HDFS中:
  
  1.echo -n root > /usr/local/bin/sqoopPWD.pwd
  
  2.hdfs dfs -put /usr/local/bin/sqoopPWD.pwd /user/hue/oozie/
  
 3.sqoop job \
  
 --create release_materiel \
  
   -- import \ 
  
 --connect jdbc:mysql://hd0:3306/throwads \
  
 --username root \
  
 --password-file /user/hue/oozie/sqoopPWD.pwd \
  
 --table materiel \
  
 --delete-target-dir \
  
 --target-dir /gp1905/release/ods/release_materiel \
  
 --fields-terminated-by '\001'
(注意-- import 有一個空格!!!)
⑸ sqoop2 1.99.7 java api 如何設置file format
//流讀入和寫入InputStreamin=null;//獲取HDFS的conf//讀取HDFS上的文件系統FileSystemhdfs=FileSystem.get(conf);//使用緩沖流,進行按行讀取的功能BufferedReaderbuff=null;//獲取日誌文件的根目錄Pathlistf=newPath("hdfs://10
⑹ sqoop支持java遠程操作么
Sqoop(發音:skup)是一款開源的工具,主要用於在Hadoop(Hive)與傳統的資料庫(mysql、postgresql...)間進行數據的傳遞,可以將一個關系型資料庫(例如 : MySQL ,Oracle ,Postgres等)中的數據導進到Hadoop的HDFS中,也可以將HDFS的數據導進到關系型資料庫中。
Sqoop項目開始於2009年,最早是作為Hadoop的一個第三方模塊存在,後來為了讓使用者能夠快速部署,也為了讓開發人員能夠更快速的迭代開發,Sqoop獨立成為一個Apache項目。
⑺ sqoop導入到HDFS怎麼都是java文件總結
如下面這個shell腳本:
#Oracle的連接字元桐粗串,其鏈虧中包含了Oracle的地址,SID,和埠號
CONNECTURL=jdbc:oracle:thin:@20.135.60.21:1521:DWRAC2
#使用的用戶名
ORACLENAME=kkaa
#使用的密碼
ORACLEPASSWORD=kkaa123
#需要從Oracle中導入的表名
oralceTableName=tt
#需要從Oracle中導入的表中的欄位名
columns=AREA_ID,TEAM_NAME
#將Oracle中的數據導入到HDFS後的存放路徑
hdfsPath=apps/as/hive/$oralceTableName
#執行導入邏輯。將Oracle中的局喚鎮數據導入到HDFS中
sqoop import --append --connect $CONNECTURL --username $ORACLENAME --password $ORACLEPASSWORD --target-dir $hdfsPath --num-mappers 1 --table $oralceTableName --columns $columns --fields-terminated-by '\001'
執行這個腳本之後,導入程序就完成了。
⑻ sqoop Error returned by javac
運行sqoop從sqlservre抽數時報錯
  
 Text.writeString(__dataOut, ContactPerson);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1508: error: cannot find symbol
   Text.writeString(__dataOut, ContactPersonTelephone);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1514: error: cannot find symbol
   Text.writeString(__dataOut, ContactPersonEmail);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1520: error: cannot find symbol
   Text.writeString(__dataOut, RequestorID);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1526: error: cannot find symbol
   Text.writeString(__dataOut, RequestorName);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1532: error: cannot find symbol
   Text.writeString(__dataOut, RequestorLogonname);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1538: error: cannot find symbol
   Text.writeString(__dataOut, RequestorCountry);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1544: error: cannot find symbol
   Text.writeString(__dataOut, RequestorTelephone);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1550: error: cannot find symbol
   Text.writeString(__dataOut, RequestorEmail);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1556: error: cannot find symbol
   Text.writeString(__dataOut, OperatorID);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1562: error: cannot find symbol
   Text.writeString(__dataOut, OperatorName);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1568: error: cannot find symbol
   Text.writeString(__dataOut, OperatorLogonName);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1574: error: cannot find symbol
   Text.writeString(__dataOut, Country);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1580: error: cannot find symbol
   Text.writeString(__dataOut, CompanyCode);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1593: error: cannot find symbol
   Text.writeString(__dataOut, NonPoPurchaseCategory);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1599: error: cannot find symbol
   Text.writeString(__dataOut, CategoryRemark);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1605: error: cannot find symbol
   Text.writeString(__dataOut, ContractNumber);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1611: error: cannot find symbol
   Text.writeString(__dataOut, Currency);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1630: error: cannot find symbol
   Text.writeString(__dataOut, PayingBankAccountNumber);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1636: error: cannot find symbol
   Text.writeString(__dataOut, CheckToRequestorName);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1642: error: cannot find symbol
   Text.writeString(__dataOut, CheckToRequestorTelephone);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1648: error: cannot find symbol
   Text.writeString(__dataOut, BankConfirmationMail);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1654: error: cannot find symbol
   Text.writeString(__dataOut, BeneficiaryName);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1660: error: cannot find symbol
   Text.writeString(__dataOut, BeneficiaryAddress);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1666: error: cannot find symbol
   Text.writeString(__dataOut, BeneficiaryBankName);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1672: error: cannot find symbol
   Text.writeString(__dataOut, BankAccountNumber);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1678: error: cannot find symbol
   Text.writeString(__dataOut, BankCode);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1684: error: cannot find symbol
   Text.writeString(__dataOut, TaxID);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1738: error: cannot find symbol
   Text.writeString(__dataOut, PaymentfileNumber);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1751: error: cannot find symbol
   Text.writeString(__dataOut, Remark);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1770: error: cannot find symbol
   Text.writeString(__dataOut, PONo);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1776: error: cannot find symbol
   Text.writeString(__dataOut, GEO);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1782: error: cannot find symbol
   Text.writeString(__dataOut, SID);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1788: error: cannot find symbol
   Text.writeString(__dataOut, UMSAttachments);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1794: error: cannot find symbol
   Text.writeString(__dataOut, TaxJurisdictionReport);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1800: error: cannot find symbol
   Text.writeString(__dataOut, DectableTaxCostCenter);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1806: error: cannot find symbol
   Text.writeString(__dataOut, ServiceTax);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1812: error: cannot find symbol
   Text.writeString(__dataOut, ServiceTaxAccount);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1818: error: cannot find symbol
   Text.writeString(__dataOut, ServiceTaxCode);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1824: error: cannot find symbol
   Text.writeString(__dataOut, Assignment);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1830: error: cannot find symbol
   Text.writeString(__dataOut, Text);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1838: error: cannot find symbol
   Text.writeString(__dataOut, ID);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1844: error: cannot find symbol
   Text.writeString(__dataOut, Subject);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1850: error: cannot find symbol
   Text.writeString(__dataOut, TicketNumber);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   /tmp/sqoop-UsageDB/compile//QueryResult.java:1856: error: cannot find symbol
   Text.writeString(__dataOut, VendorID);
   ^
   symbol:   method writeString(DataOutput,String)
   location: variable Text of type String
   Note: /tmp/sqoop-UsageDB/compile//QueryResult.java uses or overrides a deprecated API.
   Note: Recompile with -Xlint:deprecation for details.
   100 errors
   2019-06-27 19:10:40,977 ERROR [main] tool.ImportTool (ImportTool.java:run(609)) - Encountered IOException running import job: java.io.IOException: Error returned by javac
   at org.apache.sqoop.orm.CompilationManager.compile(CompilationManager.java:217)
   at org.apache.sqoop.tool.CodeGenTool.generateORM(CodeGenTool.java:97)
   at org.apache.sqoop.tool.ImportTool.importTable(ImportTool.java:478)
   at org.apache.sqoop.tool.ImportTool.run(ImportTool.java:601)
   at org.apache.sqoop.Sqoop.run(Sqoop.java:143)
   at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
   at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:179)
   at org.apache.sqoop.Sqoop.runTool(Sqoop.java:218)
   at org.apache.sqoop.Sqoop.runTool(Sqoop.java:227)
   at org.apache.sqoop.Sqoop.main(Sqoop.java:236)
   對應的是sqlserver FIle table;沒辦法指定--table.
   網上查到說指定字元,就去檢查下下字元,檢查到原因時目標表中有列欄位名叫Text,在抽數時將這個欄位去掉了。
   更改後如下
⑼ sqoop命令使用jar包,jar應該放哪個目錄下
1,rmdbs to hadoop 很簡單,使用一條命令 sqoop import --jar-file (你吵喊的jar包) --class-name (classname) --connect (mysql實友碰御例) --username (用戶名) --password (密碼) -table (表名) -hbase-table (hbase表名好岩) -column-famil...
⑽ sqoop導入到HDFS怎麼都是java文件總結
您好,我看到您的問題很久沒有人來回答,但是問題過期無人回答會被扣分的並且你的懸賞分也會被沒收!所以我給你提幾條建議:
一,你可以選擇在正確的分類下去提問,這樣知道你問題答案的人才會多一些,回答的人也會多些。
二,您可以到與您問題相關專業網站論壇里去看看,那裡聚集悉攜了許多專業人才,一定可以為你解決問題的。
三,你可以向你的網上好襲陸慧友問友打聽,他們會更加真誠熱心為你尋找答案的,甚至可以到相關網站直接搜索.
四,網上很多專業論壇以及知識平台,上面也有很多資料,我遇到專業性的問題總是上論壇求解決辦法的。
五,將你的問題問的細一些,清楚一些!讓人更加容易看懂明白是什麼意思!
謝謝拍答採納我的建議! !