Storing Metagraph Model in Relational, Document- Oriented, and Graph Databases
Total Page:16
File Type:pdf, Size:1020Kb
Storing Metagraph Model in Relational, Document- Oriented, and Graph Databases © Valeriy M. Chernenkiy © Yuriy E. Gapanyuk © Yuriy T. Kaganov © Ivan V. Dunin © Maxim A. Lyaskovsky © Vadim S. Larionov Bauman Moscow State Technical University, Moscow, Russia [email protected], [email protected], [email protected], [email protected], [email protected], [email protected] Abstract. This paper proposes an approach for metagraph model storage in databases with different data models. The formal definition of the metagraph data model is given. The approaches for mapping the metagraph model to the flat graph, document-oriented, and relational data models are proposed. The limitations of the RDF model in comparison with the metagraph model are considered. It is shown that the metagraph model addresses RDF limitations in a natural way without emergence loss. The experiments result for storing the metagraph model in different databases are given. Keywords: metagraph, metavertex, flat graph, graph database, document-oriented database, relational database. adapted for information systems description by the 1 Introduction present authors [2]. According to [2]: = , , , At present, on the one hand, the domains are becoming where – metagraph; – set of metagraph more and more complex. Therefore, models based on vertices; – set of〈 metagraph metavertices; 〉 – complex graphs are increasingly used in various fields of set of metagraph edges. science from mathematics and computer science to A metagraph vertex is described by the set of biology and sociology. attributes: = { }, , where – metagraph On the other hand, there are currently only graph vertex; – attribute. databases based on flat graph or hypergraph models that A metagraph edge is described∈ by the set of attributes, are not capable enough of being suitable repositories for the source and destination vertices and edge direction complex relations in the domains. flag: We propose to use a metagraph data model that = , , , { } , , = | , allows storing more complex relationships than a flat where – metagraph edge; – source vertex graph or hypergraph data models. (metavertex) 〈 of the edge;〉 ∈ – destination vertex This paper is devoted to methods of storage of the (metavertex) of the edge; eo – edge direction flag metagraph model based on the flat graph, document- (eo=true – directed edge, eo=false – undirected edge); oriented, and relational data models. atrk – attribute. We have tried to offer a general approach to store The metagraph fragment: metagraph data in any database with the above- = , ( ), mentioned data model. But at the same time, we where – metagraph fragment; – an element that conducted experiments on several databases. The results �� ∈ ∪ ∪ of the experiments are presented in the corresponding belongs to the union of vertices, metavertices, and edges. section. The metagraph metavertex: = { }, , , 2 The description of the metagraph model where – metagraph metavertex belongs to set of 〈 〉 ∈ metagraph metavertices ; – attribute, – In this section, we will describe the metagraph model. This model may be considered as a “logical” model of metagraph fragment. the metagraph storage. Thus, a metavertex in addition to the attributes A metagraph is a kind of complex network model, includes a fragment of the metagraph. The presence of proposed by A. Basu and R. Blanning [1] and then private attributes and connections for a metavertex is a distinguishing feature of a metagraph. It makes the definition of metagraph holonic – a metavertex may Proceedings of the XX International Conference include a number of lower level elements and in turn, “Data Analytics and Management in Data Intensive may be included in a number of higher level elements. Domains” (DAMDID/RCDL’2018), Moscow, Russia, From the general system theory point of view, a October 9-12, 2018 82 metavertex is a special case of the manifestation of the Consider there is a flat graph: emergence principle, which means that a metavertex = , , with its private attributes and connections becomes a where – set of graph vertices; – set of graph whole that cannot be separated into its component parts. edges. 〈 〉 The example of metagraph is shown in Figure 1. Then a flat graph may be unambiguously e7 transformed into bipartite graph : = , , e8 = ,, mv1 〈 , 〉, e4 mv2 e1 where – set of graph〈 vertices; 〉 – set vv22 vv44 of graph edges. The↔ set can↔ be divided into two e2 vv11 e6 disjoint and independent sets and and there e are two isomorphisms and . e3 vv33 5 vv55 Thus, we transform the edges of graph into subset of vertices of graph . The↔ set stores↔ the mv3 information about relations between vertices and edges in graph . Figure 1 The example of metagraph It is important to note that from bipartite graph point of view there is no difference whether original graph This example contains three metavertices: mv1, mv2, oriented or not, because edges of the graph are and mv3. Metavertex mv1 contains vertices v1, v2, v3 and represented as vertices and, orientation sign became the connecting them edges e1, e2, e3. Metavertex mv2 contains property of the new vertex. vertices v4, v5 and connecting them edge e6. Edges e4, e5 From the general system theory point of view, are examples of edges connecting vertices v2-v4 and v3-v5 transforming edge into vertex, we consider the relation respectively and are contained in different metavertices between entities as a special kind of higher-order entity mv1 and mv2. Edge e7 is an example of an edge connecting that includes lower-level entities. metavertices mv1 and mv2. Edge e8 is an example of an Now we will apply this approach of flattening to edge connecting vertex v2 and metavertex mv2. metagraphs. In case of metagraph we use not bipartite but Metavertex mv3 contains metavertex mv2, vertices v2, v3 tripartite target graph : and edge e2 from metavertex mv1 and also edges e4, e5, e8 = , , showing the holonic nature of the metagraph structure. = , , , The Figure 1 shows that the metagraph model allows , 〈 , 〉 . describing complex data structures and it is the metavertex The set can〈 be divided into three〉 disjoint that allows implementing emergence principle in data and indep endent↔ sets ↔, , .↔ There are structures. three isomorphisms between metagraph vertices, It should be noted that according to [2] the metagraph metavertices, edges and corresponding subsets of model also includes more complex elements such as : , , metaedges and metagraph agents. However, they are . The set stores the information about derived from the considered model elements and do not relations between ↔ vertices, metavertices,↔ edges ↔in affect the methods of metagraphs storage in different original metagraph. databases. mv2 mv 3 Mapping the metagraph model to storage 1 e1 models v2 e2 The logical model described in the previous section is a v1 higher-level model. To store the metagraph model e3 v3 efficiently, we must create mappings from “logical” model to “physical” models used in different databases. In this section, we will consider metagraph model Figure 2 The example of metagraph for flattening mappings to the flat graph model, document model, and relational model. 3.1 Mapping metagraph model to the flat graph model The main idea of this mapping is to flatten the hierarchical metagraph model. Of course, it is impossible to turn a hierarchical graph model into a flat one directly. The key idea to do this is to use multipartite graphs [3]. 83 fragments into predicate representation is described in mv1 details in [2]. The proposed textual representation may be used for storing metagraph data in a document-oriented database or text or document fields of the relational database using v1 e1 v2 e2 v3 JSON or XML formats. e 3.3 Mapping metagraph model to the relational 3 model Nowadays NoSQL databases are very popular. But mv2 traditional relational databases are still the most mature solution and widely used in information systems. Figure 3 The example of flattened metagraph Therefore, we also need the relational representation of the metagraph model. There are two ways to store Consider the example of flattening metagraph model. metagraphs in a relational database. The original metagraph is represented in Fig. 2 and The first way is to use a pure relational schema. In corresponding flat graph is represented in Fig. 3. The this case, the proposed metagraph model may be directly vertices, metavertices and edges of original metagraph are or with some optimization transformed into the database represented with vertices of different shapes. schema. The tables vertices, metavertices, edges may be From the general system theory point of view, used. The Figure 4 contains a graphical representation of emergent metagraph elements such as vertices, such a schema using PostgreSQL database. The table metavertices, edges are transformed into independent “metavertex” contains the representation of vertices and vertices of the flat graph. metavertices. The table “relation” contains the The proposed mapping may be used for storing representation of edges. metagraph data in graph or hybrid databases such as Neo4j or ArangoDB. It is important to note that flattening metagraph model does not solve all problems for graph database usage. Consider the example of a query using the Neo4j database query language “Cypher”: (n1:Label1)-[rel:TYPE]->(n2:Label2) One can see that used notation is RDF-like and suppose that graph edges are named. But flatten metagraph