Data query method and data query device
By analyzing and converting query statements, the problem of differences in multiple database dialects is solved, a unified query language is realized, user learning costs and usage thresholds are reduced, data storage barriers are broken, and data analysis scenarios are normalized.
Patent Information
- Application Number
- CN202010423661.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-05-19
- Publication Date
- 2024-12-17
- Estimated Expiration
- 2040-05-19
AI Technical Summary
In the context of massive data, the diversification of data storage solutions and the differences in database dialects have led to data developers and analysts needing to learn the query implementation of multiple databases, increasing the learning cost of users and the threshold for system use.
By receiving and parsing query statements, determining the correspondence between database functions, and generating query statements that are adapted to different database types, thereby blocking the impact of underlying storage and query engines on users and reducing learning costs and usage thresholds.
It realizes a unified query language for different database types, automatically converts functions, breaks the data storage barrier, reduces user learning costs and usage thresholds, and normalizes data analysis scenarios.
Smart Images

Figure CN113688176B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to a data query method and a data query device, and in particular to a data query solution for databases of various data storage types under big data. Background Art
[0002] In today's context of massive data, data sources are diverse, data output is becoming more and more efficient, data is widely analyzed and used, and data value is mined to drive business.
[0003] However, on the other hand, the underlying data storage options are diverse and complex, the data storage solutions and storage formats are diverse, and different storage solutions have different applicable scenarios.
[0004] For example, the underlying database can include an OLAP database for real-time analysis of hundreds of billions of data, a high-throughput, high-performance, and flexible SQL-like database Hbase, a sharded database TDDL, an ElasticSearch document database, a big data computing service Maxcompute, a big data batch processing Hive built on Hadoop, and MySQL / PostgreSQL / Db2, etc. Each data storage has its own advantages and disadvantages. Therefore, different types of data storage databases are often selected for different task processing scenarios.
[0005] Each type of data storage database has its own unique language, which can be called a "dialect" ("database dialect"). Different databases have different SQL query statement designs, just like people from different places speak different dialects. Different from other databases, only this database itself can "hear" and understand.
[0006] In this way, data developers and data analysts need to be familiar with multiple underlying data storage and query engines, learn different implementations of the same query scenario in various databases, and process data in different ways and data formats to obtain the final analysis results. This undoubtedly increases the user's learning cost and the threshold for system use.
[0007] Therefore, it is hoped that the impact of the underlying data storage and query engine on users can be shielded, so that users do not need to worry about the type of underlying data storage and only need to focus on data query itself, thereby reducing the user's usage threshold and learning cost. Summary of the invention
[0008] A technical problem to be solved by the present disclosure is to provide a data query solution, which can shield the impact of underlying data storage and query engines on users and reduce the user's usage threshold and learning cost.
[0009] According to a first aspect of the present disclosure, a data query method is provided, including: receiving a first query statement, the first query statement is based on a language of a first type of database and is for a second type of database, the second type being different from the first type; parsing the first query statement to obtain first function information of a first type of database function contained therein; determining, based on the first function information and the second type, second function information of a second type of database function corresponding to the first function information; and generating, based on the second function information, a second query statement containing the second type of database function.
[0010] Optionally, the step of parsing the first query statement may include: parsing the first query statement by traversing an AST syntax tree to obtain each function node therein.
[0011] Optionally, the step of determining the second function information of the second type database function corresponding to the first function information according to the first function information and the second type may include: determining the second function information based on a function correspondence library, the function correspondence library recording the correspondence between the first type database function and the second type database function; or determining the second function information using a tool, the tool determining the second function information corresponding to the second type database function corresponding to the first function information based on the correspondence between the first type database function and the second type database function.
[0012] Optionally, the first function information may include a first function name and / or a first parameter of a first type of database function included in the first query statement. The second function information may include a second function name and / or a second parameter of a second type of database function. The step of generating a second query statement including a second type of database function may include: replacing the first function name and / or the first parameter with the second function name and / or the second parameter.
[0013] Optionally, the first query statement may include multiple first-type database functions. The first function information may also include a nested relationship between the multiple first-type database functions. The step of generating a second query statement including a second-type database function may also include: nesting multiple corresponding second-type database functions based on the nested relationship.
[0014] Optionally, the method may also include: determining a second type of database targeted by the first query statement based on fields and / or query scenarios in the first query statement; and / or determining whether the first query statement contains a database function, and if the first query statement contains a database function, executing a step of parsing the first query statement.
[0015] Optionally, the method may further include: searching a function dictionary for a second query statement corresponding to the first query statement, wherein the function dictionary records corresponding query statements in languages of different types of databases in an associative manner.
[0016] Optionally, when the second query statement corresponding to the first query statement is not found in the function dictionary, the step of parsing the first query statement is performed.
[0017] Optionally, the method may further include: adding a new entry to the function dictionary, the new entry recording in association the first query statement and the second query statement that cannot be converted through parsing; and / or deleting an old entry from the function dictionary, the old entry recording in association the first query statement and the second query statement that can currently be converted through parsing.
[0018] According to a second aspect of the present disclosure, a data query method is provided, comprising: using the method according to the above first aspect, with the input query statement as a first query statement and the intermediate query statement as a second query statement, converting the input query statement into an intermediate query statement, wherein the input query statement is based on the language of a first type of database and is for a second type of database, the second type is different from the first type, and the intermediate query statement is based on the language of a third type of database; and using the method according to the above first aspect, with the intermediate query statement as the first query statement and the target query statement as the second query statement, converting the intermediate query statement into a target query statement, wherein the target query statement is based on the language of the second type of database.
[0019] According to a third aspect of the present disclosure, a data query method for a conversational robot is provided, comprising: receiving a query request input by a user; determining a target database and a second type thereof targeted by the query request; generating a first query statement based on the query request, the first query statement being based on a language of a database of the first type, the second type being different from the first type; parsing the first query statement to obtain first function information of a first type database function contained therein; determining second function information of a second type database function corresponding to the first function information based on the first function information and the second type; generating a second query statement containing a second type database function based on the second function information; using the second query statement to query the target database to obtain a query result; and returning the query result to the user.
[0020] According to a fourth aspect of the present disclosure, a data query method is provided, including: receiving a first query statement, the first query statement is based on the language of a first type of database and is for a second type of database, the second type being different from the first type; converting the first query statement to obtain a second query statement, the second query statement is based on the language of the second type of database; displaying the second query statement; receiving a modification instruction for the second query statement; and modifying the second query statement based on the modification instruction.
[0021] Optionally, the modification instruction may include: modification of the query object field name; and / or modification instructions related to the data storage format in the database.
[0022] According to a fifth aspect of the present disclosure, a data query device is provided, including: a receiving device, receiving a first query statement, the first query statement is based on the language of a first type of database and is for a second type of database, the second type being different from the first type; a parsing device, parsing the first query statement to obtain first function information of the first type of database function contained therein; a determining device, determining, based on the first function information and the second type, second function information of the second type of database function corresponding to the first function information; and a generating device, generating, based on the second function information, a second query statement containing the second type of database function.
[0023] Optionally, the data query device may further include: a search device for searching a second query statement corresponding to the first query statement from a function dictionary, wherein the function dictionary records corresponding query statements in languages of different types of databases in an associative manner.
[0024] Optionally, the data query device may also include: an adding device, which adds a new entry in the function dictionary, the new entry records in association the first query statement and the second query statement that cannot be converted through parsing; and / or a deleting device, which deletes the old entry from the function dictionary, the old entry records in association the first query statement and the second query statement that can currently be converted through parsing.
[0025] According to a sixth aspect of the present disclosure, a computing device is provided, comprising: a processor; and a memory on which executable codes are stored, and when the executable codes are executed by the processor, the processor executes the methods described in the first to fourth aspects above.
[0026] According to a seventh aspect of the present disclosure, a non-temporary machine-readable storage medium is provided, on which executable code is stored. When the executable code is executed by a processor of an electronic device, the processor executes the methods described in the first to fourth aspects above.
[0027] As a result, the impact of the underlying data storage and query engine on users is shielded. Users do not need to worry about the type of underlying data storage and only need to focus on data query itself. The usage threshold and learning cost are significantly reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The above and other objects, features and advantages of the present disclosure will become more apparent through a more detailed description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, wherein like reference numerals generally represent like components in the exemplary embodiments of the present disclosure.
[0029] Figure 1 The application scenario architecture of the data query solution according to the present disclosure is shown.
[0030] Figure 2 A schematic flow chart of a data query method according to the present disclosure is shown.
[0031] Figure 3 A schematic block diagram of a data query device according to the present disclosure is shown.
[0032] Figure 4 A schematic diagram of the structure of a computing device that can be used to implement the above data query method according to an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0033] The preferred embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the preferred embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.
[0034] Figure 1 The application scenario architecture of the data query solution according to the present disclosure is shown.
[0035] like Figure 1 As shown, massive data is stored in multiple databases of different types, DB1, DB2, DB3, ..., DBn.
[0036] Data can come from a variety of sources, and the data stored in various databases may also be used in a variety of different or the same scenarios.
[0037] User 1 can query the data in databases DB1, DB2, DB3, ..., DBn through device 2.
[0038] The device 2 may be, for example, an electronic device such as a computer or a mobile phone, or may also be a server.
[0039] User 1 may be, for example, a data developer or a data analyst, or any other user who needs to query data from a database.
[0040] User 1 inputs a query statement at device 2, and then terminal device 2 sends the query instruction, for example, through a server (not shown) or directly to a query interface of a corresponding database, thereby obtaining corresponding query results.
[0041] The database language of the present disclosure may be, for example, SQL (Structured Query Language). As described above, for different types of databases, there may be different SQL languages ("database dialects"), and in particular, the functions included therein may differ significantly.
[0042] In other words, for the same or similar query requirements, SQL query statements of various types of databases often have different function formats.
[0043] For example, the functions for getting the current time in the date functions of different database types are as follows:
[0044] The MySQL function is now();
[0045] The Maxcompute function is getdate();
[0046] Hive is CURRENT_DATE();
[0047] postgreSQL is selectnow etc.
[0048] In addition, date formatting functions, string processing functions, etc. are also different in different database types.
[0049] The differences in these functions bring many difficulties to the unification of query methods for different types of databases.
[0050] The data query solution disclosed in the present invention can shield the differences between different types of underlying data storage and provide users with a unified query language. For different query scenarios, functions can be automatically converted into functions under different data storage dialects, thereby breaking down data storage barriers and normalizing all data analysis scenarios, allowing users to focus only on the data itself.
[0051] Reference below Figure 2 and Figure 3 The data query scheme according to the present disclosure is described in detail.
[0052] Figure 2 A schematic flow chart of a data query method according to the present disclosure is shown.
[0053] The data query method can be used, for example, Figure 1 The process is executed at the device 2 shown, and may also be executed on a server that manages multiple databases.
[0054] Figure 3 A schematic block diagram of a data query device that can be used to implement the data query method according to the present disclosure is shown.
[0055] like Figure 3 As shown, the data query device 300 according to the present disclosure may include a receiving device 310, a parsing device 330, a determining device 340, and a generating device 350. In addition, in some embodiments, the data query device 300 may also include a searching device 320. Figure 2 The flowchart is described Figure 3 The functions of each device shown.
[0056] like Figure 2 As shown, in step S210, for example, the first query statement may be received by the receiving device 310.
[0057] The query statement here may also be in the form of a query SQL expression in some cases.
[0058] The first query statement is based on the language of the first type of database.
[0059] For example, a language applicable to a database, such as MySQL, can be set as a unified standard database language. The first query statement here is a query statement based on this unified standard database language. In other words, the user can edit the first query statement based on this unified standard database language.
[0060] Alternatively, a unified standard database language may not be set. The user may edit the first query statement based on any one of a plurality of database languages.
[0061] The first query statement may be for a second type of database, which is different from the first type. In other words, the database type applicable to the database language used in the first query statement input by the user may be different from the type of database the user expects to query. Accordingly, the database language used in the database expected to be queried may also be different from the language used in the first query statement.
[0062] In some cases, it may be determined in step S220 whether the first query statement includes a database function.
[0063] When it is determined that the first query statement does not contain a database function, the process may directly proceed to step S290, and after corresponding processing when necessary, execute a query on the targeted database and return the query result.
[0064] On the other hand, when it is determined that the first query statement includes a database function, the following query statement conversion scheme according to the present disclosure may be executed.
[0065] In step S230, the second type of the database targeted by the first query statement may be determined.
[0066] In the context of big data, there are various data acceleration solutions. Therefore, a task processing scenario often has multiple data storage options, such as Maxcompute / Hologres / ADB, etc. In this way, by determining the data or its type targeted by the query statement, the corresponding SQL query statement can be generated according to the underlying data storage corresponding to the current query scenario.
[0067] For example, the user can indicate the database or the type of the database targeted in a specific field in the first query statement. In this way, the type of the database targeted (second type) can be determined based on the field in the first query statement.
[0068] Alternatively, different query scenarios may correspond to different databases. The type of database targeted by the first query statement (second type) may be determined according to the query scenario of the first query statement.
[0069] In some cases, in step S240, for example, the second query statement corresponding to the first query statement may be searched from the function dictionary by the search device 320. The first query statement is based on the language of the second type of database.
[0070] The function dictionary may be a pre-maintained query statement correspondence library, in which corresponding query statements in different types of database languages are recorded in association. For example, in the case of setting a unified standard database language, corresponding query statements (SQL expressions) in one or more other types of database languages may be recorded in corresponding entries for some query statements (SQL expressions) in the unified standard database language.
[0071] For some identical or similar functions, the functions in different database dialects are very different. For example, SQL-like Hbase only supports simple index aggregation queries, and does not support index groupby with dimension queries. For another example, the support for the window function rownumber over() is different from that of MySQL.
[0072] For these situations, the corresponding query statements can be directly recorded in the function dictionary to reduce the complexity of the function parsing operation described below.
[0073] In addition to preparing the function dictionary in advance, the function dictionary can also be maintained continuously.
[0074] On the one hand, the data query device 300 may also provide, for example, an adding device (not shown) to add some new entries to the function dictionary. These new entries record the first query statement and the second query statement that cannot be converted by parsing in association.
[0075] On the other hand, the data query device 300 may also provide, for example, a deletion device (not shown), and with the improvement of the parsing capability described below, such as the upgrade of the parsing tools or the function correspondence library, more function correspondences are included, and some old entries may be deleted from the function dictionary. These old entries record the first query statement and the second query statement that are currently convertible by parsing in association.
[0076] The function dictionary search scheme described here can be used as a supplement to the parsing scheme described below. For some query statements containing complex functions, the corresponding query statement sets under different database types are directly recorded in the dictionary, and the corresponding query statement is directly searched from the dictionary when used.
[0077] However, the query statement may involve SQL expressions containing user-defined dimensions and / or indicators, which are not exhaustive in various task processing scenarios. If the entries contained in the function dictionary are too complex, in some cases, it will take a long time to search the function dictionary itself. Therefore, as the parsing capability improves, appropriately reducing the size of the function dictionary will help further reduce the total query time, improve system performance, and improve user experience.
[0078] Here, a solution of searching the function dictionary before the parsing operation is disclosed. It should be understood that in some cases, the parsing may be performed first, and if the second query statement cannot be successfully obtained through the parsing, the function dictionary may be tried to be searched. Alternatively, in some cases, the function dictionary may not be set and the function dictionary may not be searched.
[0079] In step S250, it may be determined whether a second query statement corresponding to the first query statement is found in the function dictionary.
[0080] When a second query statement corresponding to the first query statement is found in the function dictionary, the process proceeds to step S290 to execute a query on the targeted database based on the found second query statement and return a query result.
[0081] On the other hand, when the second query statement corresponding to the first query statement is not found in the function dictionary, the process proceeds to step S260 to generate the second query statement by parsing and converting the first query statement.
[0082] like Figure 2As shown, in step S260, for example, the first query statement may be parsed by the parsing device 330 to obtain the first function information of the first type of database function contained therein.
[0083] Here, the first query statement may be parsed by, for example, AST (Abstract Syntax Tree) traversal to obtain each function node therein. For example, Druid SQL AST traversal may be used for parsing.
[0084] The first function information may include, for example, a first function name and / or a first parameter of a first type of database function included in the first query statement.
[0085] In addition, when the first query statement includes multiple first-type database functions, the first function information may further include a nested relationship between the multiple first-type database functions.
[0086] Thus, in step S270, for example, the second function information of the second type database function corresponding to the first function information may be determined by the determination device 340 according to the first function information and the second type.
[0087] The second function information includes a second function name and / or a second parameter of the second type database function.
[0088] The functions in the query language corresponding to various types of databases and their corresponding function information are known, and their respective functions are also known. Therefore, for functions with the same functions in different databases, the corresponding relationships between them can also be sorted in advance.
[0089] For example, the correspondence between the first type of database function and the second type of database function may be recorded in a function correspondence library. In this way, the second function information may be determined based on the function correspondence library.
[0090] Alternatively, a tool may be provided, wherein the tool determines the second function information corresponding to the second type of database function corresponding to the first function information based on the corresponding relationship between the first type of database function and the second type of database function.
[0091] In step S280, for example, the generating device 350 may generate a second query statement including a second type of database function according to the second function information, that is, a query statement adapted to the underlying data storage targeted by the first query statement input by the user.
[0092] Here, the first function name may be replaced with the second function name, and / or the first parameter may be replaced / converted to the second parameter. Thus, for example, the second query statement may be generated according to the format of the second type of database function (which may also be included in the second function information).
[0093] In addition, when the first query statement contains multiple first-type database functions, multiple corresponding second-type database functions can also be nested according to the nesting relationship in the first function information (converted to the front nesting relationship of the second-type database function when necessary).
[0094] Thus, in step S290, the database targeted by the first query statement input by the user can be queried according to the second query statement generated (step S280) through parsing (step S260), conversion (step S270), etc. For example, the underlying database query interface API is called to obtain data, and then provided to the user for processing such as analysis.
[0095] So far, the data query scheme according to the present disclosure has been described in detail.
[0096] Through the data query solution disclosed in the present invention, the differences between different data storages can be shielded, the data storage barriers can be broken, and the impact of the underlying data storage on the user can be shielded, so that the user only needs to pay attention to the data itself without worrying about the underlying data storage data source, which reduces the user's learning threshold and allows the data analysis scenario to be normalized / standardized / unified.
[0097] In addition, in some cases, one or more users may initiate multiple query requests for different databases (for example, by inputting multiple query statements, which may be based on a unified standard query language, for example). According to the above solution, these query statements may be converted into query statements adapted to the corresponding database type through a query function dictionary or parsing conversion, and the corresponding underlying database query interface API may be called to perform queries in parallel to obtain data.
[0098] As described above, a language suitable for a database, such as MySQL, may be set as a unified standard database language.
[0099] The user can edit the first query statement based on this unified standard database language.
[0100] For at least one other database dialect, the above-mentioned dictionary, the above-mentioned function correspondence library or the above-mentioned tool from the standard database language to the dialect can be prepared. In this way, when the first query statement is for a database of the type corresponding to the database dialect, the first query statement can be converted into a second query statement of the database dialect according to the above-mentioned method.
[0101] The user may also edit the first query statement based on a database dialect (first database dialect) instead of the unified standard database language, while the first query statement may be targeted at another type of database using a second database dialect.
[0102] In this case, in addition to preparing the above-mentioned dictionary, the above-mentioned function correspondence library or the above-mentioned tool from the standard database language to at least one database dialect (including the second database dialect), the above-mentioned dictionary, the above-mentioned function correspondence library or the above-mentioned tool from at least one database dialect (including the first database dialect) to the standard database language (here, it may also be referred to as "intermediate language") may also be prepared. In this way, the first query statement in the first database dialect may be first converted into an intermediate query statement in the standard database language according to the above-mentioned method, and then the intermediate query statement may be converted into a second query statement in the second database dialect according to the above-mentioned method.
[0103] Alternatively, the dictionary, the function correspondence library or the tool may be prepared from at least one database dialect (including the first database dialect) to at least one database dialect (including the second database dialect). In this way, the first query statement in the first database dialect may be directly converted into the second query statement in the second database dialect according to the above method.
[0104] The data query method according to the present disclosure can be used in a conversational robot, for example, a conversational robot of a bank, a securities company, a communication service company, etc.
[0105] The conversational robot can receive query requests input by users. The query requests can be used to query any relevant content.
[0106] By analyzing the query request, the target database targeted by the query request can be determined, that is, the database to be queried to answer the query request. Accordingly, the type of the target database can also be determined, which is called the "second type" for easy distinction.
[0107] Then, a first query statement may be generated based on the query request, the first query statement being based on a language of a first type of database, such as a language of a unified standard database type. The second type of the target database is different from the first type.
[0108] According to the above method of the present disclosure, a second query statement in the database dialect applicable to the second database type may be obtained, for example, the second type database function may be included.
[0109] The second query statement is used to query the target database to obtain the query result.
[0110] The conversational bot can then return the query results to the user.
[0111] The query requests faced by the conversational robot may be for various types of databases. For example, banks, securities companies, communication service companies, etc. may store various types of data in different types of databases, or different institutions may store the same type of data in different types of databases. In this scenario, using the data query method according to the present disclosure, it is convenient to query data in various databases.
[0112] In addition, after receiving the first query statement based on the language of the first type of database and converting it to obtain the second query statement based on the language of the second type of database, the second query statement can be displayed on the user's display screen.
[0113] In this way, the user can modify or adjust the second query statement and issue a modification instruction for the second query statement.
[0114] For example, different databases have different field names for the same query object, such as the difference between "person's name" and "name". In this case, the modification instruction may be a query object field name modification instruction.
[0115] For another example, different databases have different data storage structures or storage formats, such as different storage table styles. Accordingly, the query statement may also contain some content related to the data storage format in the database. At this time, the modification instruction may be related to the data storage format in the database.
[0116] By receiving a modification instruction for the second query statement and modifying the second query statement based on the modification instruction, a proper query statement can be obtained, so that the required queried data can be successfully obtained from the corresponding database.
[0117] Figure 4 A schematic diagram of the structure of a computing device that can be used to implement the above data query method according to an embodiment of the present invention is shown.
[0118] See also Figure 4 , the computing device 400 includes a memory 410 and a processor 420 .
[0119] Processor 420 may be a multi-core processor or may include multiple processors. In some embodiments, processor 420 may include a general-purpose main processor and one or more special coprocessors, such as a graphics processing unit (GPU), a digital signal processor (DSP), etc. In some embodiments, processor 420 may be implemented using a customized circuit, such as an application-specific integrated circuit (ASIC) or a field programmable gate array (FPGA).
[0120] The memory 410 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage devices. Among them, ROM can store static data or instructions required by the processor 420 or other modules of the computer. The permanent storage device may be a readable and writable storage device. The permanent storage device may be a non-volatile storage device that does not lose the stored instructions and data even after the computer is powered off. In some embodiments, the permanent storage device uses a large-capacity storage device (such as a magnetic or optical disk, flash memory) as a permanent storage device. In some other embodiments, the permanent storage device may be a removable storage device (such as a floppy disk, optical drive). The system memory may be a readable and writable storage device or a volatile readable and writable storage device, such as a dynamic random access memory. The system memory may store some or all instructions and data required by the processor at run time. In addition, the memory 410 may include any combination of computer-readable storage media, including various types of semiconductor memory chips (DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and disks and / or optical disks may also be used. In some embodiments, the memory 410 may include a readable and / or writable removable storage device, such as a laser disc (CD), a read-only digital versatile disc (such as a DVD-ROM, a double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (such as an SD card, a mini SD card, a Micro-SD card, etc.), a magnetic floppy disk, etc. The computer-readable storage medium does not include carrier waves and transient electronic signals transmitted wirelessly or wired.
[0121] The memory 410 stores executable codes, and when the executable codes are processed by the processor 420 , the processor 420 can execute the data query method mentioned above.
[0122] The data query scheme according to the present invention has been described in detail above with reference to the accompanying drawings.
[0123] In addition, the method according to the present invention may also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing the above steps defined in the above method of the present invention.
[0124] Alternatively, the present invention may also be implemented as a non-temporary machine-readable storage medium (or computer-readable storage medium, or machine-readable storage medium) on which executable code (or computer program, or computer instruction code) is stored. When the executable code (or computer program, or computer instruction code) is executed by a processor of an electronic device (or computing device, server, etc.), the processor executes the various steps of the above-mentioned method according to the present invention.
[0125] Those skilled in the art will further appreciate that the various illustrative logical blocks, modules, circuits, and algorithm steps described in connection with the disclosure herein may be implemented as electronic hardware, computer software, or a combination of both.
[0126] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system and method according to multiple embodiments of the present invention. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or code, and the part of the module, program segment or code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0127] The embodiments of the present invention have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The terms used herein are selected to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A data query method, comprising: receiving a first query statement, the first query statement being based on a language of a first type of database and targeting a second type of database, the second type being different from the first type; Based on the database function included in the first query statement, the first query statement is parsed to obtain first function information of the first type of database function included therein; Determine, according to the first function information and the second type, second function information of a second type database function corresponding to the first function information; as well as Generate a second query statement including a second type of database function according to the second function information; Based on the fact that the first query statement does not include a database function, a query is performed on the database targeted by the first query statement.
2. The method according to claim 1, wherein: The step of parsing the first query statement includes: By traversing the AST syntax tree, the first query statement is parsed to obtain each function node therein.
3. The method according to claim 1, wherein: The step of determining second function information of a second type database function corresponding to the first function information according to the first function information and the second type comprises: Determine the second function information based on a function correspondence library, wherein the function correspondence library records the correspondence between the first type database function and the second type database function; or The second function information is determined using a tool, wherein the tool determines the second function information corresponding to the second type database function corresponding to the first function information based on the correspondence between the first type database function and the second type database function.
4. The method according to claim 1, wherein: The first function information includes a first function name and / or a first parameter of a first type of database function included in the first query statement. The second function information includes a second function name and / or a second parameter of the second type database function. The step of generating a second query statement containing a second type of database function comprises: Replace the first function name and / or first parameter with the second function name and / or second parameter.
5. The method according to claim 4, wherein: The first query statement includes a plurality of first-type database functions, and the first function information further includes a nested relationship between the plurality of first-type database functions. The step of generating a second query statement containing a second type of database function also includes: Based on the nesting relationship, a plurality of corresponding second-type database functions are nested.
6. The method according to claim 1, further comprising: Based on the fields and / or query scenarios in the first query statement, a second type of database targeted by the first query statement is determined.
7. The method according to claim 1, further comprising: A second query statement corresponding to the first query statement is searched from a function dictionary, wherein the function dictionary records corresponding query statements in languages of different types of databases in an associative manner.
8. The method according to claim 7, wherein: If the second query statement corresponding to the first query statement is not found in the function dictionary, the step of parsing the first query statement is performed.
9. The method according to claim 7, further comprising: Adding a new entry in the function dictionary, wherein the new entry records in association the first query statement and the second query statement that cannot be converted by parsing; and / or An old entry is deleted from the function dictionary, wherein the old entry records in association the first query statement and the second query statement that can be converted by parsing at present.
10. A data query method, comprising: Using the method according to any one of claims 1 to 9, with the input query statement being a first query statement and the intermediate query statement being a second query statement, the input query statement is converted into an intermediate query statement, the input query statement is based on a language of a first type of database and is for a second type of database, the second type is different from the first type, and the intermediate query statement is based on a language of a third type of database; as well as Using the method according to any one of claims 1 to 9, the intermediate query statement is used as the first query statement, the target query statement is used as the second query statement, and the intermediate query statement is converted into a target query statement, wherein the target query statement is based on the language of the second type of database.
11. A data query method for a conversational robot, comprising: Receive a query request input by a user; Determine the target database targeted by the query request and its second type; generating a first query statement based on the query request, wherein the first query statement is based on a language of a database of a first type, and the second type is different from the first type; Based on the database function included in the first query statement, the first query statement is parsed to obtain first function information of the first type of database function included therein; Determine, according to the first function information and the second type, second function information of a second type database function corresponding to the first function information; Generate a second query statement including a second type of database function according to the second function information; Use a second query statement to query the target database to obtain a query result; as well as Returning the query result to the user; Based on the fact that the first query statement does not include a database function, a query is performed on the database targeted by the first query statement.
12. A data query method, comprising: receiving a first query statement, the first query statement being based on a language of a first type of database and targeting a second type of database, the second type being different from the first type; Based on the database function included in the first query statement, convert the first query statement to obtain a second query statement, where the second query statement is based on a language of a second type of database; Display the second query statement; receiving a modification instruction for the second query statement; as well as Modify the second query statement based on the modification instruction; Based on the fact that the first query statement does not include a database function, a query is performed on the database targeted by the first query statement.
13. The method according to claim 12, wherein: The modification instruction includes: Instructions to modify the name of a query object field; and / or Instructions for modifying the format of data storage in a database.
14. A data query device, comprising: A receiving device receives a first query statement, wherein the first query statement is based on a language of a first type of database and is directed to a second type of database, the second type being different from the first type; A parsing device, based on the database function included in the first query statement, parses the first query statement to obtain first function information of the first type of database function included therein; The determining means determines, based on the first function information and the second type, second function information of a second type database function corresponding to the first function information; as well as A generating device generates a second query statement including a second type of database function according to the second function information; Based on the fact that the first query statement does not include a database function, a query is performed on the database targeted by the first query statement.
15. The apparatus according to claim 14, further comprising: The searching device searches for a second query statement corresponding to the first query statement from a function dictionary, wherein the function dictionary records corresponding query statements in languages of different types of databases in an associative manner.
16. The apparatus according to claim 15, further comprising: adding means for adding a new entry in the function dictionary, wherein the new entry records in association the first query statement and the second query statement that cannot be converted by parsing; and / or The deleting device deletes an old entry from the function dictionary, wherein the old entry records in association the first query statement and the second query statement that can be converted by parsing at present.
17. A computing device comprising: processor; as well as A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to perform the method according to any one of claims 1 to 13.
18. A non-transitory machine-readable storage medium having executable codes stored thereon, which, when executed by a processor of an electronic device, causes the processor to execute the method according to any one of claims 1 to 13.
Citation Information
Patent Citations
Query sentence processing device and query sentence processing method
CN102253984A
Universal cross-database access method
CN105260403A
Method for automatically generating sql query statement containing built-in functions of database
CN108460092A
Language conversion method and device, storage medium and data query system and method
CN108710662A
Method and device for SQL statement conversion
CN109062918A
