SQL (Structured Query Language) statement analysis method and device, equipment, storage medium and product
By generating the grammatical tree structure and disassembling the method of setting the node node, the key attributes of the SQL statement are extracted and converted to the SQL statement in existing technologies, and the problem of low -efficiency SQL statement analysis is achieved.
Patent Information
- Application Number
- CN202411351238.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-26
- Publication Date
- 2025-01-28
AI Technical Summary
In the prior art, tools that rely on manual operations or single-function parsing SQL statements cannot provide sufficient functional support, resulting in difficulty in extracting key attributes and inefficient parsing.
By receiving SQL statement information to be processed, the grammar tree structure is generated, and it is disassembled as a sub -sentence node when the nest nodes are existed, the attributes of the node are extracted, the standardized structure is transformed, and the target standardized structure is obtained.
It improves the analysis efficiency of the SQL statement, can quickly analyze the simple SQL statement, and simplify the complex multi -layer nested SQL statement into multiple simple SQL for resolution and extraction.
Smart Images

Figure CN119377246A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a SQL statement parsing method, apparatus, device, storage medium and computer program product. Background Art
[0002] In the current technical environment, the parsing and information extraction of SQL statements (Structured Query Language) usually rely on manual operations or single-function tools, such as field extraction through regular expressions, and then generating corresponding standardized structures for subsequent computer calls. When these tools process SQL statements containing complex operations, the extraction of key attributes becomes particularly difficult because existing tools often cannot provide sufficient functional support, which leads to low efficiency in parsing SQL statements.
[0003] Therefore, how to improve the parsing efficiency of SQL statements is a problem that needs to be solved urgently.
[0004] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention
[0005] The main purpose of the present application is to provide a SQL statement parsing method, apparatus, device, storage medium and computer program product, aiming to solve the technical problem in the related art that SQL statements are parsed by relying on manual operation or single-function tools, which cannot provide sufficient functional support and the extraction of key attributes becomes particularly difficult, thus resulting in low SQL statement parsing efficiency.
[0006] To achieve the above purpose, the present application proposes a SQL statement parsing method, which includes:
[0007] Receive SQL statement information to be processed, and generate a syntax tree structure based on the SQL statement information;
[0008] When it is determined that there is at least one nested statement node in the syntax tree structure, the nested statement node is disassembled to obtain a plurality of sub-statement nodes;
[0009] Extracting node attributes of each of the sub-statement nodes to obtain parsed first statement data;
[0010] The first sentence data is converted into a standardized structure to obtain a target standardized structure.
[0011] In one embodiment, the step of disassembling the nested statement node to obtain a plurality of sub-statement nodes includes:
[0012] Determine a node position corresponding to a sub-statement node in the nested statement node;
[0013] Based on each of the sub-statement nodes, generate a plurality of sub-statement identifiers;
[0014] Each of the sub-statement nodes is separated, and the sub-statement identifier is replaced at the node position. When it is determined that there is no sub-statement with a nested relationship in each of the sub-statement nodes, a plurality of sub-statement nodes are extracted.
[0015] In one embodiment, the step of generating a syntax tree structure based on the SQL statement information includes:
[0016] Performing grammatical decomposition on the SQL statement information to obtain multiple lexical units;
[0017] Each of the lexical units is converted into a grammar tree structure through a preset grammar analyzer.
[0018] In one embodiment, the step of extracting the node attributes of each of the sub-statement nodes to obtain the parsed first statement data includes:
[0019] Traverse each sub-statement node according to the preset standardized structure, and extract the attribute content in each sub-statement node;
[0020] The attribute contents are integrated to obtain parsed first sentence data.
[0021] In one embodiment, the step of converting the first sentence data into a standardized structure to obtain a target standardized structure includes:
[0022] Filling the first sentence data into a preset standardized structure to generate a standardized structure object;
[0023] After the SQL statements in all sub-statement nodes are parsed, the standardized structure object is traversed;
[0024] Determining whether a sub-statement identifier exists in the standardized structure object;
[0025] If it exists, locate the standardized structure position corresponding to the sub-statement identifier, and mount the structure object at the standardized structure position to the parent node corresponding to the sub-statement identifier;
[0026] When no sub-statement identifier exists in the standardized structure object, the target standardized structure is output.
[0027] In one embodiment, after the step of converting the first sentence data into a standardized structure to obtain a target standardized structure, the step further includes:
[0028] Obtain business scenario information;
[0029] Based on the business scenario information, converting the target standardized structure into a character string;
[0030] The statement object in the character string is converted into a target business object, so that relevant technical personnel can call the target business object based on the business scenario information.
[0031] In addition, to achieve the above purpose, the present application also proposes a SQL statement parsing device, the SQL statement parsing device comprising:
[0032] A receiving module, used for receiving SQL statement information to be processed, and generating a syntax tree structure based on the SQL statement information;
[0033] A disassembly module, configured to disassemble the nested statement node to obtain a plurality of sub-statement nodes when determining that there is at least one nested statement node in the syntax tree structure;
[0034] An extraction module, used to extract node attributes of each of the sub-statement nodes to obtain parsed first statement data;
[0035] The first conversion module is used to perform standardized structure conversion on the first sentence data to obtain a target standardized structure.
[0036] In addition, to achieve the above-mentioned purpose, the present application also proposes a SQL statement parsing device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the SQL statement parsing method described above.
[0037] In addition, to achieve the above objectives, the present application also proposes a storage medium, which is a computer-readable storage medium, and stores a computer program on the storage medium. When the computer program is executed by a processor, the steps of the SQL statement parsing method described above are implemented.
[0038] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the SQL statement parsing method described above are implemented.
[0039] The present application proposes a method, apparatus, device, storage medium and computer program product for parsing SQL statements. The present application receives SQL statement information to be processed and generates a syntax tree structure based on the SQL statement information, thereby converting the code into a tree structure representation of the code. When it is determined that there are nested statement nodes in the syntax data structure, the nested statement nodes are decomposed into multiple sub-statement nodes, and the node attributes of each sub-statement node are extracted to generate parsed first statement data. By introducing the statement decomposition step, simple SQL statements can be quickly parsed, and complex multi-layer nested SQL statements can be simplified into multiple simple SQL statements for parsing and extraction. Furthermore, the first statement data obtained after parsing is converted into a standardized structure to obtain the required target standardized structure, thereby improving the parsing efficiency of SQL statements. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0041] 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.
[0042] Figure 1 A flowchart of the first embodiment of the SQL statement parsing method of the present application is provided;
[0043] Figure 2 This is a schematic diagram of the overall architecture involved in the SQL statement parsing method of this application;
[0044] Figure 3 This is a flow chart of statement splitting involved in the SQL statement parsing method of this application;
[0045] Figure 4 This is a schematic diagram of the statement structure after the splitting is completed involved in the SQL statement parsing method of this application;
[0046] Figure 5 This is a schematic diagram of the standardized structure conversion process involved in the SQL statement parsing method of this application;
[0047] Figure 6 This is a schematic diagram of the standardized infrastructure involved in the SQL statement parsing method of this application;
[0048] Figure 7 This is a schematic diagram of the standardized structural attribute distribution involved in the SQL statement parsing method of this application;
[0049] Figure 8 This is a schematic diagram of the structural object conversion process involved in the SQL statement parsing method of this application;
[0050] Fig. 9 This is a schematic diagram of the module structure of the SQL statement parsing device according to the embodiment of the present application;
[0051] Fig.10 This is a schematic diagram of the device structure of the hardware operating environment involved in the SQL statement parsing method in the embodiment of the present application.
[0052] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0053] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0054] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0055] The main solutions of the embodiments of this application are:
[0056] Receive SQL statement information to be processed, and generate a syntax tree structure based on the SQL statement information;
[0057] When it is determined that there is at least one nested statement node in the syntax tree structure, the nested statement node is disassembled to obtain a plurality of sub-statement nodes;
[0058] Extracting node attributes of each of the sub-statement nodes to obtain parsed first statement data;
[0059] The first sentence data is converted into a standardized structure to obtain a target standardized structure.
[0060] In the prior art, manual operations or single-function tools are usually relied on, such as field extraction through regular expressions, and then the corresponding standardized structure is generated for subsequent computer calls. When these tools process SQL statements containing complex calculations, the extraction of key attributes becomes particularly difficult because the existing tools often cannot provide sufficient functional support, which leads to low efficiency in parsing SQL statements.
[0061] The present application proposes a method, apparatus, device, storage medium and computer program product for parsing SQL statements. The present application receives SQL statement information to be processed and generates a syntax tree structure based on the SQL statement information, thereby converting the code into a tree structure representation of the code. When it is determined that there are nested statement nodes in the syntax data structure, the nested statement nodes are decomposed into multiple sub-statement nodes, and the node attributes of each sub-statement node are extracted to generate parsed first statement data. By introducing the statement decomposition step, simple SQL statements can be quickly parsed, and complex multi-layer nested SQL statements can be simplified into multiple simple SQL statements for parsing and extraction. Furthermore, the first statement data obtained after parsing is converted into a standardized structure to obtain the required target standardized structure, thereby improving the parsing efficiency of SQL statements.
[0062] It should be noted that the execution subject of this embodiment may be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, an SQL statement parsing device, etc. The following takes the SQL statement parsing device as an example to illustrate this embodiment and the following embodiments.
[0063] Based on this, the embodiment of the present application provides a SQL statement parsing method, referring to Figure 1 , Figure 1 This is a flowchart of the first embodiment of the SQL statement parsing method of the present application.
[0064] In this embodiment, the SQL statement parsing method includes steps S10 to S40:
[0065] Step S10, receiving SQL statement information to be processed, and generating a syntax tree structure based on the SQL statement information;
[0066] It should be noted that the SQL statement information may be multiple SQL statements that need to be processed. Before parsing the SQL statements, the SQL statements need to be converted into a syntax tree structure.
[0067] It should be noted that the syntax tree structure may be an abstract syntax tree (AST), wherein the abstract syntax tree is a tree representation of an abstract syntax structure of a source code, and each node on the tree represents a structure in the source code.
[0068] It should be noted that this application is based on the parser generator as the basic component (this tool uses Antlr4, and can also replace or integrate other parsers, such as: calcite, Druid), generates an AST syntax tree according to the input SQL statement, and then traverses the AST nodes to extract the corresponding SQL attribute information, fills it into the predefined structure, and then provides a unified external interface to reduce the operating cost and complexity of the upper-level application directly using the AST tree, making the scenario development based on SQL statement parsing more convenient and efficient. At the same time, the tool also provides some commonly used functional interfaces, such as: SQL read and write table parsing, SQL use field parsing, table-level lineage, field lineage, SQL script parsing and other common scenarios, and users do not need to repeat development.
[0069] Specifically, the overall architecture diagram of the analysis tool involved in this application is as follows: Figure 2 As shown, the tool consists of five layers:
[0070] 1. Application layer
[0071] Use the API provided by standardized tools to build relevant application scenarios, including: customized SQL lineage analysis, SQL beautification tools, SQL rewriting tools, SQL comment filling tools, etc.
[0072] 2. External API layer
[0073] Provides an API (application programming interface) for external use and commonly used functional components, including: standardized API, SQL usage field parsing, SQL read and write table parsing, general table lineage, and general field lineage.
[0074] 3. Standardized conversion layer
[0075] Extract relevant attribute information from the AST nodes generated by SQL and generate a standardized structure.
[0076] 4. SQL parser layer
[0077] Used to extend parsers of different SQL types;
[0078] 5. Parser Generator Layer
[0079] Support different parser generator tools to improve the extensibility of the tools and the flexibility of the underlying layer.
[0080] The common functions of the system architecture include the following:
[0081] 1. Standardized API
[0082] Display SQL statements in a standardized structure;
[0083] 2. SQL uses field parsing
[0084] Extract the fields used in the SQL statement and determine which table each field belongs to;
[0085] 3. SQL read and write table analysis
[0086] Extract the tables used in the SQL statement;
[0087] 4. General table-level blood relationship analysis
[0088] Extract simple table-level blood relationship analysis to obtain the blood relationship of the table;
[0089] 5. General field-level lineage analysis
[0090] Extract simple field-level lineage analysis to obtain the lineage relationship between fields.
[0091] In a feasible implementation manner, the step S10 of generating a syntax tree structure based on the SQL statement information includes:
[0092] Performing grammatical decomposition on the SQL statement information to obtain multiple lexical units;
[0093] Each of the lexical units is converted into a grammar tree structure through a preset grammar analyzer.
[0094] It should be noted that lexical units can be TOKENS in the code. During the compilation process, the source code is first decomposed into a series of lexical units (tokens) by the lexical analyzer, and then these tokens are converted into a tree-like data structure, namely the abstract syntax tree, by the syntax analyzer. Compared with the specific syntax tree, the abstract syntax tree removes some insignificant details in the code, such as spaces, line breaks, etc., and only retains the core information related to the program semantics. As a core concept in compiler design, the abstract syntax tree not only helps to understand the internal structure of the program, but also provides strong support for code optimization, conversion and analysis.
[0095] Step S20, when it is determined that there is at least one nested statement node in the syntax tree structure, the nested statement node is disassembled to obtain a plurality of sub-statement nodes;
[0096] It should be noted that a nested statement node is a statement node that includes multiple sub-statement nodes. Since different nodes are at different levels, different nodes may be subordinate to multiple other nodes. During the parsing process, if there is only a single function, the subordinate nodes nested under the current node cannot be parsed, or the parsing speed is slow, thereby affecting the parsing efficiency of the SQL statement.
[0097] Specifically, in the embodiment of the present application, the determined nested statement nodes are disassembled, each sub-statement node is split, and after separate split processing, they are parsed one by one, thereby improving the parsing efficiency.
[0098] In a feasible implementation manner, the step S20 of disassembling the nested statement node to obtain a plurality of sub-statement nodes includes:
[0099] Determine a node position corresponding to a sub-statement node in the nested statement node;
[0100] It should be noted that, since there are sub-statement nodes at different levels in the nested statement node, the specific position of each sub-statement node is determined through the syntax tree structure, and then the node position corresponding to the sub-statement node is obtained.
[0101] Based on each of the sub-statement nodes, generate a plurality of sub-statement identifiers;
[0102] It should be noted that after determining the position of each sub-statement node, a unique identifier is generated for each sub-statement node to obtain a sub-statement identifier. After separating the sub-statement node, the sub-statement identifier replaces the sub-statement in the sub-statement node, thereby extracting the sub-statement and parsing it separately.
[0103] Each of the sub-statement nodes is separated, and the sub-statement identifier is replaced at the node position. When it is determined that there is no sub-statement with a nested relationship in each of the sub-statement nodes, a plurality of sub-statement nodes are extracted.
[0104] It should be noted that the process of separating each of the sub-statement nodes is: extracting the sub-statements in each sub-statement node, parsing the extracted sub-statements, and then filling the sub-statement identifiers into the corresponding node positions to replace the separated sub-statements.
[0105] It should be noted that after separating the sub-statement in the sub-statement node, it is also necessary to associate the parent-child relationship between the sub-statement and the original statement. The association relationship is expressed as: parent statement-sub-statement, and the relationship between the sub-statement node and the statement node corresponding to the original statement is: parent node-child node.
[0106] It should be noted that, it is continued to determine whether there are other sub-statements nested in the sub-statement, and the sub-statement extraction process is repeated. When it is determined that there are no sub-statements with nested relationships in each sub-statement node, multiple sub-statement nodes are extracted.
[0107] Specifically, the SQL statement dialect type is detected and the sub-statements are split (the process is as follows Figure 3 shown).
[0108] 1. Get the dialect type of the input SQL statement based on the SQL dialect type specified by the input user or the default dialect detection automatically used by the SQL parser;
[0109] 2. According to the dialect type, determine the specific implementer of the SQL parser (this tool uses Antlr4 by default);
[0110] 3. Generate an AST tree for the SQL statement and traverse the nodes to see if there are sub-statement nodes;
[0111] 4. If there is no sub-statement node, it is determined to be a simple statement type and the original SQL statement is output;
[0112] 5. If there is a sub-statement node, enter the sub-statement extraction process;
[0113] (1) Locate the sub-statement;
[0114] (2) Extract sub-statements from the original SQL statement;
[0115] (3) Generate a unique identifier for the extracted sub-statement;
[0116] (4) Separate the substatements and use the unique identifier to replace the original SQL position;
[0117] (5) The parent-child relationship between the associated sub-sentence and the original sentence;
[0118] (6) Continue to determine whether there is a sub-statement in the sub-statement, and repeat the above step 3;
[0119] 6. The first statement entered is the main statement, and the others are sub-statements. The statement structure after splitting is as follows Figure 4 shown.
[0120] Step S30, extracting the node attributes of each of the sub-statement nodes to obtain the parsed first statement data;
[0121] It should be noted that the process of extracting the node attributes of each node may be to traverse the nodes according to a predefined standardized structure, extract relevant attribute content, and generate the parsed first sentence data.
[0122] It should be noted that the first sentence data may be attribute content obtained after extracting attributes from sub-sentences in each node, and the target standardized structure may be generated by filling the attribute content into a preset standardized structure.
[0123] In a feasible implementation manner, the step S30 of extracting the node attributes of each of the sub-statement nodes to obtain the parsed first statement data includes:
[0124] Traverse each sub-statement node according to the preset standardized structure, and extract the attribute content in each sub-statement node;
[0125] The attribute contents are integrated to obtain parsed first sentence data.
[0126] It should be noted that when the first statement data is extracted, the SQL statements are all standardized and converted according to the processed SQL statement set;
[0127] According to the dialect type, determine the specific implementer of the SQL parser (this tool uses Antlr4 by default);
[0128] Generate AST tree for SQL statements;
[0129] Traverse the nodes according to the predefined standardized structure and extract relevant attribute content.
[0130] Step S40: performing standardized structure conversion on the first sentence data to obtain a target standardized structure.
[0131] It should be noted that after the first statement data is filled into the preset standardized structure and a standardized structure object is generated, and then the standardized structure object is generated, each sub-statement node needs to be traversed. When there is no sub-statement identifier in each node, it means that each SQL statement has been parsed and the target standardized structure can be output. When there is a sub-statement identifier in each node, it means that there are SQL statements to be parsed, and the remaining SQL statements need to be completely parsed before the final standardized structure is output.
[0132] In a feasible implementation manner, the step S40 of converting the first sentence data into a standardized structure to obtain a target standardized structure includes:
[0133] Filling the first sentence data into a preset standardized structure to generate a standardized structure object;
[0134] After the SQL statements in all sub-statement nodes are parsed, the standardized structure object is traversed;
[0135] Determining whether a sub-statement identifier exists in the standardized structure object;
[0136] If it exists, locate the standardized structure position corresponding to the sub-statement identifier, and mount the structure object at the standardized structure position to the parent node corresponding to the sub-statement identifier;
[0137] When no sub-statement identifier exists in the standardized structure object, the target standardized structure is output.
[0138] Specifically, the first sentence data is converted into a standardized structure to obtain a flow chart of a target standardized structure as shown in FIG. Figure 5 As shown, the execution steps are as follows:
[0139] 1. According to the processed SQL statement set, all SQL statements are standardized and converted;
[0140] 2. According to the dialect type, determine the specific implementer of the SQL parser (this tool uses Antlr4 by default);
[0141] 3. Generate AST tree for SQL statements;
[0142] 4. Traverse the nodes according to the predefined standardized structure and extract relevant attribute content;
[0143] 5. Fill the attribute content into the standardized structure and generate a standardized structure object;
[0144] 6. After all SQL statements are processed, the SQL standardized structure is traversed;
[0145] 7. Determine whether there is a sub-statement identifier in the standardized structure;
[0146] 8. If it does not exist, output the final standardized structure;
[0147] 9. If it exists, locate the standardized structure of the corresponding sub-statement;
[0148] 10. Mount the standardized structure into the node of the parent statement;
[0149] 11. Repeat step 7 until all substatements are processed.
[0150] 12. The basic structure of the output needs to be further processed to supplement the common attributes, which is also a key step in generalization, such as:
[0151] 1. Alias attribution
[0152] 2. Field ownership
[0153] 3. Field source
[0154] 4. * Restore
[0155] 5. Other restoration
[0156] 13. Generate the final standardized structure.
[0157] In a feasible implementation manner, after the step S40 of converting the first sentence data into a standardized structure to obtain a target standardized structure, the following step further includes:
[0158] Obtain business scenario information;
[0159] It should be noted that the business scenario information is the business scenario required to be used by the target standardized structure. Different types of standardized structures need to be called according to different business scenarios.
[0160] Specifically, all SQL standard infrastructure is a SqlStatement (Sql statement object);
[0161] There are specific structures according to different SQL statements, and each structure has its own properties according to the characteristics of different SQL statements;
[0162] INSERT statements correspond to InsertStatement, SELECT statements correspond to SelectStatement, Update statements correspond to UpdateStatement, DELETE statements correspond to DeleteStatement, etc.;
[0163] Each SqlStatement can also be a property of each other;
[0164] Take Insert and Select statements as examples. The following are the corresponding key attributes: Figure 7 Shown
[0165] Specific SQL statements and related attributes can be expanded according to business characteristics and SQL characteristics.
[0166] Based on the business scenario information, converting the target standardized structure into a character string;
[0167] The statement object in the character string is converted into a target business object, so that relevant technical personnel can call the target business object based on the business scenario information.
[0168] It should be noted that after determining the business scenario of data usage, the standardized structure of SQL statements can be converted into corresponding objects according to the usage scenario, such as Java objects, JSON objects, or other structures. The specific structure object conversion process diagram is as follows Figure 8 shown.
[0169] First convert the SQL structure standardization object into a string;
[0170] Converts a SqlStatement object, converted into a string, to another target object.
[0171] The present application proposes a method, apparatus, device, storage medium and computer program product for parsing SQL statements. The present application receives SQL statement information to be processed and generates a syntax tree structure based on the SQL statement information, thereby converting the code into a tree structure representation of the code. When it is determined that there are nested statement nodes in the syntax data structure, the nested statement nodes are decomposed into multiple sub-statement nodes, and the node attributes of each sub-statement node are extracted to generate parsed first statement data. By introducing the statement decomposition step, simple SQL statements can be quickly parsed, and complex multi-layer nested SQL statements can be simplified into multiple simple SQL statements for parsing and extraction. Furthermore, the first statement data obtained after parsing is converted into a standardized structure to obtain the required target standardized structure, thereby improving the parsing efficiency of SQL statements.
[0172] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the SQL statement parsing method of the present application. More simple transformations based on this technical concept are all within the protection scope of the present application.
[0173] This application also provides a SQL statement parsing device, please refer to Fig. 9 , the SQL statement parsing device comprises:
[0174] The receiving module 10 is used to receive SQL statement information to be processed and generate a syntax tree structure based on the SQL statement information;
[0175] A disassembly module 20, configured to disassemble the nested statement node to obtain a plurality of sub-statement nodes when determining that there is at least one nested statement node in the syntax tree structure;
[0176] An extraction module 30, used to extract node attributes of each of the sub-statement nodes to obtain parsed first statement data;
[0177] The first conversion module 40 is used to perform standardized structure conversion on the first sentence data to obtain a target standardized structure.
[0178] Optionally, the disassembly module includes:
[0179] A determination unit, used to determine a node position corresponding to a sub-statement node in the nested statement node;
[0180] A first generating unit, configured to generate a plurality of sub-statement identifiers based on each of the sub-statement nodes;
[0181] A separation unit is used to separate each of the sub-statement nodes and replace the sub-statement identifier at the node position, and when it is determined that there is no sub-statement with a nested relationship in each of the sub-statement nodes, multiple sub-statement nodes are extracted.
[0182] Optionally, the receiving module includes:
[0183] A decomposition unit, used for performing grammatical decomposition on the SQL statement information to obtain multiple lexical units;
[0184] The conversion unit is used to convert each of the lexical units into a syntax tree structure through a preset syntax analyzer.
[0185] Optionally, the extraction module includes:
[0186] An extraction module, used to traverse each sub-statement node according to a preset standardized structure and extract attribute content in each sub-statement node;
[0187] The integration module is used to integrate the attribute content to obtain the parsed first sentence data.
[0188] Optionally, the first conversion module includes:
[0189] A second generating unit, used for filling the first sentence data into a preset standardized structure to generate a standardized structure object;
[0190] A traversal unit, used for traversing the standardized structure object after the SQL statements in all sub-statement nodes are parsed;
[0191] A judging unit, used for judging whether a sub-statement identifier exists in the standardized structure object;
[0192] A mounting unit, for locating the standardized structure position corresponding to the sub-statement identifier, if it exists, and mounting the structure object at the standardized structure position to the parent node corresponding to the sub-statement identifier;
[0193] The output unit is used to output the target standardized structure until there is no sub-statement identifier in the standardized structure object.
[0194] Optionally, the device further comprises:
[0195] Acquisition module, used to obtain business scenario information;
[0196] A second conversion module, configured to convert the target standardized structure into a character string based on the business scenario information;
[0197] The third conversion module is used to convert the sentence object in the character string into a target business object, so that relevant technical personnel can call the target business object based on the business scenario information.
[0198] The SQL statement parsing device provided by the present application adopts the SQL statement parsing method in the above embodiment, and can solve the technical problem of SQL statement parsing. Compared with the prior art, the beneficial effects of the SQL statement parsing device provided by the present application are the same as the beneficial effects of the SQL statement parsing method provided by the above embodiment, and other technical features in the SQL statement parsing device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0199] The present application provides a SQL statement parsing device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the SQL statement parsing method in the above-mentioned embodiment 1.
[0200] Reference below Fig.10 , which shows a schematic diagram of the structure of a SQL statement parsing device suitable for implementing the embodiment of the present application. The SQL statement parsing device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig.10 The SQL statement parsing device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0201] like Fig.10As shown, the SQL statement parsing device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the SQL statement parsing device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the SQL statement parsing device to communicate wirelessly or wired with other devices to exchange data. Although the figure shows a SQL statement parsing device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or provided instead.
[0202] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0203] The SQL statement parsing device provided by the present application adopts the SQL statement parsing method in the above embodiment, which can solve the technical problem of SQL statement parsing. Compared with the prior art, the beneficial effects of the SQL statement parsing device provided by the present application are the same as the beneficial effects of the SQL statement parsing method provided by the above embodiment, and other technical features in the SQL statement parsing device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0204] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0205] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0206] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the SQL statement parsing method in the above-mentioned embodiment.
[0207] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0208] The computer-readable storage medium may be included in the SQL statement parsing device; or may exist independently without being assembled into the SQL statement parsing device.
[0209] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the SQL statement parsing device, the SQL statement parsing device:
[0210] Receive SQL statement information to be processed, and generate a syntax tree structure based on the SQL statement information;
[0211] When it is determined that there is at least one nested statement node in the syntax tree structure, the nested statement node is disassembled to obtain a plurality of sub-statement nodes;
[0212] Extracting node attributes of each of the sub-statement nodes to obtain parsed first statement data;
[0213] The first sentence data is converted into a standardized structure to obtain a target standardized structure.
[0214] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0215] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0216] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0217] The readable storage medium provided in the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned SQL statement parsing method, and can solve the technical problem of SQL statement parsing. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the present application are the same as the beneficial effects of the SQL statement parsing method provided in the above-mentioned embodiment, and will not be repeated here.
[0218] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned SQL statement parsing method when executed by a processor.
[0219] The computer program product provided by this application can solve the technical problem of SQL statement parsing. Compared with the prior art, the beneficial effects of the computer program product provided by this application are the same as the beneficial effects of the SQL statement parsing method provided by the above embodiment, which will not be repeated here.
[0220] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A SQL statement parsing method, characterized in that: The method comprises: Receive SQL statement information to be processed, and generate a syntax tree structure based on the SQL statement information; When it is determined that there is at least one nested statement node in the syntax tree structure, the nested statement node is disassembled to obtain a plurality of sub-statement nodes; Extracting node attributes of each of the sub-statement nodes to obtain parsed first statement data; The first sentence data is converted into a standardized structure to obtain a target standardized structure.
2. The method according to claim 1, characterized in that The step of disassembling the nested statement node to obtain a plurality of sub-statement nodes includes: Determine a node position corresponding to a sub-statement node in the nested statement node; Based on each of the sub-statement nodes, generate a plurality of sub-statement identifiers; Each of the sub-statement nodes is separated, and the sub-statement identifier is replaced at the node position. When it is determined that there is no sub-statement with a nested relationship in each of the sub-statement nodes, a plurality of sub-statement nodes are extracted.
3. The method according to claim 1, characterized in that The step of generating a syntax tree structure based on the SQL statement information includes: Performing grammatical decomposition on the SQL statement information to obtain multiple lexical units; Each of the lexical units is converted into a grammar tree structure through a preset grammar analyzer.
4. The method according to any one of claims 1 to 3, characterized in that The step of extracting the node attributes of each of the sub-statement nodes to obtain the parsed first statement data includes: Traverse each sub-statement node according to the preset standardized structure, and extract the attribute content in each sub-statement node; The attribute contents are integrated to obtain parsed first sentence data.
5. The method according to claim 1, characterized in that The step of converting the first sentence data into a standardized structure to obtain a target standardized structure includes: Filling the first sentence data into a preset standardized structure to generate a standardized structure object; After the SQL statements in all sub-statement nodes are parsed, the standardized structure object is traversed; Determining whether a sub-statement identifier exists in the standardized structure object; If it exists, locate the standardized structure position corresponding to the sub-statement identifier, and mount the structure object at the standardized structure position to the parent node corresponding to the sub-statement identifier; When no sub-statement identifier exists in the standardized structure object, the target standardized structure is output.
6. The method according to claim 1, characterized in that After the step of converting the first sentence data into a standardized structure to obtain a target standardized structure, the method further includes: Obtain business scenario information; Based on the business scenario information, converting the target standardized structure into a character string; The statement object in the character string is converted into a target business object, so that relevant technical personnel can call the target business object based on the business scenario information.
7. A SQL statement parsing device, characterized in that: The device comprises: A receiving module, used for receiving SQL statement information to be processed, and generating a syntax tree structure based on the SQL statement information; A disassembly module, configured to disassemble the nested statement node to obtain a plurality of sub-statement nodes when determining that there is at least one nested statement node in the syntax tree structure; An extraction module, used to extract node attributes of each of the sub-statement nodes to obtain parsed first statement data; The first conversion module is used to perform standardized structure conversion on the first sentence data to obtain a target standardized structure.
8. A SQL statement parsing device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the SQL statement parsing method according to any one of claims 1 to 6.
9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the SQL statement parsing method according to any one of claims 1 to 6 are implemented.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the SQL statement parsing method according to any one of claims 1 to 6 are implemented.