当前位置:网站首页>Use sqoop to export ads layer data to MySQL
Use sqoop to export ads layer data to MySQL
2022-07-02 12:15:00 【Small base o_ O】
List of articles
background
- Use Sqoop hold ADS Export layer data to MySQL
- Use
sqoop exportTo add when--columns, Avoid some strange mistakes - Use Regular expressions Get field name
technological process
- ADS Layers are not partitioned , Uncompressed , Bank deposit
- ADS Floor construction table SQL Have separate documents , If the table is updated, the table creation statement of the file must be updated
- Table name :ADS Layer of HIVE Table has
ads_Prefix , Corresponding to MySQL Remove the prefix when creating the table - Field :ADS Layer table and MySQL Tabular The field name and field order should be consistent , use ` Symbol package
- Traverse ADS Layered TABLE statement , Get with regular expression Table name 、 All field names
- It is said that Sqoop command
Code
ADS Layered TABLE statement (ADS Floor construction table .sql)
-- HIVE Create table statement , Field use ` Symbol package , The table name does not need to be wrapped
CREATE EXTERNAL TABLE ads_purchase_order_info (
`prch_order_id` BIGINT COMMENT ' Purchase order header id',
`exfactory_total_price` DOUBLE COMMENT ' Total ex factory price ',
`insert_time` STRING COMMENT ' Data insertion date '
) COMMENT ' Purchasing information ';
MySQL Create table statement
CREATE TABLE purchase_order_info (
`prch_order_id` bigint COMMENT ' Purchase order header id',
`exfactory_total_price` DOUBLE COMMENT ' Total ex factory price ',
`insert_time` text COMMENT ' Data insertion date ',
PRIMARY KEY (`prch_order_id`)
) COMMENT ' Purchasing information ';
Python
class Sqoop(Shell):
def sqoop(self, cmd):
return self.sh_cmd_and_alert(' '.join(cmd.split()))
def sqoop_export(self, mysql_tb, export_dir, columns='', update_mode='allowinsert', update_key='prch_order_id'):
""" --columns The default is all columns ; Advice and , Avoid some inexplicable bug --update-mode The default is updateonly, Can be changed to allowinsert --update-key Is an anchor column for updating ; Multiple columns are separated by commas """
return self.sqoop(r''' {sqoop} export --connect jdbc:mysql://{host}:{port}/{database} --username '{username}' --password '{password}' --table {table} --num-mappers 1 --input-fields-terminated-by '\001' --input-null-string '\\N' --input-null-non-string '\\N' --export-dir '{export_dir}' {columns} '''.format(
sqoop=self.get('sqoop', 'sqoop'),
host=self.get('mysql_host', 'localhost'),
port=self.get('mysql_port', '3306'),
database=self['mysql_db'],
username=self.get('mysql_user', 'root'),
password=self['mysql_pwd'],
table=mysql_tb,
export_dir=export_dir,
columns=columns,
))
from re import findall
s = get_sqoop()
for ads_ddl in read_sql_file('ADS Floor construction table .sql').split(';')[:-1]:
columns = '--columns ' + ','.join(findall('`([^`]+)`', ads_ddl))
hive_tb = findall(r'CREATE EXTERNAL TABLE (\S+)', ads_ddl)[0]
mysql_tb = hive_tb.replace('ads_', '')
print(s.sqoop_export(mysql_tb, EXPORT_DIR_PREFIX + hive_tb, columns))
because it is you
边栏推荐
- PyTorch nn.RNN 参数全解析
- Test shift left and right
- Those logs in MySQL
- Lekao: contents of the provisions on the responsibility of units for fire safety in the fire protection law
- LeetCode—剑指 Offer 51. 数组中的逆序对
- Codeforces 771 div2 B (no one FST, refers to himself)
- Go learning notes - multithreading
- Mysql database foundation
- 全链路压测
- Jenkins user rights management
猜你喜欢

(C语言)3个小代码:1+2+3+···+100=?和判断一个年份是闰年还是平年?和计算圆的周长和面积?

Sparkcontext: error initializing sparkcontext solution

Lekao: contents of the provisions on the responsibility of units for fire safety in the fire protection law

CDH6之Sqoop添加数据库驱动

ES集群中节点与分片的区别

自然语言处理系列(三)——LSTM

Performance tuning project case

Thesis translation: 2022_ PACDNN: A phase-aware composite deep neural network for speech enhancement

The differences and relationships among port, targetport, nodeport and containerport in kubenetes

YYGH-BUG-05
随机推荐
mysql表的增删改查(进阶)
Brush questions --- binary tree --2
post请求体内容无法重复获取
CONDA common command summary
mysql数据库基础
CPU指令集介绍
Addition, deletion, modification and query of MySQL table (Advanced)
kubenetes中port、targetPort、nodePort、containerPort的区别与联系
Maximum profit of jz63 shares
Tas (file d'attente prioritaire)
基于Arduino和ESP8266的连接手机热点实验(成功)
Those logs in MySQL
Lombok common annotations
PyTorch nn.RNN 参数全解析
Repeat, tile and repeat in pytorch_ The difference between interleave
Natural language processing series (III) -- LSTM
[C language] Yang Hui triangle, customize the number of lines of the triangle
Uniapp uni list item @click, uniapp uni list item jump with parameters
MySQL and PostgreSQL methods to grab slow SQL
Codeforces 771-div2 C (trouble, permutation is not very good)
