Structured query statement detection method, device, electronic device and storage medium

By obtaining the entities and operands to be detected in SQL statements and using predefined rules to detect their relationships, the problem of low detection accuracy of SQL statements is solved, achieving more accurate detection and reducing maintenance costs.

CN114896269BActive Publication Date: 2024-11-22BEIJING DAJIA INTERNET INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210611558.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-31
Publication Date
2024-11-22
Estimated Expiration
2042-05-31

AI Technical Summary

Technical Problem

The prior art has low accuracy when detecting SQL statements and cannot effectively adapt to different business needs, resulting in high late maintenance costs.

Method used

By obtaining the entity to be detected and the operand to be detected in the statement to be detected, and using predefined rules to detect the relationship between the entity and the operand, determine whether the statement complies with the specifications, consider business scenarios, and improve detection accuracy.

Benefits of technology

It realizes automated detection of SQL statements, improves the accuracy of detection results, makes the statements that meet the specifications more in line with business needs, and reduces the cost of later maintenance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114896269B_ABST
    Figure CN114896269B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a structured query statement detection method, device, electronic device and storage medium, and relates to the field of computer technology. The method includes: obtaining an entity to be detected and an operand to be detected according to the statement to be detected, the entity to be detected includes an entity obtained from the business information corresponding to the statement to be detected, and the operand to be detected is an operand performed on the entity to be detected; according to a predefined preset rule for describing the relationship between the entity and the operand, the relationship between the entity to be detected and the operand to be detected is detected, so as to determine whether the statement to be detected meets the specification according to the detection result. Through the detection method of the present application, the obtained structured query statement is more in line with the business scenario requirements, the accuracy of the detection process is guaranteed, and the accuracy of the structured query statement after detection is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a structured query statement detection method, device, electronic device and storage medium. Background Art

[0002] Structured Query Language (SQL) is a database query and programming language used to access data and query, update and manage relational database systems. In related technologies, some SQL language syntax specifications are formulated into a unified standard syntax text. When testing the development specifications of SQL statements, the above-mentioned unified standard syntax text is used to check the SQL statements written by data development engineers to determine whether the written SQL statements meet the specifications.

[0003] However, in actual business scenarios where SQL language encoding is used, there may be situations where SQL statements with the same meaning and the same function are encoded in different ways to meet different business needs. Therefore, when using a single-content standard grammar text to perform standard detection on files based on SQL statement encoding, the accuracy of the detection results may be low. Summary of the invention

[0004] The present disclosure provides a structured query sentence detection method, device, electronic device and storage medium to at least solve the problem of low accuracy of detection results in related technologies. The technical solution of the present disclosure is as follows:

[0005] According to a first aspect of an embodiment of the present disclosure, a structured query statement detection method is provided, the method comprising: obtaining an entity to be detected and an operand to be detected according to the statement to be detected, the entity to be detected comprising an entity obtained from business information corresponding to the statement to be detected, and the operand to be detected being an operation performed on the entity to be detected; detecting the relationship between the entity to be detected and the operand to be detected according to a predefined preset rule for describing the relationship between the entity and the operand, so as to determine whether the statement to be detected complies with the specification according to the detection result.

[0006] In a possible implementation, obtaining an entity to be detected and an operation number to be detected according to a statement to be detected includes: determining an entity corresponding to the entity name in business information as an entity to be detected according to an entity name included in the statement to be detected, and determining the operation number performed by the determined entity to be detected as the operation number to be detected.

[0007] In another possible implementation, before determining the entity corresponding to the entity name in the business information as the entity to be detected based on the entity name included in the sentence to be detected, it includes: parsing the sentence to be detected to obtain an abstract syntax tree; and extracting the entity name from the abstract syntax tree.

[0008] In another possible implementation, parsing the sentence to be detected to obtain an abstract syntax tree includes: splitting the sentence to be detected into at least one character segment containing at least one keyword; performing syntax analysis on the at least one character segment to generate an abstract syntax tree.

[0009] In another possible implementation, the entity to be detected also includes a statement type obtained from the statement to be detected. According to the entity to be detected and the operand to be detected of the statement to be detected, it also includes: traversing the statement type of the abstract syntax tree, determining the traversed statement type as the entity to be detected, and determining the operand performed on the statement type as the operand to be detected.

[0010] In another possible implementation, the entity to be detected also includes keywords obtained from the statement to be detected. According to the entity to be detected and the operand to be detected of the statement to be detected, it also includes: traversing the keywords of the abstract syntax tree, determining the traversed keywords as the entity to be detected, and determining the operands performed on the keywords as the operands to be detected.

[0011] In another possible implementation, the preset rule is an expression consisting of an entity, an operand, and an operator.

[0012] In another possible implementation, the relationship between the entity to be detected and the operand to be detected is detected according to a predefined preset rule for describing the relationship between the entity and the operand, including: taking the rule containing the entity to be detected in the preset rule as the target rule; and detecting the relationship between the entity to be detected and the operand to be detected according to the target rule.

[0013] In another possible implementation, whether the statement to be tested complies with the specification is determined based on the test results, including: if the entity to be tested and the operand to be tested are consistent with the expression composed of the entity, operand and operator in the target rule, then the statement to be tested complies with the specification; or, if the entity to be tested and the operand to be tested are inconsistent with the expression composed of the entity, operand and operator in the target rule, then the statement to be tested does not comply with the specification.

[0014] In another possible implementation, the entity name included in the statement to be detected includes a table name, and the entity obtained from the business information includes one or more of a table state, a table quantity, a table type, and a table level.

[0015] According to a second aspect of an embodiment of the present disclosure, there is provided a device comprising: an acquisition unit, configured to execute acquisition of an entity to be detected and an operand to be detected according to a statement to be detected, wherein the entity to be detected comprises an entity obtained from business information corresponding to the statement to be detected, and the operand to be detected is an operation performed on the entity to be detected; and a detection unit, configured to execute detection of the relationship between the entity to be detected and the operand to be detected according to a predefined preset rule for describing the relationship between the entity and the operand, so as to determine whether the statement to be detected complies with the specification according to the detection result.

[0016] In a possible implementation, the acquisition unit is configured to specifically perform: according to the entity name included in the statement to be detected, the entity corresponding to the entity name in the business information is determined as the entity to be detected, and the number of operations performed by the determined entity to be detected is determined as the number of operations to be detected.

[0017] In another possible implementation, the device further includes: a parsing unit configured to parse the sentence to be detected to obtain an abstract syntax tree; and an extraction unit configured to extract entity names from the abstract syntax tree.

[0018] In another possible implementation, the parsing unit is configured to specifically execute: splitting the sentence to be detected into at least one character segment containing at least one keyword; performing grammatical analysis on the at least one character segment to generate an abstract syntax tree.

[0019] In another possible implementation, the parsing unit is further configured to specifically perform: traversing the statement types of the abstract syntax tree, determining the traversed statement types as entities to be detected, and determining the operands performed on the statement types as operands to be detected.

[0020] In another possible implementation, the parsing unit is further configured to specifically perform: traversing the keywords of the abstract syntax tree, determining the traversed keywords as entities to be detected, and determining the operands performed on the keywords as operands to be detected.

[0021] In another possible implementation, the preset rule is an expression consisting of an entity, an operand, and an operator.

[0022] In another possible implementation, the detection unit is configured to specifically execute: taking a rule that includes the entity to be detected in the preset rules as a target rule; and detecting the relationship between the entity to be detected and the operand to be detected according to the target rule.

[0023] In another possible implementation, the detection unit is configured to specifically execute: if the entity to be detected and the operand to be detected are consistent with the expression composed of the entity, operand and operator in the target rule, then the statement to be detected complies with the specification; or, if the entity to be detected and the operand to be detected are inconsistent with the expression composed of the entity, operand and operator in the target rule, then the statement to be detected does not comply with the specification.

[0024] In another possible implementation, the entity name included in the statement to be detected includes a table name, and the entity obtained from the business information includes one or more of a table state, a table quantity, a table type, and a table level.

[0025] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: a processor and a memory for storing processor executable instructions; wherein the processor is configured to execute executable instructions to implement a structured query statement detection method as in the first aspect and any possible implementation manner thereof.

[0026] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute a structured query statement detection method as in the first aspect and any possible implementation manner thereof; or when instructions in the computer-readable storage medium are executed by a structured query statement detection device, the structured query statement detection device is enabled to execute a structured query statement detection method as in the first aspect and any possible implementation manner thereof.

[0027] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, including a computer program or instructions, wherein the computer program or instructions are executed by a processor as the structured query statement detection method of the first aspect and any possible implementation manner thereof.

[0028] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects: when detecting an SQL statement to be detected, firstly, the entity to be detected and the operand to be detected are obtained according to the statement to be detected, and then the relationship between the entity to be detected and the operand to be detected is detected by using the predefined rules for detecting whether the SQL statement complies with the specification, thereby realizing the automatic detection of the SQL statement. In addition, since the above rules at least include rules for describing the relationship between the business entity and the corresponding business operand, the above entities to be detected include entities obtained from the business information corresponding to the statement to be detected, therefore, the present invention fully considers the business scenarios to which the SQL statements are applied. Compared with the related method of detecting SQL statements using a single content standard grammatical text, the detection result is more accurate, so that the detected SQL statements that comply with the development specifications are more in line with the needs of the business scenarios, thereby avoiding the problem of high subsequent maintenance costs caused by the low accuracy of the developed SQL statements.

[0029] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.

[0031] Figure 1 is a schematic diagram of an electronic device according to an exemplary embodiment;

[0032] Figure 2 is a flow chart of a structured query sentence detection method according to an exemplary embodiment;

[0033] Figure 3 is a flowchart of another structured query sentence detection method according to an exemplary embodiment;

[0034] Figure 4 is a flowchart of another structured query sentence detection method according to an exemplary embodiment;

[0035] Figure 5 is a flowchart of another structured query sentence detection method according to an exemplary embodiment;

[0036] Figure 6 is a flowchart of another structured query sentence detection method according to an exemplary embodiment;

[0037] Figure 7 is a flowchart of another structured query sentence detection method according to an exemplary embodiment;

[0038] Figure 8 is a schematic diagram showing a structured query statement detection process according to an exemplary embodiment;

[0039] Fig. 9 It is a block diagram of another structured query sentence detection device according to an exemplary embodiment. DETAILED DESCRIPTION

[0040] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.

[0041] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0042] Before introducing in detail the structured query statement detection method provided by the embodiment of the present disclosure, a brief introduction is first given to the implementation environment and application scenarios involved in the embodiment of the present disclosure.

[0043] Structured Query Language (SQL) is a database query and programming language used to access data and query, update and manage relational database systems. In related technologies, some SQL language syntax specifications are formulated into a unified standard syntax text. When testing the development specifications of SQL statements, the above-mentioned unified standard syntax text is used to check the SQL statements written by data development engineers to determine whether the written SQL statements meet the specifications.

[0044] However, in actual business scenarios where SQL language encoding is used, there may be situations where SQL statements with the same meaning and the same function are encoded in different ways to meet different business needs. Therefore, when using a single-content standard grammar text to perform standard detection on files based on SQL statement encoding, the accuracy of the detection results may be low.

[0045] In response to the above problems, the present invention provides a structured query statement detection method. When detecting an SQL statement to be detected, the entity to be detected and the operand to be detected are first obtained according to the statement to be detected, and then the relationship between the entity to be detected and the operand to be detected is detected by using predefined rules for detecting whether the SQL statement complies with the specification, thereby realizing automatic detection of the SQL statement.

[0046] Furthermore, since the above rules at least include rules for describing the relationship between business entities and corresponding business operands, and the above entities to be detected include entities obtained from business information corresponding to the statements to be detected, the present invention fully considers the business scenarios to which SQL statements are applied. Compared with the related method of detecting SQL statements using standard grammar text with a single content, the detection result is more accurate, so that the detected SQL statements that meet the development specifications are more in line with the needs of the business scenarios, thereby avoiding the problem of high subsequent maintenance costs caused by low accuracy of the developed SQL statements.

[0047] The following is a brief introduction to the implementation environment (application scenario) involved in the present disclosure.

[0048] Figure 1 is a schematic diagram of an electronic device provided by the present disclosure. Figure 1 As shown, the electronic device 100 may include at least one processor 101 and a memory 103 for storing processor executable instructions. The processor 101 is configured to execute the instructions in the memory 103 to implement the structured query sentence detection method in the following embodiment.

[0049] In one implementation, the electronic device 100 detects the structured query statement stored in the memory 103. Specifically, the memory 103 pre-stores information corresponding to preset rules and structured query statements, and the processor 101 detects whether the SQL statement complies with the development specification according to the preset rules and information, and determines the detection result.

[0050] In another implementation, the electronic device 100 detects the structured query statement input by the terminal.

[0051] Specifically, after receiving the structured query statement, the electronic device 100 obtains the basic information of the statement contained in the structured query statement and the business information corresponding to the structured query statement. The electronic device 100 then detects the structured query statement based on the basic information and business information obtained above. After the detection process is completed, the electronic device 100 sends the detection result to the terminal.

[0052] The electronic device 10 may further include a communication bus 102 , at least one communication interface 104 , an input device 106 and an output device 105 .

[0053] The processor 101 may be a central processing unit (CPU), a microprocessing unit, an ASIC, or one or more integrated circuits for controlling the execution of the program of the disclosed solution.

[0054] The communication bus 102 may include a pathway for transmitting information between the above-mentioned components.

[0055] The communication interface 104 uses any transceiver or other device for communicating with other devices or communication networks, such as Ethernet, radio access network (RAN), wireless local area networks (WLAN), etc.

[0056] The input device 106 is used to receive input signals and the output device 105 is used to output signals.

[0057] The memory 103 may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory may exist independently and be connected to the processing unit through a bus. The memory may also be integrated with the processing unit.

[0058] The memory 103 is used to store instructions for executing the solution of the present disclosure, and the execution is controlled by the processor 101. The processor 101 is used to execute the instructions stored in the memory 103, thereby realizing the functions of the method of the present disclosure.

[0059] In a specific implementation, as an embodiment, the processor 101 may include one or more CPUs, such as Figure 1CPU0 and CPU1 in.

[0060] In a specific implementation, as an embodiment, the electronic device 100 may include multiple processors, such as Figure 1 1 and 107. Each of these processors may be a single-CPU processor or a multi-CPU processor. A processor herein may refer to one or more devices, circuits, and / or processing cores for processing data (e.g., computer program instructions).

[0061] The structured query sentence detection method provided by the embodiment of the present disclosure can be applied to the aforementioned Figure 1 For ease of understanding, the structured query sentence detection method provided by the present disclosure is specifically introduced below in conjunction with the accompanying drawings.

[0062] Figure 2 is a flow chart of a structured query sentence detection method according to an exemplary embodiment. Figure 2 As shown, the structured query sentence detection method is used in an electronic device, and includes the following steps S21 and S22. The electronic device can be a server, or a server and a terminal.

[0063] Step S21: Obtain the entity to be detected and the operand to be detected according to the statement to be detected.

[0064] The statement to be detected may be a structured query statement written by a program developer when writing a custom function.

[0065] In some application scenarios, the entity to be detected includes an entity obtained from the business information corresponding to the statement to be detected, and the number of operations to be detected is the number of operations performed on the entity to be detected. The above business information is information included in the business scenario to which the statement to be detected is applied.

[0066] In detail, in some implementations, the entity name included in the statement to be detected includes a table name and an output library name, and the entity obtained from the business information includes one or more of a table state, a table quantity, a table type, and a table level.

[0067] It should be noted that the table name can be an output table name or an input table name.

[0068] Furthermore, the entity obtained from the business information may be one or more of input table status, input table quantity, input table type, input table level, output table status, output table quantity, output table type and output table level.

[0069] Exemplarily, when the entity is the input table state or the output table state, its corresponding operand can be the online, offline or to-be-offline table detection. When the entity is the input table quantity or the input table quantity, its corresponding operand is a specific value, such as 1, 2, 3, etc. When the entity is the input table type or the output table type, its corresponding operand is a temporary library table, a physical table or a view. When the entity is the input table level, its corresponding operand is the data cross-layer corresponding to the table, that is, which layer of the database the table is input at. When the entity is the output table level, its corresponding operand is the data cross-layer corresponding to the table, that is, which layer of the database the table is output at.

[0070] In the above implementation, the entity name included in the statement to be detected is a table name, and the entity obtained in the business information is one or more of a table state, a table quantity, a table type, and a table level.

[0071] This implementation method clarifies the entity name and the specific scope of the entity, so that the entity name and entity obtained during the detection process are more accurate, thereby ensuring that the detection process is more accurate and faster.

[0072] The number of operations performed on the above-mentioned entity to be detected is called the number of operations to be detected.

[0073] Exemplarily, the operands performed on the above-mentioned entity to be detected can be values, views, or physical tables. For example, if the business requires that the number of tables must be 4, then the operand of the number of entity tables is 4. Alternatively, if the business requires that the table type must be a view, then the operand of the entity table type is a view. Alternatively, if the business requires a physical table of the table type, then the operand of the entity table type is a physical table.

[0074] As an implementation method, Figure 3 As shown, the above step S21 can be specifically implemented by the following steps S211 and S212.

[0075] Step S211, according to the entity name included in the sentence to be detected, determining the entity corresponding to the entity name in the business information as the entity to be detected;

[0076] Step S212: determining the number of operations executed by the entity to be detected as the number of operations to be detected.

[0077] In this implementation, the server first obtains the entity name in the statement to be detected, and then determines the entity corresponding to the above entity name in the business information to complete the targeted screening of the business entity. At the same time, the above determined entity is used as the entity to be detected. And the number of operations performed by the entity to be detected is determined as the number of operations to be detected, thereby ensuring the rapid acquisition of the entity to be detected and the operation data to be detected.

[0078] In some specific embodiments, the entity name is an input table name and / or an output table name.

[0079] Exemplarily, if the entity name is input table a, the entity corresponding to input table a may be one or more of input table a status, input table a quantity, input table a type, and input table a level.

[0080] It should be noted that the entity name and entity in the implementation mode of the present application have the same attributes, that is, they are different information of the same subject feature. It can also be understood that the information included in the sentence to be detected only includes the entity name, and the entity serves as supplementary information of the entity name.

[0081] In the above acquisition method, entities corresponding to the entity names are targetedly screened out from the business information based on the entity names. On the one hand, it ensures that the acquired entities to be detected are the entities required in the detection process, thereby ensuring the accuracy of the acquired entities to be detected; on the other hand, it ensures the rapid acquisition of entities in the business information, thereby ensuring the rapidity of acquiring the entities to be detected.

[0082] Furthermore, if Figure 4 As shown, before executing the above step S211, the following steps S41 and S42 are first executed to determine the entity name.

[0083] Step S41: Parse the sentence to be detected to obtain an abstract syntax tree.

[0084] Step S42: Extract entity names from the abstract syntax tree.

[0085] In this implementation, the server parses the sentence to be detected into an abstract syntax tree, which does not depend on the specific grammar or the details of the language, thus reducing the parsing workload and improving the parsing speed. The entity name is then extracted from the abstract syntax tree, thereby obtaining the entity name from the information included in the sentence to be detected.

[0086] By parsing the statement into an abstract syntax tree, the parsing speed of the statement is improved, thereby ensuring the rapidity of obtaining the entity name.

[0087] In one embodiment, Figure 5 As shown, the above step S41 can be specifically implemented by the following steps S411 and S412.

[0088] Step S411: split the sentence to be detected into at least one character segment containing at least one keyword.

[0089] Step S412: Perform syntax analysis on at least one character segment to generate an abstract syntax tree.

[0090] In this embodiment, the server first splits the sentence to be detected into at least one character segment of one or more keywords to ensure a smoother syntax analysis process. Then, the character segment is parsed to generate an abstract syntax tree. The syntax analysis method ensures that the statements to which the entity names obtained from the abstract syntax tree belong all conform to the general syntax specifications of structured statements.

[0091] In some specific embodiments, a lexical analysis method is used to split the sentence to be detected into one or more keyword character segments. Taking the sentence to be detected as "the table that the view depends on exceeds 5" as an example, the sentence to be detected is split into "view and table", where the entity corresponding to the view is the output table type, the entity corresponding to the table is the number of input tables, and the operand corresponding to the number of input tables is greater than 5.

[0092] By splitting the sentences and then using syntax analysis, the generated abstract syntax tree complies with the basic syntax specifications of structured sentences, ensuring the accuracy of the entity names included in the abstract syntax tree, thereby ensuring a more accurate detection process.

[0093] As another embodiment, Figure 6 As shown, the above step S21 can also be specifically implemented through the following step S21A to obtain the entity to be detected and the number of operations to be detected corresponding to the entity to be detected.

[0094] Step S21A: traverse the statement types and / or keywords of the abstract syntax tree, determine the traversed statement types and / or keywords as entities to be detected, and determine the operands performed on the statement types and / or keywords as operands to be detected.

[0095] The entity to be detected also includes a sentence type and / or a keyword obtained from the sentence to be detected.

[0096] In this embodiment, according to the abstract syntax tree, the traversed statement type and / or keyword are determined as the entity to be detected, and the operands performed on the statement type and / or keyword are determined as the operands to be detected, thereby achieving the acquisition of the entity included in the statement to be detected.

[0097] In some other implementations, the entity to be detected may include an entity obtained from the sentence to be detected, and the entity to be detected obtained from the sentence to be detected may be called a grammatical entity.

[0098] It should be noted that the grammatical entity can be used as the entity to be detected; the business entity can be used as the entity to be detected; or the grammatical entity and the entity to be detected can be used together as the entity to be detected. The entity object corresponding to the entity to be detected can be set according to the specific scenario requirements, and this application does not make specific limitations on this.

[0099] In some embodiments, the sentence type and / or keyword obtained from the sentence to be detected is used as the entity to be detected. It can be understood that the sentence entity obtained from the sentence to be detected can also be called a grammatical entity.

[0100] Taking the SQL statement type as a grammatical entity as an example, a create table / view statement cannot appear in an SQL statement, that is, the operand of the SQL statement type is not a create table / view statement.

[0101] For another example, the operands executed on the grammatical entity may also be database schema definition languages ​​(Data Definition Language, DDL statements), that is, the operands of the SQL statement type are DDL statements.

[0102] It should be noted that the statement types and keywords include the statement types and keywords included in the user-defined function, and may also include the statement types and keywords included in the non-user-defined function.

[0103] Furthermore, the entity name also includes the function name of the custom function. Then the abstract syntax tree also includes the function name of the custom function. According to the function name of the custom function, the statement type and / or keyword in the custom function is obtained, so as to determine the grammatical entities included in the custom function and the operands corresponding to the grammatical entities.

[0104] Through the above-mentioned entity acquisition method, the acquisition of the entities included in the sentence to be detected itself is achieved, so that the detection method of the present application can also use preset rules to detect the grammatical specifications in the sentence to be detected, so that the detection result obtained by using the detection method of the present application is more accurate.

[0105] Step S22: According to a predefined preset rule for describing the relationship between an entity and an operand, the relationship between the entity to be detected and the operand to be detected is detected, so as to determine whether the statement to be detected complies with the specification according to the detection result.

[0106] As an implementation method, the preset rule is an expression consisting of an entity, an operand, and an operator.

[0107] In this implementation, the preset rule is represented by an expression consisting of an entity, an operand and an operator, wherein the preset rule is an expression relationship established between the entity and the operand through the operator.

[0108] Exemplarily, output table b state = on-line, wherein the entity is the output table b state, "=" is the operator, and on-line is the operand.

[0109] Among them, one entity in the preset rule corresponds to at least one operand.

[0110] Exemplarily, the entity is an output table c type, and its corresponding operand can be a view and a physical table at the same time, and the preset rule is: (output table c type = view) and (input table c type ! = physical table).

[0111] It should be noted that the table name usually corresponds to both the output table and the input table.

[0112] Specifically, when an entity corresponds to multiple operands, the preset rule is composed of an entity, multiple operands and multiple operators. The operator can be one or more of a comparison operator, a logical operator, a connection operator, an arithmetic operator and a negation operator. Exemplarily, the operator can be "=", ">", "<", "!=", etc.

[0113] It should be noted that a preset rule may include one or more entities. An expression corresponding to a preset rule may describe a logical relationship between multiple entities corresponding to an entity name and operands corresponding to the multiple entities.

[0114] For example, table d corresponds to two entities: output table d type and input table d quantity. A view cannot depend on three tables d. The corresponding preset rule is: ((output table d type = view) and (input table d quantity > 3)) or ((output table d type = view) and (input table d type ! = physical table)).

[0115] In some implementations, the preset rule also includes corresponding preset rule description information, which is used to indicate the specific meaning expressed by the preset rule and facilitate understanding of the preset rule. The preset rule description information is detailed in the text description form in the same column as the preset rule description information in Table 1.

[0116] Exemplarily, as shown in Table 1 below, in some specific implementations, the preset rules are obtained from the preset rule description information in the preset rule base. The preset rules in the preset rule base are constructed according to the following method.

[0117] Specifically, the business requirements are determined based on the business information to which the statement to be detected is applied. The preset rule description information is determined based on the business requirements. The types restricted by the description information are determined based on the preset rule description information, such as the SQL syntax restrictions and input table output table restrictions in Table 1. And the subject restricted by the description information is determined based on the preset rule description information. The subject of the restriction is to restrict the SQL statement type and restrict the keywords.

[0118] It should be noted that the preset rules may include forward preset rules and reverse preset rules.

[0119] In the implementation manner of the present application, the case where the preset rule is a forward preset rule is considered, that is, if the forward preset rule is met, it is determined to be in compliance with the preset rule; if the forward preset rule is not met, it is determined not to be in compliance with the preset rule. The case where the preset rule is a reverse preset rule, that is, if the reverse preset rule is met, it is determined not to be in compliance with the preset rule; if the reverse preset rule is not met, it is determined to be in compliance with the preset rule.

[0120] Table 1

[0121]

[0122]

[0123] Furthermore, according to the preset rule description information in Table 1, preset rules are established, and the preset rules include forward preset rules and reverse preset rules. Among them, the reverse preset rules are used to set the relationship description information between the operands and the corresponding entities that do not meet the business requirements or the grammatical requirements, and the forward preset rules are used to set the relationship description information between the operands and the corresponding entities that meet the business requirements or the grammatical requirements. For example, the preset rule description information corresponding to the restricted keywords that do not meet the requirements and the restricted SQL statement types that do not meet the specifications in Table 1 are set in the reverse preset rules. For another example, the preset rule description information corresponding to the restrictions on output table types and input table types, the restrictions on output table types and the number of input tables, the restrictions on output table levels and input table levels, the restrictions on input table status, the restrictions on input table types, and the restrictions on output library names in Table 1 are set in the forward preset rules.

[0124] In detail, for example, the preset rule corresponding to "the create table / view statement cannot appear in the statement" in the preset rule description information of Table 1 is set in the reverse preset rule, and the expression established in the reverse preset rule is "SQL statement type = create table / view statement". It can be understood that although the SQL statement type in the expression is equal to the create table / view statement, because it is set in the reverse preset rule, the meaning of the expression is: the SQL statement type cannot include the create table / view statement. Similarly, the preset rule corresponding to "the select* statement cannot appear in the statement" is set in the reverse preset rule, and the expression "keyword = select* statement" is established, and the meaning of the expression is: the SQL statement cannot include the select* statement.

[0125] For example, in Table 1, the restriction subject can be understood as a restriction on the entity, that is, restricting the entity to a certain state, a certain statement type, or a certain value range. The preset rule of "view cannot depend on 3 tables" is: ((output table type = view) and (number of input tables > 3)) or ((output table type = view) and (input table type ! = physical table)).

[0126] Through the above rule expression method, the preset rules can express the logical relationship between entities and operands more concisely and clearly, so that the detection process of using the preset rules to detect statements is faster. Figure 7 As shown, after executing step S21, the following steps S71 and S72 are executed to determine the target rule.

[0127] Step S71: taking the rule containing the entity to be detected in the preset rules as the target rule.

[0128] Step S72: According to the target rule, the relationship between the entity to be detected and the operand to be detected is detected.

[0129] In this implementation, rules including the entity to be detected are screened out from the preset rules, and the screened out rules are used as target rules to determine the rules for detecting the sentence to be detected.

[0130] By detecting the sentences to be detected according to the determined target rules, the detection speed is improved and the accuracy of the detection results is guaranteed.

[0131] In one implementation, in combination with the above-mentioned step S71 and step S72, the above-mentioned step S22 can also be specifically implemented according to the following steps S221 and S222.

[0132] Step S221: If the entity to be detected and the operand to be detected are consistent with the expression composed of the entity, operand and operator in the target rule, the statement to be detected is in compliance with the specification.

[0133] Step S222: If the entity to be detected and the operand to be detected do not conform to the expression composed of the entity, operand and operator in the target rule, the statement to be detected does not conform to the specification.

[0134] In this embodiment, the entity to be detected and the operand to be detected are brought into the expression corresponding to the target rule, and if they match the expression, it is shown that the statement to be detected meets the specification. Otherwise, if they do not match the expression, it is shown that the statement to be detected meets the specification.

[0135] The above method of using the judgment result of the expression corresponding to the target rule as the detection result is simple and reasonable in logic, and is convenient for obtaining the detection result.

[0136] As a specific implementation method, Figure 8 As shown, the above implementation is specifically implemented using a structured query language parser and a rule engine. The structured query language parser is responsible for parsing the structure of the structured query statement and verifying whether the syntax of the structured query statement is correct; the rule engine is responsible for storing and verifying the preset rules. The metadata database mainly stores business metadata such as table status, type, level, and downstream.

[0137] Specifically, the working process of the structured query language parser and rule engine is as follows:

[0138] First, the structured query language parser parses the structured query statement. If the parsing fails, an exception is prompted. If the parsing succeeds, an abstract syntax tree is generated. Specifically, after lexical analysis, the structured query statement is split into character segments containing keywords; then the character segments are parsed to generate an abstract syntax tree for the structured statement.

[0139] Second, if the parsing is successful, traverse the above abstract syntax tree to obtain the basic information included in the structured query statement, that is, Figure 8 In detail, the basic information of the structured query statement, such as the input table name, output table name, and used function name, is extracted from the syntax tree; then, based on the structured query statement compilation principle, the basic information of the structured query statement is determined.

[0140] Third, grammatical entities are obtained according to the basic information. At the same time, business entities corresponding to the entity names in the basic information are screened out from the business information in the metadata database, and the grammatical entities and business entities are formed into an entity set as the input of the rule engine.

[0141] Fourth, the obtained grammatical entity and business entity are input into the rule executor, and the preset rules in the rule database are input into the rule executor. The rule executor uses the input preset rules to verify and detect the grammatical entity and business entity, as well as the operands corresponding to the two, so as to obtain the detection result.

[0142] It should be noted that the basic information in the above statement includes the entity name.

[0143] In the above implementation, the entity included in the corresponding business information obtained is used as the entity to be detected, and the operand corresponding to the entity to be detected is used as the operand to be detected, so that the entity to be detected and the operand to be detected are both associated with the business information. Then, according to the preset rules, the relationship between the entity to be detected and the operand to be detected is detected to complete the standard detection of the statement to be detected, thereby realizing the automatic detection of the standard detection of the structured query statement customized by the user account.

[0144] Through the above-mentioned detection method, the detection process includes the detection of whether the statement to be detected matches the correct business information. Therefore, the detection method of the present application is used to automatically detect the developed structured query statement. On the one hand, the obtained structured query statement is more in line with the business scenario requirements, the accuracy of the detection process is guaranteed, and the accuracy of the structured query statement after detection is improved, thereby avoiding the problem of high subsequent maintenance costs caused by the low accuracy of the developed structured query statement in the related technology. On the other hand, the intelligence of the detection of structured query statements is guaranteed.

[0145] The present disclosure also provides a Fig. 9 The structured query statement detection device 400 shown includes: an acquisition unit 401, a detection unit 402, a parsing unit 403, and an extraction unit 404.

[0146] The acquisition unit 401 is configured to acquire the entity to be detected and the operation number to be detected according to the sentence to be detected. The entity to be detected includes an entity obtained from the business information corresponding to the sentence to be detected. The operation number to be detected is the operation number performed on the entity to be detected. For example, the acquisition unit 401 is used to execute Figure 2 The detection unit 402 is configured to perform a detection of the relationship between the entity to be detected and the operand to be detected according to a predefined preset rule for describing the relationship between the entity and the operand, so as to determine whether the statement to be detected conforms to the specification according to the detection result. For example, the detection unit 402 is used to perform Figure 2 Step S22 in .

[0147] In a possible implementation, the acquisition unit 401 is configured to specifically perform: according to the entity name included in the statement to be detected, the entity corresponding to the entity name in the business information is determined as the entity to be detected, and the number of operations performed by the determined entity to be detected is determined as the number of operations to be detected.

[0148] In another possible implementation, the device further includes: a parsing unit 403 configured to parse the sentence to be detected to obtain an abstract syntax tree; and an extraction unit 404 configured to extract entity names from the abstract syntax tree.

[0149] In another possible implementation, the parsing unit 403 is configured to specifically execute: splitting the sentence to be detected into at least one character segment containing at least one keyword; performing syntax analysis on the at least one character segment to generate an abstract syntax tree.

[0150] In another possible implementation, the parsing unit 403 is further configured to specifically perform: traversing the statement types and / or keywords of the abstract syntax tree, determining the traversed statement types and / or keywords as entities to be detected, and determining the operands performed on the statement types and / or keywords as operands to be detected.

[0151] In another possible implementation, the preset rule is an expression consisting of an entity, an operand, and an operator.

[0152] In another possible implementation, the detection unit 402 is configured to specifically execute: taking a rule including the entity to be detected in the preset rules as a target rule; and detecting the relationship between the entity to be detected and the operand to be detected according to the target rule.

[0153] In another possible implementation, the detection unit 402 is configured to specifically execute: if the entity to be detected and the operand to be detected are consistent with the expression composed of the entity, operand and operator in the target rule, then the statement to be detected complies with the specification; if the entity to be detected and the operand to be detected are inconsistent with the expression composed of the entity, operand and operator in the target rule, then the statement to be detected does not comply with the specification.

[0154] In another possible implementation, the entity name included in the statement to be detected is a table name, and the entity obtained from the business information is one or more of a table state, a table quantity, a table type, and a table level.

[0155] Regarding the device in the above embodiment, the specific manner in which each unit module performs the operation has been described in detail in the embodiment of the method, and will not be elaborated here.

[0156] The present disclosure also provides an electronic device. Figure 1 The system shown includes: a processor 101 and a memory 103 for storing executable instructions of the processor 101; wherein the processor 101 is configured to execute the executable instructions to implement a structured query statement detection method as in any possible implementation method described above. And the same technical effect can be achieved, and to avoid repetition, it will not be described here.

[0157] The embodiment of the present disclosure also provides a computer-readable storage medium, when the instructions in the computer-readable storage medium are executed by a processor of an image processing device or an electronic device, the data processing device or the electronic device can execute the structured query statement detection method as any of the possible implementations described above. And the same technical effect can be achieved, so it will not be repeated here to avoid repetition.

[0158] The embodiment of the present disclosure also provides a computer program product, including a computer program or instruction, which is executed by a processor as a structured query statement detection method in any possible implementation manner described above. The same technical effect can be achieved, and to avoid repetition, it will not be described here.

[0159] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.

[0160] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A structured query statement detection method, It is characterized in that The method comprises: Obtain an entity to be detected and an operand to be detected according to the statement to be detected; the entity name included in the statement to be detected includes a table name, and the entity obtained in the business information includes one or more of a table state, a table quantity, a table type, and a table level; the entity to be detected is an entity corresponding to the entity name in the business information; the entity to be detected includes an entity obtained from the business information corresponding to the statement to be detected, and a statement type or a keyword obtained from the statement to be detected; the operand to be detected is an operation number performed on the entity to be detected; According to a predefined preset rule for describing the relationship between an entity and an operand, the relationship between the entity to be detected and the operand to be detected is detected to determine whether the statement to be detected complies with the specification based on the detection result; the preset rule is an expression composed of the entity, the operand and the operator.

2. The structured query statement detection method according to claim 1, It is characterized in that The step of obtaining the entity to be detected and the operand to be detected according to the statement to be detected includes: According to the entity name included in the sentence to be detected, determining the entity corresponding to the entity name in the business information as the entity to be detected, and The determined number of operations performed by the entity to be detected is determined as the number of operations to be detected.

3. The structured query statement detection method according to claim 2, It is characterized in that Before determining, according to the entity name included in the sentence to be detected, the entity corresponding to the entity name in the business information as the entity to be detected, the method further includes: Parsing the sentence to be detected to obtain an abstract syntax tree; The entity name is extracted from the abstract syntax tree.

4. The structured query statement detection method according to claim 3, It is characterized in that The step of parsing the statement to be detected to obtain an abstract syntax tree includes: Splitting the sentence to be detected into at least one character segment containing at least one keyword; Perform syntax analysis on the at least one character segment to generate the abstract syntax tree.

5. The structured query sentence detection method according to claim 3 or 4, It is characterized in that The entity to be detected also includes a statement type obtained from the statement to be detected, and the entity to be detected and the operand to be detected according to the statement to be detected also include: The statement types of the abstract syntax tree are traversed, the traversed statement types are determined as the entities to be detected, and the operands executed on the statement types are determined as the operands to be detected.

6. The structured query sentence detection method according to claim 3 or 4, It is characterized in that The entity to be detected also includes a keyword obtained from the sentence to be detected, and the entity to be detected and the operand to be detected based on the sentence to be detected also include: The keywords of the abstract syntax tree are traversed, and the traversed keywords are determined as the entities to be detected, and the operands executed on the keywords are determined as the operands to be detected.

7. The structured query statement detection method according to claim 1, It is characterized in that The detecting the relationship between the entity to be detected and the operand to be detected according to a predefined preset rule for describing the relationship between the entity and the operand includes: Taking the rule containing the entity to be detected in the preset rules as the target rule; According to the target rule, the relationship between the entity to be detected and the operand to be detected is detected.

8. The structured query statement detection method according to claim 7, It is characterized in that Determining whether the sentence to be detected complies with the specification according to the detection result includes: If the entity to be detected and the operand to be detected are consistent with the expression composed of the entity, operand and operator in the target rule, then the statement to be detected is consistent with the specification; Alternatively, if the entity to be detected and the operand to be detected do not conform to the expression composed of the entity, operand and operator in the target rule, then the statement to be detected does not conform to the specification.

9. A structured query statement detection device, It is characterized in that The device comprises: The acquisition unit is configured to acquire the entity to be detected and the operand to be detected according to the sentence to be detected; the entity name included in the sentence to be detected includes a table name, and the entity obtained in the business information includes one or more of a table state, a table quantity, a table type and a table level; the entity to be detected is an entity corresponding to the entity name in the business information; the entity to be detected includes an entity obtained from the business information corresponding to the sentence to be detected, and a statement type or a keyword obtained from the sentence to be detected; the operand to be detected is an operation number performed on the entity to be detected; The detection unit is configured to execute a detection on the relationship between the entity to be detected and the operand to be detected according to a predefined preset rule for describing the relationship between the entity and the operand, so as to determine whether the statement to be detected complies with the specification according to the detection result; the preset rule is an expression composed of the entity, the operand and the operator.

10. The structured query statement detection device according to claim 9, It is characterized in that The acquisition unit is configured to specifically execute: According to the entity name included in the sentence to be detected, determining the entity corresponding to the entity name in the business information as the entity to be detected, and The determined number of operations performed by the entity to be detected is determined as the number of operations to be detected.

11. The structured query statement detection device according to claim 10, It is characterized in that The device also includes: A parsing unit, configured to parse the sentence to be detected to obtain an abstract syntax tree; The extraction unit is configured to extract the entity name from the abstract syntax tree.

12. The structured query statement detection device according to claim 11, It is characterized in that The parsing unit is configured to specifically perform: Splitting the sentence to be detected into at least one character segment containing at least one keyword; Perform syntax analysis on the at least one character segment to generate the abstract syntax tree.

13. The structured query statement detection device according to claim 11 or 12, It is characterized in that The parsing unit is further configured to specifically execute: The statement types of the abstract syntax tree are traversed, the traversed statement types are determined as the entities to be detected, and the operands executed on the statement types are determined as the operands to be detected.

14. The structured query statement detection device according to claim 11 or 12, It is characterized in that The parsing unit is further configured to specifically execute: The keywords of the abstract syntax tree are traversed, and the traversed keywords are determined as the entities to be detected, and the operands executed on the keywords are determined as the operands to be detected.

15. The structured query statement detection device according to claim 9, It is characterized in that The detection unit is configured to specifically perform: Taking the rule containing the entity to be detected in the preset rules as the target rule; According to the target rule, the relationship between the entity to be detected and the operand to be detected is detected.

16. The structured query statement detection device according to claim 15, It is characterized in that The detection unit is configured to specifically perform: If the entity to be detected and the operand to be detected are consistent with the expression composed of the entity, operand and operator in the target rule, then the statement to be detected is consistent with the specification; Alternatively, if the entity to be detected and the operand to be detected do not conform to the expression composed of the entity, operand and operator in the target rule, then the statement to be detected does not conform to the specification.

17. An electronic device, It is characterized in that include: A processor and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the executable instructions to implement the structured query statement detection method according to any one of claims 1 to 8.

18. A computer-readable storage medium, It is characterized in that When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the structured query sentence detection method according to any one of claims 1 to 8; or When the instructions in the computer-readable storage medium are executed by the structured query statement detection device, the structured query statement detection method device is enabled to execute the structured query statement detection method according to any one of claims 1 to 8.