Structured query statement identification method and device based on feature expression
By generating and matching syntax trees based on feature expressions, the problem of the inability to effectively identify structured query statements with logical associations in the prior art is solved, which improves query efficiency and supports the identification of complex logical associations.
Patent Information
- Application Number
- CN202110889338.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-04
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2041-08-04
AI Technical Summary
The prior art cannot effectively identify structured query statements with logical associations, resulting in inefficient query in massive data environments.
A feature expression-based method is adopted to generate a query statement syntax tree set and feature syntax tree by receiving statement identification requests, and a backtracking path search algorithm is used to match to determine whether there is a structured query statement that satisfies the preset logical association relationship.
It realizes effective identification of structured query statements with logical association relationships, improves query efficiency, and supports complex logical association relationships and context logic screening.
Smart Images

Figure CN113590650B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of big data technology, and in particular to a method and device for identifying structured query statements based on feature expressions. Background Art
[0002] In a massive data environment, users use structured query statements to associate multiple data tables, filter data through operations such as filtering, merging, difference, and projection, and obtain the result data required by users after a series of complex calculations and statistics on multiple fields. In existing user query scenarios, complex statistical requirements will generate complex and lengthy query statements. Such statements have poor execution plans and low operating efficiency after submission and execution, affecting the overall efficiency of the system.
[0003] Therefore, it is necessary to identify such statements before the system entry and intercept them. In the existing methods of matching by keywords or regular expressions, there is no logical association between multiple keywords, and it is impossible to complete the selection with logical association such as "when condition A appears, condition B does not appear, and condition C appears in the subquery".
[0004] To address the above problems, no effective solution has been proposed yet. Summary of the invention
[0005] The embodiments of the present specification provide a method and device for identifying structured query statements based on feature expressions to solve the problem in the prior art that structured query statements with logical associations cannot be identified.
[0006] The embodiment of the present specification provides a method for identifying structured query statements based on feature expressions, including: receiving a statement identification request, wherein the statement identification request carries a feature expression and a set of structured query statements to be identified, the set of structured query statements includes at least one structured query statement, and the feature expression contains a preset logical association relationship used to identify the structured query statements; based on the set of structured query statements, generating a corresponding set of query statement syntax trees; based on the feature expression, generating a corresponding feature syntax tree; matching the query statement syntax tree set with the feature syntax tree to determine whether there is a structured query statement that satisfies the preset logical association relationship in the query statement syntax tree set.
[0007] In one embodiment, based on the structured query statement set, a corresponding query statement syntax tree set is generated, including: dividing each structured query statement in the at least one structured query statement into an ordered array according to words, and obtaining an ordered array corresponding to each structured query statement, wherein the ordered array includes the words obtained by the segmentation, and the index of the ordered array represents the index position of the word obtained by the segmentation in the structured query statement; based on the grammatical rules of the structured query language, the ordered array corresponding to each structured query statement is arranged into a query statement syntax tree, and the query statement syntax tree corresponding to each structured query statement is obtained.
[0008] In one embodiment, based on the grammatical rules of the structured query language, the ordered arrays corresponding to the structured query statements are arranged into a query statement grammar tree, including: starting from the initial index position of the ordered array, extracting the current word and its context in turn, matching the extracted current word and its context with the grammar rules, and if the match is successful, taking the current word and its context as a node, and continuing to match, the matched object is the subtree of the current node, and moving the index to the end of the context, if there is no match, the index moves to the next word, and when the index moves to the end of the queue, repeating the rematch from the head of the queue until the top-level grammar is matched, and outputting the corresponding query statement grammar tree.
[0009] In one embodiment, generating a corresponding feature syntax tree based on the feature expression includes: dividing the feature expression into an ordered array by words; and arranging the ordered array into a feature syntax tree corresponding to the feature expression based on a logical operator grammar.
[0010] In one embodiment, based on the logical operator grammar, the ordered array is arranged into a feature syntax tree corresponding to the feature expression, including: when the preset logical association relationship includes an AND operation, multiple conditions in the preset logical association relationship are merged into a tree; when the preset logical association relationship includes an OR operation, different sibling relationship subtrees are formed between the multiple conditions in the preset logical association relationship, and then a feature syntax tree is formed through recursion.
[0011] In one embodiment, matching the query statement syntax tree set with the characteristic syntax tree includes: matching the query statement syntax tree set with the characteristic syntax tree using a backtracking path search algorithm.
[0012] In one embodiment, after matching the query statement syntax tree set with the feature syntax tree to determine whether there is a structured query statement that satisfies the preset logical association relationship in the query statement syntax tree set, the method further includes: when it is determined that there is a structured query statement that satisfies the preset logical association relationship in the query statement syntax tree set, generating a text statement according to the syntax tree in the matching result.
[0013] The embodiments of the present specification also provide a structured query statement identification device based on a feature expression, comprising: a receiving module, used to receive a statement identification request, wherein the statement identification request carries a feature expression and a structured query statement set to be identified, the structured query statement set includes at least one structured query statement, and the feature expression contains a preset logical association relationship used to identify the structured query statement; a generating module, used to generate a corresponding query statement syntax tree set based on the structured query statement set; and also used to generate a corresponding feature syntax tree based on the feature expression; a matching module, used to match the query statement syntax tree set with the feature syntax tree to determine whether there is a structured query statement that satisfies the preset logical association relationship in the query statement syntax tree set.
[0014] An embodiment of the present specification also provides a computer device, including a processor and a memory for storing processor executable instructions, wherein when the processor executes the instructions, the steps of the structured query statement identification method based on feature expressions described in any of the above embodiments are implemented.
[0015] The embodiments of this specification also provide a computer-readable storage medium on which computer instructions are stored. When the instructions are executed, the steps of the method for identifying structured query statements based on feature expressions described in any of the above embodiments are implemented.
[0016] In an embodiment of the present specification, a method for identifying structured query statements based on feature expressions is provided, and a server can receive a statement identification request sent by a client. Among them, the statement identification request can carry a feature expression and a set of structured query statements to be identified. The structured query statement set can include at least one structured query statement. The feature expression can include a preset logical association relationship used to identify the structured query statement. The server can generate a corresponding query statement syntax tree set based on the structured query statement set. The server can also generate a corresponding feature syntax tree based on the feature expression. Afterwards, the server can match the query statement syntax tree set with the feature syntax tree to determine whether there is a structured query statement that meets the preset logical association relationship in the query statement syntax tree set, and return the matching result to the user end. In the above scheme, the feature expression is translated into a feature syntax tree using the normative consistency of the syntax tree, and each query statement in the structured query statement set is translated into a query statement syntax tree. Afterwards, the query statement syntax tree is iterated and traversed using the feature syntax tree for matching, so as to determine whether there is a structured query statement that meets the preset logical association relationship in the structured query statement set. Equivalent to the traditional screening scheme using constant expressions, the above scheme can expand the screening scope and can add logical expressions such as "and", "or", and "not", so that statements with logical associations can be identified. In addition, contextual logic screening between different query statements in a structured query statement set can be performed, which is more flexible than the traditional method and can combine complex expressions to identify more complex logical associations. At the same time, the use of feature expressions is flexible, and composite features and context-related features can be combined. All clauses can be iteratively nested to identify, and the position of clauses that meet the features in the original structured query statement can be accurately located. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The drawings described herein are used to provide a further understanding of this specification, constitute a part of this specification, and do not constitute a limitation of this specification. In the drawings:
[0018] Figure 1 A flowchart of a method for identifying structured query statements based on feature expressions in an embodiment of this specification is shown;
[0019] Figure 2 A schematic diagram of a structured query sentence identification device based on a feature expression in an embodiment of this specification is shown;
[0020] Figure 3 A schematic diagram of a structured query parser function module in an embodiment of this specification is shown;
[0021] Figure 4A schematic diagram of a feature expression parser function module in an embodiment of this specification is shown;
[0022] Figure 5 A schematic diagram of a feature finder functional module in an embodiment of this specification is shown;
[0023] Figure 6 A flowchart of a method for identifying structured query statements based on feature expressions in an embodiment of this specification is shown;
[0024] Figure 7 A schematic diagram of a computer device in an embodiment of the present specification is shown. DETAILED DESCRIPTION
[0025] The principles and spirit of this specification will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided only to enable those skilled in the art to better understand and implement this specification, and are not intended to limit the scope of this specification in any way. On the contrary, these embodiments are provided to make this specification more thorough and complete, and to fully convey the scope of this disclosure to those skilled in the art.
[0026] Those skilled in the art will appreciate that the embodiments of this specification may be implemented as a system, device, method, or computer program product. Therefore, this specification may be implemented in the following forms: complete hardware, complete software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.
[0027] The embodiments of this specification provide a method for identifying structured query statements based on feature expressions. In a scenario example of this specification, a server may receive a statement identification request sent by a client. Among them, the statement identification request may carry a feature expression and a set of structured query statements to be identified. The structured query statement set may include at least one structured query statement. The feature expression may include a preset logical association relationship used to identify the structured query statement. The server may generate a corresponding query statement syntax tree set based on the structured query statement set. The server may also generate a corresponding feature syntax tree based on the feature expression. Afterwards, the server may match the query statement syntax tree set with the feature syntax tree to determine whether there is a structured query statement that satisfies the preset logical association relationship in the query statement syntax tree set, and return the matching result to the user end.
[0028] Figure 1A flowchart of a method for identifying structured query statements based on feature expressions in an embodiment of this specification is shown. Although this specification provides method operation steps or device structures as shown in the following embodiments or drawings, more or fewer operation steps or module units may be included in the method or device based on routine or no creative labor. In steps or structures where there is no necessary causal relationship logically, the execution order of these steps or the module structure of the device is not limited to the execution order or module structure described in the embodiments of this specification and shown in the drawings. When the method or module structure is applied to an actual device or terminal product, it can be connected according to the method or module structure shown in the embodiments or drawings for sequential execution or parallel execution (for example, a parallel processor or a multi-threaded processing environment, or even a distributed processing environment).
[0029] Specifically, Figure 1 As shown, a method for identifying structured query statements based on feature expressions provided in one embodiment of this specification may include the following steps:
[0030] Step S101, receiving a statement identification request, wherein the statement identification request carries a feature expression and a set of structured query statements to be identified, the set of structured query statements includes at least one structured query statement, and the feature expression contains a preset logical association relationship used to identify the structured query statement.
[0031] The method in the embodiments of this specification can be applied to a server. The server can be a single server, a server cluster, or a cloud server, etc. The specific composition is not limited in this application.
[0032] The server may receive a statement identification request. The statement identification request may carry a feature expression and a structured query statement set to be identified. The structured query statement set may include at least one structured query statement. The feature expression may include a preset logical association relationship used to identify the structured query statement. The preset logical association relationship may include at least one of the following: and, or, not.
[0033] Step S102: Generate a corresponding query statement syntax tree set based on the structured query statement set; and generate a corresponding feature syntax tree based on the feature expression.
[0034] In response to the received statement identification request, the server can generate a corresponding query statement syntax tree set based on each structured query statement in the structured query statement set. The query statement syntax tree set can include query statement syntax trees corresponding to each structured query statement. The server can also generate a feature syntax tree corresponding to the feature expression based on the feature expression. Among them, the syntax tree is a graphical representation of the sentence structure, which represents the derivation result of the sentence and facilitates understanding of the hierarchy of the sentence grammatical structure. That is, the syntax tree is a tree formed when deducing according to a certain rule.
[0035] Step S103: Match the query statement syntax tree set with the characteristic syntax tree to determine whether there is a structured query statement satisfying the preset logical association relationship in the query statement syntax tree set.
[0036] After generating the query statement syntax tree set and the feature syntax tree, the query statement syntax tree set and the feature syntax tree can be matched to determine whether there is a structured query statement satisfying the preset logical association relationship in the query statement syntax tree set, thereby identifying the structured query statement satisfying the relationship.
[0037] The query statement identification method in the above embodiment is equivalent to the traditional identification scheme using constant expressions, which can expand the identification scope and add logical expressions such as "and", "or", and "not", so that statements with logical associations can be identified. In addition, contextual logic identification between different query statements in a structured query statement set can also be performed, which is more flexible than the traditional method and can combine complex expressions to identify more complex logical associations. At the same time, the use of feature expressions is flexible, and composite features and context-related features can be combined. All clauses can be iteratively nested to identify, and the position of the clauses that meet the features in the original structured query statement can also be accurately located.
[0038] In some embodiments of the present specification, generating a corresponding query statement syntax tree set based on the structured query statement set may include: segmenting each structured query statement in the at least one structured query statement into an ordered array according to words, and obtaining an ordered array corresponding to each structured query statement, wherein the ordered array may include the segmented words, and the index of the ordered array represents the index position of the segmented words in the structured query statement; based on the grammatical rules of the structured query language, arranging the ordered arrays corresponding to the structured query statements into a query statement syntax tree, and obtaining the query statement syntax tree corresponding to each structured query statement.
[0039] For each structured query statement in the structured query statement set, the structured query statement can be first segmented by words to form an ordered array, thereby obtaining an ordered array corresponding to each structured query statement. Each element in the ordered data is a word obtained by segmentation. The index of the ordered array represents the index position of the segmented word in the structured query statement. Afterwards, the ordered array corresponding to each structured query statement can be arranged into a query statement syntax tree based on the grammatical rules of the structured query language. Among them, the grammatical rules of the structured query language refer to the structured query language corresponding to the structured query statements in the structured query statement set. The generated query statement syntax tree can carry the index position information of each word.
[0040] The syntax rules of structured data query language may include the following: (1) DDL (Data Definition Language), including create, drop, alter and other statements that can change the table structure; (2) DQL (Data Definition Language), which may include commonly used query statements, select is the most commonly used DQL verb, and other commonly used DQL reserved words include where, order by, group by and having. These DQL reserved words are often used with other types of SQL statements; (3) DML (Data Manipulation Language), which may include the commonly used operations of adding (insert), deleting (delete) and modifying (update) in database tables; (4) DCL (Data Control Language), which may implement permission control through grant (authorization) or revoke (cancel) to determine the access of individual users and user groups to database objects; (5) TCL (Transaction Control Language) (6) CCL (Cursor Control Language), whose statements can ensure that all rows of the table affected by the DML statement are updated in a timely manner, including commit commands, savepoint commands, and rollback commands; (6) CCL (Cursor Control Language).
[0041] In some embodiments of the present specification, based on the grammatical rules of the structured query language, the ordered arrays corresponding to the structured query statements are arranged into a query statement syntax tree, which may include: starting from the initial index position of the ordered array, extracting the current word and its context in turn, matching the extracted current word and its context with the grammatical rules, and if the match is successful, taking the current word and its context as a node, and continuing to match, the matched object is the subtree of the current node, and moving the index to the end of the context, if there is no match, the index moves to the next word, and when the index moves to the end of the queue, repeating the rematch from the head of the queue until the top-level syntax is matched, and outputting the corresponding query statement syntax tree.
[0042] Specifically, the server can start from the initial index position of the ordered array, take out the current word and its context in turn, and match them with the grammar rules. If they match, the current word and its context are a node, and the matched object is the subtree of the current node. The index moves to the end of the context. If there is no match, the index moves to the next word. When the index moves to the end of the team, it repeats from the head of the team until the top-level grammar is matched. Among them, each node of the grammar tree represents a clause in the statement, and the node contains the index position information of this clause. In the above way, the query statement grammar tree corresponding to each structured query statement can be generated.
[0043] In some embodiments of the present specification, generating a corresponding feature syntax tree based on the feature expression may include: dividing the feature expression into an ordered array by words; and arranging the ordered array into a feature syntax tree corresponding to the feature expression based on a logical operator grammar.
[0044] Specifically, in order to generate a feature syntax tree corresponding to a feature expression, the server may first segment the feature expression according to words to obtain an ordered array. The elements in the ordered array are the words obtained by segmentation, and the index of the ordered array is the position of the words obtained by segmentation in the feature expression. Afterwards, the server may arrange the ordered array into a feature syntax tree corresponding to the feature expression based on the logical operator grammar. In the above manner, a feature syntax tree corresponding to the feature expression may be obtained.
[0045] In some embodiments of the present specification, based on the logical operator grammar, the ordered array is arranged into a feature syntax tree corresponding to the feature expression, which may include: when the preset logical association relationship can include an AND operation, multiple conditions in the preset logical association relationship are merging into a tree; when the preset logical association relationship can include an OR operation, different sibling relationship subtrees are formed between the multiple conditions in the preset logical association relationship, and then a feature syntax tree is formed through recursion.
[0046] Specifically, the feature expression also has a structured feature. First, the expression is split into a set of ordered arrays by word. After the expression is split, the ordered arrays are arranged into an expression syntax tree in combination with the logical operator syntax. If it is an AND operation, all expressions are merged into a tree. If it is an OR operation, different sibling relationship subtrees are formed between the conditions, and an expression tree is recursively formed. In the above way, the ordered array can be arranged into a syntax tree corresponding to the feature expression.
[0047] In some embodiments of the present specification, matching the query statement syntax tree set with the characteristic syntax tree may include: matching the query statement syntax tree set with the characteristic syntax tree using a backtracking path search algorithm.
[0048] Specifically, after processing, a query statement syntax tree set and a feature syntax tree can be obtained. Among them, the query statement syntax tree set stores query statement syntax trees in order, wherein each syntax tree contains an ordered set of sub-statements in the statement, and each sub-statement has a matching feature and is matchable. The feature syntax tree is a matching condition. The server can use a backtracking path search algorithm to match the query statement syntax tree set with the feature syntax tree. After each feature is matched according to the tree path, the path is cached. When a logical operator is encountered, the matched cached path is backtracked, and a new match is performed according to the logic and new features. When all matches are met, it is a full match, otherwise it is backtracked to the starting point, and the next syntax subtree is taken for matching, and repeated until all syntax subtrees are matched. In the above manner, the matching between the query statement syntax tree set and the feature syntax tree can be achieved, so as to determine whether there is a query statement that meets the preset logical association relationship.
[0049] In some embodiments of the present specification, after matching the query statement syntax tree set with the feature syntax tree to determine whether there is a structured query statement that satisfies the preset logical association relationship in the query statement syntax tree set, it may also include: when it is determined that there is a structured query statement that satisfies the preset logical association relationship in the query statement syntax tree set, generating a text statement according to the syntax tree in the matching result.
[0050] Specifically, after matching, if it is determined that there is a structured query statement that satisfies the preset logical association relationship in the query statement syntax tree set, a text statement is generated according to the syntax tree in the matching result. Inflow, a clause matching the feature expression can be generated, that is, the subtrees of the tree structure are reversely obtained in sequence to obtain literal values, and the text statement is reconstructed for result return.
[0051] In some embodiments of the present specification, the feature expression may include a context feature expression and / or a single sentence feature expression. Among them, the context feature expression may include keywords such as before and after. When the feature expression is a context feature expression, the query statement syntax tree corresponding to each structured query statement in the structured query statement set is matched with the syntax tree corresponding to the feature expression, so that the context logic discrimination between different query statements in the structured query statement set can be realized. When the feature expression is a document expression, matching can be performed inside the syntax tree of each query statement, and the position of the clause that meets the feature in the original structured query statement can be accurately located. For the context feature expression, if the preset logical association relationship is met, multiple query statements that meet the conditions are returned to the client. For the document feature expression, if the preset logical association relationship is met, at least one clause that meets the conditions can be returned to the client. The feature expression may also include a combination of the context feature expression and the document feature expression.
[0052] Based on the same inventive concept, a structured query statement identification device based on a feature expression is also provided in the embodiments of this specification, as described in the following embodiments. Since the principle of solving the problem by the structured query statement identification device based on a feature expression is similar to that of the structured query statement identification method based on a feature expression, the implementation of the structured query statement identification device based on a feature expression can refer to the implementation of the structured query statement identification method based on a feature expression, and the repeated parts will not be repeated. As used below, the term "unit" or "module" can be a combination of software and / or hardware that implements predetermined functions. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable. Figure 2 is a structural block diagram of a structured query statement identification device based on a feature expression according to an embodiment of the present specification, such as Figure 2 As shown, it may include: a receiving module 201, a generating module 202 and a matching module 203, and the structure is described below.
[0053] The receiving module 201 is used to receive a statement identification request, wherein the statement identification request carries a feature expression and a set of structured query statements to be identified, the set of structured query statements may include at least one structured query statement, and the feature expression contains a preset logical association relationship used to identify the structured query statement.
[0054] The generating module 202 is used to generate a corresponding query statement syntax tree set based on the structured query statement set; and is also used to generate a corresponding feature syntax tree based on the feature expression.
[0055] The matching module 203 is used to match the query statement syntax tree set with the characteristic syntax tree to determine whether there is a structured query statement that satisfies the preset logical association relationship in the query statement syntax tree set.
[0056] In some embodiments of the present specification, the generation module can be specifically used to: segment each structured query statement in the at least one structured query statement into an ordered array according to words, and obtain an ordered array corresponding to each structured query statement, wherein the ordered array may include the segmented words, and the index of the ordered array represents the index position of the segmented words in the structured query statement; based on the grammatical rules of the structured query language, arrange the ordered arrays corresponding to the each structured query statement into a query statement syntax tree, and obtain the query statement syntax tree corresponding to each structured query statement.
[0057] In some embodiments of the present specification, based on the grammatical rules of the structured query language, the ordered arrays corresponding to the structured query statements are arranged into a query statement syntax tree, which may include: starting from the initial index position of the ordered array, extracting the current word and its context in turn, matching the extracted current word and its context with the grammatical rules, and if the match is successful, taking the current word and its context as a node, and continuing to match, the matched object is the subtree of the current node, and moving the index to the end of the context, if there is no match, the index moves to the next word, and when the index moves to the end of the queue, repeating the rematch from the head of the queue until the top-level syntax is matched, and outputting the corresponding query statement syntax tree.
[0058] In some embodiments of the present specification, the generation module may be specifically used to: divide the feature expression into an ordered array by words; and arrange the ordered array into a feature syntax tree corresponding to the feature expression based on a logical operator syntax.
[0059] In some embodiments of the present specification, based on the logical operator grammar, the ordered array is arranged into a feature syntax tree corresponding to the feature expression, which may include: when the preset logical association relationship can include an AND operation, multiple conditions in the preset logical association relationship are merging into a tree; when the preset logical association relationship can include an OR operation, different sibling relationship subtrees are formed between the multiple conditions in the preset logical association relationship, and then a feature syntax tree is formed through recursion.
[0060] In some embodiments of the present specification, the matching module may be specifically used to: match the query statement syntax tree set with the feature syntax tree using a backtracking path search algorithm.
[0061] In some embodiments of the present specification, the device may further include a result generation module, which is used to: when it is determined that there is a structured query statement satisfying the preset logical association relationship in the query statement syntax tree set, generate a text statement according to the syntax tree in the matching result.
[0062] The above method is described below in conjunction with a specific embodiment. However, it should be noted that the specific embodiment is only for better illustrating the present specification and does not constitute an improper limitation on the present specification.
[0063] Please refer to Figures 3 to 6 , showing the schematic diagram of the structured query statement identification device and method based on feature expressions in this specific embodiment. The statement identification device in this specific embodiment can receive two inputs, the first input is a batch structured query statement set to be identified, the set includes one or more structured query statements; the second input is a feature expression, including a conditional expression used to identify the statement, which is an associated logical expression of one or more conditions.
[0064] In this specific embodiment, the statement identification device can be a structured query statement parser ( Figure 3 ), feature expression parser ( Figure 4 ) and Feature Finder ( Figure 5 )composition.
[0065] Please refer to Figure 3 , shows a schematic diagram of the functional modules of a structured query parser in an embodiment of this specification. Figure 3 As shown, in view of the structured characteristics of the structured query statement, the word segmentation module 301 segments the statement into a set of ordered arrays by word, and the index of the ordered array represents the index position of the word in the statement.
[0066] After word segmentation is completed, the syntax tree parsing module 302 arranges the ordered array into a query statement syntax tree in combination with the syntax of the structured query statement. The specific process can be to start from the initial index position of the ordered array, take out the current word and its context in turn, match it with the grammar rule, if it matches, the current word and its context are a node, and the matched object is the subtree of the current node, and the index moves to the end point of the following, if there is no match, the index moves to the next word, and when the index moves to the end of the team, it repeats from the head of the team until it matches the top-level syntax. Wherein, each node of the syntax tree represents a clause in the sentence, and the node contains the index position information of this clause.
[0067] Feature expressions also have structured properties and can generate feature syntax trees. Figure 4 , shows a schematic diagram of the functional module of the feature expression parser in one embodiment of this specification. Figure 4As shown, the expression segmentation module 401 can segment the expression into a set of ordered arrays by words.
[0068] After the expression segmentation is completed, the expression parsing module 402 can combine the logical operator syntax to arrange the ordered array into an expression syntax tree. If it is an AND operation, all expressions are merged into one tree. If it is an OR operation, different sibling relationship subtrees are formed between the conditions, and an expression tree is recursively formed.
[0069] Please refer to Figure 5 , showing a schematic diagram of the feature finder functional module in an embodiment of the present specification. After being processed by the structured query statement parser and the feature expression parser, two intermediate results are obtained. Intermediate result one is a set of structured query statement syntax trees, in which the structured query statement syntax trees are stored in order, each of which contains an ordered set of sub-statements in the statement, and each sub-statement has a matchable feature and is matchable. Intermediate result two is a feature expression syntax tree, and the expression syntax tree is a matching condition.
[0070] Feature matching can be performed using a backtracking path search algorithm. Each time a feature is matched according to the tree path, the path is cached. When a logical operator is encountered, the matched cached path is backtracked and a new match is performed according to the logic and new features. If all matches are met, it is a complete match. Otherwise, it backtracks to the starting point and takes the next grammar subtree for matching. Repeat until all grammar subtrees are matched. Figure 5 As shown, the iterative traversal module 501 performs the iterative traversal process. The matching search module 502 performs the matching of each node. The merging clause module 503 is used to generate a return result after the matching is successful.
[0071] Please refer to Figure 6 , which shows a flow chart of a method for identifying structured query statements based on feature expressions in an embodiment of this specification. Figure 6 As shown, a syntax tree can be obtained from the structured query statement syntax tree set in sequence ( Figure 6 601 in ). Get the next node of the syntax tree of the statement in index order, starting with the first node ( Figure 6 602 in ). Get the next node of the expression syntax tree in index order, starting with the first node ( Figure 6 603 in ). The clause represented by the sentence syntax tree node is matched with the node in the feature expression syntax tree. If the attribute values of the clause node and the feature node are the same, they are considered matched. Figure 6 If the match is successful, it means that the feature in the feature expression is hit, and the next node of the feature expression is obtained repeatedly ( Figure 6603 in the example), and obtain the position and logical relationship of the feature condition. According to the position and logical relationship, obtain the next node from the syntax tree ( Figure 6 605 in ). Repeat the matching step ( Figure 6 604 in ). If it matches, the nodes of the feature expression are obtained in turn to perform the above operations until all nodes are matched, indicating that the feature expression is completely matched. At this time, a clause matching the feature expression can be generated, that is, the subtrees of the tree structure are reversely obtained in order to obtain the literal values, and the text sentences are reconstructed and used for result return ( Figure 6 606 in ). If all nodes have been traversed and cannot be matched during the process, the feature expression cannot be matched ( Figure 6 607 in ). If no match is found, backtrack to the previous syntax tree index node to get the next node and restart the matching of the feature expression ( Figure 6 602 in the above). Get the next syntax tree from the structured query statement syntax tree set in order and repeat the above steps ( Figure 6 601 in the figure). The iterative traversal process is the iterative traversal module 501, the matching of each node is the matching search module 502, and the return result after the match is successful is the merge clause module 503. The specific matching flow chart is shown in Figure 6 shown.
[0072] The following example illustrates a method for identifying structured query statements based on feature expressions. In this specific embodiment, the structured query statement set includes the following two statements:
[0073] delete from t1 where t1.date='2020-05-01';
[0074] insert into t1(c1,c2,date)select t2.c1,t2.c2,t3.date from t2 join t3on(t1.k1=t2.k1)where t3.date='2020-05-01';
[0075] The feature expression is a combination of the context feature expression and the single sentence feature expression:
[0076] dml:insert after dml:delte&date='2020-05-01'
[0077] First, convert the structured query statement set into a structured query statement syntax tree set:
[0078]
[0079]
[0080] Then, convert the feature expression into an expression syntax tree:
[0081] express->dml:insert
[0082] ->keyword:after
[0083] ->dml:delete
[0084] operator:and
[0085] express->identify:date
[0086] ->operator:=
[0087] => value:2020-05-01
[0088] Next, matching is performed. The matching process is as follows:
[0089] Take out the first syntax node dml:delete, take out the first expression node dml:insert, the attribute values are different, there is no match, and so on until dml:insert, the attribute values are the same, a match occurs, take out the next expression node, the keyword after, indicates that it is necessary to trace back to after the initial node and before the current match, take out the first syntax node dml:delete of the next statement, take out the next expression node dml:delete, the attribute values are the same, a match occurs, the syntax node traces back to the starting point, take out the next expression node, the logical operator and, indicates that all matched nodes are traced back to match new conditions, take out the first matched node dml:insert, take out the next expression node identify:date, no match occurs, recurse to the next node until where In the identify:t3.date clause, the attribute values are the same, a match occurs, take the next syntax node operator:=, take the next expression node operator:=, the attribute values are the same, a match occurs, take the next syntax node value:2021-05-01, take the next expression node value:2021-05-01, the attribute values are the same, a match occurs, the expression has reached the end of the queue, take the first node dml:delete of the second match again, take the expression node from the head of the expression queue to start matching again, the process is the same as the matching of the first expression, and finally all are matched, and the matched syntax expression is returned.
[0090] In this specific embodiment, the standard consistency of the syntax tree is utilized to translate the feature expression into a feature syntax tree, and the syntax tree of the structured query statement is iteratively traversed. On the basis of the traditional identification using constant expressions, the identification scope is expanded, and logical expressions such as "and", "or", and "not" can be added. Contextual logic identification between different statements in a batch set can also be performed, which is more flexible than the traditional method and can combine complex expressions. The feature expression is flexible to use and can combine composite features and context-related features. All clauses can be iteratively nested and identified. The position of the clause that meets the feature in the original structured query statement can be accurately located.
[0091] From the above description, it can be seen that the embodiments of the present specification achieve the following technical effects: it is equivalent to the traditional screening scheme using constant expressions, the screening scope can be expanded, and logical expressions such as "and", "or", and "not" can be added to enable the screening of statements with logical associations; in addition, contextual logic screening between different query statements in a structured query statement set can be performed, which is more flexible than the traditional method and can combine complex expressions to identify more complex logical associations; at the same time, the use of feature expressions is flexible, and composite features and context-related features can be combined, all clauses can be iteratively nested to screen, and the position of the clauses that meet the features in the original structured query statement can be accurately located.
[0092] This specification also provides a computer device, which can be found in Figure 7 The computer device structure diagram of the structured query statement identification method based on feature expressions provided in the embodiment of this specification is shown, and the computer device may specifically include an input device 71, a processor 72, and a memory 73. Among them, the memory 73 is used to store processor executable instructions. When the processor 72 executes the instructions, the steps of the structured query statement identification method based on feature expressions described in any of the above embodiments are implemented.
[0093] In this embodiment, the input device may specifically be one of the main devices for information exchange between the user and the computer system. The input device may include a keyboard, a mouse, a camera, a scanner, a light pen, a handwriting input board, a voice input device, etc.; the input device is used to input the original data and the program for processing these numbers into the computer. The input device can also obtain and receive data transmitted from other modules, units, and devices. The processor can be implemented in any appropriate manner. For example, the processor can take the form of a computer-readable medium, a logic gate, a switch, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a programmable logic controller, and an embedded microcontroller, etc., such as a microprocessor or a processor and a computer-readable program code (such as software or firmware) that can be executed by the (micro) processor. The memory may specifically be a memory device used to store information in modern information technology. The memory may include multiple levels. In a digital system, anything that can store binary data can be a memory; in an integrated circuit, a circuit with a storage function without a physical form is also called a memory, such as a RAM, a FIFO, etc.; in a system, a storage device with a physical form is also called a memory, such as a memory stick, a TF card, etc.
[0094] In this embodiment, the functions and effects specifically realized by the computer device can be explained in comparison with other embodiments and will not be described in detail here.
[0095] In an embodiment of the present specification, a computer storage medium for a structured query statement identification method based on a feature expression is also provided, wherein the computer storage medium stores computer program instructions, and when the computer program instructions are executed, the steps of the structured query statement identification method based on a feature expression described in any of the above embodiments are implemented.
[0096] In this embodiment, the storage medium includes, but is not limited to, a random access memory (RAM), a read-only memory (ROM), a cache, a hard disk (HDD) or a memory card. The memory may be used to store computer program instructions. The network communication unit may be an interface for network connection communication set in accordance with the standard specified by the communication protocol.
[0097] In this embodiment, the functions and effects specifically implemented by the program instructions stored in the computer storage medium can be explained in comparison with other embodiments and will not be repeated here.
[0098] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of this specification can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of this specification are not limited to any specific combination of hardware and software.
[0099] It should be understood that the above description is for illustration and not for limitation. Many embodiments and many applications beyond the examples provided will be apparent to those skilled in the art upon reading the above description. Therefore, the scope of this specification should not be determined with reference to the above description, but should be determined with reference to the preceding claims and the full scope of equivalents to which these claims belong.
[0100] The above description is only the preferred embodiment of this specification and is not intended to limit this specification. For those skilled in the art, the embodiments of this specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this specification shall be included in the protection scope of this specification.
Claims
1. A structured query statement identification method based on feature expressions, characterized in that: include: Receive a statement identification request, wherein the statement identification request carries a feature expression and a structured query statement set to be identified, the structured query statement set includes at least one structured query statement, and the feature expression includes a preset logical association relationship used to identify the structured query statement; the preset logical association relationship includes at least one of the following: and, or, not; Based on the structured query statement set, a corresponding query statement syntax tree set is generated; based on the feature expression, a corresponding feature syntax tree is generated; Matching the query statement syntax tree set with the characteristic syntax tree to determine whether there is a structured query statement that satisfies the preset logical association relationship in the query statement syntax tree set; Wherein, based on the feature expression, a corresponding feature syntax tree is generated, including: Splitting the feature expression into ordered arrays by words; Based on the logic operator grammar, the ordered array is arranged into a feature grammar tree corresponding to the feature expression; Wherein, based on the logic operator grammar, the ordered array is arranged into a feature grammar tree corresponding to the feature expression, including: In the case where the preset logical association relationship includes an AND operation, merging multiple conditions in the preset logical association relationship into a tree; In the case where the preset logical association relationship includes an OR operation, different sibling relationship subtrees are formed between the multiple conditions in the preset logical association relationship, and then a feature syntax tree is formed through recursion.
2. The method according to claim 1, characterized in that Based on the structured query statement set, a corresponding query statement syntax tree set is generated, including: Segmenting each structured query statement in the at least one structured query statement into an ordered array by word, obtaining an ordered array corresponding to each structured query statement, wherein the ordered array includes the segmented words, and the index of the ordered array represents the index position of the segmented words in the structured query statement; Based on the grammatical rules of the structured query language, the ordered arrays corresponding to the structured query statements are arranged into a query statement grammar tree to obtain the query statement grammar trees corresponding to the structured query statements.
3. The method according to claim 2, characterized in that Based on the syntax rules of the structured query language, the ordered arrays corresponding to the structured query statements are arranged into a query statement syntax tree, including: Starting from the initial index position of the ordered array, the current word and its context are extracted in turn, and the extracted current word and its context are matched with the grammar rules. If the match is successful, the current word and its context are taken as a node, and the matching is continued. The matched object is the subtree of the current node, and the index is moved to the end of the context. If there is no match, the index is moved to the next word. When the index moves to the end of the team, it is repeated to rematch from the head of the team until the top-level grammar is matched, and the corresponding query statement grammar tree is output.
4. The method according to claim 1, characterized in that: Matching the query statement syntax tree set with the feature syntax tree includes: The query statement syntax tree set is matched with the feature syntax tree using a backtracking path search algorithm.
5. The method according to claim 1, characterized in that: After matching the query statement syntax tree set with the characteristic syntax tree to determine whether there is a structured query statement that satisfies the preset logical association relationship in the query statement syntax tree set, the method further includes: When it is determined that there is a structured query statement satisfying the preset logical association relationship in the query statement syntax tree set, a text statement is generated according to the syntax tree in the matching result.
6. A structured query statement identification device based on feature expressions, characterized in that: include: A receiving module is used to receive a statement identification request, wherein the statement identification request carries a feature expression and a structured query statement set to be identified, the structured query statement set includes at least one structured query statement, and the feature expression contains a preset logical association relationship used to identify the structured query statement; the preset logical association relationship includes at least one of the following: and, or, not; A generating module, used to generate a corresponding query statement syntax tree set based on the structured query statement set; and also used to generate a corresponding feature syntax tree based on the feature expression; A matching module, used for matching the query statement syntax tree set with the feature syntax tree to determine whether there is a structured query statement satisfying the preset logical association relationship in the query statement syntax tree set; Among them, the generation module is specifically used to: divide the feature expression into an ordered array according to words; based on the logical operator grammar, arrange the ordered array into a feature syntax tree corresponding to the feature expression; wherein, based on the logical operator grammar, arrange the ordered array into a feature syntax tree corresponding to the feature expression, including: when the preset logical association relationship includes an AND operation, merging multiple conditions in the preset logical association relationship into a tree; when the preset logical association relationship includes an OR operation, different sibling relationship subtrees are formed between the multiple conditions in the preset logical association relationship, and then a feature syntax tree is formed through recursion.
7. A computer device, characterized in that: The method comprises a processor and a memory for storing processor-executable instructions, wherein the processor implements the steps of the method according to any one of claims 1 to 5 when executing the instructions.
8. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the instructions are executed, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Method and apparatus for detecting structured query language injection attack
CN105160252A
Multi-source database statement checking method and device
CN111949541A