A method, device, medium and equipment for constructing a target format data request body

By converting SQL query statements into abstract syntax trees and applying preset mapping rules, a data request body in the target format is constructed, which solves the problems of poor system complexity and user experience in the existing technology, and realizes flexible support for the REST interface and maximize the utilization of database query capabilities.

CN114003583BActive Publication Date: 2024-12-24CCB FINTECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202111266470.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-28
Publication Date
2024-12-24
Estimated Expiration
2041-10-28

AI Technical Summary

Technical Problem

When supporting systems that only provide REST request access interfaces, the prior art requires the implementation of SQL statements through complex middleware and repeated results, resulting in increased system complexity and poor user experience.

Method used

By converting SQL query statements into abstract syntax trees, using preset mapping rules to build processing nodes into data request bodies in the target format, directly supporting REST interface, avoiding additional middleware services and achieving flexible syntax conversion.

Benefits of technology

No additional middleware services are required, and the support for most REST request interfaces is achieved, the database query capabilities are maximized, syntax conversion is simplified, and the complexity of the data server is reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114003583B_ABST
    Figure CN114003583B_ABST
Patent Text Reader

Abstract

The embodiment of the present application discloses a method, device, medium and equipment for constructing a target format data request body. The embodiment relates to the field of big data technology. Among them, the method includes: obtaining an SQL query statement, converting the SQL query statement into an abstract syntax tree; verifying the abstract syntax tree using pre-acquired metadata, and if there is no problem with the verification, converting the nodes of the abstract syntax tree into processing nodes; wherein the nodes of the abstract syntax tree include root nodes and child nodes; processing the processing nodes according to preset mapping rules to obtain mapping results; constructing the mapping results into a data request body in the target format to make data requests to services that support the target format. This technical solution can solve the bottleneck of pre-agreed formats, does not require additional middleware services, can achieve flexible syntax conversion, and support most REST request interfaces.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of big data technology, and in particular to a method, device, medium and equipment for constructing a target format data request body. Background Art

[0002] With the development of science and technology, data service methods are constantly improving in data solutions. In data solutions, data services are used to obtain data content. Generally, data services provide data access methods using REST request access interfaces. Ideally, all calling methods use REST requests to access data. However, with the rise of various databases, the types of interfaces supported by databases vary. For example, the lower version of ElasticSesrch still only provides REST request access interfaces.

[0003] In order to support systems that only provide REST request access interfaces, the current traditional solutions are: first, by designing a relatively fixed query mode, using the middleware server to perform corresponding conversions and encapsulation; second, by bypassing the REST interface of the original system, directly connecting to the REST interface of the original system, and repeatedly implementing statement conversion.

[0004] Currently, for systems that only provide REST request access interfaces, existing solutions increase the complexity of the entire system because different databases require different middleware. If the complex logic that has been implemented by the original system's REST interface is implemented again through SQL statements at the access end, the work is repeated and complex SQL statements need to be written, which increases the complexity of statement writing and leads to a less friendly user experience. Summary of the invention

[0005] The embodiments of the present application provide a method, device, medium and equipment for constructing a target format data request body, which does not require additional middleware services, can achieve flexible syntax conversion, support most REST request interfaces, make full use of client resources, and avoid increasing the complexity of the data server.

[0006] In a first aspect, an embodiment of the present application provides a method for constructing a target format data request body, the method comprising:

[0007] Obtain SQL query statements, and convert the SQL query statements into an abstract syntax tree;

[0008] The abstract syntax tree is verified using pre-acquired metadata, and if the verification is correct, the nodes of the abstract syntax tree are converted into processing nodes; wherein the nodes of the abstract syntax tree include a root node and child nodes;

[0009] Process the processing node according to the preset mapping rule to obtain the mapping result;

[0010] The mapping result is constructed into a data request body in the target format to make data requests to services that support the target format.

[0011] Optionally, the processing node is processed according to a preset mapping rule to obtain a mapping result, including:

[0012] Process the processing nodes according to the preset mapping rules to obtain the target request body of each processing node;

[0013] The target request body is spliced ​​to obtain the mapping result.

[0014] Optionally, the processing node includes at least one of Filter, Project, Sort and Scan;

[0015] The target request body includes at least one of source, termquery, Sort, and index name in the ElasticSearch database.

[0016] Optionally, the processing node is processed according to a preset mapping rule to obtain a target request body of each processing node, including:

[0017] If the processing node is Filter, the source request body is obtained by processing according to the preset mapping rules;

[0018] If the processing node is Project, it is processed according to the preset mapping rules to obtain the termquery request body;

[0019] If the processing node is Sort, the Sort request body is obtained by processing according to the preset mapping rule;

[0020] If the processing node is Scan, the index name request body is obtained by processing according to the preset mapping rule.

[0021] Optionally, convert the nodes of the abstract syntax tree into processing nodes, including:

[0022] If the node of the abstract syntax tree is where or having, it is converted into a Filter processing node;

[0023] If the node of the abstract syntax tree is select, it is converted into a Project processing node;

[0024] If the node of the abstract syntax tree is order by, offset or fetch, it is converted into a Sort processing node;

[0025] If the node of the abstract syntax tree is from, it is converted into a Scan processing node.

[0026] Optionally, after converting the SQL query statement into an abstract syntax tree, the method further includes:

[0027] The abstract syntax tree is verified using pre-acquired metadata. If there is a problem with the verification, it is determined to be an illegal SQL statement and an error message is returned.

[0028] Optionally, before converting the SQL statement into an abstract syntax tree, the method further includes:

[0029] Obtain and cache metadata of a service that supports a target format; wherein the metadata includes at least one of a database name, a table name, a field name, and a field type.

[0030] In a second aspect, an embodiment of the present application provides a device for constructing a target format data request body, the device comprising:

[0031] A statement conversion module, used to obtain an SQL query statement and convert the SQL query statement into an abstract syntax tree;

[0032] A verification module, used to verify the abstract syntax tree using pre-acquired metadata, and if there is no problem with the verification, convert the nodes of the abstract syntax tree into processing nodes; wherein the nodes of the abstract syntax tree include root nodes and child nodes;

[0033] A mapping module, used to process the processing node according to a preset mapping rule to obtain a mapping result;

[0034] The data request module is used to construct the mapping result into a data request body in a target format to make a data request to a service supporting the target format.

[0035] In a third aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method for constructing a target format data request body as described in the embodiment of the present application.

[0036] In a fourth aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method for constructing a target format data request body as described in the embodiment of the present application is implemented.

[0037] The technical solution provided by the embodiment of the present application provides a method, device, medium and equipment for constructing a target format data request body. First, an SQL query statement is obtained, the SQL query statement is converted into an abstract syntax tree, and then the nodes of the abstract syntax tree are converted into processing nodes; secondly, the processing node is processed according to a preset mapping rule to obtain a mapping result; and the mapping result is constructed into a data request body in the target format to make data requests to services that support the target format, solve the bottleneck of the pre-agreed format, and do not require additional middleware services. Flexible syntax conversion can be achieved, most REST request interfaces can be supported, and the data query capabilities of the database can be maximized. Using the above solution, syntax conversion can be flexibly achieved, client resources can be fully utilized, and the complexity of the data service end can be avoided. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 is a flowchart of a method for constructing a target format data request body provided in Embodiment 1 of the present invention;

[0039] Figure 2 is a flowchart of another method for constructing a target format data request body provided by Embodiment 2 of the present invention;

[0040] Figure 3 It is a structural block diagram of a device for constructing a target format data request body provided by Embodiment 3 of the present invention;

[0041] Figure 4 It is a structural schematic diagram of an electronic device provided in Example 5 of the present application. DETAILED DESCRIPTION

[0042] The present application will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present application, rather than to limit the present application. It should also be noted that, for ease of description, only the parts related to the present application, rather than all structures, are shown in the accompanying drawings.

[0043] It should be mentioned before discussing the exemplary embodiments in more detail that some exemplary embodiments are described as processes or methods depicted as flow charts. Although the flow charts describe the steps as sequential processes, many of the steps therein can be implemented in parallel, concurrently or simultaneously. In addition, the order of the steps can be rearranged. The process can be terminated when its operation is completed, but can also have additional steps not included in the accompanying drawings. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.

[0044] Embodiment 1

[0045] Figure 1It is a flowchart of a method for constructing a target format data request body provided in Example 1 of the present invention. This embodiment can be applicable to scenarios in which data is accessed through a data request body. The method can be executed by a device for constructing a target format data request body provided in an embodiment of the present application. The device can be implemented by software and / or hardware and can be integrated into an electronic device.

[0046] like Figure 1 As shown, the method for constructing a target format data request body provided by the first embodiment of the present invention includes the following steps:

[0047] S110: Obtain an SQL query statement, and convert the SQL query statement into an abstract syntax tree.

[0048] The SQL query statement retrieves data that meets the conditions from a Java Database Connectivity (JDBC) database. Exemplarily, the query data source can come from one table, multiple tables, or a view. The query result is a record set consisting of 0 rows (no data that meets the conditions) or multiple rows of records, and allows one or more fields to be selected as output fields.

[0049] The abstract syntax tree is an abstract representation of the syntax structure of the source code. It represents the syntax structure of the programming language in a tree form, and each node on the tree represents a structure in the source code. The nodes of the abstract syntax tree include root nodes and child nodes.

[0050] Specifically, the SQL query statement is stored in a table from JDBC, and the corresponding required information is stored to generate a similar log table. The SQL query statement can be obtained by reading it in the program, and then the SQL query statement is parsed and converted into an abstract syntax tree that identifies the query statement structure in a useful way.

[0051] S120: Verify the abstract syntax tree using pre-acquired metadata. If the verification is successful, convert the nodes of the abstract syntax tree into processing nodes.

[0052] Specifically, the abstract syntax tree is verified using pre-acquired metadata. When the type of a field is numeric, but the numeric type in SQL is a string, the numeric type does not match and is returned directly. When A does not exist in the metadata, the one with quotation marks is considered a string, and the one without quotation marks cannot be recognized, and it is confirmed to be problematic.

[0053] Among them, the nodes of the abstract syntax tree may include a root node and child nodes; the processing node may be a relational expression, and the relational expression processes data, usually including Sort, Join, Project, Filter and Scan functions, etc., which are not limited in the embodiments of the present invention.

[0054] Specifically, the nodes of the abstract syntax tree are converted into processing nodes. The relational expressions of all processing nodes can be found in SQL Select, such as where and having corresponding to Filter, select List corresponding to Project, order By, offset and fetch corresponding to Sort, and From corresponding to Scan / Join, etc. Finally, all the nodes of the abstract syntax tree generate corresponding processing nodes.

[0055] S130: Process the processing node according to a preset mapping rule to obtain a mapping result.

[0056] Among them, the preset mapping rule can be that each processing node corresponds to an operation processing on the data, such as where and having correspond to Filter, selectList corresponds to Project, order By, offset and fetch corresponds to Sort, From corresponds to Scan / Join, etc. The embodiment of the present invention does not limit this.

[0057] S140: Construct the mapping result into a data request body in a target format to make a data request to a service supporting the target format.

[0058] The data request body is the data sent by the client to the application programming interface.

[0059] Specifically, to construct the mapping result into a data request body in the target format, it is necessary to map the data processing operations such as Filter, Project, Sort, Scan and Join one by one. For example, Project corresponds to the _source request body in ElasticSearch, Filter corresponds to termquery, Sort corresponds to Sort, and Scan corresponds to the index name, which is equivalent to the table name of the traditional database.

[0060] The technical solution provided in the embodiment of the present application solves the bottleneck of the pre-agreed format by realizing flexible syntax conversion, does not require additional middleware services, supports most REST request interfaces, maximizes the use of database data query capabilities, fully utilizes client resources, and avoids increasing the complexity of the data server.

[0061] On the basis of the above technical solution, optionally, before converting the SQL statement into an abstract syntax tree, the method further includes: obtaining and caching metadata of services that support the target format; wherein the metadata includes at least one of a database name, a table name, a field name, and a field type. Wherein, metadata refers to data that describes data, descriptive information about information and information resources. Specifically, the metadata of services that support the target format is obtained and cached, and the metadata is accessed using system stored procedures and system functions. The system stored procedures and system functions provide an abstract layer between the system tables and the metadata, so that we can obtain the metadata of the current database object without directly querying the system tables. The advantage of this setting is that the converted SQL statement can be syntax-checked in advance to avoid the situation where the corresponding data cannot be obtained due to syntax errors, thereby improving data access efficiency and success rate.

[0062] On the basis of the above technical solution, optionally, after converting the SQL query statement into an abstract syntax tree, the method further includes: verifying the abstract syntax tree using pre-acquired metadata, and if there is a problem with the verification, it is determined to be an illegal SQL statement, and an error message is returned. Specifically, the abstract syntax tree uses pre-acquired metadata for verification. If the type of a field is a numeric type, but this numeric type in SQL is equal to a string, the type does not match, then there is a problem with the verification, it is determined to be an illegal SQL syntax, and an error message is returned. Exemplarily, if there is no A in the metadata, it is considered a string only if it is in quotation marks, and A is not in quotation marks, so the type does not match, confirming that there is a problem with the verification, A is determined to be an illegal SQL syntax, and an error message A is returned. The advantage of this setting is that the metadata pre-acquired for the converted abstract syntax tree is verified and screened, and illegal SQL statements are returned, thereby improving the efficiency of subsequent conversion steps and avoiding increasing the complexity of the system.

[0063] On the basis of the above technical solution, optionally, the nodes of the abstract syntax tree are converted into processing nodes, including: if the node of the abstract syntax tree is where or having, it is converted into a Filter processing node; if the node of the abstract syntax tree is select, it is converted into a Project processing node; if the node of the abstract syntax tree is order by, offset or fetch, it is converted into a Sort processing node; if the node of the abstract syntax tree is from, it is converted into a Scan processing node. Among them, the node of the abstract syntax tree is an intermediate data structure used for table-to-table relational operations in data structuring. Through semantic analysis of the nodes of the abstract syntax tree, it is converted into a processing node, and the conversion is performed by initializing RexBuilder; initializing RelOptPlanner; initializing RelOptCluster; initializing SqlToRelConverter. The advantage of this setting is that the nodes of the abstract syntax tree can be semantically analyzed, the corresponding logical plan can be generated, and the code can be logically optimized.

[0064] Embodiment 2

[0065] Figure 2 It is a flowchart of another method for constructing a target format data request body provided by the second embodiment of the present invention. This embodiment is optimized based on the above embodiment. The specific optimization is: processing the processing node according to the preset mapping rule to obtain the mapping result, including: processing the processing node according to the preset mapping rule to obtain the target request body of each processing node; splicing the target request body to obtain the mapping result; the processing node includes at least one of Filter, Project, Sort and Scan; the target request body includes at least one of source, termquery, Sort and index name in the ElasticSearch database; processing the processing node according to the preset mapping rule to obtain the target request body of each processing node, including: if the processing node is Filter, it is processed according to the preset mapping rule to obtain the source request body; if the processing node is Project, it is processed according to the preset mapping rule to obtain the termquery request body; if the processing node is Sort, it is processed according to the preset mapping rule to obtain the Sort request body; if the processing node is Scan, it is processed according to the preset mapping rule to obtain the index name request body.

[0066] like Figure 2 As shown, the method of this embodiment specifically includes the following steps:

[0067] S210: Obtain an SQL query statement, and convert the SQL query statement into an abstract syntax tree.

[0068] S220: Verify the abstract syntax tree using pre-acquired metadata. If the verification is successful, convert the nodes of the abstract syntax tree into processing nodes.

[0069] S230 , processing the processing nodes according to the preset mapping rules to obtain the target request body of each processing node.

[0070] Among them, the processing node is a relational expression, and the relational expression processes data, usually including Sort, Join, Project, Filter and Scan functions; the preset mapping rule is that each processing node corresponds to an operation processing on the data, such as where and having correspond to Filter, selectList corresponds to Project, order By, offset, fetch correspond to Sort, From corresponds to Scan / Join, etc., and the embodiment of the present invention does not limit this.

[0071] The target request body is to convert the processing node into a Representational State Transfer (REST) ​​structure according to the abstract syntax tree.

[0072] Specifically, the processing data Sort, Join, Project, Filter and Scan functions corresponding to the processing nodes are processed in correspondence with one operation to obtain a target request body corresponding to each processing node.

[0073] S240: splice the target request body to obtain a mapping result.

[0074] Among them, the mapping result is a string supported by REST, etc. Specifically, the attribute names in the table field entity class in the database are mapped to determine which field name corresponds to the attribute name.

[0075] S250: Construct the mapping result into a data request body in a target format to support data request by a service in the target format.

[0076] The technical solution provided in the embodiment of the present application processes the processing nodes according to the preset mapping rules to obtain the target request body of each processing node; splices the target request bodies to obtain the mapping results, thereby realizing flexible SQL semantic conversion.

[0077] On the basis of the above technical solution, optionally, the processing node includes at least one of Filter, Project, Sort and Scan, and the target request body includes at least one of source, termquery, Sort and index name in the ElasticSearch database; the processing node is processed according to the preset mapping rules to obtain the target request body of each processing node, including: if the processing node is Filter, it is processed according to the preset mapping rules to obtain the source request body; if the processing node is Project, it is processed according to the preset mapping rules to obtain the termquery request body; if the processing node is Sort, it is processed according to the preset mapping rules to obtain the Sort request body; if the processing node is Scan, it is processed according to the preset mapping rules to obtain the index name request body.

[0078] Among them, the preset mapping rules can be that each processing node corresponds to an operation processing on the data, such as where and having correspond to Filter, selectList corresponds to Project, order By, offset and fetch corresponds to Sort, From corresponds to Scan / Join, etc. The advantage of this setting is that it does not require additional middleware services, can flexibly implement conversion between syntaxes, and provide more flexible data service capabilities.

[0079] Embodiment 3

[0080] Figure 3 is a structural block diagram of a device for constructing a target format data request body provided by Embodiment 3 of the present invention, such as Figure 3 As shown, the target format data request body construction device specifically includes: a statement conversion module 310, a verification module 320, a mapping module 330 and a data request module 340. Among them,

[0081] A statement conversion module 310 is used to obtain a SQL query statement and convert the SQL query statement into an abstract syntax tree;

[0082] A verification module 320 is used to verify the abstract syntax tree using the pre-acquired metadata, and if there is no problem with the verification, the nodes of the abstract syntax tree are converted into processing nodes; wherein the nodes of the abstract syntax tree include root nodes and child nodes;

[0083] A mapping module 330 is used to process the processing node according to a preset mapping rule to obtain a mapping result;

[0084] The data request module 340 is used to construct the mapping result into a data request body in a target format to make a data request to a service supporting the target format.

[0085] Optionally, the statement conversion module 310 includes:

[0086] The verification unit is used to verify the abstract syntax tree using pre-acquired metadata after converting the SQL query statement into the abstract syntax tree. If there is a problem with the verification, it is determined to be an illegal SQL statement and an error message is returned.

[0087] Optionally, the statement conversion module 310 further includes:

[0088] The acquisition unit is used to acquire and cache metadata of services supporting the target format before converting the SQL statement into an abstract syntax tree; wherein the metadata includes at least one of a database name, a table name, a field name, and a field type.

[0089] Optionally, the verification module 320 converts the nodes of the abstract syntax tree into processing nodes, specifically including:

[0090] A first processing unit, configured to convert a node of the abstract syntax tree into a Filter processing node if the node is a where or a having;

[0091] The second processing unit is used for converting the node of the abstract syntax tree into a Project processing node if the node is a select;

[0092] A third processing unit, configured to convert a node of the abstract syntax tree into a Sort processing node if the node is order by, offset or fetch;

[0093] The fourth processing unit is used to convert the node of the abstract syntax tree into a Scan processing node if the node is from.

[0094] Optionally, the mapping module 330 specifically includes:

[0095] A mapping unit, used to process the processing nodes according to a preset mapping rule to obtain a target request body of each processing node;

[0096] The splicing unit is used to splice the target request body to obtain a mapping result.

[0097] Optionally, the mapping module 330 further includes:

[0098] A processing node unit, used for processing nodes including at least one of Filter, Project, Sort and Scan;

[0099] The target request body unit is used for the target request body to include at least one of source, termquery, Sort and index name in the ElasticSearch database.

[0100] Optionally, the mapping module 330 processes the processing node according to a preset mapping rule to obtain a target request body of each processing node, specifically including:

[0101] A first mapping unit, configured to obtain a source request body by processing according to a preset mapping rule if the processing node is a Filter;

[0102] The second mapping unit is used for processing the request body of a termquery according to a preset mapping rule if the processing node is a Project;

[0103] A third mapping unit, configured to, if the processing node is Sort, process the request according to a preset mapping rule to obtain a Sort request body;

[0104] The fourth mapping unit is used to obtain the index name request body by processing according to a preset mapping rule if the processing node is Scan.

[0105] The above-mentioned product can execute the method for constructing the target format data request body provided in the embodiment of the present application, and has the functional modules and beneficial effects corresponding to the execution method.

[0106] Embodiment 4

[0107] Embodiment 4 of the present invention provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the method for constructing a target format data request body provided in all embodiments of the present invention is implemented:

[0108] Obtain SQL query statements, and convert the SQL query statements into an abstract syntax tree;

[0109] The abstract syntax tree is verified using pre-acquired metadata, and if the verification is correct, the nodes of the abstract syntax tree are converted into processing nodes; wherein the nodes of the abstract syntax tree include a root node and child nodes;

[0110] Process the processing node according to the preset mapping rule to obtain the mapping result;

[0111] The mapping result is constructed into a data request body in the target format to make data requests to services that support the target format.

[0112] Any combination of one or more computer-readable media may be used. A computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in conjunction with an instruction execution system, device, or device.

[0113] Computer-readable signal media may include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable program code. Such propagated data signals may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0114] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0115] Computer program code for performing the operations of the present invention may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0116] Embodiment 5

[0117] Embodiment 5 of the present application provides an electronic device. Figure 4 Schematic diagram of the structure of an electronic device provided in Embodiment 5 of the present application. Figure 4 As shown, this embodiment provides an electronic device, which includes: one or more processors 420; a storage device 410, which is used to store one or more programs. When the one or more programs are executed by the one or more processors 420, the one or more processors 420 implement the method for constructing a target format data request body provided in the embodiment of the present application, and the method includes:

[0118] Obtain SQL query statements, and convert the SQL query statements into an abstract syntax tree;

[0119] The abstract syntax tree is verified using pre-acquired metadata, and if the verification is correct, the nodes of the abstract syntax tree are converted into processing nodes; wherein the nodes of the abstract syntax tree include a root node and child nodes;

[0120] Process the processing node according to the preset mapping rule to obtain the mapping result;

[0121] The mapping result is constructed into a data request body in the target format to make data requests to services that support the target format.

[0122] Of course, those skilled in the art can understand that the processor 420 also implements the technical solution of the method for constructing the target format data request body provided in any embodiment of the present application.

[0123] Figure 4 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0124] like Figure 4 As shown, the electronic device includes a processor 420, a storage device 410, an input device 430 and an output device 440; the number of the processor 420 in the electronic device can be one or more. Figure 4 A processor 420 is taken as an example; the processor 420, storage device 410, input device 430 and output device 440 in the electronic device can be connected via a bus or other means.

[0125] The storage device 410, as a computer-readable storage medium, can be used to store software programs, computer executable programs and module units, such as program instructions corresponding to the method for constructing the target format data request body in the embodiment of the present application.

[0126] The storage device 410 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created according to the use of the terminal, etc. In addition, the storage device 410 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some instances, the storage device 410 may further include a memory remotely arranged relative to the processor 420, and these remote memories may be connected via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0127] The input device 430 may be used to receive input numbers, character information or voice information, and generate key signal input related to user settings and function control of the electronic device. The output device 440 may include electronic devices such as a display screen and a speaker.

[0128] The electronic device provided in the embodiment of the present application can convert SQL into a more general abstract syntax tree, map various expressions in the syntax tree into corresponding REST request expressions, support flexible SQL semantics, and maximize the use of the database's data query capabilities.

[0129] The target format data request body construction device, medium and equipment provided in the above embodiments can execute the target format data request body construction method provided in any embodiment of the present application, and have the corresponding functional modules and beneficial effects of executing the method. For technical details not described in detail in the above embodiments, please refer to the target format data request body construction method provided in any embodiment of the present application.

[0130] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims

1. A method for constructing a target format data request body, characterized in that: The method comprises: Obtaining an SQL query statement, and converting the SQL query statement into an abstract syntax tree; The abstract syntax tree is verified using pre-acquired metadata, and if the verification is correct, the nodes of the abstract syntax tree are converted into processing nodes; wherein the nodes of the abstract syntax tree include root nodes and child nodes; and the processing nodes include at least one of Filter, Project, Sort, and Scan; Processing the processing nodes according to the preset mapping rules to obtain the target request body of each processing node; wherein the target request body includes at least one of source, termquery, Sort and index name in the ElasticSearch database; splicing the target request body to obtain a mapping result; constructing the mapping result into a data request body in a target format to make a data request to a service supporting the target format; The processing of the processing nodes according to the preset mapping rules to obtain the target request body of each processing node includes: If the processing node is a Filter, the source request body is obtained by processing according to the preset mapping rule; If the processing node is Project, the termquery request body is obtained by processing according to the preset mapping rule; If the processing node is Sort, the Sort request body is obtained by processing according to the preset mapping rule; If the processing node is Scan, the index name request body is obtained by processing according to the preset mapping rule; The step of converting the nodes of the abstract syntax tree into processing nodes includes: If the node of the abstract syntax tree is where or having, it is converted into a Filter processing node; If the node of the abstract syntax tree is select, it is converted into a Project processing node; If the node of the abstract syntax tree is order by, offset or fetch, it is converted into a Sort processing node; If the node of the abstract syntax tree is from, it is converted into a Scan processing node.

2. The method according to claim 1, characterized in that After converting the SQL query statement into an abstract syntax tree, the method further includes: The abstract syntax tree is verified using pre-acquired metadata. If there is a problem with the verification, it is determined to be an illegal SQL statement and an error message is returned.

3. The method according to claim 1, characterized in that Before converting the SQL statement into an abstract syntax tree, the method further includes: Obtain and cache metadata of a service that supports a target format; wherein the metadata includes at least one of a database name, a table name, a field name, and a field type.

4. A device for constructing a target format data request body, characterized in that: The device comprises: A statement conversion module, used to obtain an SQL query statement and convert the SQL query statement into an abstract syntax tree; A verification module, used to verify the abstract syntax tree using pre-acquired metadata, and if the verification is correct, convert the nodes of the abstract syntax tree into processing nodes; wherein the nodes of the abstract syntax tree include root nodes and child nodes; and the processing nodes include at least one of Filter, Project, Sort, and Scan; A mapping module, including a mapping unit and a splicing unit; The mapping unit is used to process the processing nodes according to the preset mapping rules to obtain the target request body of each processing node; wherein the target request body includes at least one of source, termquery, Sort and index name in the ElasticSearch database; The splicing unit is used to splice the target request body to obtain a mapping result; the data request module is used to construct the mapping result into a data request body in a target format to make a data request to a service supporting the target format; The processing of the processing nodes according to the preset mapping rules to obtain the target request body of each processing node includes: If the processing node is a Filter, the source request body is obtained by processing according to the preset mapping rule; If the processing node is Project, the termquery request body is obtained by processing according to the preset mapping rule; If the processing node is Sort, the Sort request body is obtained by processing according to the preset mapping rule; If the processing node is Scan, the index name request body is obtained by processing according to the preset mapping rule; The step of converting the nodes of the abstract syntax tree into processing nodes includes: If the node of the abstract syntax tree is where or having, it is converted into a Filter processing node; If the node of the abstract syntax tree is select, it is converted into a Project processing node; If the node of the abstract syntax tree is order by, offset or fetch, it is converted into a Sort processing node; If the node of the abstract syntax tree is from, it is converted into a Scan processing node.

5. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method for constructing a target format data request body as described in any one of claims 1 to 3 is implemented.

6. An electronic device comprising a memory, a processor and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, it implements the method for constructing a target format data request body according to any one of claims 1 to 3.

Citation Information

Patent Citations

  • Spark SQL-based distributed full text retrieval system and method

    CN107122443A

  • Data query method, system and device

    CN110399388A

  • Data processing method and device based on database engine, terminal and medium

    CN111522816A

  • Request body generation method and device based on interface document, and computer equipment

    CN112506769A

  • Database script migration method and device, computer equipment and storage medium

    CN112527815A