代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
java批量生成sqoop任务
作者:
/ 发布于
2017/8/29
/
422
用Java写了类,用于批量生成sqoop脚本任务,sqoop一行行的写不得不说很累
package data.clear; import java.io.File; import java.io.IOException; import java.util.Date; import java.util.List; import org.apache.commons.io.FileUtils; import java.io.FileOutputStream; import java.io.PrintStream; public class GeneratePartitions { public static void main(String[] args) throws IOException { List<String> lines = FileUtils.readLines(new File("d:\\wilson.zhou\\Desktop\\testtest.txt")); String template = "sqoop import --connect jdbc:postgresql://10.1.2.130:5432/xmo_dw --table %s --fields-terminated-by '\\t' --null-string '\\\\N' --null-non-string '\\\\N' --target-dir /staging/db_backup/greenplum/%s/%s --username xmo_summarizer --password YCt452uz"; String gp_table = ""; String table = ""; String partition = ""; PrintStream ps=new PrintStream(new FileOutputStream("d:\\wilson.zhou\\Desktop\\adgrouphists_2015.sh")); System.setOut(ps); for(String line: lines){ line = line.trim(); gp_table = line; if(line != null && !line.contains("2016") &&line.contains("2015")){ if(line.startsWith("rtb_summary_ext")){ table = "rtb_summary_ext"; partition = line.substring(line.lastIndexOf("_")+1); partition = partition.replace("p", ""); // System.out.println("echo `date '+%m-%d %-H:%-M:%-S'` "+gp_table); // System.out.println("mkdir -p /mapr/hkidc.hadoop.iclick/staging/db_backup/greenplum/"+table+"/"+partition+""); // System.out.println("psql xmo_dw -c \"copy xmo_dw."+gp_table+" to '/mapr/hkidc.hadoop.iclick/staging/db_backup/greenplum/"+table+"/"+partition+"/"+partition+".csv'\""); System.out.println("echo \""+gp_table+"\t"+table+"\t" + partition+"\""); System.out.println(String.format(template, gp_table, table, partition) +" -m 1 --fetch-size 50000"); }else if(line.startsWith("rtb_summary")){ table = "rtb_summary"; partition = line.substring(line.lastIndexOf("_20")+1); partition = partition.replace("p", ""); // System.out.println("echo `date '+%m-%d %-H:%-M:%-S'` "+gp_table); // System.out.println("mkdir -p /mapr/hkidc.hadoop.iclick/staging/db_backup/greenplum/"+table+"/"+partition+""); // System.out.println("psql xmo_dw -c \"copy xmo_dw."+gp_table+" to '/mapr/hkidc.hadoop.iclick/staging/db_backup/greenplum/"+table+"/"+partition+"/"+partition+".csv'\""); System.out.println("echo \""+gp_table+"\t"+table+"\t" + partition+"\""); System.out.println(String.format(template, gp_table, table, partition) +" -m 1 --fetch-size 50000"); } else if(line.startsWith("eventdatas_old")){ table = "eventdatas_old"; partition = line.substring(line.lastIndexOf("_20")+1); partition = partition.replace("p", ""); System.out.println("echo \""+gp_table+"\t"+table+"\t" + partition+"\""); System.out.println(String.format(template, gp_table, table, partition) + " --split-by id --fetch-size 50000"); }else if(line.startsWith("eventdatas_1")){ table = "eventdatas"; partition = line.substring(line.lastIndexOf("_p")+1); partition = partition.replace("p", ""); System.out.println("echo \""+gp_table+"\t"+table+"\t" + partition+"\""); System.out.println(String.format(template, gp_table, table, partition) + " --split-by id --fetch-size 50000"); }else if(line.startsWith("rtb_datas")){ table = "rtb_datas"; partition = line.substring(line.lastIndexOf("_p")+2); partition = partition.replace("p", ""); System.out.println("echo \""+gp_table+"\t"+table+"\t" + partition+"\""); System.out.println(String.format(template, gp_table, table, partition) + " --split-by id --fetch-size 50000"); }else if(line.startsWith("clickdatas")){ table = "clickdatas"; partition = line.substring(line.lastIndexOf("_")+1); partition = partition.replace("p", ""); // System.out.println("echo "+gp_table); // System.out.println("mkdir -p /mapr/hkidc.hadoop.iclick/staging/db_backup/greenplum/"+table+"/"+partition+""); // System.out.println("psql xmo_dw -c \"copy xmo_dw."+gp_table+" to '/mapr/hkidc.hadoop.iclick/staging/db_backup/greenplum/"+table+"/"+partition+"/"+partition+".csv'\""); System.out.println("echo \""+gp_table+"\t"+table+"\t" + partition+"\""); System.out.println(String.format(template, gp_table, table, partition) + " --split-by id --fetch-size 50000"); }else if(line.startsWith("imageviews")){ table = "imageviews"; partition = line.substring(line.lastIndexOf("_p")+2); partition = partition.replace("p", ""); System.out.println("echo \""+gp_table+"\t"+table+"\t" + partition+"\""); System.out.println(String.format(template, gp_table, table, partition) + " --split-by id --fetch-size 50000"); }else if(line.startsWith("adgrouphists")){ table = "adgrouphists"; partition = line.substring(line.lastIndexOf("_")+1); partition = partition.replace("p", ""); // System.out.println("echo `date '+%m-%d %-H:%-M:%-S'` "+gp_table); // System.out.println("mkdir -p /mapr/hkidc.hadoop.iclick/staging/db_backup/greenplum/"+table+"/"+partition+""); // System.out.println("psql xmo_dw -c \"copy xmo_dw."+gp_table+" to '/mapr/hkidc.hadoop.iclick/staging/db_backup/greenplum/"+table+"/"+partition+"/"+partition+".csv'\""); System.out.println("echo \""+gp_table+"\t"+table+"\t" + partition+"\""); System.out.println(String.format(template, gp_table, table, partition) + " --split-by id --fetch-size 50000"); } } } } }
试试其它关键字
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
贡献的其它代码
Label
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3