Data query method, device and computer readable storage medium
By generating query statements through a configurable query engine, the problem of frequent code changes under different database types is solved, enabling flexible and efficient data querying and result retrieval, simplifying user operations, and enhancing data security.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA MERCHANTS BANK
- Filing Date
- 2023-08-01
- Publication Date
- 2026-07-24
AI Technical Summary
With numerous and complex database types, users need to constantly modify the code, resulting in excessively high query costs. Traditional query methods lack flexibility and make it difficult to share query statements and monitor query traffic.
It employs a configurable query engine, which determines the query template corresponding to the user's query request, performs syntax parsing to generate query statements, and executes the query to obtain results. It hides the details of database connection and query statement modification, and users can obtain results simply by calling it via HTTP request.
It supports different databases and query statements without modifying the code, reducing the learning and query costs for users, improving the flexibility and efficiency of queries, and supporting data monitoring and protection of sensitive data.
Smart Images

Figure CN116991872B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of database technology, and in particular to data query methods, devices, and computer-readable storage media. Background Technology
[0002] A data query engine based on JDBC (Java Database Connectivity) is a tool or library that uses JDBC technology to query and manipulate databases. It allows developers to use Java code to connect to the database and perform operations such as queries, updates, and deletes.
[0003] In related technologies, the process of implementing a Java database connection includes selecting a database, establishing and obtaining a database connection, constructing a query statement, encapsulating and sending the query statement, receiving the query results, processing and returning the query results, and closing the connection.
[0004] However, the syntax and connection methods differ for each database type, necessitating the writing of different connection codes for each database. Furthermore, the variety of query statements necessitates frequent code modifications for their creation. Therefore, with numerous and complex database types, users are forced to constantly change their code, resulting in excessively high query costs.
[0005] The above content is only used to help understand the technical solution of the present invention and does not represent an admission that the above content is prior art. Summary of the Invention
[0006] The main objective of this invention is to provide a data query method, device, and computer-readable storage medium, aiming to solve the technical problem that users need to constantly change code and the query cost is too high when there are many complex database types.
[0007] To achieve the above objectives, the present invention provides a data query method, which includes the following steps:
[0008] Determine the query template corresponding to the user's query request;
[0009] The query request and the query template are parsed to generate the corresponding query statement;
[0010] The query statement is executed to obtain the corresponding query results, which are then sent to the user.
[0011] Optionally, the step of parsing the query request and the query template to generate the corresponding query statement includes:
[0012] Parse the request parameters in the context of the query request, as well as the database table information, return value field information, and processing information of the query template;
[0013] Based on the request parameters, the database table information, the return value field information, and the processing information, a statement to be verified is assembled.
[0014] If the statement to be verified meets the preset verification conditions, then the statement to be verified is determined as a query statement.
[0015] Optionally, the processing information includes a default filter value, a sorting field and sorting method, an aggregation field and aggregation method, and a default pagination value. The step of assembling and generating the statement to be validated based on the request parameters, the database table information, the return value field information, and the processing information includes:
[0016] Based on the filter condition values in the request body of the request parameters, or the default filter values, generate the filter information for the query statement.
[0017] Based on the sorting field and sorting method, generate the sorting information for the query statement;
[0018] Based on the aggregation fields and aggregation methods, generate grouping and aggregation information for the query statement;
[0019] Based on the pagination information value in the request body of the request parameters, or the default pagination value, generate the pagination information of the query statement;
[0020] Based on the request parameters, the database table information, the return value field information, the filtering information, the sorting information, the grouping and aggregation information, and the analysis information, a statement to be verified is assembled.
[0021] Optionally, the step of determining the query template corresponding to the user's query request includes:
[0022] Determine the corresponding interface based on the query service identifier carried in the user's query request;
[0023] If the authentication information in the request header of the query request is consistent with the authentication information of the interface, then authentication is successful.
[0024] Based on the correspondence between the interface and the query template, determine the query template corresponding to the interface.
[0025] Optionally, the step of executing the query statement, obtaining the corresponding query result, and sending the query result to the user includes:
[0026] Execute the query statement to obtain the initial query results.
[0027] The initial query results are processed according to the preset data processing script to obtain the final query results, which are then sent to the user.
[0028] Optionally, before the step of determining the query template corresponding to the user's query request, the following steps are included:
[0029] Upon receiving a user's configuration request, determine the interface information carried in the configuration request;
[0030] According to the configuration request, configure the request parameters, script, query statement and return result set;
[0031] Establish the configuration relationship between the interface information, the request parameters, the script, the query statement, and the returned result set, and generate a query template.
[0032] Optionally, after the step of establishing the configuration relationship between the interface information, the request parameters, the script, the query statement, and the returned result set, and generating the query template, the method includes:
[0033] Establish the correspondence between the configuration template and the interface;
[0034] Based on the configuration rules, determine all nodes in the interface;
[0035] Based on all the nodes and node configuration information, generate the execution chain of the interface;
[0036] All nodes in the execution chain are initialized and preprocessed to obtain the final interface;
[0037] The query domain name corresponding to the interface is determined according to the preset naming rules.
[0038] Optionally, the step of determining all nodes in the query template according to the configuration rules includes:
[0039] Determine the number of nodes in the interface whose node type is output node;
[0040] If the number of nodes is one, then the output node is used as the endpoint to determine other nodes in a recursive manner;
[0041] If there are multiple nodes or no nodes, a configuration error message will be returned.
[0042] In addition, to achieve the above objectives, the present invention also provides a data query device, the data query device comprising: a memory, a processor, and a data query program stored in the memory and executable on the processor, the data query program being configured to implement the steps of the data query method described above.
[0043] In addition, to achieve the above objectives, the present invention also provides a computer-readable storage medium storing a data query program, which, when executed by a processor, implements the steps of the data query method.
[0044] In one technical solution provided by this invention, a query template corresponding to a user's query request is determined, then a corresponding query statement is generated through syntax parsing, and finally the corresponding query result is obtained and sent to the user. Through a configurable query engine, regardless of the database or the query statement, the user does not need to modify the code. They only need to access a specific domain name and input relevant parameters, and the query engine will automatically match the query template, generate the corresponding query statement, perform the query, and return the result. Therefore, this solution can significantly reduce the user's query cost. Attached Figure Description
[0045] Figure 1 This is a flowchart illustrating the first embodiment of the data query method of the present invention;
[0046] Figure 2 This is a flowchart illustrating the second embodiment of the data query method of the present invention;
[0047] Figure 3 This is a flowchart illustrating the third embodiment of the data query method of the present invention;
[0048] Figure 4 This is a flowchart illustrating the fourth embodiment of the data query method of the present invention;
[0049] Figure 5 This is a schematic diagram of the structure of a data query device in the hardware operating environment involved in the embodiments of the present invention.
[0050] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0051] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
[0052] There are various existing query tools, such as JDBC-based data query engines, query tools based on visualization software or interfaces, and query engines based on routing and forwarding.
[0053] JDBC-based data query engines have several drawbacks. First, they have a high learning curve due to inconsistent syntax and connection methods across different database types. Second, JDBC-developed query statements require maintenance within the code, making them difficult to share. Third, JDBC cannot be used to develop new query scenarios in real-time; deployment typically follows iteration cycles, resulting in long development times. Fourth, JDBC only allows for user-based access control, making it difficult to trace downstream users. Fifth, JDBC cannot intercept or filter query requests, which can lead to slow database queries or crashes of some database nodes under high concurrency. Finally, JDBC exposes private database connection information, posing a risk of data leakage for databases containing highly sensitive data.
[0054] Visualized query tools can only retrieve data within the corresponding visualization interface, and the retrieved data can only be used for viewing or file download, and cannot be provided to other systems via APIs. Visualized methods are affected by browser performance, and the number of data records returned is limited. Visualized methods require integration with other data analysis platforms to perform data analysis and processing, which results in high platform integration costs.
[0055] Query engines based on routing forwarding distribute query statements to different databases through a unified query route. They typically only provide a few common query interfaces, and each time a new interface is added, developers need to develop and deploy it, resulting in poor flexibility and difficulty in expanding query scenarios.
[0056] In short, traditional JDBC-based query methods, when dealing with numerous and complex database types within a given industry, require users to constantly modify Java code. This makes data queries difficult for users in different departments or those without backend developers, resulting in excessively high query costs. Traditional query methods also require iterative deployment of new query functions, leading to long development cycles and poor flexibility. The query statements or code provided by traditional methods cannot be shared via interfaces, resulting in redundant development and difficulties in data sharing. Furthermore, traditional methods only manage query statements at the database level, making it difficult to monitor query statements, implement flow control, data anonymization, and data validation.
[0057] To address the aforementioned issues, this solution employs a configurable query engine that shields users from underlying details such as database connections and query statement modifications during the query process. Users can obtain the corresponding query results simply by making an HTTP request, significantly reducing the learning curve for users.
[0058] To better understand the above technical solutions, exemplary embodiments of this application will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of this application are shown in the drawings, it should be understood that this application can be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided to enable a more thorough understanding of this application and to fully convey the scope of this application to those skilled in the art.
[0059] This invention provides a data query method, referring to... Figure 1 , Figure 1 This is a flowchart illustrating a first embodiment of a data query method according to the present invention.
[0060] In this embodiment, the data query method includes:
[0061] Step S11: Determine the query template corresponding to the user's query request;
[0062] This solution adopts a configurable API (Application Programming Interface) query engine, which mainly consists of the following modules: API configuration generation module, API configuration automated deployment module, API interface query syntax parsing module, API query statement execution module, API result processor, and API query gateway module.
[0063] The management of the API development phase mainly includes: the API configuration generation module and the API configuration automated deployment module, which are mainly used for API generation and API deployment; the management of the API runtime phase mainly includes: the API interface query syntax parsing module, the API query statement execution module, the API result processor, and the API query gateway module, etc.
[0064] Understandably, the API development environment will generate domain names for several query templates and their corresponding interfaces. Each query template corresponds to a different query function, meaning the query engine supports access to multiple interfaces to enable diverse queries. When a user needs to perform a query, they simply need to access the corresponding interface by calling the domain name and entering the appropriate parameters to complete the query.
[0065] Optionally, after receiving a user's query request, the domain name information carried in the query request is parsed to determine the interface accessed by the user. Then, based on the pre-set correspondence between interfaces and query templates, the query template associated with the accessed interface is determined, that is, the query template corresponding to the user's query request.
[0066] Step S12: Perform syntax parsing on the query request and the query template to generate the corresponding query statement;
[0067] Understandably, the API interface query syntax parsing module in the API runtime management is mainly responsible for parsing the query syntax and generating the corresponding JDBC query statement for database querying.
[0068] Optionally, the query request and the query template are input into the trained syntax parsing module, which can use natural language processing techniques, keyword extraction, syntax tree parsing, semantic parsing, etc., to finally generate the corresponding query statement.
[0069] Step S121: Parse the request parameters in the context of the query request, as well as the database table information, return value field information, and processing information of the query template;
[0070] On one hand, depending on the programming language and framework used, determine the methods needed to retrieve the request parameters from the context of the query request. For example, use request.getInputStream() (to retrieve the request body parameter) and request.getParameterMap (to retrieve the path parameter) to retrieve key-value pairs of all parameters.
[0071] On the other hand, the query nodes in the query template are identified, and the database and table information stored in the query node is obtained, namely the specific database name and table name to be queried. The database and table information is used to construct the table information in the reception validation statement. The return nodes in the query template are identified, and the return value field information stored in the return node is obtained, which is used to construct the return statement in the reception validation statement. The script processing nodes in the query template are identified, and the processing information of the return node, such as filtering information, assembly information, grouping and aggregation information, is obtained, which is used to construct the processing statement in the reception validation statement.
[0072] Step S122: Assemble and generate the statement to be verified based on the request parameters, the database table information, the return value field information, and the processing information;
[0073] Optionally, the above steps achieve the acquisition of each part of the statement to be verified. Based on this, if the SQL is configured with ${param} placeholders, then the variable values are replaced and the SQL is assembled using String.replace. If the SQL is configured with #{param} placeholders, then the placeholders (?) are used to represent each part of the statement to be verified, and the actual parameter values are bound to the placeholders. The actual parameter values are stored in an array structure. The specific method is not specifically limited in this embodiment. Finally, the statement to be verified is assembled.
[0074] Step S123: If the statement to be verified meets the preset verification conditions, then the statement to be verified is determined as a query statement.
[0075] Optionally, the SQLUtils validation tool from the Druid can be used to perform syntax validation on the statement to be validated.
[0076] Furthermore, if the statement to be verified meets the preset verification conditions, such as if the statement to be verified is a single statement and is a query statement, then the verification passes, and the statement to be verified is identified as a query statement to prevent users from inputting malicious parameters, thereby ensuring the reliability of the query.
[0077] The processing information includes a default filter value, sorting field and sorting method, aggregation field and aggregation method, and a default pagination value. The step of assembling and generating the statement to be verified based on the request parameters, the database table information, the return value field information, and the processing information includes:
[0078] Step S1221: Generate filtering information for the query statement based on the filter condition value in the request body of the request parameters, or the default filter value.
[0079] Step S1222: Generate sorting information for the query statement based on the sorting field and sorting method;
[0080] Step S1223: Generate grouping and aggregation information for the query statement based on the aggregation fields and aggregation methods;
[0081] Step S1224: Generate pagination information for the query statement based on the pagination information value in the request body of the request parameters, or the default pagination value;
[0082] Step S1225: Assemble and generate the statement to be verified based on the request parameters, the database table information, the return value field information, the filtering information, the sorting information, the grouping and aggregation information, and the analysis information.
[0083] Understandably, the script processing node in the query template is identified, and the processing information of the returned node is obtained, including the default filter value, sorting field and sorting method, aggregation field and aggregation method, and default pagination value.
[0084] Optionally, if the request body of the request parameters carries a filter condition value, the filter information in the statement to be validated is set according to the filter condition value; if it does not carry a filter condition value, the filter information is set according to the default filter value in the query template, including equality filtering, range filtering, fuzzy filtering, etc.
[0085] Optionally, the sorting information in the statement to be validated can be set using the sorting field and sorting method (descending or ascending) in the query template.
[0086] Optionally, the aggregation fields and aggregation methods in the query template can be used to set the grouping aggregation information in the statement to be validated;
[0087] Optionally, if the request body of the request parameters carries pagination information, the pagination information in the statement to be validated is set according to the pagination information value; otherwise, it is set according to the default pagination value in the query template. It should be noted that whether to perform pagination processing is an optional configuration. If the user selects to perform pagination queries, the pagination query will be performed based on the grouping and aggregation information in the query statement; otherwise, if pagination is not enabled, pagination queries are not supported. This setting allows for the provision of appropriate data according to the user's needs, improving query performance.
[0088] Step S13: Execute the query statement to obtain the corresponding query results, and send the query results to the user.
[0089] Understandably, the API query statement executor module in the API runtime management is responsible for establishing a query connection with the data source bound to the API configuration and executing the query statements generated by the API syntax parsing module.
[0090] Optionally, based on the database table information in the query statement, the target database is determined, then a connection to the target database is obtained from the database connection pool, and user authentication is performed using the target database connection, and then a JDBC executor for the connection is obtained.
[0091] Optionally, a query statement is sent to the executor, and the query results returned by the executor are received. Finally, the query results are sent to the user. If an error occurs during this process, the database connection pool is reinitialized.
[0092] Step S131: Execute the query statement to obtain the initial query result of the corresponding query result;
[0093] Step S132: Process the initial query results according to the preset data processing script to obtain the final query results, and send the query results to the user.
[0094] Understandably, the API result parsing module in the API runtime management is responsible for receiving and processing the query data returned by the database, executing the predefined data processing scripts configured in the query template, and finally generating the return message.
[0095] Optionally, the following process can be followed: receive the database return data using the data format configured in the query template; ensure consistent time format and scientific notation; if the query template is configured with sorting rules, sort the returned fields according to the sorting rules; if the query template is configured with data anonymization rules, anonymize the data according to the configured anonymization method; if the query template is configured with a data processing script, call the script executor to execute the script and encapsulate the script return results; if the query template is configured with data splitting rules, split the data according to the data splitting rules; and encapsulate the return message with the variable name according to the return code configured in the query template.
[0096] In one technical solution provided in this embodiment, a query template corresponding to a user's query request is determined, then a corresponding query statement is generated through syntax parsing, and finally the corresponding query result is obtained and sent to the user. Through a configurable query engine, regardless of the database or the query statement, the user does not need to modify the code. They only need to access a specific domain name and input relevant parameters, and the query engine will automatically match the query template, generate the corresponding query statement, perform the query, and return the result. Therefore, this solution can significantly reduce the user's query cost.
[0097] Furthermore, refer to Figure 2 A second embodiment of the data query method of the present invention is proposed. Based on the above... Figure 1 In the embodiment shown, the step of determining the query template corresponding to the user's query request includes:
[0098] Step S21: If the authentication information in the request header of the query request is consistent with the authentication information of the interface, then authentication is successful;
[0099] Understandably, the API query gateway module in the API runtime management is an intermediate layer located between the client and the server, responsible for routing and forwarding query requests, authorization checks, monitoring points, etc.
[0100] Optionally, the query service unit obtains the authentication information carried in the request header of the query request, and then compares it with the authentication information of the interface associated with the query service unit. If they match, the authentication is successful, indicating that the current user has the right to query.
[0101] Step S22: Determine the corresponding interface based on the query service identifier carried in the user's query request;
[0102] Optionally, the query service unit is the actual program unit that runs after the API goes live, and different APIs can be isolated through query service units. The API gateway can determine which backend service to forward the request to based on the request identifier. That is, the API gateway first determines the query service identifier carried in the user's query request, and then forwards the query request to the corresponding query service unit based on the query service identifier.
[0103] Furthermore, each query service unit is associated with multiple interfaces, and each interface carries a corresponding query service identifier; that is, each query service unit is associated with a set of query service identifiers. The query gateway determines the query service identifier carried in the query request, compares it with the set of query service identifiers associated with each query service unit, and then sends the query request to the corresponding query service unit. The query service unit stores the mapping relationship between URLs and interfaces, so the query service unit can further find the specific interface based on the URL in the query service identifier.
[0104] Step S23: Determine the query template corresponding to the interface based on the correspondence between the interface and the query template.
[0105] Optionally, based on the pre-defined correspondence between interfaces and query templates, the query template associated with the accessed interface is determined, that is, the query template corresponding to the user's query request.
[0106] In addition, after determining the query template, the query gateway generates a query request context. The context is a memory object that stores the intermediate and final results generated by a request. When the API execution chain executes each node in sequence, it will obtain the output of the previous node as input from the context and also put its own output in the context. It will also obtain the request body and request parameter information, integrate the two information and store them in the API request context. It will set up monitoring information points, that is, after receiving a query request, it will record information such as request time, request parameters, URL, etc., and perform traffic control. It will call the query template and return the data after successful query to the user.
[0107] In one technical solution provided in this embodiment, the query request is first authenticated by the query gateway. Only after successful authentication is the request sent to the corresponding query service unit, which then determines the corresponding query template. This setup ensures that only authenticated users can access and perform query operations, protecting sensitive data and preventing unauthorized access and abuse. Furthermore, in this solution, the query gateway is responsible for routing and authentication, while multiple query service units handle various query functions. This division of labor and clear responsibilities effectively improves development and query efficiency, and facilitates maintenance and modification.
[0108] Furthermore, refer to Figure 3A third embodiment of the data query method of the present invention is proposed. Based on the above... Figure 1 In the illustrated embodiment, prior to the step of determining the query template corresponding to the user's query request, the following steps are included:
[0109] Step S31: After receiving the user's configuration request, determine the interface information carried in the configuration request;
[0110] Understandably, before performing a query, users can customize the query template in the query engine according to their application scenario. The API configuration generation module in the API development mode is responsible for generating query templates.
[0111] Optionally, upon receiving a user's configuration request, determine the interface information carried in the configuration request, including but not limited to: filling in the interface name and interface description; selecting the query service unit for the interface, which is the actual program unit that runs after the interface goes online. Different interfaces can be isolated through the query service unit, and the subsequent interface gateway will perform routing forwarding based on the query service unit; filling in the URL (Uniform Resource Locator) information, which is the final generated HTTP request domain name. The URL will serve as the unique identifier of the interface, and calling different URLs means accessing different interfaces; filling in the interface authentication information, which authenticates the interface by carrying fixed parameters in the HTTP request header. Here, the authentication parameters are configured. The authentication parameters passed by the user must match the configured parameters for successful authentication; and filling in the interface tag information, which is used to classify and manage interfaces.
[0112] Step S32: Configure the request parameters, script, query statement, and return result set according to the configuration request;
[0113] Optionally, the request parameters in the configuration request are determined, which are the input parameters when the interface is called. When the interface is executed, the query statement and script will be executed by concatenating the request parameters. The request parameters will be used as filter conditions, sorting parameters, script input parameters, etc. in the query statement. Here, the field name, field data format, field data type, etc. of the request parameters are configured.
[0114] Optionally, the script includes a request parameter script and a return parameter script. The request parameter script is used to assign default values to request parameters, perform parameter validation, and concatenate parameters. The return parameter script is used to process and filter data returned by the API.
[0115] Optionally, the query statement can be configured, which may include selecting specific database table information, configuring query pagination parameters, configuring query filtering parameters, configuring sorting fields, and selecting the fields to be returned from the database table.
[0116] Optionally, configure the returned result set, specifically including configuring the correspondence between the returned message fields and the query results, configuring the error codes and error code prompts, and configuring the returned message field names.
[0117] Step S33: Establish the configuration relationship between the interface information, the request parameters, the script, the query statement and the returned result set, and generate a query template.
[0118] Optionally, a configuration relationship can be established between the above interface information, request parameters, scripts, query statements and returned result sets to generate a query template that supports one query function.
[0119] Furthermore, an automated deployment process is implemented for the query templates, generating an externally exposed HTTP interface for easy user queries.
[0120] It's important to note that several query templates can be generated based on different configuration requests. These templates offer different effects; for example, there are query templates for relational databases, query templates for non-relational databases, and data modification templates. Each query template consists of different operators, which encapsulate data query or data modification operations for different types of databases, and also provide data processing-related operators. Different operators can be customized through configuration requests to generate different interface execution operations.
[0121] Operators follow certain configuration rules, such as: each operator has one and only one input set and one output set; variable references between operators follow the JavaScript syntax specification; each operator can have multiple parent nodes and child nodes; the final generated template has only one input operator and one output operator; the final generated template can be parsed into a single-link structure and cannot contain loops.
[0122] The configuration information for the query template consists of the following nodes (operators):
[0123] 1. Request node: The request node is used to define the input parameters of the interface and the content of the input parameter script.
[0124] a. Node Number: Defines the node execution chain number, which is executed sequentially according to the number when executing the query template.
[0125] b. Node Name: Define the node name
[0126] c. Input Parameter Information: Defines the input parameter information for the query template, including the request parameter field name, field data format, and field data type.
[0127] d. Script Information: Defines the input script, including script content and script output parameters.
[0128] 2. Query Node: The query node is used to configure specific query conditions. When the query template is executed, it will generate the corresponding query statement based on the user-configured query conditions and send it to the database for execution.
[0129] a. Node number: Same as above
[0130] b. Node name: Same as above
[0131] c. Query filtering conditions: including pagination parameters, the mapping relationship between filtering parameters and requested nodes, sorting parameters, aggregation parameters, and database output fields.
[0132] d. Database and table information query: This stores the connection information for the specific database to be queried, the specific database to be queried, and the data tables.
[0133] 3. Return Node: The return node is used to define the return message and return code information of the API interface. It can also define the return script to process the data retrieved from the database.
[0134] a. Node number: Same as above
[0135] b. Node name: Same as above
[0136] c. Return fields: Configure the correspondence between the returned fields and the database query results;
[0137] d. Return Code: Defines the return code value and description returned when the API call succeeds or fails.
[0138] e. Script Information: Define the data processing script. The script must define its content and input parameters.
[0139] As shown above, the query template configuration information includes multiple node operators, commonly used operators such as request operators, return operators, script processing operators, data anonymization operators, and data retrieval operators. Each operator corresponds to a node; request operators and return operators correspond to request nodes and return nodes respectively, and data retrieval operators correspond to query nodes. In addition, data anonymization operators are used to anonymize the data returned from the database, providing multiple anonymization methods, including full-field anonymization, personal basic information anonymization, and sensitive word anonymization. Script processing operators are used to process and manipulate temporary data generated during the execution of the query template, which can ultimately be configured through the return node and returned as the request result.
[0140] Each operator explicitly defines its inputs and outputs. Operators are referenced using the format `$nodeId.result.nodevariablename` (e.g., `$101.result.id`). The specific types of input and output parameters are defined through the `data_template` structure. Each node also defines its associated parent node, with parent and child nodes identified by template numbers. Child nodes store the parent node's node number, and execution proceeds in ascending order of these numbers. Each node has corresponding configuration information, such as query configuration information for data reading operators and script type information for script processing operators, stored in the `params` structure of each node. For a query template, the configuration information of all its nodes is aggregated to obtain the template's overall configuration information, which is then stored in the corresponding configuration file. This file will be used in subsequent production deployment processes.
[0141] In one technical solution provided in this embodiment, based on the user's configuration request, interface information, configuration request parameters, script, query statement, and return result set are configured. Then, configuration relationships are established between these parameters to generate a corresponding query template. This approach provides a more flexible and convenient configuration method, avoiding potential errors and tedious processes when users manually write configuration files. Users only need to provide some key configuration parameters, and the query engine can generate the corresponding query template based on these parameters.
[0142] Furthermore, refer to Figure 4 A fourth embodiment of the data query method of the present invention is proposed. Based on the above... Figure 3 In the illustrated embodiment, after the step of establishing the configuration relationship between the interface information, the request parameters, the script, the query statement, and the returned result set, and generating the query template, the method includes:
[0143] Step S41: Establish the correspondence between the query template and the interface;
[0144] Step S42: Determine all nodes in the interface according to the configuration rules;
[0145] Step S43: Generate the execution chain of the interface based on all the nodes and node configuration information;
[0146] Step S44: Initialize and preprocess all nodes in the execution chain to obtain the final interface;
[0147] Step S45: Determine the query domain name corresponding to the interface according to the preset naming rules.
[0148] Understandably, the API configuration automation deployment module in the API development management is responsible for automating the deployment process of the aforementioned query template. Once deployed, the query template will generate an HTTP interface exposed externally. Simply put, the deployment process involves parsing the query template's configuration information and initializing it to generate the specific query service interface.
[0149] Optionally, a correspondence can be established between query templates and interfaces, such as query template A corresponding to interface a, and query template B corresponding to interface b.
[0150] Optionally, the query service unit is configured with a scheduled task that periodically retrieves interfaces to be launched. After retrieving the interface, it performs configuration parsing and launch procedures for that interface. The specific process is as follows:
[0151] 1. API Configuration Information Acquisition: First, the basic information of the query template associated with the API will be obtained, including the URL, authentication information, traffic control information, etc. The basic information will be stored in the API global context (i.e., the actual memory in which the API runs, which exists as a JAVA object, and the corresponding information can be directly retrieved from memory in subsequent steps). This information will be used when making API calls, protecting API gateway traffic, and setting up API monitoring points.
[0152] 2. Obtain API configuration output nodes: Following the configuration rules mentioned in the API configuration generation module, each node defines its associated parent node. Parent and child nodes are identified by template number. Child nodes store the node number of their parent nodes, and execution proceeds in ascending order of these numbers. Based on this, all rows in the configuration information are traversed, and each row is checked for a node number. Finally, based on the statistical results of the node numbers, all nodes in the query template are determined.
[0153] 3. Generate API Execution Chain: Based on all nodes and node configuration information, generate the execution chain for the interface. Process each operator sequentially. During processing, first obtain the parent node of the root node and add it to the execution chain, then obtain the parent node's parent node, and so on, until the entire execution chain is generated. After the nodes are recursively processed, a serial execution chain is obtained. At this point, the execution chain contains the configuration information of each node operator, i.e., execution chain = configuration information of node 1 + configuration information of node 2 + ...
[0154] 4. API execution chain initialization:
[0155] Next, the execution chain needs to be initialized. Initializing the execution chain means initializing each node in the execution chain. The steps are as follows:
[0156] a. Initialize the configuration information of the node operator into a predefined program entity in memory, including query connection information, input, output information, script information, etc. That is, generate the corresponding structure in memory, save the corresponding information, and when the API is called, it will perform query statement concatenation or parameter processing based on the saved information.
[0157] b. Node operator preprocessing, which includes initializing the data source query connection pool (initializing the database connection pool, which stores database query connections, allowing for rapid connection establishment during API execution and reducing query time); script pre-compilation (compiling the script into bytecode files in memory, which also speeds up API requests, avoids compilation with each request, and reduces resource consumption); and query statement concatenation (pre-concatenating parts of the query statement, so that during the query, only the variables in the concatenated query statement need to be replaced according to the user-passed parameters).
[0158] After each operator node is initialized, an ApiProcessor object is generated, which resides in memory as a Java object. Once the execution chain is initialized, the corresponding interface will execute the operators in each execution chain sequentially.
[0159] The step of determining all nodes in the interface according to the configuration rules includes:
[0160] Step S421: Determine the number of nodes in the interface whose node type is output node;
[0161] Step S422: If the number of nodes is one, then using the output node as the endpoint, other nodes are determined recursively;
[0162] Step S423: If the number of nodes is multiple or does not exist, a configuration error message is returned.
[0163] Optionally, iterate through all nodes, determine whether a node is an output node based on its type, and determine the number of output nodes.
[0164] Furthermore, if there is only one output node, then the traversal is stopped at the output node as the endpoint, and other nodes are determined during the traversal.
[0165] If there is only one output node, or if there is no output node in the execution chain, a configuration error message will be returned so that the execution chain can be checked and regenerated.
[0166] After the API operator is parsed and the API execution chain is generated, the API deployment module sends an initialization success message to the gateway. Then, the gateway determines the query domain name corresponding to the interface according to the preset naming rules and opens it. The specific process is as follows: a unified prefix can be applied for for the query domain name prefix, and users can customize the URL information of the domain name suffix when creating an API. The prefix + suffix determines a domain name, and an API interface is an independent domain name that provides an HTTP request interface.
[0167] In one technical solution provided in this embodiment, the correspondence between query templates and interfaces is first established. Then, all nodes in the interface are determined, and the execution chain corresponding to the interface is determined. After initialization and preprocessing, an interface that can be directly used is obtained, and the domain name information of the interface is exposed. With this setting, the query engine will automatically process the query template and generate the query domain name corresponding to the associated interface, which can simplify and accelerate the deployment and configuration process, ensure the consistency of configuration files, reduce human error, and provide traceability and reproducibility.
[0168] Reference Figure 5 , Figure 5 This is a schematic diagram of the data query device structure in the hardware operating environment involved in the embodiments of the present invention.
[0169] like Figure 5 As shown, the data query device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to enable communication between these components. The user interface 1003 may include a display screen and an input unit such as a keyboard; optionally, the user interface 1003 may also include a standard wired interface or a wireless interface. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface). The memory 1005 may be a high-speed random access memory (RAM) or a stable non-volatile memory (NVM), such as a disk drive. The memory 1005 may also optionally be a storage device independent of the aforementioned processor 1001.
[0170] Those skilled in the art will understand that Figure 5 The structure shown does not constitute a limitation on the data query device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0171] like Figure 5 As shown, the memory 1005, which serves as a storage medium, may include an operating system, a data storage module, a network communication module, a user interface module, and a data query program.
[0172] exist Figure 5 In the data query device shown, the network interface 1004 is mainly used for data communication with other devices; the user interface 1003 is mainly used for data interaction with users; the processor 1001 and the memory 1005 in the data query device of the present invention can be set in the data query device, and the data query device calls the data query program stored in the memory 1005 through the processor 1001 and executes the data query method provided in the embodiment of the present invention.
[0173] This invention provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of any of the above-described data query methods.
[0174] Since the embodiments of the computer-readable storage medium portion correspond to the embodiments of the method portion, the embodiments of the computer-readable storage medium portion are described in the description of the embodiments of the method portion, and will not be repeated here.
[0175] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.
[0176] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0177] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0178] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.
Claims
1. A data query method, characterized in that, The data query method includes the following steps: Upon receiving a user's configuration request, determine the interface information carried in the configuration request; According to the configuration request, configure the request parameters, script, query statement and return result set; Establish the configuration relationship between the interface information, the request parameters, the script, the query statement and the returned result set, and generate a query template. The query template consists of multiple operators, each of which explicitly defines the input and output. The operators are associated with each other through variable references. An execution chain of the interface is generated according to the configuration rules. All nodes in the execution chain are initialized and preprocessed to obtain the final interface. Determine the query template corresponding to the user's query request; The query request and the query template are parsed to generate the corresponding query statement; The query statement is executed to obtain the corresponding query results, and the query results are sent to the user. The step of establishing the configuration relationship between the interface information, the request parameters, the script, the query statement, and the returned result set, and generating the query template, further includes: Establish the correspondence between the query template and the interface; Based on the configuration rules, determine the number of nodes in the interface whose node type is output node; If the number of nodes is one, then starting from the output node, all nodes are determined recursively to generate the execution chain of the interface. Initialize all nodes in the execution chain. The initialization includes: initializing the configuration information of node operators into program entities in memory, initializing the data source query connection pool, precompiling the script, and pre-concatenating the query statement; preprocessing all nodes in the execution chain to obtain the final interface; and determining the query domain name corresponding to the interface according to the preset naming rules.
2. The data query method as described in claim 1, characterized in that, The step of parsing the query request and the query template to generate the corresponding query statement includes: Parse the request parameters in the context of the query request, as well as the database table information, return value field information, and processing information of the query template; Based on the request parameters, the database table information, the return value field information, and the processing information, a statement to be verified is assembled. If the statement to be verified meets the preset verification conditions, then the statement to be verified is determined as a query statement.
3. The data query method as described in claim 2, characterized in that, The processing information includes a default filter value, sorting field and sorting method, aggregation field and aggregation method, and a default pagination value. The step of assembling and generating the statement to be verified based on the request parameters, the database table information, the return value field information, and the processing information includes: Based on the filter condition values in the request body of the request parameters, or the default filter values, generate the filter information for the query statement. Based on the sorting field and sorting method, generate the sorting information for the query statement; Based on the aggregation fields and aggregation methods, generate grouping and aggregation information for the query statement; Based on the pagination information value in the request body of the request parameters, or the default pagination value, generate the pagination information of the query statement; Based on the request parameters, the database table information, the return value field information, the filtering information, the sorting information, the grouping and aggregation information, and the analysis information, a statement to be verified is assembled.
4. The data query method as described in claim 1, characterized in that, The step of determining the query template corresponding to the user's query request includes: Determine the corresponding interface based on the query service identifier carried in the user's query request; If the authentication information in the request header of the query request is consistent with the authentication information of the interface, then authentication is successful. Based on the correspondence between the interface and the query template, determine the query template corresponding to the interface.
5. The data query method as described in claim 1, characterized in that, The steps of executing the query statement, obtaining the corresponding query result, and sending the query result to the user include: Execute the query statement to obtain the initial query results. The initial query results are processed according to the preset data processing script to obtain the final query results, which are then sent to the user.
6. A data query device, characterized in that, The data query device includes: a memory, a processor, and a data query program stored in the memory and executable on the processor, the data query program being configured to implement the steps of the data query method as described in any one of claims 1 to 5.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a data query program, which, when executed by a processor, implements the steps of the data query method as described in any one of claims 1 to 5.