Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions northwind/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vscode/
load_failures.txt
loader.log
.factorypath
46 changes: 40 additions & 6 deletions northwind/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
| :exclamation: This example only works for classic graph databases |
|----------------------------------------|

# Northwind

The Northwind graph example is a subset of Microsoft's Northwind dataset found [here](https://northwinddatabase.codeplex.com).
Expand All @@ -20,15 +23,40 @@ View the live schema visualization <a href="https://s3.amazonaws.com/datastax-gr
[![datamodel screenshot](datamodel-screenshot.png)](https://s3.amazonaws.com/datastax-graph-schema-viewer/index.html#/?schema=northwind.json)<br/>

## Create the schema
You can create the schema several different ways both explicitly and implcitly

### Explicit - Design Time
The schema is defined in `schema.groovy`.
* You can create your graph in Studio and copy and paste the schema statements to run there.
* Alternately, the statements can be run from the gremlin console.

Notes
* If using studio, then set the notebook cell mode to `graph` instead of `cql`.
* If you create the graph inside DSE Studio then you should create the graph DB with the "classic" engine.

### Implicit - Load Time via graphloader
| :exclamation: graphloader only works for classic graph databases |
|----------------------------------------|

The `northwind-mapping.groovy` config file has automated schema creation disabled. The assumption is that you will create the schema with `schema.groovy` or something like it.

Included is a `schema.groovy` file. You can create your graph in Studio and copy and paste the schema statements
to run there. Alternately, the statements can be run from the gremlin console.
The data loading utility [graphloader](https://downloads.datastax.com/#graph-loader) can create the schema as part of the data load.
1 Edit the `northwind-mapping.groovy` file. Change the following line.
* `config create_schema: false`
to
* `config create_schema: true`

## Example loading
## Load Exmaple Data
| :exclamation: graphloader only works for classic graph databases |
|-----------------------------------------|


(graphloader)[https://docs.datastax.com/en/dse/6.7/dse-dev/datastax_enterprise/graph/dgl/graphloaderTOC.html] must be downloaded separately from this example. Download the version that matches your DSE/graph version.
* Via (Datastax graphloader downloads)[https://downloads.datastax.com/#graph-loader] .
* Via `curl https://downloads.datastax.com/enterprise/dse-graph-loader-6.8.1-bin.tar.gz -o dse-graph-loader-6.8.1-bin.tar.gz`

If you load the Kryo file from within the northwind directory, you don't need to specify the path. It will
default to the data subdirectory to get the northwind.kryo file. Otherwise, specify the full path with the
`inputfile` parameter.
default to the data subdirectory to get the northwind.kryo file. Otherwise, specify the full path with the `inputfile` parameter.

Examples of loading the northwind data:

Expand All @@ -44,7 +72,7 @@ graphloader -graph northwind -address localhost northwind-mapping.groovy -inputp

## Supplemental data

### Supplemental data is not currently working as we change to custom vertex ids
** Supplemental data is not currently working as we change to custom vertex ids **

Some supplemental data has been added in csv files to provide some more connectivity within the data. It is generated data,
that includes things like relationships between customers (isRelatedTo and isFriendsWith), customer product ratings (rated),
Expand All @@ -62,3 +90,9 @@ graphloader -graph northwind -address localhost supplemental-data-mapping.groovy
# Alternatively, explicitly specify where the data files are
graphloader -graph northwind -address localhost supplemental-data-mapping.groovy -inputpath ~/graph-examples/northwind/data/
```

## Dropping the Schema
You can drop the schema to reset the environment
```
schema.drop()
```
5 changes: 5 additions & 0 deletions northwind/code/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@
<artifactId>dse-java-driver-graph</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static void basicAdd(DseSession dseSession) {

dseSession.executeGraph(
new SimpleGraphStatement(
"g.addV(label, 'networkMember', 'name', name, 'age', age)")
"g.addV('networkMember').property('name',name).property('age',age)")
.set("name", name)
.set("age", String.valueOf(age))
);
Expand All @@ -43,7 +43,7 @@ private static void basicAdd(DseSession dseSession) {
new SimpleGraphStatement(
"customer = g.V().has('customer', 'name', name).next();" +
"networkMember = g.V().has('networkMember', 'name', name).next();" +
"customer.addEdge('isMember', networkMember);")
"g.addE('isMember').from(customer).to(networkMember);")
.set("name", name)
);

Expand Down
49 changes: 30 additions & 19 deletions northwind/schema.groovy
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Works with graphs of type "classic"
system.graph('northwind').ifNotExists().create()
:remote config alias g northwind.g

Expand Down Expand Up @@ -44,25 +45,35 @@ schema.propertyKey('discontinued').Boolean().single().ifNotExists().create()
schema.propertyKey('description').Text().single().ifNotExists().create()

// Define the vertex labels with associated properties
schema.vertexLabel('customer').partitionKey('id').properties('customerId', 'title', 'name', 'address', 'city', 'postalCode', 'phone', 'fax', 'company').ifNotExists().create()
schema.vertexLabel('employee').partitionKey('id').properties('title', 'titleOfCourtesy', 'firstName', 'lastName', 'address', 'city', 'postalCode', 'extension', 'homePhone', 'hireDate', 'notes').ifNotExists().create()
schema.vertexLabel('order').partitionKey('id').properties('orderDate', 'shipName', 'shipAddress', 'shipCity', 'shipPostalCode', 'shippedDate', 'requiredDate', 'freight').ifNotExists().create()
schema.vertexLabel('item').partitionKey('id').properties('unitPrice', 'discount', 'quantity').ifNotExists().create()
schema.vertexLabel('product').partitionKey('id').properties('name', 'type', 'unitPrice', 'unitsInStock', 'unitsOnOrder', 'reorderLevel', 'discontinued').ifNotExists().create()
schema.vertexLabel('category').partitionKey('id').properties('name', 'description').ifNotExists().create()
schema.vertexLabel('country').partitionKey('id').properties('name').ifNotExists().create()
schema.vertexLabel('region').partitionKey('id').properties('name').ifNotExists().create()
schema.vertexLabel('customer').properties('fax', 'company', 'city', 'phone', 'title', 'name', 'address', 'customerId', 'id', 'postalCode').ifNotExists().create()
schema.vertexLabel('employee').properties('city', 'id', 'address', 'titleOfCourtesy', 'lastName', 'notes', 'postalCode', 'hireDate', 'firstName', 'extension', 'title', 'homePhone').ifNotExists().create()
schema.vertexLabel('order').properties('shipName', 'shipPostalCode', 'shippedDate', 'freight', 'id', 'shipCity', 'shipAddress', 'requiredDate', 'orderDate').ifNotExists().create()
schema.vertexLabel('item').properties('unitPrice', 'quantity', 'discount', 'id').ifNotExists().create()
schema.vertexLabel('product').properties('name', 'unitsOnOrder', 'reorderLevel', 'type', 'unitsInStock', 'unitPrice', 'id', 'discontinued').ifNotExists().create()
schema.vertexLabel('category').properties('id', 'description', 'name').ifNotExists().create()
schema.vertexLabel('country').properties('id', 'name').ifNotExists().create()
schema.vertexLabel('region').properties('id', 'name').ifNotExists().create()

// Define the edge labels with cardinality and how they connect vertices
schema.edgeLabel('sold').single().connection('employee', 'order').ifNotExists().create()
schema.edgeLabel('ordered').single().connection('customer', 'order').ifNotExists().create()
schema.edgeLabel('contains').single().connection('order', 'item').ifNotExists().create()
schema.edgeLabel('livesInCountry').single().connection('customer', 'country').ifNotExists().create()
schema.edgeLabel('livesInRegion').single().connection('customer', 'region').ifNotExists().create()
schema.edgeLabel('inCategory').single().connection('product', 'category').ifNotExists().create()
schema.edgeLabel('is').single().connection('item', 'product').ifNotExists().create()
schema.edgeLabel('reportsTo').single().connection('employee', 'employee').ifNotExists().create()
// Define the edge labels with default single cardinality and how they connect vertices
schema.edgeLabel('sold').connection('employee', 'order').ifNotExists().create()
schema.edgeLabel('ordered').connection('customer', 'order').ifNotExists().create()
schema.edgeLabel('contains').connection('order', 'item').ifNotExists().create()
schema.edgeLabel('livesInCountry').connection('customer', 'country').ifNotExists().create()
schema.edgeLabel('livesInRegion').connection('customer', 'region').ifNotExists().create()
schema.edgeLabel('inCategory').connection('product', 'category').ifNotExists().create()
schema.edgeLabel('is').connection('item', 'product').ifNotExists().create()
schema.edgeLabel('reportsTo').connection('employee', 'employee').ifNotExists().create()

// Add a search index on product and customer name to be able to things like regex or fuzzy searching by name
schema.vertexLabel('customer').index('search').search().by('name').ifNotExists().add()
schema.vertexLabel('product').index('search').search().by('name').ifNotExists().add()
schema.vertexLabel('customer').index('search').materialized().by('name').ifNotExists().add()
schema.vertexLabel('product').index('search').materialized().by('name').ifNotExists().add()

// Added by graphloader if not present
schema.vertexLabel('customer').index('byid').materialized().by('id').ifNotExists().add()
schema.vertexLabel('employee').index('byid').materialized().by('id').ifNotExists().add()
schema.vertexLabel('order').index('byid').materialized().by('id').ifNotExists().add()
schema.vertexLabel('item').index('byid').materialized().by('id').ifNotExists().add()
schema.vertexLabel('product').index('byid').materialized().by('id').ifNotExists().add()
schema.vertexLabel('category').index('byid').materialized().by('id').ifNotExists().add()
schema.vertexLabel('country').index('byid').materialized().by('id').ifNotExists().add()
schema.vertexLabel('region').index('byid').materialized().by('id').ifNotExists().add()
14 changes: 7 additions & 7 deletions pokemon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@

This demo is intended to help get you started with DSE Graph. It includes schemas, data, and mapper script for the DataStax Graph Loader.

##About the Data
## About the Data
The data comes to us from the [pokeapi](https://github.com/PokeAPI/pokeapi). I took the liberty of cleaning the data files and choosing the ones that had relationships applicable to a graph database. I've also changed the file and header names to help new comers better understand what's happening inside DSE Graph.


##Prerequisites
## Prerequisites
* [Learn some Graph](https://academy.datastax.com/courses/ds330-datastax-enterprise-graph) <- this will give you ideas on how to query this graph
* [DataStax Graph Loader](https://academy.datastax.com/downloads/download-drivers)
* [DataStax Enterprise 5.0 or greater](https://www.datastax.com/downloads)
* [DataStax Studio 1.0 or greater](https://www.datastax.com/downloads)


##How-to:
## How-to:
1. Start DataStax Enterprise in graph mode mode
2. Start DataStax Studio - on your local machine it'll bind to http://localhost:9091
3. Edit ```poke_mapper.groovy``` so that the paths for *inputfileV* and *inputfileE* files = `'/path/to/this/directory/data/'`

##Let's get started
## Let's get started

In DataStax Studio create a new connection with a new graph called 'poke_graph' (or what ever you want the graph to be called)
![Alt text](http://i.imgur.com/zNrR722.png)

###Next, paste the schema from the `schema.groovy` file into a new gremlin box:
### Next, paste the schema from the `schema.groovy` file into a new gremlin box:
![Alt text](http://i.imgur.com/XB7PGkU.png)

If you'd like to add more indices for different types of traversals, you can always add them after the fact. The ones in the schema file are for the Graph Loader to do look ups and match vertices to edges.
Expand All @@ -36,7 +36,7 @@ View the live schema visualization <a href="https://s3.amazonaws.com/datastax-gr
Note, there's plenty of other connections we can make with this dataset. Feel free to explore and play around!


###Now we're going to load the data
### Now we're going to load the data

`sudo ./graphloader /path/to/poke_mapper.groovy -graph poke_graph -address localhost -abort_on_prep_errors false
`
Expand All @@ -45,7 +45,7 @@ Some of the properties within the CSV files contain empty fields which is OK for



###Play time! Remember that Studio truncates results to 1000 by default.
### Play time! Remember that Studio truncates results to 1000 by default.

![Alt text](http://i.imgur.com/ptyBTBb.png)
![Alt text](http://i.imgur.com/fOFgwKe.png)