Query statement generation method, device, electronic device and computer readable medium
By obtaining and processing information in the configuration file, HiveQL query statements are automatically generated, which solves the problem of low efficiency in manually writing query statements after ETL programs, and realizes automated data consistency testing.
Patent Information
- Application Number
- CN202010852477.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-08-21
- Publication Date
- 2025-01-03
- Estimated Expiration
- 2040-08-21
AI Technical Summary
After the ETL program is executed, technicians need to manually write HiveQL query statements to test data consistency, resulting in inefficiency.
By obtaining the field list and configuration information in the target and reference configuration file, determining the field correspondence relationship, and converting it into a comparison function based on the comparison character, automatically generating query statements, reducing manual writing.
There is no need to manually write query statements, which improves the efficiency of query statement generation and automates data consistency testing after ETL programs.
Smart Images

Figure CN111966707B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of statement generation, and in particular to a query statement generation method, device, electronic device and computer-readable medium. Background Art
[0002] Data warehouses are widely used by major companies to produce analytical reports and provide support for corporate decision-making. Currently, the process of building a data warehouse requires the execution of ETL (Extract-Transform-Load) steps, which is to extract, transform, and load data from the source to the destination.
[0003] After writing the ETL program, technicians need to write HiveQL query statements for specific data to test whether the data after ETL execution is consistent with the original data, so as to determine whether there is a problem with the ETL program. Since HiveQL query statements need to be manually written for specific data every time an ETL program is written, it is inefficient. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a query statement generation method, device, electronic device and computer readable medium to solve the problem of low manual efficiency. The specific technical solution is as follows:
[0005] In a first aspect, the present application provides a method for generating a query statement, the method comprising:
[0006] Acquire a comparison symbol, a target configuration file of the target data, and a reference configuration file of the reference data, wherein the target configuration file includes a target field list and target configuration information, and the reference configuration file includes a reference field list and reference configuration information;
[0007] Determine a field correspondence between a target field in the target field list and a reference field in the reference field list having the same position as the target field, and convert the comparison operator into a comparison function according to a preset conversion condition;
[0008] Through the field correspondence, a query statement is generated according to the comparison function, the target configuration file and the reference configuration file.
[0009] Optionally, the generating a query statement according to the comparison function, the target configuration file and the reference configuration file through the field correspondence includes:
[0010] Through the field correspondence, the first mapping relationship between the data identifier and the position of the data identifier in the preset template, and the second mapping relationship between the data identifier and the data, the comparison function, the data in the target configuration file, and the data in the reference configuration file are respectively filled into the corresponding positions in the preset template to generate a query statement.
[0011] Optionally, the target configuration information includes a target database, a target data table and a target primary key, and the reference configuration information includes a reference database, a reference data table and a reference primary key; and the step of filling the comparison function, the data in the target configuration file and the data in the reference configuration file into corresponding positions in the preset template respectively through the field correspondence, the first mapping relationship between the data identifier and the position of the data identifier in the preset template and the second mapping relationship between the data identifier and the data comprises:
[0012] According to the first mapping relationship, determine the field source positions of the identifier of the target database, the identifier of the target data table, the identifier of the reference database, and the identifier of the reference data table in the preset template, and according to the second mapping relationship, fill the target database, the target data table, the reference database, and the reference data table into the field source positions respectively;
[0013] Determine the field positions of the target field and the reference field in the preset template according to the field correspondence and the field source position, and fill the target field and the reference field into the field positions;
[0014] According to the first mapping relationship, determine the primary key positions of the identifier of the target primary key and the identifier of the reference primary key in the preset template, and according to the second mapping relationship, fill the target primary key and the reference primary key into the primary key positions;
[0015] According to the first mapping relationship, the data comparison position of the identifier of the comparison function in the preset template is determined, and according to the second mapping relationship, the comparison function is filled into the data comparison position.
[0016] Optionally, the target field and the reference field both include a plurality of field data; after generating the query statement, the method further includes:
[0017] Connecting the target data table and the reference data table through the target primary key and the reference primary key;
[0018] The target field and the reference field are traversed in the following manner: target field data of the target field in the target data table and reference field data of the reference field in the reference data table are obtained, and when the target field data and the reference field data do not satisfy a preset condition, the value of the abnormal parameter recorded indicating that the preset condition is not satisfied is increased by 1;
[0019] Output the value of the abnormal parameter.
[0020] Optionally, the target primary key and the reference primary key each include a plurality of subkeys; and the acquiring of the target field data of the target field in the target data table and the reference field data of the reference field in the reference data table includes:
[0021] Determine a target subkey of the target primary key and a reference subkey in the reference primary key, wherein the target subkey and the reference subkey have a key correspondence relationship;
[0022] The target field data corresponding to the target subkey in the target field and the reference field data corresponding to the reference subkey in the reference field are determined.
[0023] Optionally, the method further comprises:
[0024] Acquire a first quantity of all field data in the target field list and a second quantity of all field data in the reference field list;
[0025] The sum of the first quantity and the second quantity is taken as a total quantity, and the total quantity is output.
[0026] In a second aspect, the present application provides a query statement generating device, the device comprising:
[0027] An acquisition module, used to acquire a comparison symbol, a target configuration file of target data, and a reference configuration file of reference data, wherein the target configuration file includes a target field list and target configuration information, and the reference configuration file includes a reference field list and reference configuration information;
[0028] A determination module, used for determining a field correspondence between a target field in the target field list and a reference field in the reference field list having the same position as the target field, and converting the comparison operator into a comparison function according to a preset conversion condition;
[0029] A generating module is used to generate a query statement according to the field correspondence, the comparison function, the target configuration file and the reference configuration file.
[0030] Optionally, the generating module includes:
[0031] A filling unit is used to fill the comparison function, the data in the target configuration file and the data in the reference configuration file into corresponding positions in the preset template according to the field correspondence, the first mapping relationship between the data identifier and the position of the data identifier in the preset template, and the second mapping relationship between the data identifier and the data, so as to generate a query statement.
[0032] In a third aspect, the present application provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus;
[0033] Memory, used to store computer programs;
[0034] The processor is used to implement any of the method steps described above when executing a program stored in the memory.
[0035] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, any of the method steps described above is implemented.
[0036] Beneficial effects of the embodiments of the present application:
[0037] The embodiment of the present application provides a method for generating a query statement, the method comprising: a processor obtains a comparison operator, a target configuration file of target data, and a reference configuration file of reference data, determines a field correspondence between a target field in a target field list and a reference field in a reference field list that has the same position as the target field, and converts the comparison operator into a comparison function through a preset conversion condition, and then generates a query statement according to the comparison function, the target configuration file, and the reference configuration file through the field correspondence. The present application automatically generates a query statement through configuration information, and there is no need to manually write a query statement, thereby improving efficiency.
[0038] Of course, implementing any product or method of the present application does not necessarily require achieving all of the above advantages at the same time. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0040] Figure 1 A flowchart of a method for generating a query statement provided in an embodiment of the present application;
[0041] Figure 2A flow chart of a method for filling data into a preset template provided in an embodiment of the present application;
[0042] Figure 3 A flow chart of a method for obtaining target field data and reference field data provided in an embodiment of the present application;
[0043] Figure 4 A schematic diagram of the structure of a query statement generating device provided in an embodiment of the present application;
[0044] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0045] 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 only 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.
[0046] An embodiment of the present application provides a query statement generation method, which can be applied to a processor to automatically generate query statements from configuration data.
[0047] The following will describe in detail a query statement generation method provided by an embodiment of the present application in combination with a specific implementation method. Figure 1 As shown, the specific steps are as follows:
[0048] Step 101: Obtain a comparison symbol, a target configuration file of target data, and a reference configuration file of reference data.
[0049] The target configuration file includes a target field list and target configuration information, and the reference configuration file includes a reference field list and reference configuration information.
[0050] In the embodiment of the present application, the data may change before and after the ELT program is executed, so the processor obtains the configuration information of the data before and after the ELT program is executed, including a comparison operator, a reference configuration file of the reference data before the ELT program is executed, and a target configuration file of the target data after the ELT program is executed. Among them, the configuration information can be in json (json_encode, JSON encoding of variables) format, and the embodiment of the present application does not limit the specific format of the configuration file.
[0051] The reference configuration information includes a reference database, a reference data table and a reference primary key, and the target configuration information includes a target database, a target data table and a target primary key. Each data has a corresponding data identifier, wherein the identifier of the reference database is the identifier of the database where the reference data is located, and each database contains multiple data tables. The identifier of the reference data table is the identifier of the data table where the reference data is located, and the identifier of the target database is the identifier of the database where the target data is located. Each database contains multiple data tables, and the identifier of the target data table is the identifier of the data table where the target data is located. The reference primary key is the field primary key of the reference data table, and the target primary key is the field primary key of the target data table. Comparison operators are symbols used for comparison, including: “=”, “<”, “>”, “≤”, and “≥”.
[0052] In the embodiments of the present application, the comparison symbol, the target configuration file and the reference configuration file may be manually configured or automatically configured by the processor through data. The present application does not specifically limit the source of the configuration information.
[0053] Step 102: Determine the field correspondence between the target field in the target field list and the reference field in the reference field list that has the same position as the target field, and convert the comparison operator into a comparison function through a preset conversion condition.
[0054] In the embodiment of the present application, the target field list includes multiple fields, and the reference field list includes multiple fields. The processor needs to establish a field correspondence relationship between the target field and the reference field, including two ways:
[0055] Method 1: The processor determines a target field located at a preset position in the target list and a reference field located at the same preset position in the reference list, and establishes a field correspondence relationship between the target field and the reference field.
[0056] Method 2: The processor first establishes multiple field correspondences, where the field correspondence includes the position of the field in the field list, and then the processor fills the target field at the corresponding position in the target field list and the reference field at the corresponding position in the reference field list into the field correspondence.
[0057] The processor also converts the comparison symbol into a comparison function by using a preset conversion condition. The preset conversion condition is the correspondence between the comparison symbol and the comparison function. The comparison function may be a UDF (User-Defined Functions).
[0058] Exemplarily, the comparison symbol “=” is converted into the comparison function “is_equal”; the comparison symbol ">” is converted into the comparison function “is_more_than”.
[0059] Step 103: Generate a query statement based on the field correspondence, the comparison function, the target configuration file, and the reference configuration file.
[0060] In the embodiment of the present application, after determining the field correspondence, the processor generates a query statement according to the comparison function, the target configuration file, and the reference configuration file.
[0061] Exemplarily, the query statement may be a HiveQL statement or a SQL (Structured Query Language) statement.
[0062] As an optional implementation, the processor fills the comparison function, the data in the target configuration file, and the data in the reference configuration file into corresponding positions in the preset template through field correspondence, a first mapping relationship between the data identifier and the position of the data identifier in the preset template, and a second mapping relationship between the data identifier and the data, thereby generating a query statement.
[0063] In an embodiment of the present application, the processor automatically generates a query statement based on the configuration information, eliminating the need for manual writing of the query statement, thereby reducing manual operations and improving production efficiency.
[0064] As an optional implementation, Figure 2 As shown, the process in which the processor fills the comparison function, the data in the target configuration file, and the data in the reference configuration file into the corresponding positions in the preset template respectively through the field correspondence, the first mapping relationship between the data identifier and the position of the data identifier in the preset template, and the second mapping relationship between the data identifier and the data is:
[0065] Step 201: According to the first mapping relationship, determine the field source positions of the target database identifier, the target data table identifier, the reference database identifier and the reference data table identifier in the preset template, and according to the second mapping relationship, fill the target database, the target data table, the reference database and the reference data table into the field source positions respectively.
[0066] The processor can determine the field source positions of the target database identifier, the target data table identifier, the reference database identifier, and the reference data table identifier in the preset template according to the first mapping relationship between the data identifier and the position of the data identifier in the preset template. After determining the field source position, the processor fills the target database, the target data table, the reference database, and the reference data table into the field source position respectively according to the second mapping relationship between the data identifier and the data.
[0067] In the embodiment of the present application, the database, data table, field list and comparison operator all have identifiers. Programming 1 is a schematic programming of configuration information. It can be seen from Programming 1 that the target configuration file includes the target database "test_db1", the target data table "test_table1", the target field list "a, b", and the target primary key "id1", wherein the identifier of the target database is "db1", the identifier of the target data table is "table1", the identifier of the target field list is "fields1", and the identifier of the target primary key is "key1". The reference configuration file includes the reference database "test_db2", the reference data table "test_table2", the reference field list "x, y", and the reference primary key "id2", wherein the identifier of the reference database is "db2", the identifier of the reference data table is "table2", the identifier of the reference field list is "fields2", and the identifier of the reference primary key is "key2". The comparison operator is "=", and the identifier of the comparison operator is "comparator".
[0068] Programming 1
[0069]
[0070] Programming 2 is a schematic programming of the query statement. It can be seen from Programming 2 that the target database is identified as "db1", and the target data table is identified as "table1". The processor fills the data of the target database and the data of the target data table "test_db1.test_table1" into the field source position in the preset template according to "db1" and "table1"; the reference database is identified as "db2", and the reference data table is identified as "table2". The processor fills the data of the reference database and the data of the reference data table "test_db2.test_table2" into the field source position in the preset template according to "db2" and "table2".
[0071] Programming 2
[0072]
[0073]
[0074] Step 202: According to the field correspondence and the field source position, determine the field position of the target field and the reference field in the preset template, and fill the target field and the reference field into the field position.
[0075] In an embodiment of the present application, the target field originates from a target data table in a target database, and the processor determines the target field source of the target field based on the target database and the target data table. The reference field originates from a reference data table in a reference database, and the processor determines the reference field source of the reference field based on the reference database and the reference data table.
[0076] The processor determines the first position of the target field in the preset template according to the source of the target field, determines the second position of the reference field in the preset template according to the source of the reference field, then associates the first position and the second position according to the field correspondence, and finally determines the field positions of the target field and the reference field in the preset template, and the processor fills the target field and the reference field into the field positions respectively.
[0077] For example, it can be seen from Programming 2 that "test_db1.test_table1" is equivalent to "t1", the target field source of the target field "x" is "t1", "test_db2.test_table2" is equivalent to "t2", the reference field source of the reference field "y" is "t2", and there is a field correspondence between the target field "x" and the reference field "y", so the target field "x" and the reference field "y" can be filled in the field position to form (t1.a, t2.x).
[0078] Step 203: According to the first mapping relationship, determine the primary key positions of the target primary key identifier and the reference primary key identifier in the preset template, and according to the second mapping relationship, fill the target primary key and the reference primary key into the primary key positions.
[0079] In an embodiment of the present application, the processor can determine the primary key positions of the target primary key identifier and the reference primary key identifier in the preset template based on a first mapping relationship between the data identifier and the position of the data identifier in the preset template, and then fill in the target primary key corresponding to the target primary key identifier and the reference primary key corresponding to the reference primary key identifier into the primary key positions based on a second mapping relationship.
[0080] For example, it can be seen from programming 1 that the target primary key is identified as "key1" and the reference primary key is identified as "key2". In programming 2, the processor fills "id1" into the primary key position according to "key1" and fills "id2" into the primary key position according to "key2".
[0081] Step 204: According to the first mapping relationship, determine the data comparison position of the identifier of the comparison function in the preset template, and according to the second mapping relationship, fill the comparison function into the data comparison position.
[0082] In an embodiment of the present application, the identifiers of the comparison function and the comparison operator are the same. The processor can determine the data comparison position of the identifier of the comparison function in the preset template based on a first mapping relationship between the data identifier and the position of the data identifier in the preset template, and then fill the comparison function into the data comparison position based on a second mapping relationship.
[0083] Exemplarily, it can be seen from programming 2 that the processor fills the comparison function “is_equal” into the data comparison position according to the identifier “comparator” of the comparison function.
[0084] The processes in steps 201 to 204 may be executed in parallel or in sequence, and this application does not impose any specific limitation.
[0085] The processor fills the comparison function, the data in the target configuration file and the data in the reference configuration file into corresponding positions in the preset template and generates a query statement.
[0086] As an optional implementation method, after generating the query statement, the above method also includes: connecting the target data table and the reference data table through the target primary key and the reference primary key; traversing the target field and the reference field in the following manner: obtaining the target field data of the target field in the target data table, and the reference field data of the reference field in the reference data table, and when the target field data and the reference field data do not meet the preset conditions, adding 1 to the value of the abnormal parameter of the record indicating that the preset conditions are not met; and outputting the value of the abnormal parameter.
[0087] In the embodiment of the present application, the target data table has a corresponding target primary key, the reference data table has a corresponding reference primary key, and the processor connects the target data table and the reference data table through the target primary key and the reference primary key. The target field includes multiple field data, and the reference field includes multiple field data.
[0088] The processor traverses the target field and the reference field in the following manner: the processor obtains the target field data of the target field in the target data table and the reference field data of the reference field in the reference data table, and determines whether the target field data and the reference field data meet the preset condition, wherein the preset condition is a size comparison condition. If the processor determines that the target field data and the reference field data meet the preset condition, the value of the abnormal parameter recorded indicating that the preset condition is not met is added by 0; if the processor determines that the target field data and the reference field data do not meet the preset condition, the value of the abnormal parameter recorded indicating that the preset condition is not met is added by 1. After the processor traverses the target field and the reference field, it outputs the value of the abnormal parameter.
[0089] In the embodiment of the present application, the preset function is is_equal. Before and after the execution of the ETL program, if the ETL program has no faults, the target field data at the target position in the target field is the same as the target field data at the same position in the reference field. If the processor determines that the target field data is not the same as the reference field data, the abnormal parameter is the value that the target field data is not the same as the reference field data. The processor adds 1 to the value of the abnormal parameter that is recorded to indicate the difference, and outputs the value of the abnormal parameter.
[0090] Table 1
[0091] total_count a_x_count 10000 122
[0092] As shown in Table 1, which is a schematic diagram of the field comparison result, "a_x_count" indicates the number of abnormal parameters in which the target field data is different from the reference field data in the target field a and the reference field x. a_x_count is 122, indicating that the number of abnormal parameters in the target field a and the reference field x is 122.
[0093] As an optional embodiment, the method further includes: obtaining a first quantity of all field data in the target field list and a second quantity of all field data in the reference field list; taking the sum of the first quantity and the second quantity as the total quantity, and outputting the total quantity.
[0094] The processor obtains the field data of all fields in the target field list, and determines that the number of all field data in the target field list is the first number. The processor obtains the field data of all fields in the reference field list, and determines that the number of all field data in the reference field list is the second number. The processor uses the sum of the first number and the second number as the total number of all field data, and outputs the total number. By setting the total number and the value of the abnormal parameter, the proportion of the abnormal parameter in the total number can be inferred, thereby determining the accuracy of the ETL program. Among them, the proportion of the abnormal parameter in the total number is inversely proportional to the total number. The higher the proportion of the abnormal parameter in the total number, the lower the accuracy of the ETL program.
[0095] As an optional embodiment, if the processor determines that the target field data and the reference field data do not meet the preset conditions, the value of the recorded normal parameter that meets the preset conditions is increased by 0; if the processor determines that the target field data and the reference field data meet the preset conditions, the value of the recorded normal parameter that meets the preset conditions is increased by 1, and the value of the normal parameter is output.
[0096] As an optional embodiment, Figure 3 As shown, obtaining target field data of a target field in a target data table and reference field data of a reference field in a reference data table includes:
[0097] Step 301: Determine the target subkey of the target primary key and the reference subkey in the reference primary key.
[0098] Among them, the target subkey and the reference subkey have a key correspondence relationship.
[0099] In an embodiment of the present application, the target primary key and the reference primary key both include multiple subkeys, and the processor determines a target subkey of the target primary key and a reference subkey in the reference primary key, and the target subkey and the reference subkey have a key correspondence relationship.
[0100] Table 2
[0101] id1 a 1 Test_a 2 Test_c
[0102] As shown in Table 2, Table 2 is a schematic diagram of a target data table. Table 2 includes two sub-keys "id1-1" and "id1-2", and field a includes field data "Test_a" and "Test_c".
[0103] Table 3
[0104] id2 x 1 Test_a 2 Test_c
[0105] As shown in Table 3, Table 3 is a schematic diagram of a reference data table. Table 3 includes two sub-keys "id2-1" and "id2-2", and field x includes field data "Test_a" and "Test_c".
[0106] The processor determines the target subkey "id1-1" and the reference subkey "id2-1".
[0107] Step 302: Determine the target field data corresponding to the target subkey in the target field, and the reference field data corresponding to the reference subkey in the reference field.
[0108] In an embodiment of the present application, the processor determines the target field data in the target field corresponding to the target subkey, and the reference field data in the reference field corresponding to the reference subkey.
[0109] Exemplarily, the target field data in the target field corresponding to the target subkey "id1-1" is "Test_a", and the reference field data in the reference field corresponding to the reference subkey "id2-1" is "Test_a".
[0110] Based on the same technical concept, the embodiment of the present application also provides a query statement generating device, such as Figure 4 As shown, the device comprises:
[0111] An acquisition module 401 is used to acquire a comparison symbol, a target configuration file of target data, and a reference configuration file of reference data, wherein the target configuration file includes a target field list and target configuration information, and the reference configuration file includes a reference field list and reference configuration information;
[0112] A determination module 402 is used to determine a field correspondence between a target field in the target field list and a reference field in the reference field list having the same position as the target field, and convert the comparison operator into a comparison function according to a preset conversion condition;
[0113] The generating module 403 is used to generate a query statement according to the field correspondence, the comparison function, the target configuration file and the reference configuration file.
[0114] Optionally, the generating module 403 includes:
[0115] The filling unit is used to fill the comparison function, the data in the target configuration file and the data in the reference configuration file into the corresponding positions in the preset template through the field correspondence, the first mapping relationship between the data identifier and the position of the data identifier in the preset template, and the second mapping relationship between the data identifier and the data, so as to generate a query statement.
[0116] Optionally, the target configuration information includes a target database, a target data table and a target primary key, and the reference configuration information includes a reference database, a reference data table and a reference primary key; and the filling unit includes:
[0117] A first filling subunit is used to determine the field source positions of the identifier of the target database, the identifier of the target data table, the identifier of the reference database, and the identifier of the reference data table in the preset template according to the first mapping relationship, and fill the target database, the target data table, the reference database, and the reference data table into the field source positions according to the second mapping relationship;
[0118] The second filling subunit is used to determine the field positions of the target field and the reference field in the preset template according to the field correspondence and the field source position, and fill the target field and the reference field into the field position;
[0119] A third filling subunit is used to determine the primary key positions of the identifier of the target primary key and the identifier of the reference primary key in the preset template according to the first mapping relationship, and fill the target primary key and the reference primary key into the primary key positions according to the second mapping relationship;
[0120] The fourth filling subunit is used to determine the data comparison position of the identifier of the comparison function in the preset template according to the first mapping relationship, and fill the comparison function into the data comparison position according to the second mapping relationship.
[0121] Optionally, the target field and the reference field each include a plurality of field data; the device further includes:
[0122] A connection module, used for connecting the target data table and the reference data table through the target primary key and the reference primary key;
[0123] The traversal module is used to traverse the target field and the reference field in the following manner: obtaining the target field data of the target field in the target data table and the reference field data of the reference field in the reference data table, and when the target field data and the reference field data do not meet the preset condition, adding 1 to the value of the abnormal parameter of the record indicating that the preset condition is not met;
[0124] The first output module is used to output the value of the abnormal parameter.
[0125] Optionally, the target primary key and the reference primary key each include multiple subkeys; the traversal module includes:
[0126] A first determining sub-unit is used to determine a target sub-key of a target primary key and a reference sub-key in a reference primary key, wherein the target sub-key and the reference sub-key have a key corresponding relationship;
[0127] The second determination subunit is used to determine the target field data corresponding to the target subkey in the target field and the reference field data corresponding to the reference subkey in the reference field.
[0128] Optionally, the device further comprises:
[0129] An acquisition module, used for acquiring a first quantity of all field data in a target field list and a second quantity of all field data in a reference field list;
[0130] The second output module is used to take the sum of the first quantity and the second quantity as the total quantity and output the total quantity.
[0131] The embodiment of the present application provides a method for generating a query statement, the method comprising: a processor obtains a comparison operator, a target configuration file of target data, and a reference configuration file of reference data, determines a field correspondence between a target field in a target field list and a reference field in a reference field list that has the same position as the target field, and converts the comparison operator into a comparison function through a preset conversion condition, and then generates a query statement according to the comparison function, the target configuration file, and the reference configuration file through the field correspondence. The present application automatically generates a query statement through configuration information, without the need to manually write a query statement, thereby improving efficiency.
[0132] Based on the same technical concept, an embodiment of the present invention further provides an electronic device, such as Figure 5 As shown, it includes a processor 501, a communication interface 502, a memory 503 and a communication bus 504, wherein the processor 501, the communication interface 502, and the memory 503 communicate with each other through the communication bus 504.
[0133] Memory 503, used for storing computer programs;
[0134] The processor 501 is used to implement the above steps when executing the program stored in the memory 503.
[0135] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0136] The communication interface is used for communication between the above electronic device and other devices.
[0137] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0138] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0139] In another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above methods are implemented.
[0140] In another embodiment of the present invention, a computer program product including instructions is provided, which enables the computer to execute any one of the methods in the above embodiments when the computer program product is executed on the computer.
[0141] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.
[0142] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0143] The above description is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest range consistent with the principles and novel features applied for herein.
Claims
1. A query statement generation method, characterized in that: The method comprises: Acquire a comparison symbol, a target configuration file of the target data, and a reference configuration file of the reference data, wherein the target configuration file includes a target field list and target configuration information, and the reference configuration file includes a reference field list and reference configuration information; Determine a field correspondence between a target field in the target field list and a reference field in the reference field list having the same position as the target field, and convert the comparison operator into a comparison function according to a preset conversion condition; Generate a query statement according to the comparison function, the target configuration file and the reference configuration file through the field correspondence relationship; The step of generating a query statement according to the comparison function, the target configuration file and the reference configuration file through the field correspondence includes: By means of the field correspondence, the first mapping relationship between the data identifier and the position of the data identifier in the preset template, and the second mapping relationship between the data identifier and the data, the comparison function, the data in the target configuration file, and the data in the reference configuration file are respectively filled into the corresponding positions in the preset template to generate a query statement; The target configuration information includes a target database, a target data table and a target primary key, and the reference configuration information includes a reference database, a reference data table and a reference primary key; the first mapping relationship between the field correspondence, the data identifier and the position of the data identifier in the preset template, and the second mapping relationship between the data identifier and the data, respectively filling the comparison function, the data in the target configuration file and the data in the reference configuration file into the corresponding positions in the preset template includes: According to the first mapping relationship, determine the field source positions of the identifier of the target database, the identifier of the target data table, the identifier of the reference database, and the identifier of the reference data table in the preset template, and according to the second mapping relationship, fill the target database, the target data table, the reference database, and the reference data table into the field source positions respectively; Determine the field positions of the target field and the reference field in the preset template according to the field correspondence and the field source position, and fill the target field and the reference field into the field positions; According to the first mapping relationship, determine the primary key positions of the identifier of the target primary key and the identifier of the reference primary key in the preset template, and according to the second mapping relationship, fill the target primary key and the reference primary key into the primary key positions; According to the first mapping relationship, the data comparison position of the identifier of the comparison function in the preset template is determined, and according to the second mapping relationship, the comparison function is filled into the data comparison position.
2. The method according to claim 1, characterized in that The target field and the reference field both include a plurality of field data; after the query statement is generated, the method further includes: Connecting the target data table and the reference data table through the target primary key and the reference primary key; The target field and the reference field are traversed in the following manner: target field data of the target field in the target data table and reference field data of the reference field in the reference data table are obtained, and when the target field data and the reference field data do not meet the preset condition, the value of the abnormal parameter recorded indicating that the preset condition is not met is increased by 1; Output the value of the abnormal parameter.
3. The method according to claim 2, characterized in that The target primary key and the reference primary key both include multiple subkeys; the step of acquiring the target field data of the target field in the target data table and the reference field data of the reference field in the reference data table includes: Determine a target subkey of the target primary key and a reference subkey in the reference primary key, wherein the target subkey and the reference subkey have a key correspondence relationship; The target field data corresponding to the target subkey in the target field and the reference field data corresponding to the reference subkey in the reference field are determined.
4. The method according to claim 2 or 3, characterized in that: The method further comprises: Acquire a first quantity of all field data in the target field list and a second quantity of all field data in the reference field list; The sum of the first quantity and the second quantity is taken as a total quantity, and the total quantity is output.
5. A query statement generating device, characterized in that: The device comprises: An acquisition module, used to acquire a comparison symbol, a target configuration file of target data, and a reference configuration file of reference data, wherein the target configuration file includes a target field list and target configuration information, and the reference configuration file includes a reference field list and reference configuration information; A determination module, used for determining a field correspondence between a target field in the target field list and a reference field in the reference field list having the same position as the target field, and converting the comparison operator into a comparison function according to a preset conversion condition; A generating module, configured to generate a query statement according to the field correspondence, the comparison function, the target configuration file and the reference configuration file; Wherein, the generating module comprises: A filling unit, used to fill the comparison function, the data in the target configuration file, and the data in the reference configuration file into corresponding positions in the preset template respectively through the field correspondence, the first mapping relationship between the data identifier and the position of the data identifier in the preset template, and the second mapping relationship between the data identifier and the data, so as to generate a query statement; Wherein, the target configuration information includes a target database, a target data table and a target primary key, and the reference configuration information includes a reference database, a reference data table and a reference primary key; and the filling unit is further used for: According to the first mapping relationship, determine the field source positions of the identifier of the target database, the identifier of the target data table, the identifier of the reference database, and the identifier of the reference data table in the preset template, and according to the second mapping relationship, fill the target database, the target data table, the reference database, and the reference data table into the field source positions respectively; Determine the field positions of the target field and the reference field in the preset template according to the field correspondence and the field source position, and fill the target field and the reference field into the field positions; According to the first mapping relationship, determine the primary key positions of the identifier of the target primary key and the identifier of the reference primary key in the preset template, and according to the second mapping relationship, fill the target primary key and the reference primary key into the primary key positions; According to the first mapping relationship, the data comparison position of the identifier of the comparison function in the preset template is determined, and according to the second mapping relationship, the comparison function is filled into the data comparison position.
6. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing any of the methods described in claims 1-4 when executing a program stored in a memory.
7. A computer-readable storage medium, characterized in that: The computer-readable 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 4 is implemented.
Citation Information
Patent Citations
Cross-data-source query method, apparatus and system
CN106570022A
Data synchronizing method and device
CN106649378A
