dgsee

package module
v0.0.0-...-7d7267f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2021 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

dgsee GoDoc

dgraph consistency check and visualize edge cardinalities

Why

Planning a schema is one thing, importing and inserting data is another. Issues may sneak into the system without being noticed. I needed a tool to check if some of my edges have correct cardinalities - to avoid and detect any potential errors in the future.

Install

go get -u github.com/ppp225/dgsee

import (
  "github.com/ppp225/dgsee"
)

Usage

See /example/main.go for full example.

dgsee offers 2 functions:

dgsee.DiscoverEdges(ctx, dg)
ok := dgsee.RunConsistencyChecks(ctx, dg, relations)
  • DiscoverEdges queries schema and then the database, and lists edges along with example consistency check code for this database.
  • RunConsistencyChecks takes a config, and checks if constraints are met.

DiscoverEdges

Output looks like this:

[INFO]               |      (C)ardinality |             | [predicate name]                     | [nodes] |(C)| -edges- |(C)| [nodes] |
[INFO] -------------------------------------------------------------------------------------------------------------------------------
[INFO] Found relation     (1..41)-(1..108) for predicate [director.film]                           [1623] (n)<--7391--->(n)   [6356]
[INFO] Found relation    (1..3290)-(1..14) for predicate [genre]                                   [6356] (n)<--23679-->(n)    [283]
[INFO] Found relation              (-)-(1) for predicate [performance.actor]                     [119258] (-)--119258-->(1)      [-]
...

full output can be found here: /example/output-examples/1million.txt

At a glance we can see, for example for the [genre] edge, that there are 6356 movies, 283 genres, each move has from 1 to 14 genres, and there are 23679 edges.

RunConsistencyChecks

Lets assume 14 genres per movie is too much, and we want only the most relevant. We can then enforce, that the above [genre] edge should have between 1 and 3 genres per movie. So we resolve the issues, and then create a definition like:

var relations = []dgsee.EdgeCardinality{
  {"n", "genre", "1..3"}
  // {"n", "genre", "n"} // or if we want to keep it without constrants
}
ok := dgsee.RunConsistencyCheck(ctx, dg, relations) // returns true if constraints are met, or false if they fail.

Future plans

  • Add checks for other predicates than uid
  • Performance tune (currently uses has(*) function for all edges. Takes a second for 1million dataset and a minute for 21million)
  • Integrate with types - currently doesn't detect orphan nodes (i.e. 1..n will not fail (when a movie has no genres) because we don't know the starting node)

Note

Everything may or may not change ¯\_(ツ)_/¯

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscoverEdges

func DiscoverEdges(ctx context.Context, dg *dgo.Dgraph)

DiscoverEdges queries schema and lists all relations. Prints out example code to consistency check edges for found cardinalities

func RunConsistencyChecks

func RunConsistencyChecks(ctx context.Context, dg *dgo.Dgraph, relations []EdgeCardinality) (ok bool)

RunConsistencyChecks checks, if schema relations have correct 1-1 or 1-n relations

Types

type EdgeCardinality

type EdgeCardinality struct {
	From string
	Edge string
	To   string
}

EdgeCardinality represents a single edge with cardinality of the relation. If edge isn't reverse, 'from' should be "-"

example of correct from/to values: "0" "1" "2" "n" " 0..1" "0..2" "1..n" "1..5"

examples: {"1", "movieCredit", "n"}, {"n", "parent", "2"}, {"1..n", "something", "n"},

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址