A method, apparatus, device, medium, or product for processing SQL.
By parsing and reversing the SQL, generating graphical representations, and trimming the target field logic, the problem of high SQL processing complexity in the data lake and data warehouse fields is solved, and the accuracy and efficiency of field logic extraction are improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-07
- Publication Date
- 2026-04-03
AI Technical Summary
In the fields of data lakes and/or data warehouses, determining the processing logic of a field from complex SQL is a challenge, and existing technologies suffer from time consumption and low accuracy.
By parsing the SQL to be processed, generating a graphical representation, cropping the graphical representation of the target field, and performing reverse parsing, the SQL of the target field is obtained, simplifying the related parts and nested selection logic, and extracting the processing logic of the target field.
It improves the accuracy and efficiency of field logic extraction, overcomes the shortcomings of manual extraction being time-consuming and inaccurate, and achieves more efficient SQL processing.
Smart Images

Figure CN118132585B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to an SQL processing method, apparatus, device, medium, or product. Background Technology
[0002] Structured Query Language (SQL), such as Hive SQL, is a commonly used query language. However, due to the high complexity of SQL, it is challenging to determine the processing logic of a certain field from SQL in some application areas, such as those related to data lakes and / or data warehouses. Summary of the Invention
[0003] To address the aforementioned technical problems, this application provides an SQL processing method, apparatus, device, medium, and product.
[0004] To achieve the above objectives, the technical solution provided in this application is as follows:
[0005] This application provides an SQL processing method, the method comprising:
[0006] After obtaining the SQL to be processed, the SQL is parsed to obtain a graphical representation of the SQL to be processed; the graphical representation is used to describe the execution process of the SQL to be processed; the execution process includes processing logic for at least one candidate field; the at least one candidate field includes a target field;
[0007] The graphical representation corresponding to the target field is cropped from the graphical representation corresponding to the SQL to be processed; the graphical representation corresponding to the target field is used to describe the processing logic of the target field;
[0008] The graphical representation corresponding to the target field is subjected to inverse parsing to obtain the SQL corresponding to the target field.
[0009] In one possible implementation, the process of determining the graphical representation corresponding to the SQL to be processed includes: converting the SQL to be processed into an abstract syntax tree corresponding to the SQL to be processed; and converting the abstract syntax tree corresponding to the SQL to be processed into a graphical representation corresponding to the SQL to be processed.
[0010] The process of determining the SQL corresponding to the target field includes: converting the graphical representation of the target field into an abstract syntax tree corresponding to the target field; and converting the abstract syntax tree corresponding to the target field into the SQL corresponding to the target field.
[0011] In one possible implementation, the step of trimming the graphical representation corresponding to the target field from the graphical representation corresponding to the SQL to be processed includes: extracting the related portion of the target field from the graphical representation corresponding to the SQL to be processed; performing at least one simplification process on the related portion to obtain the graphical representation corresponding to the target field; the at least one simplification process includes one or more of invalid connection trimming, invalid field trimming, and nested selection merging; the invalid connection trimming is used to simplify the multi-table join logic in the related portion; the invalid field trimming is used to remove fields from the related portion that do not affect the target field; the nested selection merging is used to simplify the multi-level nested selection logic in the related portion.
[0012] In one possible implementation, the invalid join pruning process includes: if the associated portion includes left join logic, and the right table processing logic in the left join logic does not affect the target field, then the right table processing logic is deleted from the associated portion; if the associated portion includes right join logic, and the left table processing logic in the right join logic does not affect the target field, then the left table processing logic is deleted from the associated portion.
[0013] In one possible implementation, the nested selection merging process includes: if the multi-level nested selection logic in the associated part satisfies the predicate merging condition, then at least two conditions in the multi-level nested selection logic are merged; if the multi-level nested selection logic in the associated part satisfies the invalid subquery merging condition, then at least two levels of selection logic in the multi-level nested selection logic are merged.
[0014] In one possible implementation, the method further includes: displaying the SQL corresponding to the target field and the graphical representation of the target field.
[0015] In one possible implementation, after obtaining the SQL corresponding to the target field, the method further includes:
[0016] Based on the SQL corresponding to the target field and the SQL generated from the physical table in the SQL corresponding to the target field, update the SQL to be processed, and continue to execute the step of parsing and processing the SQL to be processed until the preset stopping condition is reached; the physical table is obtained by executing the generated SQL.
[0017] In one possible implementation, updating the SQL to be processed based on the SQL corresponding to the target field and the SQL generated by the physical table in the SQL corresponding to the target field includes:
[0018] The generated SQL of the physical table is transformed to obtain the subquery statement corresponding to the physical table; the processing logic described by the subquery statement is consistent with the processing logic described by the generated SQL.
[0019] Replace the physical table in the SQL corresponding to the target field with the subquery statement corresponding to the physical table to obtain the updated SQL to be processed.
[0020] This application provides an SQL processing apparatus, including:
[0021] The parsing unit is used to parse the SQL to be processed after obtaining it, and to obtain a graphical representation of the SQL to be processed; the graphical representation is used to describe the execution process of the SQL to be processed; the execution process includes processing logic for at least one candidate field; the at least one candidate field includes a target field;
[0022] The trimming unit is used to trim the graphical representation corresponding to the target field from the graphical representation corresponding to the SQL to be processed; the graphical representation corresponding to the target field is used to describe the processing logic of the target field;
[0023] The inverse parsing unit is used to perform inverse parsing processing on the graphical representation corresponding to the target field to obtain the SQL corresponding to the target field.
[0024] This application provides an electronic device, the device comprising: a processor and a memory;
[0025] The memory is used to store instructions or computer programs;
[0026] The processor is configured to execute the instructions or computer program in the memory, so that the electronic device performs the SQL processing method provided in this application.
[0027] This application provides a computer-readable medium storing instructions or computer programs that, when executed on a device, cause the device to perform the SQL processing method provided in this application.
[0028] This application provides a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for executing the SQL processing method provided in this application.
[0029] Compared with related technologies, this application has at least the following advantages:
[0030] In the technical solution provided in this application, after obtaining the SQL to be processed, such as the SQL input by the user, the SQL to be processed is first parsed to obtain a graphical representation corresponding to the SQL to be processed, so that the graphical representation can be used to describe the execution process of the SQL to be processed, such as the graphical representation being able to describe the execution process of the SQL to be processed in a visual way; then, when the execution process includes processing logic for at least one candidate field, and the at least one candidate field includes a target field, such as a field specified by the user that needs to be processed by the processing logic, the graphical representation corresponding to the target field is cropped from the graphical representation corresponding to the SQL to be processed, so that the target field is... The graphical representation corresponding to the target field is used to describe the processing logic of the target field. Finally, the graphical representation corresponding to the target field is reverse parsed to obtain the SQL corresponding to the target field, so that the SQL corresponding to the target field can represent the processing logic of the target field. This allows subsequent processing of the target field to be completed by executing the SQL corresponding to the target field. This enables the extraction of the processing logic of a field from the SQL, thereby effectively overcoming the defects caused by manually extracting the processing logic of a field, such as long time consumption and low accuracy. This is beneficial to improving the extraction effect of field logic, such as extraction accuracy and extraction efficiency. Attached Figure Description
[0031] To more clearly illustrate the technical solutions in the embodiments or related technologies of this application, the drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0032] Figure 1 A flowchart illustrating an SQL processing method provided in an embodiment of this application;
[0033] Figure 2 A schematic diagram illustrating a graphical representation of a target field provided in an embodiment of this application;
[0034] Figure 3 A schematic diagram of a physical table probing upwards, provided for an embodiment of this application;
[0035] Figure 4 This is a schematic diagram of the structure of an SQL processing device provided in an embodiment of this application;
[0036] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0037] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.
[0038] To better understand the technical solution provided in this application, the SQL processing method provided in this application will be explained below with reference to some accompanying drawings. For example... Figure 1 As shown, the SQL processing method provided in this application includes S1-S3 as described below. Wherein, the... Figure 1 This is a flowchart of an SQL processing method provided in an embodiment of this application.
[0039] S1: After obtaining the SQL to be processed, the SQL to be processed is parsed and processed to obtain a graphical representation of the SQL to be processed; the graphical representation is used to describe the execution process of the SQL to be processed; the execution process includes the processing logic of at least one candidate field; the at least one candidate field includes the target field.
[0040] The SQL to be processed refers to the SQL required to determine the relevant logic of a certain field, such as Hive SQL; and the SQL to be processed can include at least one statement, such as 100 statements. Furthermore, this application does not limit the implementation method of the SQL to be processed. For example, the SQL to be processed can refer to SQL input by the user, such as a piece of code containing multiple SQL statements. Alternatively, the SQL to be processed can refer to SQL obtained through a certain method.
[0041] The graphical representation of the SQL to be processed is used to describe the execution process of the SQL, so that the graphical representation can intuitively describe the execution process of the SQL to be processed in a visual way. For example, the graphical representation can use a similar... Figure 2The diagram illustrates the execution process of the SQL to be processed, allowing the graphical representation to visually depict the various tables, fields, relationships between different tables and fields, and the processing logic of each field involved in the execution of the SQL. Therefore, in one possible implementation, the graphical representation of the SQL to be processed can be used to describe the processing logic of at least one candidate field, enabling the graphical representation to show how these candidate fields are processed during the execution of the SQL. Here, the at least one candidate field represents some or all of the fields involved in the execution of the SQL. The i-th candidate field refers to the i-th field involved in the execution of the SQL, such as... Figure 2 The `submit_id` field is shown. The processing logic for the i-th candidate field describes how to process the i-th candidate field when executing the SQL to be processed, so that the processing logic for the i-th candidate field can represent the processing approach and chain of the i-th candidate field when executing the SQL to be processed. i is a positive integer, i≤I, where I is a positive integer and I represents the number of fields in the at least one candidate field, such as the total number of fields involved in executing the SQL to be processed.
[0042] Furthermore, this application does not limit the method of obtaining the graphical representation corresponding to the SQL to be processed mentioned above. For example, it can use any existing or future method that can process SQL into visual data, such as similar to Figure 2 The method shown in the diagram is implemented.
[0043] For example, in order to improve the processing effect of SQL, this application also provides a possible implementation of the process of obtaining the graphical representation of the SQL to be processed mentioned above. In this implementation, the process of obtaining the graphical representation of the SQL to be processed may specifically include steps 11-12 below.
[0044] Step 11: Convert the SQL to be processed into an Abstract Syntax Tree (AST) corresponding to the SQL to be processed.
[0045] It should be noted that this application does not limit the implementation of step 11 above. For example, it can specifically be: performing syntax parsing on the SQL to be processed to obtain the abstract syntax tree corresponding to the SQL. Furthermore, this application does not limit the implementation of this syntax parsing process. For example, it can employ any existing or future method capable of converting SQL into an AST, such as the method implemented using Apache Calcite.
[0046] Therefore, in one possible implementation, step 11 above can specifically be: using Apache Calcite to perform syntax parsing on the SQL to be processed, obtaining the abstract syntax tree corresponding to the SQL. Here, Apache Calcite is a dynamic data management framework, and it includes many pre-built databases and query engines, enabling it to be used to build various types of databases and data processing systems, and to convert SQL statements into ASTs.
[0047] Step 12: Convert the abstract syntax tree corresponding to the SQL to be processed into a graphical representation of the SQL to be processed.
[0048] It should be noted that this application does not limit the implementation of step 12 above. For example, it can be implemented using any existing or future method that can convert AST into visual data, such as by using a pre-defined visualization algorithm.
[0049] For example, in order to better improve the SQL processing effect, step 12 above may specifically include steps 121-123 below.
[0050] Step 121: Based on the abstract syntax tree corresponding to the SQL to be processed, determine the multiple tables corresponding to the SQL to be processed and the relationships between the multiple tables.
[0051] This involves multiple tables representing all or some of the tables involved in executing the SQL query, such as physical tables and intermediate processing results. It's important to note that physical tables refer to tables stored in the database, such as... Figure 2 The various physical tables shown or Figure 3 The tables shown are stored in the various databases. Intermediate processing results refer to the results obtained by processing some tables, such as... Figure 2 The join result set and select result set shown.
[0052] Furthermore, this application does not limit the implementation of the multiple tables in step 121 above. For example, in one possible implementation, the multiple tables may include some or all of the types shown in Table 1 below, so that the multiple tables can comprehensively represent the tables involved in executing the SQL to be processed, such as tables stored in the database and tables generated by some processing, which is beneficial to improving the SQL processing effect.
[0053]
[0054] Table 1. Some table types and their related information
[0055] In addition, regarding the "relationship between multiple tables" in step 121 above, the relationship is used to describe the relationship between different tables, such as input-output relationship, so that the relationship can represent the upstream and downstream relationship between these tables.
[0056] Furthermore, this application does not limit the implementation of step 121 above. For example, it can specifically be: after obtaining the abstract syntax tree corresponding to the SQL to be processed, the abstract syntax tree can be semantically parsed to obtain multiple tables corresponding to the SQL to be processed and the relationship between the multiple tables, so that this information can represent some tables involved in the execution of the SQL to be processed and the input-output relationship between these tables.
[0057] Step 122: Based on the abstract syntax tree corresponding to the SQL to be processed, the multiple tables mentioned above, and the relationships between the multiple tables, determine the logical relationship between at least two fields corresponding to the SQL to be processed, so that the logical relationship can indicate how one field is obtained from another field through what kind of processing.
[0058] The "at least two fields" refers to the fields involved in the multiple tables mentioned above, so that the "at least two fields" can represent all or part of the fields involved in the execution of the SQL to be processed.
[0059] In addition, for the above at least two fields, the logical relationship between the at least two fields is used to represent the reasoning logic between different fields, so that the logical relationship can more precisely represent the relationship between the fields in different tables involved in the execution of the SQL to be processed. For example, a field in the downstream table can be obtained by processing one or more fields in the upstream table.
[0060] Furthermore, this application does not limit the implementation of the logical relationship in step 122 above; for example, it may include the following:
[0061] Table 2 shows some or all of the logical relationships.
[0062]
[0063] Table 2. Some logical relationship types and related information.
[0064] It should be noted that for the UDFs shown in Table 2 above, if no UDTF / UDAF appears in the processing from the upstream table to the downstream table, it can be considered a UDF. Furthermore, in a visual representation, the upstream and downstream fields involved in the UDF are connected by lines. Additionally, if the downstream field is obtained by processing the upstream field through a UDF function, the abbreviation of the UDF function name, such as "icon," is displayed to the right of the downstream field. If there are nested UDFs, only the outermost UDF is displayed. Moreover, since there are many UDF functions, only commonly used UDFs are displayed as abbreviations, and the rest are displayed as... Figure 2 The fx function shown is sufficient. Also, if the upstream field does not require UDF processing to obtain the downstream field, the right side of the downstream field will be empty. Furthermore, UDFs include two main categories: unprocessed and processed. Processed UDFs can specifically include data type conversion, arithmetic operations (e.g., addition, subtraction, multiplication, division), string manipulation (e.g., length adjustment, concatenation, truncation, replacement, etc.), conditional statements (e.g., if, case, etc.), window functions (e.g., row_number, rank, dense_rank, etc.), and other UDF functions.
[0065] It should also be noted that for the UDTF shown in Table 2 above, if the processing logic from the upstream table to the downstream table involves a UDTF, it can be considered as UDTF processing (Note: UDTF used with lateral view is considered lateral view logic, here only UDTF used after select); and in the intuitive graphical representation, a new row "udtf logic" is added so that the fields used by the UDTF logic are connected with the "UDTF logic", and the UDTF output fields are connected with their upstream fields.
[0066] It should be further clarified that, regarding the UDAFs shown in Table 2 above, if the processing logic from the upstream table to the downstream table involves a UDAF, it can be considered UDAF processing. Furthermore, if group by logic exists, a new row for "group by logic" is added to connect the upstream fields used in the group by logic with the "group by logic". Additionally, if the upstream field is processed by a UDAF function to obtain the downstream field, an icon representing the abbreviation of the UDAF function name is displayed to the right of the downstream field. If there is nested UDAF and UDF, only the outermost function is displayed. Moreover, since there are too many UDAF functions, only commonly used UDAFs are displayed as abbreviations, and the rest are displayed as... Figure 2 The fx function shown is sufficient. UDAFs that need to display specific abbreviations include: max, count, min, avg, sum, etc.
[0067] Furthermore, this application does not limit the implementation of step 122 above. For example, it can specifically be: after obtaining the abstract syntax tree corresponding to the SQL to be processed, the abstract syntax tree can be subjected to semantic parsing processing to obtain the processing logic between different tables, and based on the processing logic, the logical relationship between at least two fields corresponding to the SQL to be processed can be determined.
[0068] Step 123: Based on the multiple tables mentioned above, the relationships between the multiple tables, and the logical relationships between at least two fields mentioned above, construct a graphical representation of the SQL to be processed so that the graphical representation can intuitively represent the multiple tables, the relationships between the multiple tables, and the logical relationships between at least two fields.
[0069] Based on the relevant content of steps 121 to 123 above, for the SQL to be processed above, after obtaining the abstract syntax tree corresponding to the SQL to be processed, the abstract syntax tree is first subjected to semantic parsing to obtain some tables involved in the execution of the SQL to be processed, the input and output relationships between these tables, and the logical relationships between different fields in these tables; then, based on this information, a graphical representation corresponding to the SQL to be processed is constructed so that the graphical representation can intuitively represent this information.
[0070] Based on the relevant content of S1 above, after obtaining the SQL to be processed, the SQL to be processed is parsed to obtain the corresponding graphical representation, so that the graphical representation can intuitively describe the execution process of the SQL to be processed. Thus, the graphical representation can describe the processing logic of each field involved in the execution of the SQL to be processed in a visual way, so that the processing logic of the field specified by the user can be determined with the help of the graphical representation.
[0071] S2: Extract the graphical representation of the target field from the graphical representation of the SQL to be processed; the graphical representation of the target field is used to describe the processing logic of the target field.
[0072] The target field refers to the field that exists among at least one of the candidate fields mentioned above and needs to be processed by the processing logic.
[0073] Furthermore, this application does not limit the method of obtaining the target field. For example, in some application scenarios, the target field is specified by the user through a certain method. It should be noted that this application does not limit the method of specifying the target field; for example, the user can input content into an input box, such as... Figure 2 The example shown is "submit," where the target field is specified using a specific method. Alternatively, users can specify the target field by selecting it from a list.
[0074] Furthermore, for the target field mentioned above, the graphical representation corresponding to the target field refers to the result obtained by cropping from the graphical representation corresponding to the SQL to be processed, such as... Figure 2 The graphical representation of the submit field shown is used to visually describe the processing logic of the target field, thereby enabling the graphical representation of the target field to show how the target field is processed when the SQL to be processed is executed.
[0075] Furthermore, this application does not limit the implementation of S2 above. For example, it can specifically be: deleting the part that is unrelated to the target field from the graphical representation corresponding to the SQL to be processed, such as the part that does not affect the target field, to obtain the graphical representation corresponding to the target field, so that the graphical representation corresponding to the target field can represent the part that exists in the graphical representation corresponding to the SQL to be processed and is related to the target field, such as the part that can affect the target field.
[0076] In fact, in order to better improve the extraction effect of field logic, this application also provides a possible implementation of S2 above. In this implementation, S2 may specifically include steps 21-22 below.
[0077] Step 21: Extract the related part of the target field from the graphical representation of the SQL to be processed.
[0078] The associated part of the target field refers to the part in the graphical representation of the SQL to be processed that is related to the target field, so that the associated part can represent the logic related to the target field involved in the execution of the SQL to be processed, such as the logic that uses the target field as the processing object, the logic that involves conditions including the target field, and the logic that uses the target field as the generation object.
[0079] In addition, this application does not limit the implementation of step 21 above. For example, it can specifically be: deleting the part that is not related to the target field from the graphical representation corresponding to the SQL to be processed, and obtaining the related part of the target field.
[0080] Step 22: Perform at least one simplification process on the associated portion of the target field to obtain a graphical representation of the target field; the at least one simplification process includes one or more of invalid join pruning, invalid field pruning, and nested selection merging; the invalid join pruning process is used to simplify the multi-table join logic in the associated portion; the invalid field pruning process is used to remove fields from the associated portion that do not affect the target field; the nested selection merging process is used to simplify the multi-level nested selection logic in the associated portion.
[0081] Among them, at least one simplification process is used to simplify the processing logic described by the associated portion of the target field; and the at least one simplification process includes one or more of invalid connection pruning, invalid field pruning, and nested selection merging processes.
[0082] Invalid join pruning simplifies multi-table join logic in the related parts of a target field, ensuring that the simplified multi-table join logic does not contain tables that cannot contribute to the target field. Here, multi-table join logic refers to the logic described by a certain join statement, such as the logic described by multiple left joins or multiple right joins.
[0083] Furthermore, this application does not limit the implementation method of the above invalid link clipping process; for example, it can be implemented according to pre-set rules.
[0084] For example, in order to improve the processing effect, the above invalid link clipping process can specifically include steps 221-222 below.
[0085] Step 221: If the associated part of the target field includes left join logic, and the right table processing logic in the left join logic does not affect the target field, then delete the right table processing logic from the associated part.
[0086] The left join logic refers to the logic described by the left join statement, such as the processing logic described by the SQL in the first column of Table 3 below.
[0087] The right table processing logic refers to the logic that exists in the left join logic above and is used to process the right table.
[0088] Based on step 221 above, for any left join logic appearing in the association part of the target field, if the right table processing logic in the left join logic does not affect the target field, it can be determined that the right table cannot contribute to the target field. Therefore, it can be determined that there is an invalid join in the left join logic, and thus the invalid join can be directly deleted from the left join logic, i.e., the right table processing logic. This ensures that there are no invalid joins in the deleted left join logic, and therefore, there are no tables in the deleted left join logic that cannot contribute to the target field. Consequently, the association part including the deleted left join logic can more concisely describe how to process the target field. It should be noted that if the target field only appears in the association conditions involved in the left join logic, such as the condition "ona.id = b.id", simplification can be determined based on the specific scenario.
[0089]
[0090] Table 3 Simplified example of left join
[0091] Step 222: If the associated part of the target field includes right join logic, and the left table processing logic in the right join logic does not affect the target field, then delete the left table processing logic from the associated part.
[0092] The right join logic refers to the logic implemented using the right join statement.
[0093] The left table processing logic refers to the logic that exists in the right join logic above and is used to process the left table.
[0094] Based on step 222 above, for any right join logic appearing in the association part of the target field, if the left table processing logic in the right join logic does not affect the target field, it can be determined that the left table cannot contribute to the target field. Therefore, it can be determined that there is an invalid join in the right join logic, and thus the invalid join can be directly deleted from the right join logic, i.e., the left table processing logic. This ensures that there are no invalid joins in the deleted right join logic, and therefore, there are no tables in the deleted right join logic that cannot contribute to the target field. Consequently, the association part including the deleted right join logic can more concisely describe how to process the target field. It should be noted that if the target field only appears in the association condition involved in the right join logic, simplification may be necessary depending on the specific scenario.
[0095] Based on the relevant content of steps 221 to 222 above, it can be seen that in some application scenarios, invalid connection pruning can be performed on the associated part of the target field above to remove invalid connections in the associated part, thereby improving the field logic extraction effect.
[0096] Invalid field pruning is used to remove fields that do not affect the target field from its associated parts. This application does not limit the implementation method of invalid field pruning; for example, it can be implemented using pre-defined rules to retain only fields and processing code that contribute to the target field, and / or it can be used to retain only the target field for caliber tracing, pruning other fields when they have no impact on the target field. It should be noted that all fields in the WHERE clause must be retained. Additionally, the retention of ON, GROUP BY, and lateralView depends on the specific business scenario.
[0097] Nested select merging is used to simplify multi-level nested select logic in the related parts of the target field. This multi-level nested select logic refers to logic described by multiple nested select statements, such as the logic described by the SQL in the first column of Table 4.
[0098]
[0099] Table 4 Examples of Nested Selection Merge Processing
[0100] Furthermore, this application does not limit the implementation of nested selection merging processing. For example, it may specifically include steps 223-224 below.
[0101] Step 223: If the multi-level nested selection logic in the associated part of the target field satisfies the predicate merging condition, then at least two conditions in the associated part are merged.
[0102] Among them, the predicate merging condition refers to the pre-defined condition that the multi-level nested selection logic that can merge WHERE conditions satisfies, such as the condition described in the second row of Table 4.
[0103] Furthermore, this application does not limit the implementation of step 223 above. For example, it can be: if the multi-level nested selection logic in the associated part of the target field satisfies the predicate merging condition, then at least two conditions in the associated part are merged to ensure that the processing logic represented by the merged associated part is consistent with the processing logic represented by the associated part before merging, and that the number of SQL statements corresponding to the merged associated part is less than the number of SQL statements corresponding to the associated part before merging. Here, the number of SQL statements corresponding to the merged associated part refers to the number of statements in the SQL obtained by reverse parsing based on the merged associated part. The number of SQL statements corresponding to the associated part before merging refers to the number of statements in the SQL obtained by reverse parsing based on the associated part before merging.
[0104] Step 224: If the multi-level nested selection logic in the associated part of the target field satisfies the invalid subquery merging condition, then at least two levels of selection logic in the multi-level nested selection logic in the associated part will be merged.
[0105] Among them, the invalid subquery merging condition refers to the pre-set condition that the multi-level nested selection logic with invalid subqueries must satisfy, such as the condition described in the third row of Table 4.
[0106] Furthermore, this application does not limit the implementation of step 224 above. For example, it can specifically be: if the multi-level nested selection logic in the associated part of the target field satisfies the invalid subquery merging condition, then at least two levels of selection logic in the multi-level nested selection logic are merged into one level of selection logic, such as deleting the invalid subquery corresponding to the invalid subquery merging condition from the multi-level nested selection logic. Here, the invalid subquery refers to the logic that exists in the multi-level nested selection logic that satisfies the invalid subquery merging condition and is used to represent redundant semantics, such as the logic described by the deleted statement described in the third row of Table 4.
[0107] Based on the relevant content of steps 223 to 224 above, it can be seen that in some application scenarios, nested selection and merging processing can be performed on the related parts of the target field above to eliminate redundant logic in the related parts, thereby improving the field logic extraction effect.
[0108] Based on the relevant content of steps 21 to 22 above, in one possible implementation, after obtaining the graphical representation corresponding to the SQL to be processed, the associated part of the target field is first extracted from the graphical representation corresponding to the SQL to be processed, so that the associated part can represent the content related to the target field in the graphical representation corresponding to the SQL to be processed; then, at least one simplification process is performed on the associated part to obtain the graphical representation corresponding to the target field, so that the graphical representation can represent the processing logic of the target field involved in the execution of the SQL to be processed as concisely as possible, which is beneficial to improving the field logic extraction effect.
[0109] Based on the relevant content of S2 above, after obtaining the graphical representation of the SQL to be processed, the graphical representation of the target field is cropped from the graphical representation so that the graphical representation can describe in a visual way the processing logic of the target field involved in the execution of the SQL to be processed.
[0110] S3: Perform reverse parsing on the graphical representation corresponding to the target field to obtain the SQL corresponding to the target field.
[0111] In this context, reverse parsing refers to the reverse process of "parsing" in S1 above, so that the reverse parsing can be used to restore a graphical representation to SQL.
[0112] Furthermore, this application does not limit the implementation of S3 above. For example, it may specifically include: first converting the graphical representation corresponding to the target field into an abstract syntax tree corresponding to the target field; then converting the abstract syntax tree corresponding to the target field into SQL corresponding to the target field, so that the SQL corresponding to the target field can represent the query statement in the SQL to be processed that describes the processing logic of the target field.
[0113] Based on the relevant content of S1 to S3 above, it is known that for the SQL processing method provided in this application embodiment, after obtaining the SQL to be processed, such as the SQL input by the user, the SQL to be processed is first parsed to obtain a graphical representation corresponding to the SQL to be processed, so that the graphical representation can be used to describe the execution process of the SQL to be processed, such as the graphical representation being able to describe the execution process of the SQL to be processed in a visual way; then, when the execution process includes processing logic for at least one candidate field, and the at least one candidate field includes a target field, such as a field specified by the user that needs to be processed by the processing logic, the target field is cropped from the graphical representation corresponding to the SQL to be processed. The graphical representation of the target field is used to describe its processing logic. Finally, the graphical representation is reverse-parsed to obtain the SQL corresponding to the target field, enabling the SQL to represent its processing logic. This allows subsequent processing of the target field to be completed by executing the SQL. This method effectively extracts the processing logic of a field from the SQL, overcoming the drawbacks of manual extraction, such as time consumption and low accuracy. This improves the accuracy and efficiency of field logic extraction.
[0114] Furthermore, this application does not limit the executing entity of the SQL processing method provided in the embodiments of this application. For example, the SQL processing method provided in the embodiments of this application can be applied to a terminal device. Alternatively, the SQL processing method provided in the embodiments of this application can also be implemented through the data interaction process between the terminal device and the server. The terminal device can be a smartphone, computer, personal digital assistant (PDA), tablet computer, etc. The server can be a standalone server, a cluster server, or a cloud server.
[0115] In addition, to better improve the user experience, this application also provides a possible implementation of the SQL processing method, in which the SQL processing method may further include step 31 below.
[0116] Step 31: Display the SQL corresponding to the target field and the graphical representation of the target field.
[0117] In this application, after obtaining the SQL corresponding to the target field and the graphical representation of the target field, both can be displayed to the user so that the user can understand the processing logic of the target field involved in executing the SQL from multiple perspectives, such as SQL and visualization, which is beneficial to improving the user experience.
[0118] Furthermore, in some application scenarios, the physical tables appearing in the SQL may be generated by executing other SQL. Therefore, in order to better improve the field logic extraction effect, this application also provides a possible implementation of the SQL processing method. In this implementation, the SQL processing method may include steps 41-44 below.
[0119] Step 41: After obtaining the SQL to be processed, the SQL to be processed is parsed to obtain a graphical representation of the SQL to be processed; the graphical representation is used to describe the execution process of the SQL to be processed; the execution process includes the processing logic of at least one candidate field; the at least one candidate field includes the target field.
[0120] It should be noted that the relevant content of step 41 can be found in S1 above.
[0121] Step 42: Extract the graphical representation of the target field from the graphical representation of the SQL to be processed; the graphical representation of the target field is used to describe the processing logic of the target field.
[0122] It should be noted that the relevant content of step 42 can be found in S2 above.
[0123] Step 43: Perform reverse parsing on the graphical representation corresponding to the target field to obtain the SQL corresponding to the target field.
[0124] It should be noted that the relevant content of step 43 can be found in S3 above.
[0125] Step 44: Based on the SQL corresponding to the target field and the SQL generated by the physical table in the SQL corresponding to the target field, update the SQL to be processed, and return to continue executing the step "parse and process the SQL to be processed" in step 41 above and its subsequent steps until the preset stopping condition is reached.
[0126] The output SQL for the physical table describes how the physical table was generated. It's clear that the physical table is obtained by executing this output SQL. For example, for... Figure 3For the databases shown, each physical table in the Data Warehouse Middle (DWM) is obtained by processing some physical tables in the Data Warehouse Detail (DWD); each physical table in the DWD is obtained by processing some physical tables in the Operational Data Store (ODS). It should be noted that the physical tables in the SQL statements used in the Application (APP) layer typically originate from the DWM.
[0127] Furthermore, this application does not limit the implementation method of the SQL generated above; for example, it can be statements such as with, insert, cachetable, etc.
[0128] Furthermore, this application does not limit the implementation method updated in step 44 above. For example, in order to better improve the SQL processing effect, step 44 may specifically include steps 441-442 below.
[0129] Step 441: Transform the output SQL of the physical table in the SQL corresponding to the target field to obtain the subquery statement corresponding to the physical table; the processing logic described by the subquery statement is consistent with the processing logic described by the output SQL.
[0130] The subquery statement corresponding to the physical table is used to represent the logic described by the output SQL of the physical table using the select statement, so as to convert the output SQL into a subquery statement.
[0131] Furthermore, this application does not limit the implementation method of the "deformation process" in step 441 above. For example, it can be implemented by means of pre-set deformation rules.
[0132] Step 442: Replace the physical table in the SQL corresponding to the target field with the subquery statement corresponding to the physical table to obtain the updated SQL to be processed.
[0133] In this application, for the physical table in the SQL corresponding to the target field, after obtaining the subquery statement corresponding to the physical table, the corresponding physical table in the SQL corresponding to the target field can be directly replaced with the subquery statement corresponding to the physical table to obtain the updated SQL to be processed. This ensures that the updated SQL does not contain the physical table, but does contain the subquery statement corresponding to the physical table. This allows for upward probing of the physical table, thus better meeting user needs. Since the subquery statement corresponding to the physical table uses a select statement to represent the logic described by the output SQL of the physical table, it makes the subquery statement corresponding to the physical table more compatible with the SQL corresponding to the target field. This effectively avoids problems caused by incompatibility between diverse output SQL and the SQL corresponding to the target field, thereby improving the extraction effect of field logic.
[0134] Based on the relevant content of steps 441 to 442 above, after obtaining the SQL corresponding to the target field, some physical tables involved in the SQL corresponding to the target field can be replaced with query statements that can describe the processing logic of these physical tables, so as to realize the upward exploration of physical tables, thereby better meeting user needs.
[0135] A preset stopping condition refers to the condition required to stop the iteration process; however, this application does not limit the preset stopping condition. For example, the preset stopping condition can be determined based on the upward exploration layer constraint information provided by the user. The upward exploration layer constraint is used to indicate how many layers to explore upwards; however, this application does not limit the upward exploration layer constraint. For example, it can include the string "explore upwards to DWD".
[0136] Based on the relevant content of steps 41 to 44 above, this application further supports probing upwards to some physical tables on the basis of SQL trimming, so as to obtain query statements that can describe the processing logic of these physical tables, thus better meeting user needs.
[0137] Based on the SQL processing method provided in the embodiments of this application, the embodiments of this application also provide an SQL processing device, which is described below in conjunction with... Figure 4 Explanation and clarification will be provided. Among them, Figure 4 This is a schematic diagram of the structure of an SQL processing device provided in an embodiment of this application. It should be noted that for technical details of the SQL processing device provided in this embodiment, please refer to the relevant content of the SQL processing method above.
[0138] like Figure 4 As shown, the SQL processing device 400 provided in this application embodiment includes:
[0139] The parsing unit 401 is used to parse the SQL to be processed after obtaining it, and to obtain a graphical representation of the SQL to be processed; the graphical representation is used to describe the execution process of the SQL to be processed; the execution process includes processing logic for at least one candidate field; the at least one candidate field includes a target field;
[0140] The trimming unit 402 is used to trim the graphical representation corresponding to the target field from the graphical representation corresponding to the SQL to be processed; the graphical representation corresponding to the target field is used to describe the processing logic of the target field;
[0141] The reverse parsing unit 403 is used to perform reverse parsing processing on the graphical representation corresponding to the target field to obtain the SQL corresponding to the target field.
[0142] In one possible implementation, the parsing unit 401 is specifically used to: convert the SQL to be processed into an abstract syntax tree corresponding to the SQL to be processed; and convert the abstract syntax tree corresponding to the SQL to be processed into a graphical representation corresponding to the SQL to be processed.
[0143] The inverse parsing unit 403 is specifically used to: convert the graphical representation corresponding to the target field into the abstract syntax tree corresponding to the target field; and convert the abstract syntax tree corresponding to the target field into the SQL corresponding to the target field.
[0144] In one possible implementation, the pruning unit 402 is specifically configured to: extract the related portion of the target field from the graphical representation corresponding to the SQL to be processed; perform at least one simplification process on the related portion to obtain the graphical representation corresponding to the target field; the at least one simplification process includes one or more of invalid connection pruning, invalid field pruning, and nested selection merging; the invalid connection pruning is used to simplify the multi-table join logic in the related portion; the invalid field pruning is used to remove fields from the related portion that do not affect the target field; the nested selection merging is used to simplify the multi-level nested selection logic in the related portion.
[0145] In one possible implementation, the invalid join pruning process includes: if the associated portion includes left join logic, and the right table processing logic in the left join logic does not affect the target field, then the right table processing logic is deleted from the associated portion; if the associated portion includes right join logic, and the left table processing logic in the right join logic does not affect the target field, then the left table processing logic is deleted from the associated portion.
[0146] In one possible implementation, the nested selection merging process includes: if the multi-level nested selection logic in the associated part satisfies the predicate merging condition, then at least two conditions in the multi-level nested selection logic are merged; if the multi-level nested selection logic in the associated part satisfies the invalid subquery merging condition, then at least two levels of selection logic in the multi-level nested selection logic are merged.
[0147] In one possible implementation, the SQL processing device 400 further includes:
[0148] The display unit is used to display the SQL corresponding to the target field and the graphical representation of the target field.
[0149] In one possible implementation, the SQL processing device 400 further includes:
[0150] The update unit is used to update the SQL to be processed based on the SQL corresponding to the target field and the output SQL of the physical table in the SQL corresponding to the target field, and continue to execute the step of parsing and processing the SQL to be processed until a preset stop condition is reached; the physical table is obtained by executing the output SQL.
[0151] In one possible implementation, the update unit is specifically used to: transform the output SQL of the physical table to obtain a subquery statement corresponding to the physical table; the processing logic described by the subquery statement is consistent with the processing logic described by the output SQL; and replace the physical table in the SQL corresponding to the target field with the subquery statement corresponding to the physical table to obtain the updated SQL to be processed.
[0152] Based on the above-described SQL processing device 400, it is understood that, for the SQL processing device 400 provided in this application embodiment, after obtaining the SQL to be processed, such as the SQL input by the user, the SQL to be processed is first parsed to obtain a graphical representation corresponding to the SQL to be processed, so that the graphical representation can be used to describe the execution process of the SQL to be processed, such as the graphical representation being able to describe the execution process of the SQL to be processed in a visual manner; then, when the execution process includes processing logic for at least one candidate field, and the at least one candidate field includes a target field, such as a field specified by the user that needs to be processed by the processing logic, the target field is cropped from the graphical representation corresponding to the SQL to be processed. The graphical representation corresponding to the target field is used to describe the processing logic of the target field. Finally, the graphical representation corresponding to the target field is reverse parsed to obtain the SQL corresponding to the target field, so that the SQL corresponding to the target field can represent the processing logic of the target field. This allows subsequent processing of the target field to be completed by executing the SQL corresponding to the target field. This enables the extraction of the processing logic of a field from the SQL, thereby effectively overcoming the defects caused by manually extracting the processing logic of a field, such as long time consumption and low accuracy. This is beneficial to improving the extraction effect of field logic, such as extraction accuracy and extraction efficiency.
[0153] In addition, this application also provides an electronic device, which includes a processor and a memory: the memory is used to store instructions or computer programs; the processor is used to execute the instructions or computer programs in the memory so that the electronic device performs any implementation of the SQL processing method provided in this application.
[0154] See Figure 5 The diagram illustrates a structural schematic of an electronic device 500 suitable for implementing embodiments of the present disclosure. The terminal devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 5 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.
[0155] like Figure 5As shown, the electronic device 500 may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 into a random access memory (RAM) 503. The RAM 503 also stores various programs and data required for the operation of the electronic device 500. The processing unit 501, ROM 502, and RAM 503 are interconnected via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0156] Typically, the following devices can be connected to I / O interface 505: input devices 506 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 507 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 508 including, for example, magnetic tapes, hard disks, etc.; and communication devices 509. Communication device 509 allows electronic device 500 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 5 An electronic device 500 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.
[0157] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 509, or installed from a storage device 508, or installed from a ROM 502. When the computer program is executed by the processing device 501, it performs the functions defined in the methods of embodiments of this disclosure.
[0158] The electronic device provided in this embodiment belongs to the same inventive concept as the method provided in the above embodiments. Technical details not described in detail in this embodiment can be found in the above embodiments, and this embodiment has the same beneficial effects as the above embodiments.
[0159] This application also provides a computer-readable medium storing instructions or a computer program that, when executed on a device, causes the device to perform any implementation of the SQL processing method provided in this application.
[0160] It should be noted that the computer-readable medium described in this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in connection with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.
[0161] In some implementations, clients and servers can communicate using any currently known or future-developed network protocol such as HTTP (Hypertext Transfer Protocol) and can interconnect with digital data communication (e.g., communication networks) of any form or medium. Examples of communication networks include local area networks (“LANs”), wide area networks (“WANs”), the Internet (e.g., the Internet of Things), and end-to-end networks (e.g., ad hoc end-to-end networks), as well as any currently known or future-developed networks.
[0162] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.
[0163] The aforementioned computer-readable medium carries one or more programs, which, when executed by the electronic device, enable the electronic device to perform the aforementioned methods.
[0164] Computer program code for performing the operations of this disclosure can be written in one or more programming languages or a combination thereof, including but not limited to object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0165] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0166] The units described in the embodiments of this disclosure can be implemented in software or hardware. The names of the units / modules do not necessarily limit the specific unit itself.
[0167] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: Field Programmable Gate Arrays (FPGAs), Application-Specific Integrated Circuits (ASICs), Application Standard Products (ASSPs), System-on-Chip (SoCs), Complex Programmable Logic Devices (CPLDs), and so on.
[0168] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0169] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the systems or apparatus disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and relevant parts can be referred to the method section.
[0170] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0171] It should also be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0172] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0173] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A SQL processing method, characterized in that, The method includes: After obtaining the SQL to be processed, the SQL to be processed is parsed to obtain a graphical representation of the SQL to be processed; the graphical representation is used to describe the execution process of the SQL to be processed; the execution process includes processing logic for at least one candidate field; the at least one candidate field includes a target field, and the target field needs to be determined by processing logic; The graphical representation corresponding to the target field is cropped from the graphical representation corresponding to the SQL to be processed; the graphical representation corresponding to the target field is used to describe the processing logic of the target field; The graphical representation corresponding to the target field is subjected to inverse parsing to obtain the SQL corresponding to the target field, wherein the SQL corresponding to the target field is executed to complete the processing of the target field; The step of cropping the graphical representation corresponding to the target field from the graphical representation corresponding to the SQL to be processed includes: Extract the related part of the target field from the graphical representation corresponding to the SQL to be processed; and The associated part is simplified to obtain a graphical representation of the target field.
2. The method according to claim 1, characterized in that, The process of determining the graphical representation corresponding to the SQL to be processed includes: Convert the SQL to be processed into an abstract syntax tree corresponding to the SQL to be processed; Convert the abstract syntax tree corresponding to the SQL to be processed into a graphical representation of the SQL to be processed; The process of determining the SQL corresponding to the target field includes: Convert the graphical representation corresponding to the target field into an abstract syntax tree corresponding to the target field; The abstract syntax tree corresponding to the target field is converted into the SQL corresponding to the target field.
3. The method according to claim 1, characterized in that, The simplification process includes one or more of the following: invalid join pruning, invalid field pruning, and nested selection merging. The invalid join pruning is used to simplify the multi-table join logic in the associated part. The invalid field pruning is used to remove fields from the associated part that do not affect the target field. The nested selection merging process is used to simplify the multi-level nested selection logic in the associated part.
4. The method according to claim 3, characterized in that, The invalid connection pruning process includes: If the associated part includes left join logic, and the right table processing logic in the left join logic does not affect the target field, then the right table processing logic is deleted from the associated part. If the associated part includes right join logic, and the left table processing logic in the right join logic does not affect the target field, then the left table processing logic is deleted from the associated part.
5. The method according to claim 3, characterized in that, The nested selection merging process includes: If the multi-level nested selection logic in the associated part satisfies the predicate merging condition, then at least two conditions in the multi-level nested selection logic will be merged. If the multi-level nested selection logic in the associated part satisfies the invalid subquery merging condition, then at least two levels of selection logic in the multi-level nested selection logic will be merged.
6. The method according to claim 1, characterized in that, The method further includes: Display the SQL corresponding to the target field and the graphical representation of the target field.
7. The method according to claim 1, characterized in that, After obtaining the SQL corresponding to the target field, the method further includes: Based on the SQL corresponding to the target field and the SQL generated from the physical table in the SQL corresponding to the target field, update the SQL to be processed, and continue to execute the step of parsing and processing the SQL to be processed until the preset stopping condition is reached; the physical table is obtained by executing the generated SQL.
8. The method according to claim 7, characterized in that, The step of updating the SQL to be processed based on the SQL corresponding to the target field and the SQL generated by the physical table in the SQL corresponding to the target field includes: The generated SQL of the physical table is transformed to obtain the subquery statement corresponding to the physical table; the processing logic described by the subquery statement is consistent with the processing logic described by the generated SQL. Replace the physical table in the SQL corresponding to the target field with the subquery statement corresponding to the physical table to obtain the updated SQL to be processed.
9. An SQL processing device, characterized in that, include: The parsing unit is used to parse the SQL to be processed after obtaining it, and to obtain a graphical representation of the SQL to be processed; the graphical representation is used to describe the execution process of the SQL to be processed. The execution process includes processing logic for at least one candidate field; The at least one candidate field includes a target field that needs to be processed by the processing logic to determine its value. The trimming unit is used to trim the graphical representation corresponding to the target field from the graphical representation corresponding to the SQL to be processed; the graphical representation corresponding to the target field is used to describe the processing logic of the target field; The inverse parsing unit is used to perform inverse parsing processing on the graphical representation corresponding to the target field to obtain the SQL corresponding to the target field, wherein the SQL corresponding to the target field is executed to complete the processing of the target field; The process of cropping the graphical representation corresponding to the target field from the graphical representation corresponding to the SQL to be processed includes: Extract the related part of the target field from the graphical representation corresponding to the SQL to be processed; and The associated part is simplified to obtain a graphical representation of the target field.
10. An electronic device, characterized in that, The device includes: a processor and a memory; The memory is used to store instructions or computer programs; The processor is configured to execute the instructions or computer program in the memory to cause the electronic device to perform the method according to any one of claims 1-8.
11. A computer-readable medium, characterized in that, The computer-readable medium stores instructions or computer programs that, when executed on the device, cause the device to perform the method according to any one of claims 1-8.
12. A computer program product, characterized in that, It includes a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the method of any one of claims 1-8.
Citation Information
Patent Citations
Structured query language statement visualization method and device
CN110874367A
Unified authority management method, system and device, and storage medium
CN112149107A
Method and system for generating optimal membership-check queries
US20140181073A1