A grammatical error processing method, device, cluster, storage medium and program product
By escaping or replacing the target syntax unit that causes syntax parsing errors in database statements on the computing device, the syntax error problem during database statement parsing is solved, which improves robustness and compatibility and lowers the threshold for use.
Patent Information
- Application Number
- CN202411915067.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-24
- Publication Date
- 2025-05-13
- Estimated Expiration
- 2044-12-24
AI Technical Summary
When computing devices parse database statements, syntax errors may be detected, such as the alias of column information coincident and conflict with keywords, resulting in poor robustness and compatibility, and increasing the threshold for use.
By processing after errors occur during the parsing of database statements, the target syntax unit that causes syntax parsing errors is escaped or replaced to resolve the errors and improve the robustness and compatibility of computing devices when parsing database statements.
It significantly improves the fault tolerance and robustness of computing devices when analyzing database statements, lowers the threshold for use, and ensures the integrity of database functions.
Smart Images

Figure CN119441257B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a grammatical error processing method, device, cluster, storage medium and program product. Background Art
[0002] In commonly used database operation languages, a database statement is usually composed of multiple grammatical units (tokens). Each token consists of one or more characters, and different tokens often have different attributes. For example, the widely used structured query language (SQL) has: keywords (such as: SELECT, WHERE, FROM, etc.), identifiers, constants, operators (such as: <, =, >, etc.). The computing device needs to correctly parse the attributes of the token before it can be executed smoothly.
[0003] When the computing device parses the database statement, it may detect a syntax error. For example, the alias of the column information overlaps with the keyword. In other words, the computing device parses the identifier in the database statement input by the user as a keyword, resulting in the inability to find the corresponding syntax rule, causing a syntax error.
[0004] After a computing device detects a syntax error, the traditional solution is to directly inform the user of the syntax error and let the user correct the error in the database statement by themselves. This method seriously lacks fault tolerance and has poor robustness. It also introduces the problem of database forward compatibility, which causes instability in customer use. Summary of the invention
[0005] The present application provides a syntax error processing method, device, cluster, storage medium and program product. After an error occurs in the process of parsing a database statement, the target syntax unit that causes the syntax parsing error is escaped, replaced, etc. to resolve the error. While ensuring that the functions of the database are fully retained, the robustness and compatibility of the computing device when parsing database statements are significantly improved, and the usage threshold is lowered.
[0006] In a first aspect, the present application provides a method for handling grammatical errors, the method comprising: after a computing device receives a first database statement, the computing device determines a target grammatical unit in the first database statement, the first database statement being a database statement in which the target grammatical unit does not conform to a first grammatical rule when a grammatical analysis is performed using the target grammatical unit as a keyword, the aforementioned target grammatical unit comprising one or more characters; then, the computing device processes the target grammatical unit, and the processed target grammatical unit conforms to at least one grammatical rule including the first grammatical rule when a subsequent grammatical analysis is performed.
[0007] It can be understood that after a certain grammatical unit token in the first database statement is used as a keyword for grammatical analysis and does not comply with the first grammatical rule, the computing device obtains the first database statement and automatically processes the target grammatical unit that causes the error, instead of directly reporting an error to the user. The processed target grammatical unit can comply with at least one grammatical rule including the first grammatical rule during subsequent grammatical analysis, which significantly improves the fault tolerance and robustness of the computing device when parsing database statements.
[0008] In a possible implementation, the computing device processes the target grammatical unit, including: the computing device escapes the target grammatical unit, and the escaped target grammatical unit is used as an identifier in subsequent grammatical analysis; or, the computing device replaces the target grammatical unit.
[0009] It can be understood that by escaping or replacing the target syntax unit through the computing device, the processing operation after detecting the error in the database statement is realized, and then when the database statement is parsed again subsequently, the error caused by treating the target syntax unit as a keyword for syntax analysis can be avoided, thereby improving the robustness of the computing device in parsing database statements.
[0010] In a possible implementation, the computing device escapes the target grammar unit, including: the computing device obtains version information corresponding to the target grammar unit; if the version information matches the target version range, the computing device escapes the target grammar unit.
[0011] It is understandable that the computing device escapes the target syntax units whose version information conforms to the target version range. This can solve the overlap conflict problem between new keywords and identifiers in database statements that is common in version upgrade scenarios, and can improve the fault tolerance and robustness of the computing device when parsing database statements.
[0012] In one possible implementation, a computing device escapes a target grammatical unit, including: the computing device obtains the similarity between a grammatical rule of a first database statement and a grammatical rule in a grammar library corresponding to the target grammatical unit; if there is no second grammatical rule in the grammar library whose similarity meets a first target threshold range, the computing device escapes the target grammatical unit.
[0013] It can be understood that before escaping the target grammatical unit, the computing device first determines whether the statement is highly similar to the grammatical rule corresponding to the target grammatical unit. If the similarity is low, that is, there is no second grammatical rule in the grammar library whose similarity meets the first target threshold range, the target grammatical unit will be escaped. This can reduce the probability of escape errors and help improve the fault tolerance, accuracy and efficiency of the computing device when parsing database statements.
[0014] In a possible implementation, the computing device escapes the target grammatical unit, including: the computing device adds an escape symbol to the target grammatical unit; or the computing device generates a target instruction, where the target instruction is used to indicate that the target grammatical unit is used as an identifier in subsequent grammatical analysis.
[0015] It is understandable that the computing device can add an escape symbol or generate a target instruction that can instruct the target syntax unit to be used as an identifier in subsequent syntax analysis, so that the target syntax unit will no longer be used as a keyword in subsequent parsing, thereby avoiding syntax errors.
[0016] In one possible implementation, a computing device replaces a target grammatical unit, including: the computing device obtains the similarity between the grammatical rule of the first database statement and each grammatical rule in the grammar library; if there is a second grammatical rule in the grammar library whose similarity meets a second target threshold range, the computing device replaces the target grammatical unit with the corresponding grammatical unit in the grammar rule.
[0017] It can be understood that the computing device obtains the similarity between the grammatical rules of the first database statement and the grammatical rules in the grammar library, and when there is a second grammatical rule in the grammar library that is highly similar to the statement, the computing device replaces the target grammatical unit with the corresponding grammatical unit in the second grammatical rule. In this way, when the replaced database statement is subsequently parsed again, it can have a higher degree of match with the second grammatical rule and can continue to be parsed smoothly, avoiding errors caused by taking the target grammatical unit as a keyword for grammatical analysis, thereby improving the fault tolerance of the computing device when parsing database statements.
[0018] In one possible implementation, the method also includes: after the database system is upgraded, the computing device obtains upgrade information, the upgrade information includes: new keywords, version information corresponding to the new keywords, and grammatical rules corresponding to the new keywords, and the database system is used to perform grammatical analysis on database statements.
[0019] It is understandable that after the computing device upgrades the database system version, it obtains relevant upgrade information, which helps to use the upgrade information to determine how to handle the target syntax unit that caused the error when an error occurs in parsing database statements, thereby improving the computing device's fault tolerance when parsing database statements and the accuracy of handling syntax errors.
[0020] In a second aspect, the present application provides a grammatical error processing device, which is used to execute any one of the grammatical error processing methods provided in the first aspect above.
[0021] In a possible implementation, the present application may divide the grammatical error handling device into functional modules according to the method provided in the first aspect above. For example, each functional module may be divided according to each function, or two or more functions may be integrated into one module. Exemplarily, the present application may divide the grammatical error handling device into a determination module, a processing module, etc. according to the function. The description of the possible technical solutions and beneficial effects executed by each of the functional modules divided above can refer to the technical solutions provided in the first aspect above or its corresponding possible implementation, and will not be repeated here.
[0022] In a third aspect, an embodiment of the present application provides a computing device, which includes a processor and a memory, wherein the processor is coupled to the memory; the memory is used to store computer instructions, which are loaded and executed by the processor so that the computing device implements the grammatical error handling method described in the above aspects.
[0023] In a fourth aspect, an embodiment of the present application provides a computing device cluster, which includes at least one computing device, each computing device includes a processor and a memory, and the processor is coupled to the memory; the processor of at least one computing device is used to execute computer instructions stored in the memory of at least one computing device, so that the computing device cluster executes the grammatical error handling method provided in various optional implementation methods of the above-mentioned first aspect.
[0024] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium, in which at least one computer program instruction is stored, and the computer program instruction is loaded and executed by a processor to implement the grammatical error handling method as described in the above aspects.
[0025] In a sixth aspect, an embodiment of the present application provides a computer program product, the computer program product including computer instructions, the computer instructions stored in a computer-readable storage medium. A processor of a computing device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computing device executes the grammatical error handling method provided in various optional implementations of the first aspect above.
[0026] For the specific description of the second to sixth aspects and their various implementations in the present application, reference may be made to the detailed description in the first aspect and its various implementations; and for the beneficial effects of the second to sixth aspects and their various implementations, reference may be made to the beneficial effects analysis in the first aspect and its various implementations, which will not be repeated here.
[0027] These and other aspects of the present application will become more apparent from the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 A schematic diagram of a database statement execution process provided in an embodiment of the present application;
[0029] Figure 2 A schematic diagram of a system architecture provided for an embodiment of the present application;
[0030] Figure 3 A schematic diagram of the structure of a computing device provided in an embodiment of the present application;
[0031] Figure 4 A flowchart of a grammatical error processing method provided in an embodiment of the present application;
[0032] Figure 5 A schematic diagram of an application of a grammatical error processing method provided in an embodiment of the present application;
[0033] Figure 6 A schematic diagram of the structure of a grammatical error processing device provided in an embodiment of the present application;
[0034] Figure 7 A schematic diagram of a computing device provided in an embodiment of the present application;
[0035] Figure 8 A schematic diagram of a computing device cluster provided in an embodiment of the present application;
[0036] Fig. 9 A schematic diagram of a connection method between computing device clusters provided in an embodiment of the present application. DETAILED DESCRIPTION
[0037] In order to make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the implementation methods of the present application will be further described in detail below in conjunction with the accompanying drawings.
[0038] The term "multiple" as used herein refers to two or more than two. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the related objects are in an "or" relationship.
[0039] Furthermore, in the description of the embodiments of the present application, unless otherwise specified, "multiple" refers to two or more than two. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, ac, bc, or abc, where a, b, and c can be single or multiple.
[0040] In addition, in order to facilitate the clear description of the technical solutions of the embodiments of the present application, in the embodiments of the present application, the words "first", "second" and the like are used to distinguish the same items or similar items with substantially the same functions and effects. Those skilled in the art will understand that the words "first", "second" and the like do not limit the quantity and execution order, and the words "first", "second" and the like do not necessarily limit the differences. At the same time, in the embodiments of the present application, the words "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or design solutions. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a concrete manner for ease of understanding.
[0041] First, the application scenarios of the embodiments of the present application are exemplarily introduced.
[0042] like Figure 1 As shown, Figure 1 A schematic diagram of a database statement execution process provided in an embodiment of the present application, wherein the parsing of SQL statements is taken as an example. Figure 1 The SQL parser shown can parse the received database statements. The parsing process is usually divided into lexical analysis, grammatical analysis, and semantic analysis.
[0043] Specifically, lexical analysis includes: decomposing SQL statements into multiple grammatical units (tokens), and identifying and recording the type and position of each grammatical unit, where the type can include keywords such as SELECT, FROM, WHERE, table names, column names, operators, etc., and then performing grammatical analysis based on the aforementioned lexical analysis results. This process includes: combining the grammatical units generated during the lexical analysis process into a grammatical tree (query tree) according to SQL grammatical rules, and then checking whether the SQL statement complies with the grammatical rules. At the same time, a grammatical tree is generated to determine the logical structure of the query, and then performing semantic analysis (analyze). This process includes: parsing information such as table names and column names, checking the semantic correctness of SQL statements, and converting SQL statements into appropriate internal data structures.
[0044] When the SQL parser determines that the database statement can be parsed successfully, the relevant data is sent to Figure 1The SQL optimizer shown in the figure generates a relational algebra-based logical plan based on the received syntax tree. The logical plan is then rewritten by the rule-based optimizer (RBO) to generate the final logical execution plan. The logical execution plan is then enumerated by the cost-based optimizer (CBO) to output the final execution plan.
[0045] Finally, by Figure 1 The SQL executor shown executes the obtained execution plan, thereby successfully executing the database statement.
[0046] In the above parsing process, the following problem may be encountered: there is a token in the database statement input by the user that can be used as both a keyword and an identifier, and the computing device usually parses such a token as a keyword by default. However, if the user enters it as an identifier, then the database statement is likely to have syntactic errors, which ultimately leads to the failure of the SQL statement to be successfully executed.
[0047] This problem often occurs after the database kernel version is upgraded. Specifically, the new database kernel version may introduce new functions, and the new functions may involve new keywords and grammatical rules around the new keywords. Once the new keywords overlap with the object names (such as table names, column names, function names), aliases (such as column aliases, table aliases) and other identifiers used by users, it is very easy to cause syntax errors during the parsing process. If such errors are directly fed back to users, it will cause trouble to users. From the user's perspective, statements that were able to execute normally before the upgrade suddenly report errors after the upgrade, which seriously reduces the user experience and work efficiency. Therefore, this problem needs to be solved urgently.
[0048] However, in the traditional syntax parsing mechanism, an error will be directly reported after a problem is detected in the database statement. To avoid the error, one solution is to modify the user's business code for adaptation. For example, the identifier with overlapping conflicts can be changed to other names that do not overlap with keywords, or the user can actively add escape symbols to these identifiers that overlap with keywords when entering database statements, such as "" and ''. The computing device will parse the characters included in the escape symbols as identifiers by default. The idea of this solution is to avoid syntax errors as much as possible before performing syntax parsing. In other words, this approach does not improve the syntax parsing mechanism at all, but transfers the problem to the user, resulting in an increase in the threshold for using the database. Once the user does not have the corresponding technical capabilities, it is difficult to quickly and accurately locate the problem, and it is even more difficult to solve the problem. It is easy to cause the user to still fail to parse after multiple modifications and re-entry, which significantly reduces work efficiency and database usability. In addition, frequent modifications to business codes are not conducive to user business migration.
[0049] In another related technology, a keyword whitelist is added to the kernel side of the database, and then the keywords are blocked through relevant control parameters. That is to say, the blocked keywords will not be identified as keywords during parsing. Although this approach can avoid misidentifying identifiers that may have overlapping conflicts as keywords, the idea of this solution is still to block keywords that may cause parsing errors in advance before parsing, thereby avoiding parsing errors. The defect of this solution is that due to the simple and rough blocking of keywords, the features and functions related to these blocked keywords cannot be used, which seriously weakens the functional richness of the database and greatly reduces the availability of the database.
[0050] In view of this, an embodiment of the present application proposes a syntax error handling method. After a syntax error occurs when parsing a database statement, a subsequent processing process for the error is added, which can also be said to be a fault-tolerant process. The target syntax unit that causes the error is processed to resolve the error occurring during the parsing process. In this way, there is no need for the user to actively modify the business code, nor is there any need to completely block the keywords in advance. This ensures that the functions of the database are fully retained while significantly improving the robustness and compatibility of the computing device when parsing database statements, thereby lowering the threshold for use.
[0051] In some feasible embodiments, the method includes: after receiving a first database statement, the computing device determines a target grammatical unit in the first database statement, the first database statement is a database statement in which the target grammatical unit does not conform to a first grammatical rule when the target grammatical unit is used as a keyword for grammatical analysis, and the target grammatical unit includes one or more characters; then, the computing device processes the target grammatical unit, and the processed target grammatical unit conforms to at least one grammatical rule including the first grammatical rule when the grammatical analysis is performed subsequently. Since the computing device processes the target grammatical unit that causes the relevant error, the processed target grammatical unit can conform to at least one grammatical rule including the first grammatical rule when the grammatical analysis is performed subsequently, thereby significantly improving the fault tolerance of the computing device when parsing database statements.
[0052] Secondly, the system architecture of the embodiment of the present application is exemplarily introduced.
[0053] like Figure 2 As shown, Figure 2 A schematic diagram of a system architecture provided in an embodiment of the present application, wherein: Figure 2 The SQL engine 1200 shown can receive the database statement sent by the client 1100 and combine it with the data in the storage engine 1300, such as Figure 2 The keyword table 1310 and the upgrade log table 1320 shown perform corresponding database operations.
[0054] The SQL engine 1200 specifically includes: a SQL parser 1210, a SQL optimizer 1220 and a SQL executor 1230. Different from the traditional SQL parser, Figure 2 The SQL syntax parser 1210 shown may also include a syntax error processing module 1211 and a keyword conflict processing module 1212 for further analyzing and processing the database statements with detected syntax errors, etc.
[0055] The aforementioned SQL engine 1200 and storage engine 1300 can be run on Figure 3 On the computing device 2000 shown, Figure 3 A schematic diagram of a computing device provided in an embodiment of the present application is provided. Figure 3 The computing device 2000 shown includes at least a memory 2010 , a processor 2020 , and a bus 2030 .
[0056] The processor 220 can be used to obtain database statements, parse database statements, process detected syntax errors, etc. The memory 210 can be used to store logic codes corresponding to the syntax error processing method provided in the embodiment of the present application.
[0057] Optionally, the computing device 2000 can be various types of server devices such as a rack server and a whole cabinet server. The computing device 2000 can also be a terminal computing device such as a computer, a mobile terminal, a tablet computer, a laptop computer, a desktop computer, an all-in-one computer, a personal digital assistant (PDA), an ultra-mobile personal computer (UMPC), etc.
[0058] Optionally, the memory 2010 may include a random access memory (RAM), a read-only memory (ROM), etc., wherein the memory 2010 can run a necessary operating system in its RAM, as well as a determination module, a processing module, and other modules for executing the grammatical error handling method provided in the present application.
[0059] In some feasible embodiments, the memory 2010 can also be used to store Figure 2 The storage engine 1300 shown, that is, Figure 2 The storage engine 1300 shown may be built into the computing device 2000, or, in some other feasible embodiments, Figure 2 The storage engine 1300 shown may also be placed in Figure 3 The device is outside the computing device 2000 shown, but the computing device 2000 can communicate with it to obtain data therein.
[0060] Optionally, the processor 2020 may be a central processing unit (CPU) or other general-purpose processor, an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), a digital signal processor (DSP) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or any conventional processor, etc.
[0061] Optionally, bus 2030 may be a peripheral component interconnect (PCI) bus, etc., and the present application does not limit the type of bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3The bus 2030 is represented by only one line, but it does not mean that there is only one bus or one type of bus. The bus 2030 may include a path for transmitting information between various components of the computing device 2000 (for example, the memory 2010 and the processor 2020).
[0062] It should be noted that the system architecture and application scenarios described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Ordinary technicians in this field can know that with the evolution of the system architecture and the emergence of new business scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0063] For ease of understanding, the following is an exemplary introduction to the grammatical error handling method provided in the embodiment of the present application in conjunction with the accompanying drawings. The grammatical error handling method is applicable to Figure 3 Computing device 2000 is shown.
[0064] Before the computing device executes the grammatical error handling method provided by the embodiment of the present application, or in other words, before the following step S110, the database statement can be parsed through a variety of methods, including but not limited to word element analysis, grammatical analysis, etc. of the database statement. The present application does not impose any restrictions on this, and the computing device that parses the database statement can be the same as the computing device that executes the grammatical error handling method, or it can be a different computing device.
[0065] In the following embodiments, the syntax errors detected by parsing and processing database statements by the same computing device are taken as an example. That is to say, when the computing device detects that there is a syntax error in the database statement, it can execute the syntax error handling method provided in the embodiment of the present application to try to solve it, instead of directly reporting the error to the user, thereby improving fault tolerance and compatibility.
[0066] Figure 4 A schematic diagram of a grammatical error handling method provided in an embodiment of the present application, the method specifically comprises the following steps:
[0067] S110: After receiving the first database statement, the computing device determines a target grammatical unit in the first database statement.
[0068] The first database statement received by the computing device is a database statement in which the target grammatical unit does not conform to the first grammatical rule when the target grammatical unit is used as a keyword for grammatical analysis, and the target grammatical unit includes one or more characters.
[0069] Specifically, Figure 2The SQL syntax parser 1210 shown may parse the first database statement one syntax unit at a time. Thus, after detecting that a target syntax unit does not conform to the syntax rule, the syntax error handling method provided in the embodiment of the present application may be executed. Thus, the first database statement received by the computing device usually involves only one syntax error. Alternatively, in other feasible embodiments, if there are multiple syntax errors in the first database statement, the computing device may also process them one by one in the order in which they are discovered.
[0070] In one possible implementation, the computing device may determine the type of the target grammatical unit by obtaining a token of the target grammatical unit, wherein the token is usually obtained during word analysis, and the computing device determines the type and position corresponding to each token in the database statement based on the separator.
[0071] For example, a user wants to query information of column a from table a, and uses days as an alias for the query result of the column, and then inputs an SQL statement (first database statement) into the computing device: select column_a as days fromtable_a. In the latest version upgrade, days is introduced as a new keyword, and before that the statement could be parsed normally.
[0072] The computing device parses the database statement, and the parsing process includes: first, the computing device decomposes the database statement according to the separator to obtain multiple grammatical units (tokens); then, the computing device determines whether the type of each token is a keyword or an identifier by querying the keyword table. The keywords in the aforementioned first database statement are: select, as, days, from, and the identifiers are: column_a, table_a. The aforementioned tokens can also record the position of the characters, such as the token corresponding to select records its position as position 1, and the token corresponding to column_a records its position as position 1.
[0073] Then, the computing device matches relevant grammar rules from the grammar rule library in combination with the aforementioned information. The computing device first determines the grammar rule corresponding to select from the grammar rule library as the first candidate grammar rule for subsequent parsing. Afterwards, the computing device determines the grammar rule that matches select ... as ... from the first candidate grammar rules as the second candidate grammar rule for subsequent parsing. However, when the computing device continues parsing, since select ... as ... does not contain the keyword days, there is no grammar rule in the grammar rule library that can match select ... as days, which causes a grammatical error in the parsing process.
[0074] Furthermore, the computing device can determine through the token corresponding to days that the grammatical analysis of days as a keyword does not comply with the grammatical rules in the grammatical rule library. In other words, the target grammatical unit in the first database statement is days.
[0075] S120: The computing device processes the target grammatical unit.
[0076] After executing step S120, the computing device can make the processed target grammatical unit comply with at least one grammatical rule including the first grammatical rule during subsequent grammatical analysis.
[0077] Step S120 is described in detail below. The computing device may process the target grammatical unit in at least one of the following implementations, including:
[0078] A first possible implementation manner: the computing device escapes the target grammatical unit so that the escaped target grammatical unit is used as an identifier in subsequent grammatical analysis.
[0079] A second possible implementation method is: the computing device replaces the target grammatical unit.
[0080] In an embodiment of the present application, in order to further improve the efficiency and accuracy of handling grammatical errors, the computing device may first obtain the version information corresponding to the target grammatical unit when executing the first possible implementation method. If the version information meets the target version range, the computing device will escape the target grammatical unit. Otherwise, the computing device may report an error.
[0081] Among them, the target version range can be set by the user. When setting, if the user only sets the minimum value of the target version range, the computing device can use the latest version information as the maximum value of the target version range. Correspondingly, if the user only sets the maximum value of the target version range, the computing device can use the oldest version information as the minimum value of the target version range, which can further improve ease of use.
[0082] Moreover, by setting the target version range, users can flexibly adjust the computing device's ability to handle syntax errors. For example, when a new version is released, the version information is included in the target version range, thereby effectively avoiding errors caused by frequent additions of new keywords and maintaining a highly fault-tolerant operating strategy for a period of time after the version upgrade. When the version has been released for a period of time and relevant personnel can flexibly and accurately apply the new keywords added to the version, the version information can be excluded from the target version range and database statements involving relevant keywords can be strictly parsed.
[0083] Exemplarily, the target version range set by the user is (1.5, 3.1], that is, the computing device will escape the target syntax unit only when the version information corresponding to the target syntax unit is greater than 1.0 and less than or equal to 3.1. For example, the version information corresponding to the target syntax unit obtained by the computing device is 2.0. Since the version information meets the aforementioned target version range, the computing device escapes the target syntax unit.
[0084] In an embodiment of the present application, in addition to the aforementioned version information, the computing device may also first obtain the similarity between the grammatical rules of the first database statement and the grammatical rules corresponding to the target grammatical unit in the grammar library. If there is no second grammatical rule in the grammar library whose similarity meets the first target threshold range, the target grammatical unit is escaped.
[0085] Among them, the user can set the first target threshold range so that the computing device will escape the target grammatical unit only when it determines that the similarity between the grammatical rules of the first database statement and the grammatical rules corresponding to the target grammatical unit in the grammar library is not high enough, or that the grammatical rules of the first database statement are irrelevant to the grammatical rules corresponding to the target grammatical unit.
[0086] Exemplarily, the first target threshold range is greater than 80%, while the similarities between the grammatical rules of the first database statement acquired by the computing device and the three grammatical rules corresponding to the target grammatical unit in the grammar library are 30%, 50%, and 30%, respectively, which do not meet the first target threshold range. It can also be considered that the grammatical rules adopted by the first database statement are basically unrelated to the grammatical rules corresponding to the target grammatical unit.
[0087] In an embodiment of the present application, the computing device may also make a judgment based on the above two types of information. That is, the computing device obtains the version information corresponding to the target grammatical unit and the similarity between the grammatical rule of the first database statement and the grammatical rule corresponding to the target grammatical unit in the grammar library. The computing device will escape the target grammatical unit only when the version information meets the target version range and there is no second grammatical rule in the grammar library whose similarity meets the first target threshold range. Otherwise, the computing device may report an error. This can further avoid possible escape errors and improve the efficiency and accuracy of the computing device in handling grammatical errors.
[0088] Exemplarily, the target version range set by the user is (2.0, 3.5], the first target threshold range is greater than 80%, the version information corresponding to the target grammar unit obtained by the computing device is 3.5, and the similarities between the grammar rules of the obtained first database statement and the three grammar rules corresponding to the target grammar unit in the grammar library are 10%, 20%, and 20%, respectively, which means that the version information is consistent with the target version range, and there is no second grammar rule in the grammar library whose similarity meets the first target threshold range, and then the computing device escapes the target grammar unit.
[0089] In an embodiment of the present application, a specific escape method includes at least: a computing device adds an escape symbol to a target grammatical unit, or a computing device generates a target instruction, and the target instruction is used to indicate that the target grammatical unit is used as an identifier during subsequent grammatical analysis.
[0090] Exemplarily, an escape symbol "" is added to the target syntax unit days to obtain "days", or the computing device can generate a shielding instruction, such as set disable_keyword_options = 'days', wherein the shielding instruction can also set a validity period, for example, it is effective only at the next parsing, or it is effective within 24 hours, or it is effective for a long time until the shielding is lifted. Through the flexible validity period setting, the problem of missing database functions caused by long-term shielding of a keyword can be effectively avoided, and the integrity of database functions is improved while improving fault tolerance.
[0091] In an embodiment of the present application, when executing the aforementioned second possible implementation method, the computing device may also first obtain the similarity between the grammatical rules of the first database statement and the grammatical rules in the grammar library. If there is a second grammatical rule in the grammar library whose similarity meets the second target threshold range, the computing device replaces the target grammatical unit with the corresponding grammatical unit in the grammar rule.
[0092] The second grammatical rule and the first grammatical rule may be the same grammatical rule or different, and this application does not limit this. The computing device may traverse all grammatical rules in the grammatical library, find the grammatical rule with the highest similarity to the grammatical rule of the first database statement, and then replace the target grammatical unit with the corresponding grammatical unit in the grammatical rule. Alternatively, the computing device may first determine some candidate grammatical rules from the grammatical library through the grammatical unit located before the target grammatical unit in the first database statement, and then determine the grammatical rule with the highest similarity to the grammatical rule of the first database statement from the candidate grammatical rules, and perform corresponding replacement operations.
[0093] Moreover, when the computing device obtains the similarity between the grammatical rules of the first database statement and the grammatical rules in the grammar library, it can calculate the final similarity by comprehensively calculating the similarity between grammatical units, the similarity between the types of grammatical units, the similarity of the arrangement order of different grammatical units, etc., and combining the corresponding weight coefficients.
[0094] Exemplarily, the second target threshold range is greater than 80%, and the similarity between the grammatical rules of the first database statement obtained by the computing device and the various grammatical rules in the grammar library indicates that there is a grammatical rule with a similarity of 90%, and then the computing device can replace the target grammatical unit with the grammatical unit in the grammar rule corresponding to the target grammatical unit.
[0095] Among them, the aforementioned corresponding relationship can be: the position of the target grammatical unit in the first database statement is the same, for example, the target grammatical unit is at position 3 in the grammatical rule corresponding to the first database statement, and then, the computing device can replace the target grammatical unit with the grammatical unit at position 3 in the second grammatical rule.
[0096] Through the above steps S110-S120, the computing device can escape, replace, and other processes the target grammatical unit that caused the error after an error occurs when parsing the first database statement, so that the same error can be avoided when the subsequent parsing is performed again, thereby improving the availability of the database and improving the efficiency and accuracy of the computing device in handling grammatical errors.
[0097] In addition, after the computing device executes the above-mentioned syntax error handling operation, the computing device can continue to parse the database statement. If an error is detected again, the aforementioned steps S110-S120 can be executed again, and so on. Through multiple syntax error handling, multiple errors in the statement can be resolved. In the embodiment of the present application, in order to improve the overall parsing efficiency, an upper limit on the number of retries can also be set. When the syntax error handling method provided in the embodiment of the present application reaches the upper limit on the number of retries, an error can be directly reported.
[0098] As mentioned above, in some feasible embodiments, the computing device will inevitably encounter errors that are difficult to correct. At this time, the computing device needs to report errors in a timely manner to remind the user to make adjustments, and in order to make it more convenient for the user to solve the error. In an embodiment of the present application, when reporting an error, the computing device can provide richer error information, such as the target grammatical unit is a keyword, the version information of the target grammatical unit, etc., thereby significantly improving the problem location capability and improving ease of use.
[0099] Taking a database kernel upgrade scenario as an example, after the database system is upgraded, the computing device obtains upgrade information, where the upgrade information may include: newly added keywords, version information corresponding to the newly added keywords, and grammatical rules corresponding to the newly added keywords. The aforementioned database system may be run on Figure 3 The computing device shown is used to perform syntax analysis on database statements.
[0100] Optionally, the computing device may store the upgrade information in Figure 2 In the keyword table 1310 and upgrade log table 1320 shown, specifically, the computing device can record the name of the newly added keyword, the grammatical rules related to the newly added keyword (or the reason for introducing the keyword), the version information corresponding to the newly added keyword (that is, the version information of the database system), and the keyword attributes (such as reserved keywords, non-reserved keywords) and other information into the keyword table 1310, and record the previous version information and the current version information into the upgrade log table 1320.
[0101] The following is combined with Figure 5 , the syntax error handling method provided in the embodiment of the present application is described again, wherein, Figure 5 An application diagram of a grammatical error processing method provided in an embodiment of the present application includes:
[0102] S210: The computing device parses the database statement.
[0103] In this step, Figure 5 The parsing module in the computing device shown can perform multiple analysis steps such as word element analysis, grammatical analysis, semantic analysis, etc. on the database statement. If no error is detected in each step, the computing device directly executes step S270.
[0104] S220, the computing device detects a syntax error, triggering a syntax error handling process.
[0105] For example, in the latest database version upgrade (from version 1.5 to version 2.0), days was introduced as a new keyword, and then the user entered the database statement: select column_a as days fromtable_a. Before the upgrade, days was parsed as an identifier and could be parsed and executed normally. However, because days is parsed as a keyword in the new version and there is no grammar rule such as select ... as daysfrom... in the grammar library, the computing device detects a grammar error, thereby triggering the grammar error handling process.
[0106] S230: The computing device determines whether the syntax error is caused by a keyword within the target version range.
[0107] Exemplarily, the target version range is (1.0, 2.0]. Since the version information corresponding to days is 2.0, it meets the aforementioned target version range. That is, the computing device determines that the syntax error is caused by a keyword within the target version range, and then the computing device executes step S240. Otherwise, the computing device executes step S280.
[0108] S240: The computing device obtains the similarity between the grammatical rules of the database statement and the grammatical rules in the grammar library.
[0109] In this step, the computing device may specifically first obtain the similarity between the grammatical rules of the database statement and the grammatical rules involving the keywords causing grammatical errors in the grammar library, so as to determine whether the grammatical rules of the database statement are irrelevant to the grammatical rules involving the keywords causing grammatical errors in the grammar library (if they do not meet the first target threshold range, they can be considered irrelevant). If it is determined that there is no relevance, the computing device executes step S250, or the computing device may further determine whether there are other grammatical rules in the grammar library that are highly relevant to the grammatical rules of the database statement. If so, the computing device executes step S250; if not, the computing device may execute step S280.
[0110] S250: The computing device processes the target grammatical unit.
[0111] In this step, the computing device may specifically perform processing such as escaping and replacing on the target grammatical unit.
[0112] Exemplarily, add "" or `` processing keywords to obtain the processed database statement: select column_a as " days" from table_a, or shield the keyword days (only effective in the next analysis), and then the computing device executes step S260.
[0113] As another example, if the computing device determines that there are other grammatical rules in the grammar library that are highly related to the grammatical rules of the database statement, the computing device can replace the keyword. For example, the input database statement is select column_aas "year" days table_a, and the similarity between the grammatical rules of the database statement and select ... as ... from ... meets the threshold range set by the user. Therefore, the computing device replaces days with from and obtains selectcolumn_a as "year" from table_a.
[0114] S260: The computing device performs another analysis.
[0115] In this step, Figure 5 The parsing module shown parses the processed database statement again. If there is still a syntax error, step S220 can be repeated.
[0116] S270, the computing device executes the database statement.
[0117] In this step, the computing device can confirm that there is no error in the database statement through the previous steps, and then execute it normally, which will not be described in detail here.
[0118] S280: The computing device reports an error.
[0119] In this step, the computing device can combine the syntax unit that caused the syntax error, the stored upgrade information and other information to display detailed error information to the user. For example, a syntax error is detected, which is caused by the target syntax unit days in the input database statement. Days is a reserved keyword newly introduced in version 2.0.
[0120] Through the above steps S210-S280, the computing device can efficiently resolve the detected grammatical errors, process the target grammatical units, significantly improve the usability and fault tolerance of the database, and provide detailed error information when the problem cannot be resolved, thereby improving the positioning and delimiting capabilities.
[0121] The above mainly introduces the scheme of the embodiment of the present application from the perspective of the method. It is understandable that, in order to realize the above functions, the grammatical error handling device includes at least one of the hardware structure and software modules corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the embodiments of the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the embodiments of the present application.
[0122] The embodiment of the present application can divide the grammatical error handling device into functional units according to the above method example. For example, each functional unit can be divided according to each function, or two or more functions can be integrated into one processing unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional units. It should be noted that the division of units in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0123] For example, Figure 6 A schematic diagram of a grammatical error processing device provided in an embodiment of the present application. The grammatical error processing device 800 is applied to a computing device, or the grammatical error processing device 800 may be a computing device. The grammatical error processing device 800 includes:
[0124] A determination module 810 is configured to determine, after receiving a first database statement, a target grammatical unit in the first database statement, wherein the first database statement is a database statement in which the target grammatical unit does not conform to a first grammatical rule when the target grammatical unit is used as a keyword for grammatical analysis, and the target grammatical unit includes one or more characters;
[0125] The processing module 820 is used to process the target grammatical unit, so that the processed target grammatical unit complies with at least one grammatical rule including the first grammatical rule during subsequent grammatical analysis.
[0126] For example, combined with Figure 4 , the determination module 810 can be used to perform the following steps: Figure 4 As shown in S110, the processing module 820 can be used to perform the following steps: Figure 4 S120 shown.
[0127] In a possible implementation, the processing module 820 is further used to: escape the target grammatical unit, and use the escaped target grammatical unit as an identifier in subsequent grammatical analysis; or replace the target grammatical unit.
[0128] In a possible implementation, the processing module 820 is further used to: obtain version information corresponding to the target syntax unit; if the version information matches the target version range, escape the target syntax unit.
[0129] In a possible implementation, the processing module 820 is also used to: obtain the similarity between the grammatical rule of the first database statement and the grammatical rule corresponding to the target grammatical unit in the grammar library; if there is no second grammatical rule in the grammar library whose similarity meets the first target threshold range, escape the target grammatical unit.
[0130] In a possible implementation, the processing module 820 is further used to: add an escape symbol to the target syntax unit; or generate a target instruction, wherein the target instruction is used to indicate that the target syntax unit is used as an identifier during subsequent syntax analysis.
[0131] In a possible implementation, the processing module 820 is also used to: obtain the similarity between the grammatical rules of the first database statement and each grammatical rule in the grammar library; if there is a second grammatical rule in the grammar library whose similarity meets the second target threshold range, replace the target grammatical unit with the corresponding grammatical unit in the grammar rule.
[0132] In a possible implementation, the device also includes an acquisition module, which is used to: obtain upgrade information after the database system is upgraded, and the upgrade information includes: new keywords, version information corresponding to the new keywords, and grammatical rules corresponding to the new keywords. The database system is used to perform grammatical analysis on database statements.
[0133] As a feasible example, the grammatical error handling device 800 provided in the present application is implemented through a software module. For example, the software module can be provided to users through a cloud service subscription model, and users can choose different subscription levels according to their needs. For example, the software module can also provide enterprise-level customized services with professional domain customization, interface personalization and extended functions according to the needs of users or enterprises.
[0134] In addition, the grammatical error processing device 800 provided by the present application can also be provided to users as a value-added service, which is not limited by the present application. When the grammatical error processing device 800 is implemented by a software module, the grammatical error processing device 800 can also be embedded in a database statement parsing software or a database system.
[0135] The present application embodiment also provides a computing device 100. Figure 7 As shown, the computing device 100 includes: a bus 102, a processor 104, a memory 106, and a communication interface 108. The processor 104, the memory 106, and the communication interface 108 communicate through the bus 102. The computing device 100 can be a server or a terminal device. It should be understood that the embodiment of the present application does not limit the number of processors and memories in the computing device 100.
[0136] The bus 102 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 7 The bus 102 is represented by only one line, but it does not mean that there is only one bus or one type of bus. The bus 102 may include a path for transmitting information between various components of the computing device 100 (eg, the memory 106, the processor 104, and the communication interface 108).
[0137] The processor 104 may include any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0138] The memory 106 may include a volatile memory, such as a random access memory (RAM). The processor 104 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD).
[0139] The memory 106 stores executable program codes, and the processor 104 executes the executable program codes to respectively implement the functions of the aforementioned determination module and processing module, thereby implementing the grammatical error processing method. That is, the memory 106 stores instructions for executing the grammatical error processing method.
[0140] The embodiment of the present application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smart phone.
[0141] like Figure 8 As shown, the computing device cluster includes at least one computing device 100. The memory 106 in one or more computing devices 100 in the computing device cluster may store the same instructions for executing the syntax error handling method.
[0142] In some possible implementations, the memory 106 of one or more computing devices 100 in the computing device cluster may also store partial instructions for executing the grammatical error handling method. In other words, the combination of one or more computing devices 100 may jointly execute instructions for executing the grammatical error handling method.
[0143] It should be noted that the memory 106 in different computing devices 100 in the computing device cluster can store different instructions, which are respectively used to execute part of the functions of the grammatical error processing device. That is, the instructions stored in the memory 106 in different computing devices 100 can implement the functions of one or more modules in the determination module and the processing module.
[0144] In some possible implementations, one or more computing devices in the computing device cluster may be connected via a network, which may be a wide area network or a local area network. Fig. 9 A possible implementation is shown. Fig. 9 As shown, two computing devices 100A and 100B are connected via a network. Specifically, the network is connected via a communication interface in each computing device. In this type of possible implementation, the memory 106 in the computing device 100A stores instructions for executing the functions of the determination module. At the same time, the memory 106 in the computing device 100B stores instructions for executing the functions of the processing module.
[0145] It should be understood that Fig. 9The functions of the computing device 100A shown in FIG. 1 may also be completed by multiple computing devices 100. Similarly, the functions of the computing device 100B may also be completed by multiple computing devices 100.
[0146] The embodiment of the present application also provides a computer program product including instructions. The computer program product may be software or a program product including instructions that can be run on a computing device or stored in any available medium. When the computer program product is run on at least one computing device, the at least one computing device executes the grammatical error handling method.
[0147] The embodiment of the present application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that can be stored by a computing device or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk). The computer-readable storage medium includes instructions that instruct the computing device to execute the grammatical error handling method, or instruct the computing device to execute the grammatical error handling method.
[0148] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for handling grammatical errors, characterized in that: The method comprises: After receiving a first database statement, determining a target grammatical unit in the first database statement, the first database statement being a database statement in which the target grammatical unit does not conform to a first grammatical rule when the target grammatical unit is used as a keyword for grammatical analysis, the target grammatical unit including one or more characters; Obtaining version information corresponding to the target grammar unit; if the version information conforms to the target version range, obtaining the similarity between the grammar rule of the first database statement and the grammar rule corresponding to the target grammar unit in the grammar library; If the second grammar rule whose similarity meets the first target threshold range does not exist in the grammar library, the target grammar unit is escaped; the escaped target grammar unit is used as an identifier in subsequent grammar analysis, and the escaped target grammar unit meets at least one grammar rule including the first grammar rule in subsequent grammar analysis.
2. The method according to claim 1, characterized in that The escaping of the target grammatical unit includes: Adding an escape symbol to the target syntax unit; or, A target instruction is generated, where the target instruction is used to instruct to use the target grammatical unit as an identifier when performing subsequent grammatical analysis.
3. The method according to claim 1, characterized in that The method further comprises: After the database system is upgraded, upgrade information is obtained, the upgrade information including: newly added keywords, version information corresponding to the newly added keywords, and grammatical rules corresponding to the newly added keywords. The database system is used to perform grammatical analysis on database statements.
4. A grammatical error processing device, characterized in that: The device comprises: a determination module, configured to determine, after receiving a first database statement, a target grammatical unit in the first database statement, wherein the first database statement is a database statement in which the target grammatical unit does not conform to a first grammatical rule when the target grammatical unit is used as a keyword for grammatical analysis, and the target grammatical unit includes one or more characters; A processing module, configured to obtain version information corresponding to the target grammar unit; if the version information conforms to the target version range, obtain the similarity between the grammar rule of the first database statement and the grammar rule corresponding to the target grammar unit in the grammar library; If the second grammar rule whose similarity meets the first target threshold range does not exist in the grammar library, the target grammar unit is escaped; the escaped target grammar unit is used as an identifier in subsequent grammar analysis, and the escaped target grammar unit meets at least one grammar rule including the first grammar rule in subsequent grammar analysis.
5. The device according to claim 4, characterized in that The processing module is further used for: Adding an escape symbol to the target syntax unit; or, A target instruction is generated, where the target instruction is used to instruct to use the target grammatical unit as an identifier when performing subsequent grammatical analysis.
6. The device according to claim 4, characterized in that The device further includes an acquisition module, wherein the acquisition module is configured to: After the database system is upgraded, upgrade information is obtained, the upgrade information including: newly added keywords, version information corresponding to the newly added keywords, and grammatical rules corresponding to the newly added keywords. The database system is used to perform grammatical analysis on database statements.
7. A computing device, characterized in that The computing device includes a processor and a memory; the processor is coupled to the memory; the memory is used to store computer instructions, and the computer instructions are loaded and executed by the processor to enable the computing device to implement the grammatical error handling method as described in any one of claims 1-3.
8. A computing device cluster, characterized in that: comprising at least one computing device, each computing device comprising a processor and a memory; The processor of the at least one computing device is used to execute instructions stored in the memory of the at least one computing device, so that the computing device cluster executes the grammatical error handling method according to any one of claims 1 to 3.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes computer instructions; when the computer instructions are executed in a computing device, the computing device executes the grammatical error processing method according to any one of claims 1 to 3.
10. A computer program product, characterized in that When the computer program product is run in a computing device, the computing device executes the grammatical error processing method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Method and system for automatically repairing SQL (Structured Query Language) grammar error
CN118428355A