Query statement checking method and device, equipment and storage medium

By performing syntax and execution plan checks on HiveQL query statements, errors are automatically fixed, and the quality of query statements is solved, the correctness and efficiency of query are improved, and the difficulty of development and debugging is reduced.

CN119988412APending Publication Date: 2025-05-13BEIJING YOUTEJIE INFORMATION TECH
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510148416.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-11
Publication Date
2025-05-13

AI Technical Summary

Technical Problem

HiveQL query statements often have syntax and quality problems, which increase the difficulty of development and debugging, which may lead to query failure and data inaccuracy, and bring security risks.

Method used

Obtain the inspection result information by performing grammar checking and execution plan checking on the query statement. When error messages are found, the query statements are automatically repaired based on these error messages, and the repaired statements are run in the target data to obtain the query results.

Benefits of technology

It significantly improves the quality of query statements, ensures the correctness and efficiency of query, reduces the difficulty of development and debugging, and avoids the problems of query failure and data inaccuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119988412A_ABST
    Figure CN119988412A_ABST
Patent Text Reader

Abstract

The invention discloses a checking method, device and equipment for a query statement and a storage medium. The checking method comprises the steps that grammar checking and execution plan checking are conducted on the query statement to obtain checking result information; when it is determined that the check result information contains error information, automatically repairing the query statement based on the error information; and running the repaired query statement in target data to obtain a query result. According to the method, the query statements are subjected to grammar check and execution plan check, so that multi-aspect check of the query statements is realized, and when error information is checked, the new query statements are automatically repaired, so that the quality of the query statements is remarkably improved, and query performance and high efficiency are ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a query statement checking method, device, equipment and storage medium. Background Art

[0002] In big data processing and analysis, Hive is a widely used data warehouse tool that allows users to operate on large-scale data stored in a cluster through a SQL-like query language, such as HiveQL query statements.

[0003] However, the written HiveQL query statements usually have syntax and quality problems, which not only increase the difficulty of development and debugging, but may also cause query failures and inaccurate data, thereby posing security risks. Summary of the invention

[0004] The invention provides a query statement checking method to improve the quality of the query statement.

[0005] According to a first aspect of the present invention, there is provided a query statement checking method, comprising: performing a syntax check and an execution plan check on the query statement to obtain check result information;

[0006] When it is determined that the inspection result information contains error information, automatically repairing the query statement based on the error information;

[0007] The repaired query statement is run in the target data to obtain the query result.

[0008] According to another aspect of the present invention, there is provided a query statement checking device, comprising:

[0009] The check module is used to perform syntax check on query statements and execution plan check to obtain check result information;

[0010] A repair module, configured to automatically repair the query statement based on the error information when it is determined that the inspection result information contains error information;

[0011] The running module is used to run the repaired query statement in the target data to obtain the query result.

[0012] According to another aspect of the present invention, there is provided an electronic device, the electronic device comprising:

[0013] at least one processor; and

[0014] a memory communicatively connected to the at least one processor; wherein,

[0015] The memory stores a computer program that can be executed by the at least one processor. The computer program is executed by the at least one processor so that the at least one processor can perform the method described in any embodiment of the present invention.

[0016] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the method described in any embodiment of the present invention when executed.

[0017] The technical solution of the embodiment of the present invention realizes multi-faceted checking of query statements by performing syntax checking and execution plan checking on query statements, and automatically repairs new search statements when error information is detected, thereby significantly improving the quality of query statements and ensuring query performance and efficiency.

[0018] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0020] Figure 1 is a flowchart of a query statement checking method provided according to the first embodiment of the present invention;

[0021] Figure 2 is a flow chart of a query statement checking method provided according to Embodiment 2 of the present invention;

[0022] Figure 3 is a schematic diagram of the structure of a query statement checking device provided according to Embodiment 3 of the present invention;

[0023] Figure 4 It is a schematic diagram of the structure of an electronic device provided by Embodiment 4 of the present invention. DETAILED DESCRIPTION

[0024] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0025] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention 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 invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0026] Embodiment 1

[0027] Figure 1 A flowchart of a query statement checking method is provided for the first embodiment of the present invention. This embodiment is applicable to the case of checking query statements. The method can be executed by a query statement checking device, which can be implemented in the form of hardware and / or software. Figure 1 As shown, the method includes:

[0028] Step S101, perform syntax check and execution plan check on the query statement to obtain check result information.

[0029] Optionally, a syntax check and an execution plan check are performed on the query statement, including: checking the query statement using a pre-configured parser to obtain a syntax check result; constructing an execution plan query statement corresponding to the query statement when it is determined that the syntax check passes, and performing an execution plan check on the query statement based on the execution plan query statement to obtain an execution plan check result.

[0030] Specifically, the main goal of this embodiment is to ensure that the query statements written by the user in the database warehouse system, for example, HiveSQL, are correct in syntax, style and logic, and can be efficiently executed in the target database Hive. The checks involved in this embodiment mainly include syntax checking and execution plan checking, among which the syntax checking mainly ensures the correctness of the syntax, and the execution plan checking mainly ensures the correctness of the logic, and the execution plan checking will only be performed if the syntax checking passes. Of course, this embodiment is only an example, and does not limit the specific detection content of the query statement. As long as the correctness of the query statement can be guaranteed, it is within the protection scope of this application.

[0031] Optionally, a pre-configured parser is used to check the query statement to obtain a syntax check result, including: parsing the query statement with a pre-configured parser to obtain an abstract syntax tree; performing a syntax check on the abstract syntax tree to determine whether there is a syntax error, if so, calling an error listener to record syntax error information, and using the syntax error information as the syntax check result, wherein the syntax error information includes the error location and the error cause, otherwise, the syntax check pass is used as the syntax check result.

[0032] Among them, the goal of the grammar check in this embodiment is to check the grammatical errors in the query statement, and before the grammar check, the parser file will be used to configure the parser in advance, such as the ANTLR parser, which includes grammar rules in the parser file, so that the query statement can be passed to the parser, and the parser will parse the query statement line by line based on the configured grammar rules to generate an abstract syntax tree, wherein the abstract syntax tree includes key information of each query field. The abstract syntax tree is subjected to grammar check. When a grammar error is detected on the abstract syntax tree, the ANTLR error listener will be called to record the grammar error information, and the error location and the cause of the error will be included in the error information, such as the line number and column number, which are easy to locate; if it is determined through the grammar check that there is no grammar error, the grammar check will be passed as the grammar check result. In addition, the custom ANTLR error listener is one of the core components of the tool, which can capture grammar errors that occur during the parsing process and provide detailed error information, and the design and implementation of the listener have a high technical threshold and are not easily copied by other tools.

[0033] Optionally, an execution plan check is performed on the query statement based on the execution plan query statement to obtain an execution plan check result, including: running the execution plan query statement in the connected target database to obtain the execution plan query result, wherein the execution plan query result includes logical execution steps and physical execution steps; determining whether execution error information is captured from the execution plan query result, and if so, using the execution error information as the execution plan check result, otherwise, using the execution plan check pass as the execution plan check result.

[0034] Specifically, in this implementation, if the syntax check passes, the query statement will continue to be checked for execution plan, so that potential logical problems in the query statement can be discovered in advance, ensuring that the query statement can be correctly executed in the target database, and this is specifically implemented using Hive's EXPLAIN command. In this implementation, an execution plan query statement will be constructed based on the query statement, for example, EXPLAIN query, the format is EXPLAIN<original_query> , of course, this embodiment is only an example, and the specific format of the execution plan query statement is not limited. Pyhive will be used to connect to the target database, and the above-constructed execution plan query statement will be executed in the target database to obtain the execution plan query result, wherein the execution plan query result includes logical execution steps and physical execution steps. Of course, this embodiment is only an example, and the specific content contained in the execution plan query result is not limited. In addition, in this embodiment, the execution plan query result will be captured abnormally. When the execution error message is captured, it means that there is a logical error in the query statement, and the execution error message is used as the execution plan check result. When the execution error message is not captured, it means that the execution plan check of the query statement passes. In addition, the tool not only uses the EXPLAIN command to verify the syntax of the query, but also provides performance optimization suggestions by analyzing the execution plan. This in-depth execution plan analysis is one of the unique selling points of the tool, which can help users write more efficient query statements.

[0035] Step S102: When it is determined that the check result information contains error information, the query statement is automatically repaired based on the error information.

[0036] Optionally, the query statement is automatically repaired based on the error information, including: extracting the error location and error cause in the syntax error information; determining a repair strategy according to the error cause, and automatically repairing the syntax at the error location of the query statement based on the repair strategy.

[0037] Specifically, in this embodiment, after the query statement is syntax checked, if the syntax check result is passed, it means that there is no syntax error in the query statement, and the query statement is directly checked for execution plan. However, when the syntax check result includes syntax error information, it means that there is a syntax error in the query statement, that is, the syntax check fails. In this case, the query statement needs to be repaired first, and then the execution plan check of the repaired query statement is continued after the repair is completed.

[0038] Among them, in this embodiment, when the query statement is automatically repaired in syntax, the query statement and syntax error information are specifically sent to the automatic repair component, and the automatic repair component extracts the error position and error cause in the syntax error information, first determines the repair strategy according to the error cause, and then performs automatic syntax repair at the error position of the query statement based on the repair strategy. After the repair is completed, if the repair is successful, the repaired query statement will be returned, and then the execution plan check will be performed based on the repaired query statement. If the repair fails, the subsequent execution plan check will be terminated and a syntax repair failure report will be generated and recorded in the form of a log. Among them, the syntax repair failure report includes the overall process of syntax repair and the specific steps of syntax repair failure, so that it is convenient for maintenance personnel to repair the repair logic or hardware structure of the automatic repair unit according to the syntax repair failure report, thereby ensuring the normal operation of the automatic repair component. Of course, this embodiment is only an example, and does not limit the specific method of syntax repair.

[0039] Optionally, the query statement is automatically repaired based on the error information, including: obtaining an error object of the query statement according to the execution error information; and automatically repairing the execution plan of the error object of the query statement.

[0040] Specifically, in this embodiment, when the query statement is automatically repaired by the execution plan, the query statement and the execution error information are sent to the automatic repair component. Since the logical execution steps and physical execution steps of the query result of the execution plan correspond to different objects in the query statement, the automatic repair component will determine the error object in the query statement according to the execution error information, referring to the corresponding relationship between the logical execution steps and the physical execution steps and the query statement object, and then automatically repair the error object in the query statement. After the repair is completed, if the repair is successful, the repaired query statement is returned, and the subsequent query work is performed based on the repaired query statement; if the repair fails, the backward query work will be terminated and the execution plan repair failure report will be generated and recorded in the form of a log. Among them, the execution plan repair failure report contains the overall process of the execution plan repair and the specific steps of the execution plan repair failure, so that the maintenance personnel can repair the repair logic or hardware mechanism of the automatic repair unit according to the execution plan repair failure report, thereby ensuring the normal operation of the automatic repair component. Of course, this embodiment is only an example, and does not limit the specific method of the execution plan repair.

[0041] Step S103: Run the repaired query statement in the target data to obtain the query result.

[0042] Optionally, before running the repaired query statement in the target database to obtain the query result, the method further includes: creating a connection object according to connection parameters provided by the user, wherein the connection parameters include a host name, a port number, and a user name; and connecting to the target database based on the connection object.

[0043] Specifically, in this embodiment, after determining that the query statement repair is completed, the repaired query statement will be executed, and before execution, the connection parameters provided by the user will be obtained, wherein the connection parameters include relevant information such as the host name, port number, and user name. According to the connection parameters, pyhive is used to create a connection object, and a connection is made to the target database based on the connection object. Then, the cursor.execute() method of pyhive is used to execute the repaired query statement in the target database and obtain the query result.

[0044] Among them, a multi-level grammar checking mechanism is adopted in this embodiment. The tool combines the ANTLR parser and Hive's EXPLAIN command to provide a multi-level grammar checking mechanism. This combination ensures that the query statement is not only grammatically correct, but also can avoid potential logical errors through verification of the actual execution plan; this application can not only detect errors, but also try to automatically fix some common grammatical errors and style problems, which greatly reduces the workload of users to manually modify queries and improves the efficiency of query writing; the tool is designed as a modular structure, and each module is independent of each other, which is easy to expand and maintain. It supports different versions of HiveSQL syntax, and the checking rules can be easily adjusted through the configuration file; through the EXPLAIN command, the tool can not only detect grammatical errors, but also analyze the execution plan of the query and provide performance optimization suggestions. This is especially important for users who deal with large-scale data sets.

[0045] In the implementation mode of the present application, by performing syntax checking and execution plan checking on the query statements, a multi-faceted check of the query statements is achieved, and when error information is detected, the new search statements are automatically repaired, thereby significantly improving the quality of the query statements and ensuring query performance and efficiency.

[0046] Embodiment 2

[0047] Figure 2 A flowchart of a query statement checking method provided in the second embodiment of the present invention is provided. This embodiment is based on the above embodiment. After obtaining the check result information when determining that the query statement check is abnormal, it also includes: determining the information recording structure; and recording the error information in the log unit according to the information recording structure. Figure 2 As shown, the method includes:

[0048] Step S201, perform syntax check and execution plan check on the query statement to obtain check result information.

[0049] Optionally, a syntax check and an execution plan check are performed on the query statement, including: checking the query statement using a pre-configured parser to obtain a syntax check result; constructing an execution plan query statement corresponding to the query statement when it is determined that the syntax check passes, and performing an execution plan check on the query statement based on the execution plan query statement to obtain an execution plan check result.

[0050] Optionally, a pre-configured parser is used to check the query statement to obtain a syntax check result, including: parsing the query statement with a pre-configured parser to obtain an abstract syntax tree; performing a syntax check on the abstract syntax tree to determine whether there is a syntax error, if so, calling an error listener to record syntax error information, and using the syntax error information as the syntax check result, wherein the syntax error information includes the error location and the error cause, otherwise, the syntax check pass is used as the syntax check result.

[0051] Optionally, an execution plan check is performed on the query statement based on the execution plan query statement to obtain an execution plan check result, including: running the execution plan query statement in the connected target database to obtain the execution plan query result, wherein the execution plan query result includes logical execution steps and physical execution steps; determining whether execution error information is captured from the execution plan query result, and if so, using the execution error information as the execution plan check result, otherwise, using the execution plan check pass as the execution plan check result.

[0052] Step S202: When it is determined that the check result information contains error information, the query statement is automatically repaired based on the error information.

[0053] Optionally, the query statement is automatically repaired based on the error information, including: extracting the error location and error cause in the syntax error information; determining a repair strategy according to the error cause, and automatically repairing the syntax at the error location of the query statement based on the repair strategy.

[0054] Optionally, the query statement is automatically repaired based on the error information, including: obtaining an error object of the query statement according to the execution error information; and automatically repairing the execution plan of the error object of the query statement.

[0055] Step S203: Run the repaired query statement in the target data to obtain the query result.

[0056] Optionally, before running the repaired query statement in the target database to obtain the query result, the method further includes: creating a connection object according to connection parameters provided by the user, wherein the connection parameters include a host name, a port number, and a user name; and connecting to the target database based on the connection object.

[0057] Step S204, determining the information recording structure, and recording the error information in the log unit according to the information recording structure.

[0058] Specifically, in the process of checking the query statement in this embodiment, when error information is detected, such as syntax error information or execution error information, it will also be recorded in the log unit in the form of a log. Among them, the information recording structure will be determined in advance when recording, and the log recording will be performed according to the determined information recording structure, so as to facilitate the unification of the format in the log unit. Of course, this embodiment is only an example, and does not limit the specific recording structure used in the log unit.

[0059] Among them, in this embodiment, the tool adds an exception handling mechanism to each module, and uses the logging module to record detailed error information. Even in a complex environment, the tool can run stably and provide users with clear error reports. And in this embodiment, for the repair failure in the automatic repair process, the generated repair failure report will also be recorded in the form of a log, so as to facilitate the subsequent maintenance of the automatic repair unit based on the log record. Therefore, this embodiment can automatically detect and try to correct syntax errors, style problems and other potential logical errors in HiveSQL statements. The tool not only provides detailed error reports, but also has a robust exception handling mechanism to ensure stable operation even in complex environments, and can provide users with efficient and accurate support in complex HiveSQL query writing environments.

[0060] In the implementation mode of the present application, by performing syntax checking and execution plan checking on the query statements, a multi-faceted check of the query statements is achieved, and when error information is detected, the new search statements are automatically repaired, thereby significantly improving the quality of the query statements and ensuring query performance and efficiency.

[0061] Embodiment 3

[0062] Figure 3 A schematic diagram of the structure of a query statement checking device provided in Embodiment 3 of the present invention. Figure 3 As shown, the device includes: an inspection module 310, a repair module 320 and an operation module 330.

[0063] The checking module 310 is used to perform syntax checking and execution plan checking on the query statement to obtain the checking result information;

[0064] A repair module 320, configured to automatically repair the query statement based on the error information when it is determined that the check result information contains error information;

[0065] The running module 330 is used to run the repaired query statement in the target data to obtain the query result.

[0066] Optionally, the checking module includes a grammar checking unit, which is used to check the query statement using a pre-configured parser to obtain a grammar checking result;

[0067] When it is determined that the syntax check passes, an execution plan query statement corresponding to the query statement is constructed, and an execution plan check is performed on the query statement based on the execution plan query statement to obtain an execution plan check result.

[0068] Optionally, a syntax checking unit, used to parse the query statement using a pre-configured parser to obtain an abstract syntax tree;

[0069] Perform a syntax check on the abstract syntax tree to determine whether there is a syntax error. If so, call the error listener to record the syntax error information and use the syntax error information as the syntax check result. The syntax error information includes the error location and error cause.

[0070] Otherwise, the syntax check is passed as the syntax check result.

[0071] Optionally, the checking module includes an execution plan checking unit, which is used to execute an execution plan query statement in the connected target database to obtain an execution plan query result, wherein the execution plan query result includes a logical execution step and a physical execution step;

[0072] Determine whether execution error information is captured from the execution plan query result. If so, use the execution error information as the execution plan check result. Otherwise, use the execution plan check pass as the execution plan check result.

[0073] Optionally, a repair module is used to extract the error location and error cause from the syntax error information;

[0074] A repair strategy is determined according to the cause of the error, and based on the repair strategy, the syntax is automatically repaired at the error location of the query statement.

[0075] Optionally, the repair module is also used to obtain the error object of the query statement according to the execution error information;

[0076] Automatically repair the execution plan for the error object of the query statement.

[0077] Optionally, the device further comprises a database connection module, which is used to create a connection object according to connection parameters provided by a user, wherein the connection parameters include a host name, a port number and a user name;

[0078] Connect to the target database based on the connection object.

[0079] Optionally, the device also includes a log recording module for determining the information recording structure;

[0080] The error information is recorded in the log unit according to the information recording structure.

[0081] The query statement checking device provided in the embodiment of the present invention can execute the query statement checking method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0082] Embodiment 4

[0083] Figure 4 The present invention is a block diagram of an electronic device 10 that can be used to implement an embodiment of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0084] like Figure 4 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0085] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0086] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as a query statement checking method.

[0087] In some embodiments, the query statement checking method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the query statement checking method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the query statement checking method in any other appropriate manner (e.g., by means of firmware).

[0088] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0089] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0090] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0091] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0092] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0093] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

[0094] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

[0095] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for checking a query statement, characterized in that: include: Perform syntax check and execution plan check on query statements to obtain check result information; When it is determined that the inspection result information contains error information, automatically repairing the query statement based on the error information; The repaired query statement is run in the target data to obtain the query result.

2. The method according to claim 1, characterized in that The syntax check and execution plan check of the query statement include: Check the query statement using a pre-configured parser to obtain syntax check results; When it is determined that the syntax check passes, an execution plan query statement corresponding to the query statement is constructed, and an execution plan check is performed on the query statement based on the execution plan query statement to obtain an execution plan check result.

3. The method according to claim 2, characterized in that The query statement is checked using a pre-configured parser to obtain a syntax check result, including: The query statement is parsed using a pre-configured parser to obtain an abstract syntax tree; Performing a syntax check on the abstract syntax tree to determine whether there is a syntax error, and if so, calling an error listener to record syntax error information, and using the syntax error information as the syntax check result, wherein the syntax error information includes an error location and an error cause, Otherwise, the syntax check is passed as the syntax check result.

4. The method according to claim 2, characterized in that: The performing an execution plan check on the query statement based on the execution plan query statement to obtain an execution plan check result includes: Run an execution plan query statement in the connected target database to obtain an execution plan query result, wherein the execution plan query result includes a logical execution step and a physical execution step; Determine whether execution error information is captured from the execution plan query result. If so, use the execution error information as the execution plan check result. Otherwise, use the execution plan check pass as the execution plan check result.

5. The method according to claim 3, characterized in that: The automatically repairing the query statement based on the error information includes: Extracting the error position and error cause from the grammatical error information; A repair strategy is determined according to the cause of the error, and automatic syntax repair is performed at the error position of the query statement based on the repair strategy.

6. The method according to claim 4, characterized in that The automatically repairing the query statement based on the error information includes: Acquire an error object of the query statement according to the execution error information; An execution plan is automatically repaired for the error object of the query statement.

7. The method according to claim 1, characterized in that Before executing the repaired query statement in the target data to obtain the query result, the method further includes: Creating a connection object according to connection parameters provided by a user, wherein the connection parameters include a host name, a port number, and a user name; A connection is established with the target database based on the connection object.

8. The method according to claim 1, characterized in that After obtaining the inspection result information when it is determined that the query statement inspection is abnormal, the method further includes: Determine the information record structure; The error information is recorded in a log unit according to the information recording structure.

9. A query statement checking device, characterized in that: include: The check module is used to perform syntax check on query statements and execution plan check to obtain check result information; A repair module, configured to automatically repair the query statement based on the error information when it is determined that the inspection result information contains error information; The running module is used to run the repaired query statement in the target data to obtain the query result.

10. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the method according to any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the method according to any one of claims 1 to 8 when executed.

Citation Information

Cited By

  • Execution method and device of database query statement and storage medium

    CN121070961A