Data query method, device and equipment based on interface generation and medium

By analyzing natural language query statements and generating interfaces, the problem of efficient access to multi-source heterogeneous databases was solved, a user-friendly data query method was implemented, efficiency and accuracy were improved, costs were reduced, and system compatibility and security were enhanced.

CN120873072BActive Publication Date: 2026-02-27SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511403710.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-09-29
Publication Date
2026-02-27
Estimated Expiration
2045-09-29

AI Technical Summary

Technical Problem

When dealing with multi-source heterogeneous databases, traditional methods require the development of specific interfaces or query tools for each database, which increases development costs, reduces the flexibility and efficiency of data access, and requires users to master the professional knowledge of different databases, thus increasing the user's cost.

Method used

By analyzing the received natural language query statements, the system determines the data query requirements and interface requirements, generates the target data query statement, and obtains the target query data based on a preset interface template or set, supporting efficient access to multi-source heterogeneous databases.

Benefits of technology

It enables users lacking professional database knowledge to efficiently and accurately obtain the data they need through natural language, improving the efficiency and accuracy of data query, reducing data processing costs, and enhancing system compatibility and data security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120873072B_ABST
    Figure CN120873072B_ABST
Patent Text Reader

Abstract

The application discloses a data query method and device based on an interface, equipment and a medium, and relates to the technical field of computers, which comprises the following steps: analyzing a query statement to determine corresponding data query requirement information and interface requirement information; matching data fields and data tables from a preset database based on the data query requirement information, and generating a corresponding target data query statement; determining whether a preset interface corresponding to the interface requirement information exists in a preset interface set; if not, generating a target interface corresponding to the interface requirement information based on a preset interface template, and if so, taking the preset interface as the target interface; determining a target data source corresponding to the data query requirement information, and obtaining target query data corresponding to the data query requirement information from the target data source through the target interface based on a query parameter corresponding to the target data query statement. Thus, users who lack professional database knowledge can efficiently and accurately obtain required data through natural language.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, in particular to a data query method and device based on interface generation, equipment and medium. BACKGROUND

[0002] In the current information society, data has become an important core asset of enterprises and organizations. With the advent of the era of big data, the scale and variety of data have increased dramatically, and database systems have shown diversification and heterogeneity. Multi-source heterogeneous databases refer to systems composed of databases of different types, structures and storage methods, which may include relational databases, non-relational databases, new databases, data warehouses, big data platforms, etc.

[0003] When dealing with multi-source heterogeneous databases, due to significant differences in different database SQL (Structured Query Language) languages, data type mismatches, schema differences, etc., traditional methods usually require the development of specific interfaces or query tools for each database, which not only increases development costs, but also reduces data access flexibility and efficiency, and requires users to master professional database knowledge of different databases, greatly increasing user costs. SUMMARY

[0004] Therefore, the purpose of the present application is to provide a data query method and device based on interface generation, which can enable users lacking professional database knowledge to efficiently and accurately obtain the required data through natural language. The specific scheme is as follows:

[0005] In a first aspect, the present application discloses a data query method based on interface generation, comprising:

[0006] analyzing the received query statement to determine the data query requirement information and interface requirement information corresponding to the query statement; the query statement is a natural language for data query;

[0007] matching the corresponding data fields and data tables from the preset database based on the data query requirement information, and generating a target data query statement according to the data fields and data tables;

[0008] determining whether there is a preset interface corresponding to the interface requirement information in the preset interface set;

[0009] if not, generating a target interface corresponding to the interface requirement information based on a preset interface template, and if there is, taking the preset interface as the target interface;

[0010] determine a target data source corresponding to the data query requirement information, and acquire target query data corresponding to the data query requirement information from the target data source based on a query parameter corresponding to the target data query statement through the target interface.

[0011] Optionally, the analysis on the received query statement comprises:

[0012] identifying stop words in the query statement and eliminating the stop words from the query statement to obtain an eliminated query statement;

[0013] performing word segmentation on the eliminated query statement to obtain a plurality of query words, identifying parts of speech corresponding to the plurality of query words, and then labeling the plurality of query words through the parts of speech to obtain labeled query words;

[0014] identifying named entities in the labeled query words and determining a grammatical relationship between the labeled query words;

[0015] generating a target topology structure corresponding to the labeled query words based on the named entities and the grammatical relationship;

[0016] analyzing the target topology structure to determine data query requirement information and interface requirement information corresponding to the query statement.

[0017] Optionally, the analysis on the target topology structure to determine data query requirement information and interface requirement information corresponding to the query statement comprises:

[0018] analyzing the target topology structure through a preset model to identify a query intent corresponding to the query statement, and generating data query requirement information according to the query intent;

[0019] determining an interface type corresponding to the query statement, an interface parameter corresponding to the interface type, and a data return format according to the query intent, and generating interface requirement information according to the interface type, the interface parameter, and the data return format.

[0020] Optionally, the matching of the data query requirement information with the preset database to determine a target data table, a target data field, and a target corresponding relationship between the target data table and the target data field in the preset database comprises:

[0021] matching the data query requirement information with the preset database to determine a target data table, a target data field, and a target corresponding relationship between the target data table and the target data field in the preset database.

[0022] generating a to-be-confirmed data query statement based on the target data table, the target data field, and the target correspondence by preset database syntax rules;

[0023] performing syntax checking on the to-be-confirmed data query statement to determine whether there is a syntax error in the to-be-confirmed data query statement;

[0024] if there is a syntax error in the to-be-confirmed data query statement, modifying the to-be-confirmed data query statement based on the syntax error to obtain a to-be-optimized data query statement;

[0025] if there is no syntax error in the to-be-confirmed data query statement, taking the to-be-confirmed data query statement as the to-be-optimized data query statement;

[0026] optimizing the to-be-optimized data query statement based on preset optimization rules to obtain a target data query statement; the preset optimization rules are adding data indexes to the to-be-optimized data query statement or performing query splitting.

[0027] Optionally, the generating the target interface corresponding to the interface requirement information based on the preset interface template comprises:

[0028] determining a target interface template corresponding to the interface type from a preset interface template set, and generating a target interface according to the target interface template, the interface parameter, and the data return format;

[0029] Correspondingly, the method further comprises:

[0030] adding the target interface to the preset interface set to update the preset interface set, and taking the obtained updated interface set as a new preset interface set.

[0031] Optionally, the determining the target data source corresponding to the data query requirement information and acquiring target query data corresponding to the data query requirement information from the target data source based on a query parameter corresponding to the target data query statement through the target interface comprises:

[0032] determining a target data source corresponding to the data query requirement information;

[0033] executing the target data query statement in the preset database and acquiring a corresponding execution result data set;

[0034] cyclically traversing the execution result data set to extract a field value corresponding to the execution result data set, and generating a query parameter based on the field value;

[0035] The target interface is used to obtain target query data corresponding to the data query requirement information from the target data source based on a query parameter corresponding to the target data query statement.

[0036] Optionally, the data query method based on interface generation further includes:

[0037] The response duration of the target interface is monitored, and if the response duration is greater than a preset response duration threshold, the target interface is optimized according to a preset interface optimization rule, and the obtained optimized interface is used as a new target interface; the preset interface optimization rule is a rule for optimizing the query logic and interface code of the target interface.

[0038] In a second aspect, the present application discloses a data query device based on interface generation, which includes:

[0039] An information determination module is configured to analyze a received query statement to determine data query requirement information and interface requirement information corresponding to the query statement; the query statement is a natural language used for data query.

[0040] A query statement generation module is configured to match corresponding data fields and data tables from a preset database based on the data query requirement information, and generate a target data query statement according to the data fields and data tables.

[0041] An interface matching module is configured to determine whether a preset interface corresponding to the interface requirement information exists in a preset interface set.

[0042] An interface determination module is configured to generate a target interface corresponding to the interface requirement information based on a preset interface template if the preset interface does not exist, and use the preset interface as the target interface if the preset interface exists.

[0043] A data query module is configured to determine a target data source corresponding to the data query requirement information, and obtain target query data corresponding to the data query requirement information from the target data source based on a query parameter corresponding to the target data query statement through the target interface.

[0044] In a third aspect, the present application discloses an electronic device, which includes:

[0045] A memory is configured to save a computer program.

[0046] A processor is configured to execute the computer program to implement the data query method based on interface generation as described above.

[0047] In a fourth aspect, the present application discloses a computer readable storage medium for storing a computer program, wherein the computer program is executed by a processor to implement the data query method based on interface generation as described above.

[0048] In the present application, the received query statement can be analyzed to determine the data query requirement information and the interface requirement information corresponding to the query statement; the query statement is a natural language for data query; the corresponding data field and data table are matched from the preset database based on the data query requirement information, and the target data query statement is generated according to the data field and data table; it is determined whether there is a preset interface corresponding to the interface requirement information in the preset interface set; if not, the target interface corresponding to the interface requirement information is generated based on the preset interface template, and if so, the preset interface is used as the target interface; the target data source corresponding to the data query requirement information is determined, and the target query data corresponding to the data query requirement information is obtained from the target data source through the target interface based on the query parameter corresponding to the target data query statement.

[0049] As can be seen, by the method of the present application, the query statement can be analyzed to determine the corresponding data query requirement information and interface requirement information, then the data field and data table are matched from the preset database based on the data query requirement information, and the corresponding target data query statement is generated; it is determined whether there is a preset interface corresponding to the interface requirement information in the preset interface set, in the case of not existing, the target interface corresponding to the interface requirement information is generated based on the preset interface template, in the case of existing, the preset interface is used as the target interface, finally the target data source corresponding to the data query requirement information is determined, and the target query data corresponding to the data query requirement information is obtained from the target data source through the target interface based on the query parameter corresponding to the target data query statement. In this way, users who lack professional database knowledge can easily obtain the required data through natural language, thereby realizing efficient access and operation of multi-source heterogeneous databases, and significantly improving the efficiency and accuracy of data query, reducing data processing cost, enhancing system compatibility, ensuring data security, and providing solid support for enterprises and organizations in data-driven decision-making. BRIEF DESCRIPTION OF DRAWINGS

[0050] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings in the following description are only embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor based on the provided drawings.

[0051] Figure 1A data query method flowchart based on interface generation disclosed in the present application;

[0052] Figure 2 A data query flowchart disclosed in the present application;

[0053] Figure 3 A specific data query flowchart disclosed in the present application;

[0054] Figure 4 An apparatus structure diagram of a data query based on interface generation disclosed in the present application;

[0055] Figure 5 An electronic device structure diagram disclosed in the present application. DETAILED DESCRIPTION

[0056] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.

[0057] Currently, when processing multi-source heterogeneous databases, due to the significant differences between different database SQL languages, data type mismatches, mode differences and other problems, the traditional method usually needs to develop specific interfaces or query tools for each database, which not only increases the development cost, but also reduces the flexibility and efficiency of data access, and requires users to master the professional database knowledge of different databases, greatly increasing the user's use cost.

[0058] In order to overcome the above technical problems, the present application discloses a data query method, device, equipment and medium based on interface generation, which can enable users lacking professional database knowledge to efficiently and accurately obtain the required data through natural language.

[0059] Referring to Figure 1 The embodiments of the present application disclose a data query method based on interface generation, which comprises:

[0060] Step S11, analyzing the received query statement to determine the data query requirement information and the interface requirement information corresponding to the query statement; the query statement is a natural language for data query.

[0061] In this embodiment, data query is performed through a data access system, as shown in Figure 2 First, the query statement input by the user needs to be analyzed, and the query statement input by the user is a natural language for data query, specifically, as shown in Figure 3As shown, it is necessary to identify the stop words in the query sentence and remove the stop words from the query sentence to obtain the removed query sentence, for example, to identify the words such as "of", "is", "in" and the like which have less influence on semantics. Then the removed query sentence needs to be processed for word segmentation to obtain a plurality of query words, and the parts of speech corresponding to the plurality of query words are identified, and then the plurality of query words are labeled through the parts of speech to obtain labeled query words, for example, using natural language processing tools such as NLTK (Natural Language Toolkit), HanLP (Han Language Processing) and the like to perform word segmentation on the input natural language text and label the part of speech of each word, such as noun, verb, adjective and the like. Then it is necessary to identify the named entities in the labeled query words and determine the grammatical relationship between the labeled query words, for example, the subject-predicate-object structure, and generate the target topology structure corresponding to the labeled query words based on the named entities and the grammatical relationship, that is, to convert the preprocessed natural language into a structured intermediate representation form, for example, using a tree structure or a graph structure to represent the grammatical and semantic relationship of the sentence, which is convenient for subsequent modules to process.

[0062] Finally, the target topology needs to be analyzed to determine the data query requirement information and the interface requirement information corresponding to the query statement, that is, the target topology is analyzed through a preset model to identify the query intent corresponding to the query statement, and the data query requirement information is generated according to the query intent, and the interface type corresponding to the query statement, the interface parameters corresponding to the interface type and the data return format are determined according to the query intent, and the interface requirement information is generated according to the interface type, the interface parameters and the data return format. It needs to be explained that when identifying the query intent corresponding to the query statement, machine learning algorithm and domain knowledge base can be used to analyze the intermediate representation output by the natural language processing module through a deep learning model such as a Transformer model to identify the main intent of the user query. For example, it is judged whether the user is performing single-table query, multi-table join, aggregation statistics or data comparison operation. And the semantic relationship in the query statement also needs to be further parsed, based on dependency syntax and knowledge graph, the logical relationship between entities is inferred, the association between each entity and the specific meaning of the query condition are clarified, and semantic ambiguity is eliminated. For example, in the above example, it is determined that "the past month" is a time range condition, "sales exceeding 100,000 yuan" is a numerical filtering condition, and "product information" is the target data of the query. Considering the context information of the query statement, if the user has performed a related query before, the historical query record and the current query statement are combined to more accurately understand the user's intent. For example, the user has previously queried the sales data of a certain product, and this time the user queries "look at the inventory situation of these products again", the system can understand that "these products" refer to the products queried according to the context. In this way, by analyzing the query statement input by the user, the natural language query input by the user can be converted into structured data that can be processed by a computer, so as to facilitate subsequent processing, and thus improve the efficiency of data query.

[0063] Step S12, based on the data query requirement information, matching the corresponding data fields and data tables from the preset database, and generating a target data query statement according to the data fields and data tables.

[0064] In this embodiment, as Figure 2 the SQL generation and optimization in Figure 3As shown, the data query requirement information needs to be matched with the preset database to determine the target data table, the target data field, and the target correspondence relationship between the target data table and the target data field in the preset database corresponding to the data query requirement information. It needs to be noted that after the connection with the preset database is established, the metadata information of the database needs to be collected, including the table name, the field name, the field type, the primary key, the foreign key, the index, the view, and the like. These metadata information describes the overall structure and data organization method of the database. The relational database obtains the table structure, the field type, the index, the foreign key, and the like through the metadata interface; the non-relational database traverses the collection structure of the document-type database such as MongoDB, and extracts the field distribution and the data type. Then, the data query requirement is matched with the database schema model to determine the specific table, the field, and the relationship therebetween involved in the query. For example, according to the entity information in the query statement, the corresponding table and field in the database are found, and it is determined how to obtain the required data through these table and field. Further, the schema information can be stored in the cache to support quick query and update, reduce the repeated parsing overhead, and the database can be regularly scanned to detect the table structure change such as the field addition, deletion, and the like, and the cache is automatically updated.

[0065] Further, the to-be-confirmed data query statement needs to be generated based on the target data table, the target data field, and the target correspondence relationship through the preset database syntax rule. Specifically, an initial SQL statement can be generated according to the SQL syntax rule of the target database. For example, a SQL statement similar to “SELECT * FROM product table WHERE sales date BETWEEN [start date of the past month] AND [end date of the past month] AND sales amount > 100000” is generated. Then, the to-be-confirmed data query statement needs to be checked for syntax to determine whether there is a syntax error in the to-be-confirmed data query statement, and then to ensure that the statement conforms to the syntax specification of the target database, and to avoid query failure due to syntax error. If there is a syntax error in the to-be-confirmed data query statement, the to-be-confirmed data query statement is corrected based on the syntax error to obtain the to-be-optimized data query statement, and if there is no syntax error in the to-be-confirmed data query statement, the to-be-confirmed data query statement is taken as the to-be-optimized data query statement.

[0066] Finally, the query statement to be optimized can be optimized based on preset optimization rules to obtain the target query statement. These preset optimization rules include adding data indexes or splitting the query. Specifically, various optimization strategies can be used to optimize the generated SQL statement. For example, based on the index information provided by the database schema analysis module, appropriate index hints can be added to the query statement to enable the database to execute queries more efficiently. Complex query statements can be rewritten and decomposed into multiple simple subqueries to reduce the database's processing burden. Finally, the optimal join algorithm and execution plan can be selected based on the characteristics of the query conditions.

[0067] Step S13: Determine whether there is a preset interface in the preset interface set that corresponds to the interface requirement information.

[0068] In this embodiment, as Figure 3 As shown, it's necessary to determine whether a pre-defined interface corresponding to the interface requirement already exists in the pre-defined interface set based on the interface requirement information. For example, if the interface type corresponding to the query statement is RESTful API (Application Programming Interface) or SOAP (Simple Object Access Protocol), it's necessary to check whether these two types of interfaces already exist in the current pre-defined interface set. It should be noted that the pre-defined interface set can be used for interface management, including interface registration, publishing, and version control (e.g., coexistence of / api / v1 / query and / api / v2 / query), access permission settings, rate limiting strategies, caching strategies, and call monitoring. Through interface management, users can easily view and manage their owned interfaces, understand their usage and performance metrics, and system administrators can perform global management of all interfaces to ensure their security and stability. Full lifecycle management of interfaces is achieved through canary releases and interface retirement.

[0069] Step S14: If it does not exist, generate a target interface corresponding to the interface requirement information based on the preset interface template; if it exists, use the preset interface as the target interface.

[0070] In this embodiment, if the preset interface corresponding to the interface requirement information does not exist in the current preset interface set, the interface corresponding to the interface requirement information needs to be generated. Specifically, a target interface template corresponding to the interface type can be determined from the preset interface template set, and a target interface can be generated according to the target interface template, the interface parameter, and the data return format. That is, the code and the document of the interface are generated by using the template, and the generated interface code has good readability and maintainability, and the document can clearly describe the function, parameter, return value, and other information of the interface.

[0071] In step S15, the target data source corresponding to the data query requirement information is determined, and the target query data corresponding to the data query requirement information is acquired from the target data source based on the query parameter corresponding to the target data query statement through the target interface.

[0072] In this embodiment, the query data needs to be acquired from the target data source corresponding to the data query requirement information. Specifically, the target data source corresponding to the data query requirement information needs to be determined. It needs to be noted that these data sources can be different types of databases such as relational databases MySQL (My Structured Query Language), Oracle, non-relational databases MongoDB, Redis (Remote Dictionary Server), and other data storage forms such as file systems and API interfaces. Then, the target data query statement is executed in the preset database, and the corresponding execution result data set is acquired. Then, the execution result data set is iteratively traversed to extract the field value corresponding to the execution result data set, and the query parameter is generated based on the field value. Finally, the target query data corresponding to the data query requirement information is acquired from the target data source based on the query parameter corresponding to the target data query statement through the target interface. Since the target query data can come from different data sources, the query results acquired from different data sources need to be integrated, the data format is unified, the missing values and type inconsistency problems are handled, and finally the results are sorted, de-duplicated, and paginated to generate the final query result set to meet the user display requirement.

[0073] Further, the interface can be optimized. Specifically, the response time of the target interface can be monitored. If the response time is greater than a preset response time threshold, the target interface is optimized according to a preset interface optimization rule to obtain an optimized interface as a new target interface. The preset interface optimization rule is a rule for optimizing the query logic and the interface code of the target interface.

[0074] In this embodiment, the received query statement can be analyzed to determine the data query requirement information and the interface requirement information corresponding to the query statement; the query statement is a natural language for data query; the corresponding data field and data table are matched from the preset database based on the data query requirement information, and the target data query statement is generated according to the data field and data table; it is determined whether there is a preset interface corresponding to the interface requirement information in the preset interface set; if not, the target interface corresponding to the interface requirement information is generated based on the preset interface template, and if there is, the preset interface is used as the target interface; the target data source corresponding to the data query requirement information is determined, and the target query data corresponding to the data query requirement information is obtained from the target data source through the target interface based on the query parameter corresponding to the target data query statement. As can be seen, through the method of this embodiment, the query statement can be analyzed to determine the corresponding data query requirement information and interface requirement information, and then the data field and data table are matched from the preset database based on the data query requirement information, and the corresponding target data query statement is generated; it is determined whether there is a preset interface corresponding to the interface requirement information in the preset interface set, in the case of not existing, the target interface corresponding to the interface requirement information is generated based on the preset interface template, and in the case of existing, the preset interface is used as the target interface, finally the target data source corresponding to the data query requirement information is determined, and the target query data corresponding to the data query requirement information is obtained from the target data source through the target interface based on the query parameter corresponding to the target data query statement. In this way, on the one hand, users who lack professional database knowledge can easily obtain the required data through natural language, thereby realizing efficient access and operation of multi-source heterogeneous databases; on the other hand, the functions of automatic semantic understanding, SQL statement generation and optimization, and multi-source data integration reduce the time of manually writing and debugging SQL statements, improve the efficiency and accuracy of data access; on the other hand, it supports access and integration of multiple different types of data sources, can adapt to complex heterogeneous data environment of enterprises, improves the compatibility and expansibility of the system, and shields the underlying differences.

[0075] As a preferred embodiment, in order to protect data security, various security mechanisms can be used to ensure that only authorized users can access sensitive data and prevent security problems such as data leakage, tampering, unauthorized access, and malicious attacks. Specifically, the user can be authenticated before accessing the data access system. Various authentication methods can be used, such as username / password authentication, digital certificate authentication, multi-factor authentication, such as SMS verification code, fingerprint recognition, etc., to ensure the authenticity and legality of the user's identity and reject unauthenticated requests. In addition, users can be assigned different data access permissions based on their roles and responsibilities. The permission management uses a fine-grained control strategy that can be accurate to the table, field, or even data record level. For example, ordinary users can only query the business data they are responsible for, while administrator users can query and manage the data of the entire system. Input parameter formats can also be verified, such as whether the date format is correct, whether the numerical value is within the legal range, and illegal parameters are rejected. SQL injection protection can also be performed, such as using precompiled statements or regular expression filtering of dangerous characters such as 、 to prevent malicious SQL code execution. Data encryption can also be performed to encrypt sensitive data during data transmission and storage. Symmetric or asymmetric encryption algorithms can be used to ensure that data is not stolen or tampered with during transmission, and even if the data is illegally obtained during storage, the content cannot be read. In addition, all user data access operations can be audited and monitored, recording information such as user operation time, operation content, operation result, etc. Through the audit log, abnormal operation behavior can be detected in a timely manner, the source of data leakage can be traced back, and evidence can be provided for the investigation of security incidents. Finally, when illegal access or system anomalies are detected, an alarm notification is sent. In this way, a complete security and permission control module can be implemented to protect data security from multiple aspects such as user identity authentication, permission management, data encryption, and audit monitoring, effectively preventing data leakage and unauthorized access.

[0076] As a preferred embodiment, in order to improve the performance and response speed of the data access system, the performance indicators of the system can be monitored in real time, including query response time, system throughput, resource utilization, such as processor usage, memory usage, disk read-write status, etc. By deploying monitoring tools and collectors in the system, these performance data are collected and displayed to the system administrator in the form of intuitive charts or reports. Through threshold judgment, such as response time > 500ms, error rate > 5%, or machine learning algorithms, such as isolation forest algorithm, performance anomalies are identified. Further, performance bottlenecks in the system can be analyzed based on performance monitoring data. For example, if it is found that the response time of a certain query is too long, it is analyzed whether the performance problem is caused by low SQL statement execution efficiency, unreasonable database index, network delay or other reasons. Then, corresponding optimization strategies are developed and implemented for the performance problems found. Optimization strategies can include adjusting database configuration parameters, optimizing SQL statements, increasing cache mechanisms, and horizontally or vertically expanding the system, etc. For example, for frequently accessed data, cache it in memory to reduce direct access to the database; for the case of insufficient system resources, increase server hardware resources or use distributed architecture for expansion. Finally, the performance indicators before and after optimization can be compared to re-evaluate the performance of the system and verify the optimization effect. According to the evaluation results, it is decided whether further adjustment of the optimization strategy is needed to achieve continuous performance optimization of the system, and corresponding optimization reports are generated, such as response time trend chart, throughput comparison table, etc., for reference by operation and maintenance personnel. In this way, through real-time monitoring, bottleneck analysis and optimization strategy implementation, the system can still maintain good performance and response speed under high concurrency and large data volume, improving user experience.

[0077] As a preferred embodiment, the content in Figure 2 will be described in detail, and the content in Figure 3 will be described in detail in combination with specific application scenarios. Among them, such as Figure 2As shown, after receiving the query statement input by the user, the query statement needs to be processed by natural language processing, such as removing stop words, part-of-speech tagging, and the like, and then semantic understanding needs to be performed to understand the intent and semantic information of the query statement input by the user, such as semantic relationships, logical relationships between entities, and the like. Further, database schema analysis is also needed, for example, according to the entity information in the query statement, the corresponding tables and fields in the database are found, and it is determined how to obtain the required data through these tables and fields. Then SQL statement generation is needed, which can generate an initial SQL statement according to the SQL syntax rules of the target database, and optimize the initial SQL statement to obtain the target data query statement. After the query statement is determined, multi-source data integration can be performed to process query requests involving multiple data sources, integrate data from different data sources, and execute the optimized SQL statement to obtain the corresponding query result. Then it needs to be judged whether the required interface exists in the current preset interface set, if not, the required interface needs to be generated. Further, in order to protect data security, permission verification and corresponding security protection are also needed for the user to ensure that only authorized users can access sensitive data, and to prevent security problems such as data leakage, tampering, unauthorized access, and malicious attacks, and performance monitoring and optimization can also be performed to monitor the performance indicators of the system in real time, including query response time, system throughput, resource utilization, such as processor usage, memory usage, disk read-write status, etc., analyze the performance bottlenecks of the system, and develop and implement corresponding optimization strategies for the performance problems found. Finally, when calling the interface, the target query data corresponding to the data query requirement information is obtained from the target data source through the generated interface and the query parameters corresponding to the query statement.

[0078] Further, taking a specific implementation as an example, the content in Figure 3 is described in detail, and the specific scenario is as follows: MySQL: stores structured data such as orders and users; MongoDB: stores unstructured data such as product reviews; Elasticsearch: stores search index data. Business personnel need to obtain cross-database data through natural language queries, such as "Query the top 10 customer names and contact information of order amount in C region during A year B month", and encapsulate the query as a reusable API interface for front-end application calling. The processing process of natural language processing is as follows:

[0079] Word segmentation: "A year B month period", "C region", "order amount", "top 10", "customer name", "contact information";

[0080] Part-of-speech tagging: time word ("A year B month period"), place word ("C region"), noun ("order amount"), quantity word ("top 10");

[0081] Named entity recognition: time entity ("B month"), place entity ("C region"), business entity ("order amount", "customer name");

[0082] Dependency syntax analysis: "query" is the core verb of the subject-predicate structure, "order amount" is the object, and "top 10" is the attributive modifier of "customer name".

[0083] Semantic understanding process as follows:

[0084] Intent recognition: aggregate query (filtering + sorting + TopN);

[0085] Entity linking: "order amount" → orders.amount field; "customer name" → customers.name field; "contact information" → customers.phone field;

[0086] Relationship reasoning: "B month" → orders.create_time BETWEEN 'A year-B month-01' AND 'A year-B month-30'; "C region" → orders.region = 'C'; "top 10" → ORDER BY orders.amount DESC LIMIT 10.

[0087] Database schema analysis process as follows:

[0088] Schema discovery: There are orders and customers tables in MySQL; orders table structure: id, customer_id, amount, create_time, region; customers table structure: id, name, phone, email;

[0089] Schema association: association is established through orders.customer_id = customers.id.

[0090] SQL generation and optimization process as follows:

[0091] Initial SQL generation: according to the semantic analysis results, the corresponding SQL statement is generated;

[0092] Index analysis: found that the orders table lacks a composite index of create_time and region;

[0093] Query optimization: suggest creating a composite index CREATE INDEX idx_time_region ON orders(create_time, region).

[0094] Multi-source data integration and query execution process as follows:

[0095] Data source routing: Determine all data in MySQL, no need to integrate across sources;

[0096] Query execution: Execute optimized SQL, return result set.

[0097] Intelligent interface generation and management process as follows:

[0098] Interface metadata extraction: Interface name: get-top-customers-by-order-amount; Path: / api / v1 / orders / top-customers; Parameters: startDate, endDate, region; Return value: List<{name:string, phone: string}>

[0099] Interface code and document generation: Automatically generate interface documents, including interface address, request method (GET / POST), parameter description (if any), return result example, etc.

[0100] Interface configuration: Permission policy: only "data analyst" role can call cache policy: result cache 1 hour.

[0101] Security and permission control process as follows:

[0102] Identity authentication: Verify user JWT token;

[0103] Permission verification: Check if the user has the "data analyst" role;

[0104] Parameter verification: Verify that startDate and endDate are in a legal date format; Verify that region is a predefined list of regions;

[0105] SQL injection protection: Use precompiled statements, automatically escape special characters.

[0106] Performance optimization process as follows:

[0107] Monitoring indicators: Interface average response time: 200ms; Daily call times: 500 times; Cache hit rate: 30%;

[0108] Optimization suggestions: Create composite index idx_time_region for orders table; Adjust cache policy, extend cache time for popular regions (such as "C region") to 2 hours.

[0109] See Figure 4As shown, the embodiment of the present application discloses a data query device based on interface generation, comprising:

[0110] An information determination module 11 is configured to analyze a received query statement to determine data query requirement information and interface requirement information corresponding to the query statement; the query statement is a natural language for data query;

[0111] A query statement generation module 12 is configured to match corresponding data fields and data tables from a preset database based on the data query requirement information, and generate a target data query statement according to the data fields and data tables;

[0112] An interface matching module 13 is configured to determine whether a preset interface corresponding to the interface requirement information exists in a preset interface set;

[0113] An interface determination module 14 is configured to generate a target interface corresponding to the interface requirement information based on a preset interface template if the preset interface does not exist, and use the preset interface as the target interface if the preset interface exists;

[0114] A data query module 15 is configured to determine a target data source corresponding to the data query requirement information, and acquire target query data corresponding to the data query requirement information from the target data source based on a query parameter corresponding to the target data query statement through the target interface.

[0115] In this embodiment, the received query statement can be analyzed to determine the data query requirement information and the interface requirement information corresponding to the query statement; the query statement is a natural language for data query; the corresponding data field and data table are matched from the preset database based on the data query requirement information, and the target data query statement is generated according to the data field and data table; it is determined whether there is a preset interface corresponding to the interface requirement information in the preset interface set; if not, the target interface corresponding to the interface requirement information is generated based on the preset interface template, and if so, the preset interface is used as the target interface; the target data source corresponding to the data query requirement information is determined, and the target query data corresponding to the data query requirement information is obtained from the target data source through the target interface based on the query parameter corresponding to the target data query statement. As can be seen, through the method of this embodiment, the query statement can be analyzed to determine the corresponding data query requirement information and interface requirement information, and then the data field and data table are matched from the preset database based on the data query requirement information, and the corresponding target data query statement is generated; it is determined whether there is a preset interface corresponding to the interface requirement information in the preset interface set, and in the case where there is no, the target interface corresponding to the interface requirement information is generated based on the preset interface template, and in the case where there is, the preset interface is used as the target interface, and finally the target data source corresponding to the data query requirement information is determined, and the target query data corresponding to the data query requirement information is obtained from the target data source through the target interface based on the query parameter corresponding to the target data query statement. In this way, users who lack professional database knowledge can easily obtain the required data through natural language, thereby realizing efficient access and operation of multi-source heterogeneous databases, significantly improving the efficiency and accuracy of data query, reducing data processing cost, enhancing system compatibility, ensuring data security, and providing solid support for enterprises and organizations in data-driven decision-making.

[0116] In some embodiments, the information determination module 11 can specifically include:

[0117] A data elimination sub-module, configured to identify stop words in the query statement, and eliminate the stop words from the query statement to obtain an eliminated query statement;

[0118] A data labeling sub-module, configured to perform word segmentation processing on the eliminated query statement to obtain a plurality of query words, identify the parts of speech corresponding to the plurality of query words, and then label the plurality of query words through the parts of speech to obtain labeled query words;

[0119] A data recognition sub-module, configured to identify named entities in the labeled query words, and determine the grammatical relationships between the labeled query words;

[0120] The structure generation submodule is configured to generate a target topology structure corresponding to the labeled query word based on the named entity and the syntax relationship.

[0121] The structure analysis submodule is configured to analyze the target topology structure to determine data query requirement information and interface requirement information corresponding to the query statement.

[0122] In some embodiments, the structure analysis submodule can specifically include:

[0123] The structure analysis unit is configured to analyze the target topology structure by using a preset model to identify a query intent corresponding to the query statement, and generate data query requirement information according to the query intent.

[0124] The information generation unit is configured to determine an interface type, an interface parameter corresponding to the interface type, and a data return format corresponding to the query statement according to the query intent, and generate interface requirement information according to the interface type, the interface parameter, and the data return format.

[0125] In some embodiments, the query statement generation module 12 can specifically include:

[0126] The relationship determination unit is configured to match the data query requirement information with a preset database to determine a target data table, a target data field, and a target corresponding relationship between the target data table and the target data field in the preset database corresponding to the data query requirement information.

[0127] The query statement generation unit is configured to generate a to-be-confirmed data query statement based on the target data table, the target data field, and the target corresponding relationship by using a preset database syntax rule.

[0128] The syntax checking unit is configured to perform syntax checking on the to-be-confirmed data query statement to determine whether there is a syntax error in the to-be-confirmed data query statement.

[0129] The syntax correction unit is configured to correct the to-be-confirmed data query statement based on the syntax error to obtain a to-be-optimized data query statement if there is a syntax error in the to-be-confirmed data query statement.

[0130] The statement determination unit is configured to use the to-be-confirmed data query statement as the to-be-optimized data query statement if there is no syntax error in the to-be-confirmed data query statement.

[0131] The sentence optimization unit is configured to optimize the to-be-optimized data query sentence based on a preset optimization rule to obtain a target data query sentence; the preset optimization rule is to add a data index to the to-be-optimized data query sentence or to perform query splitting.

[0132] In some embodiments, the interface determination module 14 can specifically include:

[0133] The interface generation unit is configured to determine a target interface template corresponding to the interface type from a preset interface template set, and generate a target interface according to the target interface template, the interface parameter, and the data return format.

[0134] In some embodiments, the data query apparatus based on interface generation can further include:

[0135] The set updating unit is configured to add the target interface to the preset interface set to update the preset interface set, and take the obtained updated interface set as a new preset interface set.

[0136] In some embodiments, the data query module 15 can specifically include:

[0137] The data source determination unit is configured to determine a target data source corresponding to the data query requirement information.

[0138] The sentence execution unit is configured to execute the target data query sentence in the preset database and obtain a corresponding execution result data set.

[0139] The parameter generation unit is configured to loop through the execution result data set to extract a field value corresponding to the execution result data set, and generate a query parameter based on the field value.

[0140] The data acquisition unit is configured to acquire target query data corresponding to the data query requirement information from the target data source based on the query parameter corresponding to the target data query sentence through the target interface.

[0141] In some embodiments, the data query apparatus based on interface generation can further include:

[0142] The interface optimization unit is configured to monitor a response time length of the target interface, and if the response time length is greater than a preset response time length threshold, optimize the target interface according to a preset interface optimization rule to take an obtained optimized interface as a new target interface; the preset interface optimization rule is a rule for optimizing a query logic and an interface code of the target interface.

[0143] Further, the embodiments of the present application also disclose an electronic device,Figure 5 is an electronic device 20 structure diagram shown according to an exemplary embodiment, the contents of the figure cannot be considered as any limitation on the scope of use of the present application.

[0144] Figure 5 An electronic device 20 structure diagram provided for the embodiments of the present application. The electronic device 20, specifically can include: at least one processor 21, at least one memory 22, power supply 23, communication interface 24, input output interface 25 and communication bus 26. Wherein, the memory 22 is used to store computer programs, the computer programs are loaded and executed by the processor 21, to realize the related steps in the data query method based on interface generation disclosed in any of the preceding embodiments. In addition, the electronic device 20 in the embodiment can be an electronic computer.

[0145] In the embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol followed is any communication protocol applicable to the technical solution of the present application, which is not specifically limited here; the input output interface 25 is used to obtain external input data or output data to the outside world, and the specific interface type can be selected according to the specific application needs, which is not specifically limited here.

[0146] In addition, the memory 22 as a resource storage carrier can be a read-only memory, a random access memory, a magnetic disk or an optical disk, etc., and the resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage mode can be temporary storage or permanent storage.

[0147] Among them, the operating system 221 is used to manage and control each hardware device on the electronic device 20 and the computer program 222, which can be Windows Server, Netware, Unix, Linux, etc. In addition to the computer program capable of completing the data query method based on interface generation executed by the electronic device 20 disclosed in any of the preceding embodiments, the computer program 222 can further include a computer program capable of completing other specific work.

[0148] Further, the present application also discloses a computer readable storage medium for storing a computer program; wherein the computer program is executed by the processor to realize the data query method based on interface generation disclosed in the preceding. The specific steps of the method can refer to the corresponding contents disclosed in the preceding embodiments, which will not be repeated here.

[0149] The various embodiments described in the specification are progressive in nature, and each embodiment highlights the differences from other embodiments. The same or similar parts among the various embodiments can be mutually referred to. For the apparatus disclosed by the embodiments, since it corresponds to the method disclosed by the embodiments, the description is relatively simple, and the relevant parts can be referred to the method part.

[0150] Those skilled in the art will further appreciate that the individual steps of the examples described in connection with the embodiments disclosed herein can be embodied in electronic hardware, computer software, or combinations of both. The various examples have been described in relation to the described embodiments, as a means of generalizing the interchangeability of hardware and software under the principles mentioned above. The particular implementation of an individual example in either hardware or software can be determined by the particular application and design constraints imposed on the overall system. Skilled artisans will appreciate that the principles described herein can be practiced in a variety of system environments, and that the described implementations are merely examples and not intended to limit the scope of the application.

[0151] The steps of a method or algorithm described in connection with the embodiments disclosed herein can be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module can reside in random access memory (RAM), flash memory, read-only memory (ROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0152] Finally, it needs to be pointed out that, in this document, the relationship terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between the entities or operations. Moreover, the terms "include", "contain" or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. Without more limitations, the element defined by the statement "including a" does not exclude the presence of another identical element in the process, method, article or device including the element.

[0153] The above describes the technical solutions provided by the present application in detail, and the principles and implementation manners of the present application are described by using specific examples. The above description of the embodiments is only used to help understand the method and core idea of the present application; at the same time, for those skilled in the art, according to the idea of the present application, the specific implementation manner and application range can be changed; and the above description of the specification should not be understood as limiting the present application.

Claims

1. A method for generating a data query based on an interface, characterized in that, The method comprises the following steps: analyzing the received query statement to determine the data query requirement information and the interface requirement information corresponding to the query statement; the query statement is a natural language for data query; matching the corresponding data field and data table from the preset database based on the data query requirement information, and generating a target data query statement according to the data field and data table; determining whether there is a preset interface corresponding to the interface requirement information in the preset interface set; if not, generating a target interface corresponding to the interface requirement information based on the preset interface template, and if there is, taking the preset interface as the target interface; determining the target data source corresponding to the data query requirement information, and obtaining the target query data corresponding to the data query requirement information from the target data source based on the query parameters corresponding to the target data query statement through the target interface; wherein, the analysis of the received query statement to determine the data query requirement information and the interface requirement information corresponding to the query statement comprises: identify the stop words in the query statement, and remove the stop words from the query statement to obtain the removed query statement; performing word segmentation processing on the removed query statement to obtain a plurality of query words, identifying the parts of speech corresponding to the plurality of query words, and then labeling the plurality of query words through the parts of speech to obtain labeled query words; identify the named entities in the labeled query words and determine the syntactic relationship between the labeled query words; generate the target topology structure corresponding to the labeled query words based on the named entities and the syntactic relationship; analyze the target topology structure to determine the data query requirement information and the interface requirement information corresponding to the query statement; wherein, the matching of the corresponding data field and data table from the preset database based on the data query requirement information, and the generation of a target data query statement according to the data field and data table, comprises: matching the data query requirement information with the preset database to determine the target data table, the target data field and the target corresponding relationship between the target data table and the target data field in the preset database corresponding to the data query requirement information; generating a to-be-confirmed data query statement based on the target data table, the target data field and the target corresponding relationship through the preset database syntax rules; performing syntax checking on the to-be-confirmed data query statement to determine whether there is a syntax error in the to-be-confirmed data query statement; if there is a syntax error in the to-be-confirmed data query statement, modifying the to-be-confirmed data query statement based on the syntax error to obtain a to-be-optimized data query statement; if there is no syntax error in the to-be-confirmed data query statement, taking the to-be-confirmed data query statement as the to-be-optimized data query statement; optimizing the to-be-optimized data query statement based on the preset optimization rules to obtain a target data query statement; the preset optimization rules are to add data index or perform query splitting to the to-be-optimized data query statement.

2. The interface-generated data query method of claim 1, wherein, The target topology is analyzed to determine data query requirement information and interface requirement information corresponding to the query statement, including: The target topology is analyzed by a preset model to identify a query intention corresponding to the query statement, and data query requirement information is generated according to the query intention; According to the query intention, the interface type corresponding to the query statement, the interface parameter corresponding to the interface type, and the data return format are determined, and the interface requirement information is generated according to the interface type, the interface parameter, and the data return format.

3. The method of claim 2, wherein, The target interface corresponding to the interface requirement information is generated based on a preset interface template, including: A target interface template corresponding to the interface type is determined from a preset interface template set, and a target interface is generated according to the target interface template, the interface parameter, and the data return format; Correspondingly, the method further includes: The target interface is added to the preset interface set to update the preset interface set, and the obtained updated interface set is used as a new preset interface set.

4. The method of claim 1, wherein, The target data source corresponding to the data query requirement information is determined, and the target query data corresponding to the data query requirement information is obtained from the target data source based on the query parameter corresponding to the target data query statement through the target interface, including: A target data source corresponding to the data query requirement information is determined; The target data query statement is executed in the preset database, and a corresponding execution result data set is obtained; The execution result data set is iteratively traversed to extract field values corresponding to the execution result data set, and query parameters are generated based on the field values; The target query data corresponding to the data query requirement information is obtained from the target data source based on the query parameter corresponding to the target data query statement through the target interface.

5. The method of claim 1 to 4, wherein, Further comprising: The response time of the target interface is monitored, and if the response time is greater than a preset response time threshold, the target interface is optimized according to a preset interface optimization rule to obtain an optimized interface as a new target interface; The preset interface optimization rule is a rule for optimizing the query logic and interface code of the target interface.

6. A data query apparatus based on interface generation, characterized by, Including: An information determination module for analyzing a received query statement to determine data query requirement information and interface requirement information corresponding to the query statement; The query statement is a natural language for data query; A query statement generation module for matching corresponding data fields and data tables from a preset database based on the data query requirement information, and generating a target data query statement according to the data fields and data tables; An interface matching module for determining whether a preset interface corresponding to the interface requirement information exists in a preset interface set; An interface determination module for generating a target interface corresponding to the interface requirement information based on a preset interface template if the preset interface does not exist, and using the preset interface as the target interface if the preset interface exists; The data query module is configured to determine a target data source corresponding to the data query requirement information, and acquire target query data corresponding to the data query requirement information from the target data source based on a query parameter corresponding to the target data query statement through the target interface. The information determination module includes: The data elimination submodule is configured to identify stop words in the query statement, and eliminate the stop words from the query statement to obtain an eliminated query statement. The data labeling submodule is configured to perform word segmentation processing on the eliminated query statement to obtain a plurality of query words, identify parts of speech corresponding to the plurality of query words, and then label the plurality of query words based on the parts of speech to obtain labeled query words. The data identification submodule is configured to identify named entities in the labeled query words, and determine a grammatical relationship between the labeled query words. The structure generation submodule is configured to generate a target topology structure corresponding to the labeled query words based on the named entities and the grammatical relationship. The structure analysis submodule is configured to analyze the target topology structure to determine data query requirement information and interface requirement information corresponding to the query statement. The query statement generation module includes: The relationship determination unit is configured to match the data query requirement information with a preset database to determine a target data table corresponding to the data query requirement information, a target data field, and a target corresponding relationship between the target data table and the target data field in the preset database. The query statement generation unit is configured to generate a to-be-confirmed data query statement based on the target data table, the target data field, and the target corresponding relationship through a preset database syntax rule. The syntax checking unit is configured to perform syntax checking on the to-be-confirmed data query statement to determine whether there is a syntax error in the to-be-confirmed data query statement. The syntax correction unit is configured to correct the to-be-confirmed data query statement based on the syntax error to obtain a to-be-optimized data query statement if there is a syntax error in the to-be-confirmed data query statement. The statement determination unit is configured to use the to-be-confirmed data query statement as the to-be-optimized data query statement if there is no syntax error in the to-be-confirmed data query statement. The statement optimization unit is configured to optimize the to-be-optimized data query statement based on a preset optimization rule to obtain a target data query statement. The preset optimization rule is to add a data index to the to-be-optimized data query statement or perform query splitting.

7. An electronic device, comprising: The memory is configured to save a computer program. The processor is configured to execute the computer program to implement the interface-based data query method of any one of claims 1 to 5. The memory is configured to save a computer program.

8. A computer-readable storage medium, characterized in that, The processor is configured to execute the computer program to implement the interface-based data query method of any one of claims 1 to 5.

Citation Information

Patent Citations

  • Database query method and device, equipment and storage medium

    CN119557329A

  • Data query method and device, computer equipment and storage medium

    CN120216555A