Abstract
Relational databases (RDBs) remain the cornerstone of structured data storage, yet they often face performance bottlenecks with complex, join-heavy queries. Knowledge Graphs (KGs) offer a more flexible alternative for representing interconnected data, particularly for advanced AI applications like semantic parsing and question answering. However, migrating from RDBs to KGs is challenging due to the need for consistent data and query translation. This paper introduces Rel2Graph, a framework that automates the migration of RDB schemas to property graphs and translates SQL queries into semantically equivalent Cypher queries. By leveraging metadata analysis and pattern-based translation, Rel2Graph achieves high execution accuracy on the Spider and KaggleDBQA benchmarks, ensuring that data integrity is maintained across formats.
Introduction
While relational databases excel at structured storage, the increasing complexity of data relationships in AI-driven applications has highlighted the advantages of Knowledge Graphs. KGs facilitate more natural representations of interconnected entities and can significantly simplify complex queries that would otherwise require numerous joins in SQL. Despite these benefits, the transition from RDB to KG remains a bottleneck. A complete migration requires not only moving the data but also ensuring that existing analytical workflows—expressed as SQL queries—can be translated into the graph's native query language, such as Cypher. Rel2Graph addresses this gap by providing an automated pipeline for both schema migration and query translation, ensuring that moving data to a graph format does not break the ability to ask complex questions.
Methodology
Rel2Graph consists of two primary modules designed to handle the structural and functional aspects of the migration, supplemented by a data repairment phase.
Database Mapping
The Metadata Analyzer module examines the schema of a relational database to determine how tables should be represented in a graph. It utilizes rules based on Primary Keys (PK) and Foreign Keys (FK) to categorize tables. "Entity tables" are transformed into graph nodes, while "linking tables" (associative entities) are transformed into graph edges. This process ensures that the inherent relationships within the relational model are explicitly captured as traversable paths in the KG. This mapping logic also extends to handling hyperedges—relationships involving more than two entities—by mapping them to intermediate nodes or multiple edges as required by the property graph model.
Query Mapping (SQL2Cypher)
The SQL2Cypher module translates conjunctive SQL queries into pattern-based Cypher queries. It parses SQL into a JSON-serializable tree and maps keywords like SELECT, FROM, and JOIN to their Cypher equivalents (RETURN, MATCH). A key advantage of this approach is the simplification of queries; expensive SQL JOIN operations are replaced with direct graph traversals, which are often more concise and efficient. The system verifies the success of this translation by comparing the result sets of the original SQL and the generated Cypher.
Data Repairment
To handle real-world "messy" data, Rel2Graph includes a Data Repairment phase. In many databases, such as those in the KaggleDBQA benchmark, foreign keys are not explicitly defined in the schema. Rel2Graph cleverly infers these relationships by analyzing the JOIN statements in provided SQL queries, essentially using the usage of the data to repair and enrich the structure of the resulting graph.
Evaluation and Results
The authors evaluated Rel2Graph using two major semantic parsing benchmarks: Spider (a large-scale, cross-domain dataset) and KaggleDBQA (a challenging dataset featuring un-normalized real-world databases). The primary metric for success was Execution Accuracy (EA), which provides a rigorous proof of data integrity.
- CySpider: Achieved an EA of 88.43%, demonstrating that the vast majority of complex relational queries can be perfectly replicated in a property graph.
- CyKaggleDBQA: Achieved an EA of 63.60%. While lower than Spider, this reflects the inherent difficulty of mapping poorly structured data and provides a realistic baseline for future research.
The system demonstrated significant scalability, successfully migrating KaggleDBQA into a graph containing over 4.7 million nodes and 2.5 million edges. This scale proves that Rel2Graph can handle industry-sized datasets while maintaining query functionality.
Conclusion
Rel2Graph provides a robust framework for bridging the gap between relational databases and knowledge graphs. By automating both data migration and query translation, it ensures that organizations can leverage the benefits of graph-based data representations without losing the ability to perform complex analytical queries. While limitations exist regarding parser dependencies and implicit ordering in SQL, Rel2Graph establishes a strong foundation for future research in automated database migration and graph-based semantic parsing.
Summary updated