Abstract
Although a few approaches are proposed to convert relational databases to graphs, there is a genuine lack of systematic evaluation across a wider spectrum of databases. Recognising the important issue of query mapping, this paper proposes an approach called Rel2Graph, an automatic knowledge graph construction (KGC) approach from an arbitrary number of relational databases. Our approach also supports the mapping of conjunctive SQL queries into pattern-based NoSQL queries. We evaluate our proposed approach on two widely used relational database-oriented datasets: Spider and KaggleDBQA benchmarks for semantic parsing. We employ the execution accuracy (EA) metric to quantify the proportion of results by executing the NoSQL queries on the property knowledge graph we construct, which aligns with the results of SQL queries performed on relational databases. Consequently, the counterpart property knowledge graph of benchmarks can be ensured to have high accuracy and integrity.
Introduction
Relational databases (RDBs) are the gold standard for structured storage, but they become cumbersome when dealing with highly interconnected data. Performing multiple "JOIN" operations is computationally expensive and syntactically complex. Property Knowledge Graphs (PKGs) offer a more natural way to represent these relationships, but the transition is difficult.
Existing tools for Knowledge Graph Construction (KGC) often require manual intervention, fail to handle "messy" real-world data, or lack mechanisms to translate existing SQL queries into graph queries. Rel2Graph addresses these gaps by providing an end-to-end pipeline that automates both data migration and query mapping while ensuring result consistency across systems.
The Rel2Graph Framework
Rel2Graph consists of three main components designed to handle the complexities of database migration:
- Metadata Analyzer: This module analyzes Primary Key (PK) and Foreign Key (FK) constraints to distinguish between "Entity Tables" (nodes) and "Linking Tables" (edges), including complex "hyperedges."
- Data Repairment: This module identifies and fixes common real-world database issues: missing primary keys, incorrect foreign key definitions, duplicate rows, and table name collisions.
- SQL2Cypher Mapping: A recursive algorithm parses SQL queries into a JSON-based tree and maps them to Cypher. It intelligently transitions from table-based joins to path-based graph patterns, recognizing that foreign keys become redundant in a graph where edges represent the connections.
Datasets and Evaluation
The framework was evaluated using two prominent semantic parsing benchmarks:
- Spider: A large-scale, cross-domain dataset featuring 200 databases and over 5,000 complex SQL queries.
- KaggleDBQA: A challenging dataset of real-world, unnormalized databases from Kaggle, providing a "stress test" for the data repairment module.
Success is measured using Execution Accuracy (EA)—the percentage of queries that return identical results in both the RDB and the generated PKG.
Key Results and Insights
- High Reliability: The system achieved an 88.43% EA on CySpider, suggesting high reliability for well-structured datasets. On the more difficult CyKaggleDBQA, it achieved 63.60% EA.
- The Consistency Loop: Rel2Graph uses a "Check and Repair" scenario, comparing source RDB statistics against the generated graph to ensure integrity.
- Complex Query Support: The system successfully handles complex SQL features including
GROUP BY,HAVING,UNION, and nested sub-queries.
Limitations and Future Work
Current limitations include a dependency on external SQL parsers and minor discrepancies in implicit sorting behaviors between SQL and Cypher. Future work will explore larger benchmarks like BIRD and translation to other graph languages like SPARQL to further generalize the framework.
Summary updated