SQL statement dynamic generation method and device of ETL, computer equipment and storage medium

Dynamically generating SQL statements through UDF functions and the Handlebars template engine solves the development and maintenance difficulties caused by the static definition of SQL statements in traditional ETL, achieves the flexibility and scalability of SQL statements, and lowers the technical threshold.

CN118733607APending Publication Date: 2024-10-01杭州美创科技股份有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410656307.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-24
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

The static definition of SQL statements in the traditional ETL process makes development and maintenance difficult. It is difficult for non-technical professionals to understand and write complex SQL statements, which limits the scalability and flexibility of the system.

Method used

Use UDF functions combined with Node.js and Handlebars template engines to dynamically generate SQL statements. By defining UDF functions containing variables, use Handlebars syntax to render and embed them into SQL templates to generate flexible SQL statements.

Benefits of technology

It lowers the technical threshold for SQL statement generation, improves the readability and scalability of SQL statements, reduces development costs and time, and enhances code reusability and maintainability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118733607A_ABST
    Figure CN118733607A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses an SQL statement dynamic generation method and device of ETL, computer equipment and a storage medium. The method comprises the following steps: defining a UDF function; obtaining related data of the to-be-generated statement; a UDF function is rendered by using a Node and Handlebars according to the related data; generating an SQL statement according to the rendered UDF function; and executing the SQL statement. By implementing the method provided by the embodiment of the invention, the technical threshold of SQL statement generation can be reduced, and the readability, flexibility and expandability of the SQL statement can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a method for generating SQL statements, and more specifically to a method, device, computer equipment and storage medium for dynamically generating SQL statements for ETL. Background Art

[0002] In traditional ETL processes, SQL statements are usually statically defined, which means that SQL queries, joins, aggregations, filters, and transformation operations are hard-coded directly in the code. This statically defined SQL statement has the following disadvantages:

[0003] Complex SQL statements involve associations, aggregations, and transformations between multiple tables. It is challenging for non-technical professionals to read and understand these SQL statements, which leads to communication barriers between developers and business users and increases the difficulty of development and maintenance. Writing complex SQL statements requires a deep understanding of database structure, table relationships, and query syntax. Non-technical professionals may not have sufficient SQL knowledge and experience to write such SQL statements, so they need to rely on technical professionals for development, which increases development costs and time. Statically defined SQL statements usually have fixed logic and structure. When requirements change or new data sources are added, SQL statements need to be manually modified and adjusted, which limits the scalability and flexibility of the system and increases the maintenance workload. In statically defined SQL statements, ETL logic is tightly coupled with code, which makes logic changes and code reuse difficult, increasing the difficulty of maintenance and debugging.

[0004] Therefore, it is necessary to design a new method to lower the technical threshold of SQL statement generation and improve the readability, flexibility and scalability of SQL statements. Summary of the invention

[0005] The purpose of the present invention is to overcome the defects of the prior art and provide a method, device, computer equipment and storage medium for dynamically generating SQL statements for ETL.

[0006] To achieve the above object, the present invention adopts the following technical solution: a method for dynamically generating SQL statements for ETL, comprising:

[0007] Define UDF function;

[0008] Get the relevant data of the statement to be generated;

[0009] Use Node and Handlebars to render UDF functions based on relevant data;

[0010] Generate SQL statements based on the rendered UDF function;

[0011] Execute the SQL statement.

[0012] A further technical solution is: the definition of the UDF function includes:

[0013] A UDF function containing variables is defined using Handlebars syntax, wherein the variables include at least one of text, date, time, date and time, number, table reference, column reference, and complex expression.

[0014] The further technical solution is: using Node and Handlebars to render the UDF function according to the relevant data to obtain the SQL statement includes:

[0015] Use Node.js and the Handlebars template engine to fill relevant data into the template corresponding to the UDF function and perform rendering operations.

[0016] A further technical solution is: generating an SQL statement according to the rendered UDF function includes:

[0017] Embed the rendered UDF function into the SQL template to build the corresponding SQL statement.

[0018] Its further technical solution is: the execution of the SQL statement includes:

[0019] Passing the SQL statement to a database execution engine to establish a database connection;

[0020] The database execution engine is used to extract data from a source database, process the extracted data, and load the processed data into a target database.

[0021] The present invention also provides a device for dynamically generating SQL statements for ETL, comprising:

[0022] Function definition unit, used to define UDF function;

[0023] A data acquisition unit, used to acquire relevant data of the sentence to be generated;

[0024] The rendering unit is used to render the UDF function based on the relevant data using Node and Handlebars;

[0025] A statement generation unit, used to generate SQL statements according to the rendered UDF function;

[0026] An execution unit is used to execute the SQL statement.

[0027] A further technical solution is: the definition unit is used to define a UDF function containing variables using Handlebars syntax, wherein the variables include at least one of text, date, time, date and time, number, table reference, column reference, and complex expression.

[0028] A further technical solution is: the rendering unit is used to use Node.js and Handlebars template engines to fill relevant data into the template corresponding to the UDF function and perform rendering operations.

[0029] The present invention further provides a computer device, which includes a memory and a processor. The memory stores a computer program, and the processor implements the above method when executing the computer program.

[0030] The present invention also provides a storage medium, wherein the storage medium stores a computer program, and the computer program implements the above method when executed by a processor.

[0031] Compared with the prior art, the present invention has the following beneficial effects: the present invention defines a UDF function, and uses Node and Handlebars to render the UDF function according to relevant data, so as to generate an SQL statement according to the rendered UDF function, and selects different UDF functions according to actual conditions, thereby reducing the technical threshold for generating SQL statements and improving the readability, flexibility and scalability of SQL statements.

[0032] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.

[0034] Figure 1 A schematic diagram of an application scenario of a method for dynamically generating SQL statements for ETL provided by an embodiment of the present invention;

[0035] Figure 2 A flowchart of a method for dynamically generating SQL statements for ETL provided by an embodiment of the present invention;

[0036] Figure 3 A schematic block diagram of an ETL SQL statement dynamic generation device 300 provided in an embodiment of the present invention;

[0037] Figure 4A schematic block diagram of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0038] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0039] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.

[0040] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0041] It should be further understood that the term "and / or" used in the present description and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0042] See also Figure 1 and Figure 2 , Figure 1 A schematic diagram of an application scenario of a method for dynamically generating SQL statements for ETL provided in an embodiment of the present invention. Figure 2 A schematic flow chart of a method for dynamically generating SQL statements for ETL provided in an embodiment of the present invention. The method for dynamically generating SQL statements for ETL is applied in a server. The server interacts with a terminal for data, obtains data related to the statements to be generated from the terminal, and uses Node as the operating environment, and with the help of the Handlebars template engine, realizes the dynamic selection of UDF functions and the dynamic generation of ETL SQL statements. Users can select appropriate functions from the UDF function library provided by the system, or intuitively define data conversion and mapping rules by dragging and dropping in a visual interface, without the need for in-depth SQL knowledge, and select source library fields, target model fields, and conversion logic by dragging and configuring interface elements, thereby dynamically generating SQL statements and reducing development time and cost.

[0043] Figure 2FIG. 1 is a flow chart of a method for dynamically generating SQL statements for ETL provided by an embodiment of the present invention. Figure 2 As shown, the method includes the following steps S110 to S150.

[0044] S110. Define a UDF function.

[0045] In this embodiment, the UDF function includes at least one of an aggregation function, a comparison operator, a search function, a string function, a mathematical function, a conditional function, and a conversion function.

[0046] Specifically, aggregate functions such as SUM, COUNT, AVG, etc. are used to perform aggregation operations on data; comparison operators such as equal to (=), greater than (>), less than (<), etc. are used to perform conditional comparison in data processing; search functions such as FIND, INDEX, CONTAINS, etc. are used to find specific substrings in a string or perform matching operations; string functions such as CONCAT, SUBSTRING, UPPER, etc. are used to process and operate on strings; mathematical functions such as ABS, ROUND, POWER, etc. are used to perform mathematical operations and calculations on numbers; conditional functions such as IF, CASE WHEN, COALESCE, etc. are used to process and convert data according to conditions; conversion functions such as CAST, CONVERT, TO_DATE, etc. are used for conversion operations between data types.

[0047] In this embodiment, the Handlebars syntax is used to define a UDF function containing variables, wherein the variables include at least one of text, date, time, date and time, number, table reference, column reference, and complex expression.

[0048] Specifically, use Handlebars syntax to define a UDF function that contains variables. You can use text, date, time, datetime, number, table reference, column reference, complex expression and other content variables to build a UDF function. For example, you can define a UDF function as follows:

[0049] function myFunction({{var1}},{{var2}}){

[0050] / / Use variables var1 and var2 here

[0051] }

[0052] Among them, {{var1}} and {{var2}} are Handlebars syntax, indicating variables that need to be filled in subsequent steps.

[0053] Using Handlebars syntax to define UDF functions containing variables can easily process different types of data and increase flexibility. Variables containing complex expressions can implement more complex data processing logic.

[0054] S120: Obtain relevant data of the statement to be generated.

[0055] In this embodiment, in this step, it is necessary to prepare the content to be filled into the UDF function template. It may include text, date, time, date and time, numbers, table references, column references, complex expressions, etc. Determine the numerical value or string representation of the date, time or date and time, as well as the type and value of the number. At the same time, it is also necessary to determine the table name and column name to be referenced, which can be a string variable or a value obtained from a data source. For complex expressions, it is necessary to determine their content and format.

[0056] For example, you can prepare a date variable such as date="2024-04-26", an integer variable such as number="42", a table name variable such as tableName="my_table", a column name variable such as columnName="my_column", and a complex expression variable such as expression="SUM(column1) / COUNT(column2)".

[0057] In summary, when preparing the content to be filled into the UDF function template, you can include the following types of variables:

[0058] Text: can be any string, used to replace the text part in the UDF function template.

[0059] Date, Time, and DateTime: Determines a numeric or string representation of a date, time, or datetime. You can use specific datetime formats, such as ISO 8601 format (such as "2024-04-26").

[0060] Number: Determine the type and value of the number, which can be an integer, floating point number, etc.

[0061] Table reference and column reference: Determine the table name and column name to be referenced. It can be a string variable or a value obtained from a data source.

[0062] Complex Expression: Determine the content and format of a complex expression. It can be an expression containing mathematical operations, logical operations, function calls, etc.

[0063] By preparing these variables, you can fill them into the UDF function template to generate the final UDF function code. Then, you can embed the UDF function code into the SQL statement to build the corresponding query statement. When executing the query statement, you can connect to the database, extract data and perform corresponding processing.

[0064] After obtaining these data, they can be cleaned before use. Specifically, operations such as removing spaces and special characters from text data can be performed; formatting, converting and verifying date data; formatting, converting and verifying time data; processing and converting date and time data to adapt to different date and time formats and requirements; formatting, rounding and verifying numeric data; referencing other tables in SQL statements for data association and connection operations; referencing other columns in SQL statements for data processing and conversion operations; using complex expressions and logic to perform calculations and data processing in SQL statements.

[0065] UDF CASEWHEN template content example: {{#with value}}CASE{{#rules}}WHEN{{condition}}THEN{{result}}{{ / rules}}{{#defaultValue}}ELSE{{.}}{{ / defaultValue}}END{{ / with}}.

[0066] S130. Use Node and Handlebars to render the UDF function according to relevant data.

[0067] In this embodiment, Node.js and Handlebars template engine are used to fill relevant data into the template corresponding to the UDF function and perform rendering operation.

[0068] In this embodiment, Node is a JavaScript runtime environment based on the Chrome V8 engine, which can run JavaScript code on the server side. It provides rich functions and libraries, allowing developers to use JavaScript for server-side programming and perform tasks such as file operations and network communication. Handlebars is a simple, extensible JavaScript template engine that allows developers to define and use templates to generate dynamic content. Handlebars uses {{}} tags to identify variables and expressions, which can easily perform data interpolation and logic control.

[0069] In this embodiment, Handlebars will replace the variables in the template and the provided data to generate a specific SQL statement.

[0070] Specifically, first use the Handlebars.compile() function to create a UDF function template, then use the myFunctionTemplate() function to fill the prepared data into the template to generate the final UDF function code, and finally, store the generated code in the myFunctionCode variable for use in subsequent steps.

[0071] Node.js, as the backend operating environment, has powerful data processing and rendering capabilities. The Handlebars template engine is simple and easy to use, supports common operations such as conditional judgment and looping, and can easily fill data into the template.

[0072] S140: Generate an SQL statement according to the rendered UDF function.

[0073] In this embodiment, the rendered UDF function is embedded into the SQL template to construct a corresponding SQL statement.

[0074] Specifically, use the Handlebars.compile() function to create a SQL template, and then use the sqlTemplate() function to fill the prepared data into the template to generate the final SQL statement, where {{expression}} represents the UDF function to be executed, {{tableName}} represents the table name to be queried, {{columnName}} represents the column name to be filtered, and {{number}} represents the number to be filtered.

[0075] In this embodiment, the user can select a suitable function from the UDF function library provided by the system, or intuitively define data conversion and mapping rules by dragging and dropping in a visual interface. Without in-depth SQL knowledge, the user can select source library fields, target model fields, and conversion logic by dragging and configuring interface elements, thereby dynamically generating SQL statements and reducing development time and cost.

[0076] Select source database fields, target model fields, and conversion logic by dragging and configuring interface elements. The visual interface allows users to intuitively define data conversion and mapping rules without in-depth SQL knowledge, thereby dynamically generating SQL statements.

[0077] By embedding the rendered UDF function into the SQL template, you can generate SQL statements that meet your needs and ensure the accuracy and completeness of data processing.

[0078] S150: Execute the SQL statement.

[0079] In one embodiment, the above-mentioned step S150 may include steps S151 - S152 .

[0080] S151, passing the SQL statement to a database execution engine to establish a database connection;

[0081] S152: Utilize the database execution engine to extract data from the source database, process the extracted data, and load the processed data into the target database.

[0082] Specifically, use the mysql.createConnection() function to create a database connection object. Then, use the connection.query() function to pass the generated SQL statement to the database execution engine to perform data query operations. The query results will be returned through the callback function. Finally, use the connection.end() function to close the database connection.

[0083] In this embodiment, the generated SQL statement is passed to the database execution engine, a database connection is established, data is extracted from the source database, and the extracted data is cleaned, formatted, and filtered, etc. The converted data is loaded into the target database.

[0084] Pass the generated SQL statement to the database execution engine, usually communicating through a database connection; establish a connection with the source database in the application. This requires providing connection information such as the database address, port, user name, password, etc.; extract qualified data from the source database by executing SQL query statements. The execution engine will read the corresponding data from the database according to the definition of the query statement; perform pre-processing operations on the extracted data, including data cleaning (such as removing duplicate values, processing missing values), format conversion (such as unifying the date and time format, converting numeric types) and data filtering (such as filtering data by conditions); load the processed data into the target database. This includes establishing a connection with the target database and inserting or updating data into the corresponding table of the target database.

[0085] Through the above steps, data can be extracted from the source database and loaded into the target database after processing, completing the data migration or data integration operation.

[0086] By executing SQL statements through the database execution engine, data can be efficiently extracted from the source database; the database execution engine provides a wealth of data processing functions, which can clean, convert and perform other operations on the extracted data; the establishment and reuse of database connections can improve the efficiency and performance of data processing and reduce resource consumption; loading the processed data into the target database can ensure data consistency and availability.

[0087] For example, by defining an insert into udf function, a SQL statement is generated through node and Handlebars:

[0088] Define a UDF function:

[0089] INSERT INTO{{sinkTable}}({{sinkFields}});

[0090] SELECT {{sourceFields}};

[0091] FROM {{sourceTable}};

[0092] WHERE {{condition}};

[0093] Then, prepare the data:

[0094] const templateData = {

[0095] sinkTable:'sink_table',

[0096] sinkFields:'field1,field2,field3',

[0097] sourceFields:'source_field1,source_field2,source_field3',

[0098] sourceTable:'source_table',

[0099] condition:'source_field1=123'

[0100] };

[0101] Next, use Node and Handlebars to render the UDF and generate the final SQL statement:

[0102] const Handlebars=require('handlebars');

[0103] const sqlTemplate = `

[0104] INSERT INTO{{sinkTable}}({{sinkFields}})

[0105] SELECT {{sourceFields}}

[0106] FROM{{sourceTable}}

[0107] WHERE {{condition}};`;

[0108] const compiledTemplate=Handlebars.compile(sqlTemplate);

[0109] const sqlStatement=compiledTemplate(templateData);

[0110] Finally, the generated SQL statements are passed to the database execution engine to implement data extraction, conversion, and loading operations.

[0111] INSERT INTO sink_table(field1,field2,field3)

[0112] SELECT source_field1,source_field2,source_field3

[0113] FROM source_table

[0114] WHERE source_field1=123.

[0115] The method of this embodiment flexibly generates SQL statements according to specific needs, reducing the workload of manually writing SQL; using UDF functions can improve the reusability and maintainability of the code and avoid repeated writing of similar logic; using Node and Handlebars for rendering can easily fill in variables and templates, improving the readability and usability of the code; dynamically generating SQL statements can adapt to changing data processing needs and provide more powerful data operation capabilities.

[0116] The method of this embodiment allows SQL statements to be dynamically generated according to specific needs, rather than manually written. By using Node.js and Handlebars template engines, SQL statements can be flexibly generated according to different data requirements and conditions, thereby lowering the technical threshold and enabling more people to quickly generate the required SQL statements.

[0117] Using UDF (user defined function) can encapsulate commonly used logic into functions, which increases the readability of the code. Moreover, when using Handlebars syntax to define UDF functions, the code can be clearer and easier to understand because Handlebars provides a concise syntax for handling variables and logic.

[0118] By using Handlebars syntax to define UDF functions, different types of data can be easily processed, and variables containing complex expressions are supported, which increases the flexibility and scalability of data processing. In addition, using Node.js as the backend operating environment and the Handlebars template engine makes the system highly scalable, making it easy to add new functions or adjust existing functions to meet changing needs.

[0119] In general, this method makes generating SQL statements simpler, more flexible, and more readable by leveraging modern technologies and tools, such as Node.js and Handlebars, and encapsulating common logic into UDF functions, thereby lowering the technical threshold and improving the readability, flexibility, and scalability of SQL statements.

[0120] The above-mentioned method for dynamically generating SQL statements for ETL defines a UDF function, and uses Node and Handlebars to render the UDF function according to relevant data, so as to generate SQL statements according to the rendered UDF function, and selects different UDF functions according to actual conditions, thereby reducing the technical threshold for generating SQL statements and improving the readability, flexibility and scalability of SQL statements.

[0121] Figure 3 FIG. 3 is a schematic block diagram of an ETL SQL statement dynamic generation device 300 provided in an embodiment of the present invention. Figure 3 As shown, corresponding to the above ETL SQL statement dynamic generation method, the present invention also provides an ETL SQL statement dynamic generation device 300. The ETL SQL statement dynamic generation device 300 includes a unit for executing the above ETL SQL statement dynamic generation method, and the device can be configured in a desktop computer, a tablet computer, a laptop, and other terminals. Specifically, please refer to Figure 3 The ETL SQL statement dynamic generation device 300 includes a function definition unit 301, a data acquisition unit 302, a rendering unit 303, a statement generation unit 304 and an execution unit 305.

[0122] The function definition unit 301 is used to define the UDF function; the data acquisition unit 302 is used to acquire the relevant data of the statement to be generated; the rendering unit 303 is used to render the UDF function according to the relevant data using Node and Handlebars; the statement generation unit 304 is used to generate an SQL statement according to the rendered UDF function; and the execution unit 305 is used to execute the SQL statement.

[0123] In one embodiment, the definition unit is used to define a UDF function containing variables using Handlebars syntax, wherein the variables include at least one of text, date, time, date and time, number, table reference, column reference, and complex expression.

[0124] In one embodiment, the rendering unit 303 is used to use Node.js and Handlebars template engines to fill relevant data into the template corresponding to the UDF function and perform rendering operations.

[0125] In one embodiment, the statement generating unit 304 is used to embed the rendered UDF function into the SQL template to construct a corresponding SQL statement.

[0126] In one embodiment, the execution unit 305 includes a transmission subunit and a processing subunit.

[0127] The transfer subunit is used to transfer the SQL statement to the database execution engine to establish a database connection; the processing subunit is used to extract data from the source database using the database execution engine, process the extracted data, and load the processed data into the target database.

[0128] It should be noted that those skilled in the art can clearly understand that the specific implementation process of the above-mentioned ETL SQL statement dynamic generation device 300 and each unit can refer to the corresponding description in the aforementioned method embodiment, and for the convenience and brevity of description, it will not be repeated here.

[0129] The above-mentioned ETL SQL statement dynamic generation device 300 can be implemented in the form of a computer program. The computer program can be used in Figure 4 Runs on the computer device shown.

[0130] See also Figure 4 , Figure 4 5 is a schematic block diagram of a computer device provided in an embodiment of the present application. The computer device 500 may be a server, wherein the server may be an independent server or a server cluster composed of multiple servers.

[0131] See also Figure 4The computer device 500 includes a processor 502 , a memory and a network interface 505 connected via a system bus 501 , wherein the memory may include a non-volatile storage medium 503 and an internal memory 504 .

[0132] The non-volatile storage medium 503 can store an operating system 5031 and a computer program 5032. The computer program 5032 includes program instructions, and when the program instructions are executed, the processor 502 can execute a method for dynamically generating SQL statements for ETL.

[0133] The processor 502 is used to provide computing and control capabilities to support the operation of the entire computer device 500 .

[0134] The internal memory 504 provides an environment for the operation of the computer program 5032 in the non-volatile storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute a method for dynamically generating SQL statements for ETL.

[0135] The network interface 505 is used to communicate with other devices over the network. Figure 4 The structure shown in the figure is merely a block diagram of a portion of the structure related to the solution of the present application, and does not constitute a limitation on the computer device 500 to which the solution of the present application is applied. The specific computer device 500 may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0136] The processor 502 is used to run the computer program 5032 stored in the memory to implement the following steps:

[0137] Define a UDF function; obtain relevant data of the statement to be generated; use Node and Handlebars to render the UDF function according to the relevant data; generate an SQL statement according to the rendered UDF function; and execute the SQL statement.

[0138] In one embodiment, when the processor 502 implements the step of defining the UDF function, it specifically implements the following steps:

[0139] A UDF function containing variables is defined using Handlebars syntax, wherein the variables include at least one of text, date, time, date and time, number, table reference, column reference, and complex expression.

[0140] In one embodiment, when the processor 502 implements the step of using Node and Handlebars to render the UDF function according to relevant data to obtain the SQL statement, the processor 502 specifically implements the following steps:

[0141] Use Node.js and the Handlebars template engine to fill relevant data into the template corresponding to the UDF function and perform rendering operations.

[0142] In one embodiment, when the processor 502 implements the step of generating an SQL statement according to the rendered UDF function, the processor 502 specifically implements the following steps:

[0143] Embed the rendered UDF function into the SQL template to build the corresponding SQL statement.

[0144] In one embodiment, when the processor 502 implements the step of executing the SQL statement, it specifically implements the following steps:

[0145] The SQL statement is passed to a database execution engine to establish a database connection; the database execution engine is used to extract data from a source database, process the extracted data, and load the processed data into a target database.

[0146] It should be understood that in the embodiment of the present application, the processor 502 may be a central processing unit (CPU), and the processor 502 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0147] It can be understood by those skilled in the art that all or part of the processes in the method for implementing the above embodiment can be completed by instructing the relevant hardware through a computer program. The computer program includes program instructions, and the computer program can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiment of the above method.

[0148] Therefore, the present invention also provides a storage medium. The storage medium may be a computer-readable storage medium. The storage medium stores a computer program, wherein when the computer program is executed by a processor, the processor executes the following steps:

[0149] Define a UDF function; obtain relevant data of the statement to be generated; use Node and Handlebars to render the UDF function according to the relevant data; generate an SQL statement according to the rendered UDF function; and execute the SQL statement.

[0150] In one embodiment, when the processor executes the computer program to implement the step of defining a UDF function, the processor specifically implements the following steps:

[0151] A UDF function containing variables is defined using Handlebars syntax, wherein the variables include at least one of text, date, time, date and time, number, table reference, column reference, and complex expression.

[0152] In one embodiment, when the processor executes the computer program to implement the step of using Node and Handlebars to render the UDF function according to relevant data to obtain an SQL statement, the processor specifically implements the following steps:

[0153] Use Node.js and the Handlebars template engine to fill relevant data into the template corresponding to the UDF function and perform rendering operations.

[0154] In one embodiment, when the processor executes the computer program to implement the step of generating an SQL statement according to the rendered UDF function, the processor specifically implements the following steps:

[0155] Embed the rendered UDF function into the SQL template to build the corresponding SQL statement.

[0156] In one embodiment, when the processor executes the computer program to implement the step of executing the SQL statement, the processor specifically implements the following steps:

[0157] The SQL statement is passed to a database execution engine to establish a database connection; the database execution engine is used to extract data from a source database, process the extracted data, and load the processed data into a target database.

[0158] The storage medium may be a USB flash drive, a mobile hard disk, a read-only memory (ROM), a magnetic disk, or an optical disk, etc., which are computer-readable storage media that can store program codes.

[0159] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0160] In the several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of each unit is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.

[0161] The steps in the method of the embodiment of the present invention can be adjusted in order, combined and deleted according to actual needs. The units in the device of the embodiment of the present invention can be combined, divided and deleted according to actual needs. In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0162] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, terminal, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention.

[0163] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A method for dynamically generating SQL statements for ETL, characterized in that: include: Define UDF function; Get the relevant data of the statement to be generated; Use Node and Handlebars to render UDF functions based on relevant data; Generate SQL statements based on the rendered UDF function; Execute the SQL statement.

2. The method for dynamically generating SQL statements for ETL according to claim 1, characterized in that: The definition of the UDF function includes: A UDF function containing variables is defined using Handlebars syntax, wherein the variables include at least one of text, date, time, date and time, number, table reference, column reference, and complex expression.

3. The method for dynamically generating SQL statements for ETL according to claim 1, characterized in that: The use of Node and Handlebars to render the UDF function according to the relevant data to obtain the SQL statement includes: Use Node.js and the Handlebars template engine to fill relevant data into the template corresponding to the UDF function and perform rendering operations.

4. The method for dynamically generating SQL statements for ETL according to claim 1, characterized in that: The generating of SQL statements according to the rendered UDF function includes: Embed the rendered UDF function into the SQL template to build the corresponding SQL statement.

5. The method for dynamically generating SQL statements for ETL according to claim 1, characterized in that: The executing of the SQL statement comprises: Passing the SQL statement to a database execution engine to establish a database connection; The database execution engine is used to extract data from a source database, process the extracted data, and load the processed data into a target database.

6. A device for dynamically generating SQL statements for ETL, characterized in that: include: Function definition unit, used to define UDF function; A data acquisition unit, used to acquire relevant data of the sentence to be generated; The rendering unit is used to render the UDF function based on the relevant data using Node and Handlebars; A statement generation unit, used to generate SQL statements according to the rendered UDF function; An execution unit is used to execute the SQL statement.

7. The device for dynamically generating SQL statements for ETL according to claim 6, characterized in that: The definition unit is used to define a UDF function containing variables using Handlebars syntax, wherein the variable includes at least one of text, date, time, date and time, number, table reference, column reference, and complex expression.

8. The device for dynamically generating SQL statements for ETL according to claim 6, characterized in that: The rendering unit is used to use Node.js and Handlebars template engine to fill relevant data into the template corresponding to the UDF function and perform rendering operation.

9. A computer device, characterized in that: The computer device comprises a memory and a processor, the memory stores a computer program, and the processor implements the method according to any one of claims 1 to 5 when executing the computer program.

10. A storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.