# AMANDA: A Middleware for Automatic Migration between Different Database Paradigms
## 3 The Middleware
\begin{table}
\begin{tabular}{c c c c c} \hline
**Author** & **SQL DB** & **NonSQL SB** & **Dataset** & **Approach** \\ \hline \hline \multirow{2}{*}{[PERSON] et al.} & \multirow{2}{*}{IBM Informix} & \multirow{2}{*}{Neo4J} & A small set of data from & Read database metadata \\  & & & & does not obtain tables information \\ \hline \hline \multirow{2}{*}{[PERSON] et al.} & \multirow{2}{*}{MySQL} & \multirow{2}{*}{Neo4J} & \multirow{2}{*}{Database from MOOC} & Read database metadata \\  & & & & to obtain tables information \\ \hline \hline \multirow{2}{*}{[PERSON] et al.} & \multirow{2}{*}{MySQL} & \multirow{2}{*}{Neo4J} & Legal Document System & SchemmaCrawler and \\  & & & & Java SQL Library \\ \hline \multirow{2}{*}{[PERSON] et al.} & \multirow{2}{*}{SQL Server} & \multirow{2}{*}{Neo4j} & Northwind, & \multirow{2}{*}{Functional dependencies} \\  & & & & Wikipedia-2008 subset, & \\ \hline \hline \multirow{2}{*}{[PERSON] et al.} & \multirow{2}{*}{SQL Server} & \multirow{2}{*}{Neo4J} & \multirow{2}{*}{Northwind and IMDB} & Entity Relation (ER) \\  & & & & diagram \\ \hline \hline \multirow{2}{*}{[PERSON] et al.} & \multirow{2}{*}{MySQL} & \multirow{2}{*}{Neo4J} & \multirow{2}{*}{Northwind} & Read database metadata \\  & & & & to obtain tables information \\ \hline \hline \multirow{2}{*}{[PERSON] et al.} & \multirow{2}{*}{OracleDB} & \multirow{2}{*}{MongoDB} & \multirow{2}{*}{N/A} & Formal rules and \\  & & & & source’s DB ER \\  & & & & diagram \\ \hline \multirow{2}{*}{[PERSON] et al.} & \multirow{2}{*}{MySQL} & \multirow{2}{*}{MySQL + Apache Jena Fuseki} & Retail business & Ontology and \\  & & & & combination of SQL \\  & & & & and NoSQL DB \\ \hline \hline \multirow{2}{*}{[PERSON] et al.} & \multirow{2}{*}{MySQL} & \multirow{2}{*}{HBase + Phoenix} & TPC-H & Query translation \\  & & & & and denormalization \\ \hline \multirow{2}{*}{[PERSON] et al.} & \multirow{2}{*}{MySQL} & \multirow{2}{*}{MongoDB} & Database of an & Database snapshot \\  & & & academic department & and streaming of \\ \hline \hline \multirow{2}{*}{Our Solution} & \multirow{2}{*}{Postgres} & \multirow{2}{*}{Dgraph} & Northwind and IMDB & Direct query the database \\  & & & & to migrate data \\  & & & & specified in schema.json \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Related works. database (e.g., Dgraph) is expected to use its class, given that Dgraph has its way of writing and reading data. In this work, Dgraph is employed as the target database. The framework output consists of files representing the data to be migrated. The built-in tools of the graph databases use such files as an input, e.g., Dgraph receives RDF files as the input used to populate the database. In summary, AMANDA reads the tables and attributes defined in a _vertex_ array in the file _schema.json_, as shown in Listing 1. After that, through the defined tables and attributes, the data are fetched from the source database (Figure 2A) through SQL queries, and the result is converted into nodes in a graph (Figure 2B). After the nodes are defined, AMANDA reads the _edges_ section in the _schema.json_, as shown in Listing 2, and uses the primary and foreign key to define the edges (Figure 2C). The nodes and edges definitions are saved in RDF format, as shown in Listing 3. The SQL queries used to fetch data from the source database are built as string templates and shown in Listing 4:  
```
1{
2\"vertices\":[{
3\"source\":{
4//Table'snameinsourceDB
5\"tableName\":\"customers\",
6\"orderField\":\"CustomerID\"
7},
8\"target\":{
9//VertexnameintargetDB
10\"vertexName\":\"Customer\",
11\"vertexIDs\":[
12//InDgraph,eachentitymusthaveanuniqueID
13\"CustomerID\"
14]
15},
16\"fields\":[

Figure 1: AMANDA middleware architecture. * 17 \"CustomerID\";
* 18 \"CompanyName\",
* 19 \"ContactName\",
* 20 \"ContactTitle\",
* 21 \"Address\",
* 22 \"City\",
* 23 \"Region\",
* 24 \"PostalCode\",
* 25 \"Country\",
* 26 \"Phone\",
* 27 \"Fax\"
* 28 ]
* 29 ]
* 30...
* 31 ]
* 22 ]

**Listing 2**. Example of Edge.