MCPcopy Index your code
hub / github.com/YANG-DB/yang-db

github.com/YANG-DB/yang-db @v0.5

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.5 ↗ · + Follow
14,257 symbols 95,181 edges 1,765 files 1,461 documented · 10%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

From Graph to Elastic - A tail of a Yang-DB...

http://www.yangdb.org/

Build Status Coverage Status GitHub license Twitter Follow

Use

  • Add yang.db as maven dependency https://jitpack.io/#YANG-DB/yang-db
  • Download yang.db get latest docker release docker pull yangdb/yang.db

Run

  • Download [yang.db] (https://github.com/YANG-DB/yang-db) latest docker release docker pull yangdb/yang.db
  • Run: docker run -p 8888:88 --net=host -it yangdb/yang.db:Sep-2019-RC3
  • Changing yang.db's configuration using docker environment variable:

docker run \

-e ELASTICSEARCH_HOST=1.1.1.1 \

-e ELASTICSEARCH_CLUSTER_NAME='staging' \

-p 8888:88 -it yangdb/yang.db:Sep-2019-RC1

Project YANG-DB

Members:
Contributors:
Dev/Ops
License:

GitHub license

Code Coverage:

Coverage Status

Dependencies Tags:

Infrastructure Technologies

Introduction

A Post introducing our new Open source initiative for building a Scalable Distributed Graph DB Over Elasticsearch https://www.linkedin.com/pulse/making-db-lior-perry/

Another usage of Elasticsearch as a graph DB https://medium.com/@imriqwe/elasticsearch-as-a-graph-database-bc0eee7f7622

The world of graph databases has had a tremendous impact during the last few years, in particularity relating to social networks and their effect of our everyday activity.

The once mighty (and lonely) RDBMS is now obliged to make room for an emerging and increasingly important partner in the data center: the graph database.

Twitter’s using it, Facebook’s using it, even online dating sites are using it; they are using a relationship graphs. After all, social is social, and ultimately, it’s all about relationships.

There are two main elements that distinguish graph technology: storage and processing.

Graph DB - Storage

Graph storage commonly refers to the structure of the database that contains graph data.

Such graph storage is optimized for graphs in many aspects, ensuring that data is stored efficiently, keeping nodes and relationships close to each other in the actual physical layer.

Graph storage is classified as non-native when the storage comes from an outside source, such as a relational, columnar or any other type of database (most cases a NoSQL store is preferable)

Non-native graph databases usually comprise of existing relational, document and key value stores, adapted for the graph data model query scenarios.

Graph DB - Processing

Graph Processing includes accessing the graph, traversing the vertices & edges and collecting the results.

A traversal is how you query a graph, navigating from starting nodes to related nodes, following relationships according to some rules.

finding answers to questions like "what music do my friends like that I don’t yet own?"

Graph Models

One of the more popular models for representing a graph is the Property Model.

Property model

This model contains connected entities (the nodes) which can hold any number of attributes (key-value-pairs).

Nodes

Nodes have a unique id and list of attributes represent their features and content.

Nodes can be marked with labels representing their different roles in your domain. In addition to relationship properties, labels can also serve metadata over graph elements.

Nodes are often used to represent entities but depending on the domain relationships may be used for that purpose as well.

Relationships

Relationship is represented by the source and target node they are connecting and in case of multiple connections between the same vertices – additional label of property to distinguish (type of relationship)

Relationships organize nodes into arbitrary structures, allowing a graph to resemble a list, a tree, a map, or a compound entity — any of which may be combined into yet more complex structures.

Very much like foreign keys between tables in relational DB model, In the graph model relationship describes the relations between the vertices.

One major difference in this model (compared to the strict relational schema) is that this schema-less structure enables adding / removing relationship between vertices without any constraints.

Additional graph model is the Resource Description Framework (RDF) model.

Why Elastic

Our use-case is in the domain of the social networks. A very large social graph that must be frequently updated and available for both:

  • simple (mostly textual) search

  • graph based queries.

All the read & write are made in concurrency with reasonable response time and ever growing throughput.

The first requirement was fulfilled using Elasticsearch – a well known and established NoSql document search and storage engine capable of containing very large volume of data.

For the second requirement we decided that our best solution would be to use elasticsearch as the non-native graph-DB storage layer.

As mentioned before, a graph-DB storage layer can be implemented using a non-native storage such as NoSql storage.

In future discussion I’ll get into details why the most popular community alternative for graph-DB – Neo4J, could not fit our needs.

Modeling data as graph

The first issue on our plate is to design the data model representing the graph, as a set of vertices and edges.

With elastic we can utilize its powerful search abilities to efficiently fetch node & relation documents according to the query filters.

Elastic Index

In elasticsearch each index can be described as a table for a specific schema, the index itself is partitioned into shared which allow scale and redundancy (with replicas) across the cluster.

A document is routed to a particular shard in an index using the following formula:

shard_num = hash(_routing) % num_primary_shards

Each index has a schema (called type in elastic) which defines the documents structure (called mapping in elastic). Each index can hold only a single type of mapping (since elastic 6)

The vertices index will contain the vertices documents with the properties, the edges index will contain the edges documents with their properties.

Query Language

The way we describe how to traverse the graph (data source)

There are few graph-oriented query languages:

Some of the languages are more pattern based and declarative, some are more imperative – they all describe the logical way of traversing the data.

Cypher

Let’s consider Cypher - a declarative, SQL-inspired language for describing patterns in graphs visually using an ascii-art syntax.

It allows us to state what we want to select, insert, update or delete from our graph data without requiring us to describe exactly how to do it.

alt text

From logical to physical

Once a logical query is given we need to translate it to the physical layer of the data storage which is elasticsearch.

Elastic has a query DSL which is focused on search and aggregations – not on traversing, we need an additional translation phase that will take into account the schematic structure of the graph (and the underlying indices).

Logical to physical query translation is a process that involves few steps:

  • validating the query against the schema

  • translating the labels into real schema entities (indices)

  • creating the physical elastic query

This is the process in a high-level review, in practice - there will be more stages that optimize the logical query; in some cases it is possible to create multiple physical plans (execution plans) and rank them according to some efficiency (cost) strategy such as count of elements needed to fetch...

Conclusion

We started with discussing the purpose of graphs DB in today’s business use cases and reviewed different models for representing a graph. Understanding the fundamental logical building blocks that a potential graph DB should consist and discussed an existing NoSql candidate to fulfill the storage layer requirements.

Once we selected elasticsearch as the storage layer we took the LDBC Social Network Benchmark graph model and simplified it to be optimized in that specific storage. We discussed the actual storage schema with the redundant properties and reviewed cypher language to query the storage in an sql-like graph pattern language.

We continued to see the actual transformation of the cypher query into a physical execution query that will run by Elasticsearch.

In the last section we took a simple graph query and drilled down into the details of the execution strategies and the bulking mechanism.

Start Using

  • See http://www.yangdb.org
  • See http://www.yangdb.org/general-info.html
  • See http://www.yangdb.org/docker.html
  • See http://www.yangdb.org/get-involved.html

Extension points exported contracts — how you extend this code

GraphElementSchemaProviderFactory (Interface)
Created by Roman on 25/05/2017. [124 implementers]
fuse-dv/fuse-dv-core/src/main/java/com/yangdb/fuse/executor/ontology/GraphElementSchemaProviderFactory.java
Statistics (Interface)
Created by moti on 4/18/2017. [8 implementers]
fuse-dv/fuse-dv-epb/src/main/java/com/yangdb/fuse/epb/plan/statistics/Statistics.java
LabelProvider (Interface)
Created by Roman on 22/05/2017. [115 implementers]
fuse-dv/fuse-dv-unipop/src/main/java/com/yangdb/fuse/unipop/controller/utils/labelProvider/LabelProvider.java
PlanOpTranslationStrategy (Interface)
Created by benishue on 08-Mar-17. [34 implementers]
fuse-dv/fuse-dv-gta/src/main/java/com/yangdb/fuse/gta/strategy/PlanOpTranslationStrategy.java
ControllerManagerFactory (Interface)
Created by lior.perry on 19/03/2017. [12 implementers]
unipop-core/src/main/java/org/unipop/query/controller/ControllerManagerFactory.java
BaseSuiteMarker (Interface)
Marker interface for Test Suite classes [21 implementers]
fuse-test/fuse-test-framework/src/main/java/com/yangdb/test/BaseSuiteMarker.java
GeoJsonObjectVisitor (Interface)
Visitor to handle all different types of GeoJsonObject. @param return type of the visitor. [7 implementers]
fuse-geojson/src/main/java/org/geojson/GeoJsonObjectVisitor.java
AsgStrategy (Interface)
Created by lior.perry on 27/02/2017. [114 implementers]
fuse-asg/src/main/java/com/yangdb/fuse/asg/strategy/AsgStrategy.java

Core symbols most depended-on inside this repo

get
called by 4785
fuse-dv/fuse-dv-unipop/src/main/java/com/yangdb/fuse/unipop/controller/utils/idProvider/EdgeIdProvider.java
put
called by 2893
fuse-dv/fuse-dv-unipop/src/main/java/com/yangdb/fuse/unipop/controller/utils/map/MapBuilder.java
build
called by 2294
fuse-dv/fuse-dv-unipop/src/main/java/com/yangdb/fuse/unipop/controller/search/SearchOrderProviderFactory.java
size
called by 1974
fuse-dv/fuse-dv-unipop/src/main/java/com/yangdb/fuse/unipop/process/traversal/traverser/ThinPath.java
of
called by 1621
fuse-dv/fuse-dv-epb/src/main/java/com/yangdb/fuse/epb/plan/estimation/pattern/estimators/PatternCostEstimator.java
instance
called by 1600
fuse-dv/fuse-dv-stat/src/main/java/com/yangdb/fuse/stat/model/configuration/Type.java
of
called by 1596
fuse-model/src/main/java/com/yangdb/fuse/model/query/properties/constraint/Constraint.java
add
called by 1540
fuse-model/src/main/java/com/yangdb/fuse/model/execution/plan/planTree/BuilderIfc.java

Shape

Method 11,236
Class 1,832
Function 875
Interface 245
Enum 69

Languages

Java94%
TypeScript6%

Modules by API surface

fuse-domain/fuse-domain-knowledge/fuse-domain-knowledge-poc/src/main/resources/public/assets/lib/d3.v3.min.js374 symbols
fuse-service/src/main/resources/public/assets/bigdesk/js/lib/D3-v2.8.1/d3.v2.min.js254 symbols
fuse-dv/fuse-dv-unipop/src/main/java/com/yangdb/fuse/unipop/controller/search/QueryBuilder.java185 symbols
fuse-dv/fuse-dv-unipop/src/main/java/com/yangdb/fuse/unipop/controller/search/AggregationBuilder.java105 symbols
fuse-domain/fuse-domain-dragons/fuse-domain-dragons-test/src/test/java/com/yangdb/fuse/services/engine2/data/EntityRelationEntityIT.java102 symbols
fuse-dv/fuse-dv-unipop/src/test/java/com/yangdb/fuse/unipop/controller/discrete/DiscreteTraversalTest.java81 symbols
fuse-core/src/main/java/com/yangdb/fuse/dispatcher/epb/PlanTracer.java78 symbols
fuse-domain/fuse-domain-knowledge/fuse-domain-knowledge-poc/src/main/resources/public/assets/lib/jquery-1.10.2.min.js74 symbols
fuse-model/src/main/java/com/yangdb/fuse/model/ontology/Ontology.java71 symbols
fuse-model/src/main/java/com/yangdb/fuse/model/asgQuery/AsgQueryUtil.java69 symbols
fuse-domain/fuse-domain-knowledge/fuse-domain-knowledge-test/src/main/java/com/yangdb/fuse/assembly/knowledge/domain/Relation.java58 symbols
fuse-domain/fuse-domain-knowledge/fuse-domain-knowledge-test/src/main/java/com/yangdb/fuse/assembly/knowledge/domain/EntityValue.java58 symbols

For agents

$ claude mcp add yang-db \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact