Kettle realizes dynamic table query

foreword

Requirements:
There is an information table in the database, and information is recorded every day. The amount of data is large, and a table is created every day for storage.
The name of the table changes every day, and the information needs to be obtained from the table of the day and synchronized to the specified database.

Scheduled format:
tableName_yyyyMMdd ( abcd_20230701 )

This test environment:

system Windows10
Software version kettle 7.1.0.0-12
MySQL driver mysql-connector-java-8.0.19.jar

Kettle takes yesterday's time & sets any time variable

Dynamic table name query data:

  • The first transformation settings table named variable
  • The second level of conversion is to get the variables and bring them into sql to query the data
    insert image description here

1. Get the table name

insert image description here

1. Create a conversion getTableName, drag it in获取系统信息,字段选择,设置变量

insert image description here

2. Open the edit interface for obtaining system information, fill in the name, click the type to select the type of information to be obtained

insert image description here

3. Open 字段选择, select 元数据, and set field properties

insert image description here

4. Open the setting variable, fill in the relevant information, or click Get Field to automatically fill in the field information

insert image description here
表名转换It ends here.

2. Update data according to the table name

insert image description here
The implementation steps are as follows:

  • Create a new conversion autoQuery, drag it in 表输入,插入/更新
  • Table operations need to connect to the database. This time Kettle uses the 8.x version of the MySQL driver

insert image description here

1. Open the table input, select the database, fill in the sql statement, use the ${TODAY} variable set before, and check to replace the variable in the SQL statement, otherwise the variable will not take effect

insert image description here

2. Open Insert/Update, specify the target table, fill in the query keywords, and fill in the update fields

insert image description here

This is the end of the data conversion based on the table name update.

3. Job execution conversion

insert image description here

  • Create a new job autoTable, drag it into START, first call to get the table name conversion, then call the update data conversion based on the table name, and finally drag it in successfully
  • Save the job and run it.

Summarize

If this article is helpful to you, I hope that the big guys can 关注, 点赞, 收藏, 评论support a wave, thank you very much!
Please correct me if I am wrong!!!

Reference 1

Guess you like

Origin blog.csdn.net/weixin_42326851/article/details/131490901