Unified SQL (Structured Query Language) query method and device and electronic equipment
Through unified SQL query methods, SQL query requests are converted into Gremlin and SPARQL queries, solving the problem of unified query for Gremlin and SPARQL graph databases, and improving query efficiency and convenience.
Patent Information
- Application Number
- CN202411841332.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-13
- Publication Date
- 2025-04-29
AI Technical Summary
The prior art is difficult to implement unified SQL query of Gremlin graph database and SPARQL graph database, resulting in inefficient data access and complex management.
Through a unified SQL query method, using a pre-configured graph database, the user's SQL query request is converted into corresponding Gremlin queries and/or SPARQL queries, and parallel queries and/or distributed calculations are performed to obtain query results.
It realizes unified SQL query of Gremlin graph database and SPARQL graph database, improves query efficiency and convenience, and is suitable for efficient management and utilization of multi-source graph data in modern enterprises.
Smart Images

Figure CN119903072A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of graph database technology, and in particular to a unified SQL query method and device, and electronic equipment. Background Art
[0002] Graph databases have significant advantages in processing complex related data, however, querying these databases usually requires specialized query languages. Among them, Gremlin and SPARQL are two commonly used graph database query languages. Gremlin is a graph traversal language used for databases that support tinkerpop, such as JanusGraph, AWS Neptune, etc. It is a declarative language. SPARQL is a query language for RDF data, commonly used in databases like Virtuoso and GraphDB. This poses a challenge to users who are accustomed to using SQL (the standard query language for relational databases). Traditional query systems have difficulty in performing unified queries on these two different types of graph databases, resulting in inefficient data access and complex management. At present, some SQL query engines, although supporting unified queries on multiple heterogeneous data sources, are insufficient in directly supporting graph databases. Therefore, an improved system is needed to implement unified SQL queries on Gremlin graph databases and SPARQL graph databases. Summary of the invention
[0003] The technical problem to be solved by the present invention is how to implement a unified SQL query on a Gremlin graph database and a SPARQL graph database; in view of this, the present invention provides a unified SQL query method and device, and an electronic device.
[0004] The technical solution adopted by the present invention is a unified SQL query method, comprising:
[0005] Step S1, receiving a user's SQL query request, and using a pre-configured graph database to convert the query request into a corresponding database query operation;
[0006] Step S2, executing the database query operation after query conversion on the target database;
[0007] Step S3, collecting and integrating the query results of the target database.
[0008] In one embodiment, the use of a pre-configured graph database and conversion thereof into a corresponding database query operation includes:
[0009] The pre-configured Gremlin graph database and SPARQL graph database convert the query request into a Gremlin query and / or a SPARQL query.
[0010] In one embodiment, the database query operation after query conversion is performed on the target database, including:
[0011] The Gremlin query operation and / or the SPARQL query operation after the query conversion is executed on the target database.
[0012] In one embodiment, the method further includes: formatting the query result.
[0013] In one embodiment, the converting the query request into a corresponding database query operation using a preconfigured graph database further includes:
[0014] Dynamically load and configure Gremlin and SPARQL data source drivers.
[0015] In one embodiment, the database query operation after query conversion is performed on the target database, including:
[0016] The database query operation is specifically parallel query and / or distributed computing.
[0017] Another aspect of the present invention further provides a unified SQL query device, comprising:
[0018] A conversion unit, configured to receive a user's SQL query request, and convert the query request into a corresponding database query operation using a pre-configured graph database;
[0019] An execution unit configured to execute a database query operation after query conversion on a target database;
[0020] The output unit is configured to collect and integrate the query results of the target database.
[0021] Another aspect of the present invention provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the unified SQL query method as described in any one of the above items when executed by the processor.
[0022] Another aspect of the present invention further provides a computer storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the unified SQL query method as described in any one of the above items are implemented.
[0023] Compared with the prior art, the present invention has at least the following advantages:
[0024] The present invention proposes a unified SQL query method, which realizes unified SQL query on Gremlin graph database and SPARQL graph database by improving data source adaptation, query parsing, execution engine and result processing, thereby improving query efficiency and convenience. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 A schematic diagram of a unified SQL query method according to an embodiment of the present invention;
[0026] Figure 2 A schematic diagram of the unified SQL query implementation principle according to an embodiment of the present invention;
[0027] Figure 3 A schematic diagram of the composition of a unified SQL query device according to an embodiment of the present invention;
[0028] Figure 4 FIG. 1 is a schematic diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0029] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined purpose, the present invention is described in detail below in conjunction with the accompanying drawings and preferred embodiments.
[0030] Unless otherwise defined, all terms (including technical terms and scientific terms) used in this article have the same meaning as commonly understood by ordinary technicians in the field to which this application belongs. It should also be understood that terms (such as terms defined in commonly used dictionaries) should be interpreted as having the same meaning as their meaning in the context of the relevant technology, and will not be interpreted in an idealized or overly formal sense unless explicitly defined in this article.
[0031] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0032] In an embodiment of the present invention, a unified SQL query method is provided. Figure 1 As shown, including:
[0033] Step S1, receiving a user's SQL query request, and using a pre-configured graph database to convert the query request into a corresponding database query operation;
[0034] Step S2, executing the database query operation after query conversion on the target database;
[0035] Step S3, collecting and integrating the query results of the target database.
[0036] In one embodiment, the use of a pre-configured graph database and conversion thereof into a corresponding database query operation includes:
[0037] The pre-configured Gremlin graph database and SPARQL graph database convert the query request into a Gremlin query and / or a SPARQL query.
[0038] In this embodiment, the database query operation after query conversion is performed on the target database includes:
[0039] The Gremlin query operation and / or the SPARQL query operation after the query conversion is executed on the target database.
[0040] In this embodiment, the method further includes: formatting the query result.
[0041] In this embodiment, the use of a pre-configured graph database to convert the query request into a corresponding database query operation also includes:
[0042] Dynamically load and configure Gremlin and SPARQL data source drivers.
[0043] In this embodiment, the database query operation after query conversion is performed on the target database includes:
[0044] The database query operation is specifically parallel query and / or distributed computing.
[0045] The method provided in this embodiment will be described in detail below with reference to the accompanying drawings.
[0046] refer to Figure 2 The method provided in this embodiment can be understood from the software level as the following implementation modules, including: a data source adaptation module, a query parsing module, an execution engine module and a result processing module.
[0047] In summary, the data source adapter module is responsible for identifying and adapting the Gremlin graph database and the SPARQL graph database to ensure compatibility with this system. The query parsing module receives the user's SQL query request and parses it into Gremlin query and SPARQL query. The execution engine module executes the converted Gremlin query plan and SPARQL query plan. The result processing module collects and integrates the query results and provides multiple output methods.
[0048] Specifically, the data source adapter module can be configured as follows:
[0049] System administrators can add, modify, and delete Gremlin and SPARQL data source information through the management interface.
[0050] Gremlin DB (Gremlin Database): A graph database that supports the Gremlin query language (such as JanusGraph).
[0051] SPARQLDB (SPARQL database): a graph database that supports the SPARQL query language (such as Ontotext GraphDB).
[0052] The query parsing module can be configured as:
[0053] The user submits an SQL query request through the client. The query parsing module parses the SQL query using a set of predefined rules and mappings. The Sql2Gremlin module converts the SQL query into a Gremlin query, and the Sql2Sparql module converts the SQL query into a SPARQL query. For technical implementation, existing open source libraries and tools can be used, such as Apache Calcite, an open source query parsing and optimization framework that supports multiple SQL dialects. Calcite can be used to parse SQL queries and generate Gremlin or SPARQL queries through custom conversion rules. The following sample code uses Apache Calcite to parse SQL and convert it into a Gremlin query. The principle of converting SQL to SPARQL queries is similar.
[0054] For ease of understanding, a specific implementation code is provided below.
[0055]
[0056]
[0057] The execution engine module can be configured as:
[0058] Distribute the query plan to the target graph database to execute the Gremlin query plan and SPARQL query plan after query parsing. Support multi-node parallel query and distributed computing, make full use of computing resources, and improve query execution efficiency.
[0059] The result processing module can be configured as:
[0060] Collects Gremlin and SPARQL query results, and integrates and formats them. Provides multiple output methods, including structured data (such as JSON, CSV), reports, visual charts, etc. For the standardized output results, it can be further integrated with the function of querying relational databases to complete federated queries.
[0061] Using the above implementation module, users can view and download query results through the client.
[0062] Through the collaborative work of the above modules, the present invention realizes unified SQL query on Gremlin graph database and SPARQL graph database, improves the convenience and efficiency of data access, and is suitable for efficient management and utilization of multi-source graph data in modern enterprises.
[0063] The second embodiment of the present invention corresponds to the first embodiment. Figure 3 As shown, this embodiment introduces a unified SQL query device, including the following components:
[0064] A conversion unit, configured to receive a user's SQL query request, and convert the query request into a corresponding database query operation using a pre-configured graph database;
[0065] An execution unit configured to execute a database query operation after query conversion on a target database;
[0066] The output unit is configured to collect and integrate the query results of the target database.
[0067] In this embodiment, the conversion unit is specifically configured as follows:
[0068] The pre-configured Gremlin graph database and SPARQL graph database convert the query request into a Gremlin query and / or a SPARQL query.
[0069] In this embodiment, the execution unit is specifically configured as follows:
[0070] The Gremlin query operation and / or the SPARQL query operation after the query conversion is executed on the target database.
[0071] In this embodiment, the device is further used to: format the query result.
[0072] In this embodiment, the conversion unit is further configured as follows:
[0073] Dynamically load and configure Gremlin and SPARQL data source drivers.
[0074] In this embodiment, the execution unit is further configured as follows:
[0075] The database query operation is specifically parallel query and / or distributed computing.
[0076] A third embodiment of the present invention is an electronic device, such as Figure 4 As shown, it can be understood as a physical device, including a processor and a memory storing instructions executable by the processor. When the instructions are executed by the processor, the following operations are performed:
[0077] Step S1, receiving a user's SQL query request, and using a pre-configured graph database to convert the query request into a corresponding database query operation;
[0078] Step S2, executing the database query operation after query conversion on the target database;
[0079] Step S3, collecting and integrating the query results of the target database.
[0080] The fourth embodiment of the present invention, the process of the unified SQL query method of this embodiment is the same as that of the first, second or third embodiment, the difference is that, in terms of engineering implementation, this embodiment can be implemented by means of software plus a necessary general hardware platform, of course, it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the method of the present invention can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, disk, optical disk), including a number of instructions for a device to execute the method described in the embodiment of the present invention.
[0081] Through the description of the specific implementation methods, a deeper and more specific understanding of the technical means and effects adopted by the present invention to achieve the predetermined purpose should be obtained. However, the accompanying drawings are only for reference and illustration purposes and are not intended to limit the present invention.
Claims
1. A unified SQL query method, characterized in that: include: Step S1, receiving a user's SQL query request, and using a pre-configured graph database to convert the query request into a corresponding database query operation; Step S2, executing the database query operation after query conversion on the target database; Step S3, collecting and integrating the query results of the target database.
2. The unified SQL query method according to claim 1, characterized in that: The pre-configured graph database is used to convert it into a corresponding database query operation, including: The pre-configured Gremlin graph database and SPARQL graph database convert the query request into a Gremlin query and / or a SPARQL query.
3. The unified SQL query method according to claim 2, characterized in that: The database query operation after query conversion is performed on the target database, comprising: The Gremlin query operation and / or the SPARQL query operation after the query conversion is executed on the target database.
4. The unified SQL query method according to claim 3, characterized in that: The method further includes: formatting the query result.
5. The unified SQL query method according to claim 2, characterized in that: The method of using a pre-configured graph database to convert the query request into a corresponding database query operation further includes: Dynamically load and configure Gremlin and SPARQL data source drivers.
6. The unified SQL query method according to claim 3, characterized in that: The database query operation after query conversion is performed on the target database, comprising: The database query operation is specifically parallel query and / or distributed computing.
7. A unified SQL query device, characterized in that: include: A conversion unit, configured to receive a user's SQL query request, and convert the query request into a corresponding database query operation using a pre-configured graph database; An execution unit configured to execute a database query operation after query conversion on a target database; The output unit is configured to collect and integrate the query results of the target database.
8. An electronic device, characterized in that: The electronic device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the unified SQL query method as claimed in any one of claims 1 to 6 when executed by the processor.
9. A computer storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the unified SQL query method according to any one of claims 1 to 6.