1. 程式人生 > >sqoop 常用命令整理

sqoop 常用命令整理

sqoop import --connect jdbc:mysql://server.foo.com/db --table bar \
    --direct -- --default-character-set=latin1
10.轉換為物件  --map-column-java <mapping>  轉換為java資料型別  --map-column-hive <mapping>  轉轉為hive資料型別11.增加匯入
  --check-column (col)  Specifies the column to be examined when determining which rows to import.  --incremental (mode)  Specifies how Sqoop determines which rows are new. Legal values for mode include append and lastmodified.  --last-value (value)  Specifies the maximum value of the check column from the previous import.增加匯入支援兩種模式append和lastmodified,用--incremental來指定。
12.匯入大物件
,比如BLOB和CLOB列時需要特殊處理,小於16MB的大物件可以和別的資料一起儲存,超過這個值就儲存在_lobs的子目錄當中。它們採用的是為大物件做過優化的儲存格式,最大能儲存2^63位元組的資料,我們可以用--inline-lob-limit引數來指定每個lob檔案最大的限制是多少。如果設定為0,則大物件使用外部儲存。13.分隔符、轉移字元下面的這句話
  Some string, with a comma.  Another "string with quotes"使用這句命令匯入$ sqoop import --fields-terminated-by , --escaped-by \\ --enclosed-by '\"' ...會有下面這個結果  "Some string, with a comma.","1","2","3"...  "Another \"string with quotes\"","4","5","6"...使用這句命令匯入$ sqoop import --optionally-enclosed-by '\"' (the rest as above)...  "Some string, with a comma.",1,2,3...  "Another \"string with quotes\"",4,5,6...14.hive匯入引數
  --hive-home <dir>  重寫$HIVE_HOME  --hive-import          插入資料到hive當中,使用hive的預設分隔符  --hive-overwrite  重寫插入  --create-hive-table  建表,如果表已經存在,該操作會報錯!  --hive-table <table-name>  設定到hive當中的表名  --hive-drop-import-delims  匯入到hive時刪除 \n, \r, and \01   --hive-delims-replacement  匯入到hive時用自定義的字元替換掉 \n, \r, and \01   --hive-partition-key          hive分割槽的key  --hive-partition-value <v>  hive分割槽的值  --map-column-hive <map>          型別匹配,sql型別對應到hive型別15.hive空值處理
sqoop會自動把NULL轉換為null處理,但是hive中預設是把\N來表示null,因為預先處理不會生效的。我們需要使用 --null-string 和 --null-non-string來處理空值 把\N轉為\\N。
sqoop import  ... --null-string '\\N' --null-non-string '\\N'
16.匯入資料到hbase匯入的時候加上--hbase-table,它就會把內容匯入到hbase當中,預設是用主鍵作為split列。也可以用--hbase-row-key來指定,列族用--column-family來指定,它不支援--direct。如果不想手動建表或者列族,就用--hbase-create-table引數。17.程式碼生成引數,沒看懂  --bindir <dir>  Output directory for compiled objects  --class-name <name>  Sets the generated class name. This overrides --package-name. When combined with --jar-file, sets the input class.  --jar-file <file>  Disable code generation; use specified jar  --outdir <dir>  Output directory for generated code  --package-name <name>  Put auto-generated classes in this package  --map-column-java <m>  Override default mapping from SQL type to Java type for configured columns.18.通過配置檔案conf/sqoop-site.xml來配置常用引數
<property>
    <name>property.name</name>
    <value>property.value</value>
 </property>
如果不在這裡面配置的話,就需要像這樣寫命令