From 438c3b7750b8bc560b1ec329e9e28c78ab358ec9 Mon Sep 17 00:00:00 2001 From: Joe Freeman Date: Thu, 24 Dec 2020 17:48:34 -0500 Subject: [PATCH 1/3] add missing spaces in README.md markdown --- pokemon/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pokemon/README.md b/pokemon/README.md index fcd18ff..092671e 100644 --- a/pokemon/README.md +++ b/pokemon/README.md @@ -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. @@ -36,7 +36,7 @@ View the live schema visualization dse-java-driver-graph 1.3.0 + + org.slf4j + slf4j-simple + 1.7.25 + diff --git a/northwind/code/src/main/java/com/datastax/examples/northwind/Northwind.java b/northwind/code/src/main/java/com/datastax/examples/northwind/Northwind.java index de42f43..105655c 100644 --- a/northwind/code/src/main/java/com/datastax/examples/northwind/Northwind.java +++ b/northwind/code/src/main/java/com/datastax/examples/northwind/Northwind.java @@ -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)) ); @@ -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) ); diff --git a/northwind/schema.groovy b/northwind/schema.groovy index a9a4184..87ac3c1 100644 --- a/northwind/schema.groovy +++ b/northwind/schema.groovy @@ -44,25 +44,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() \ No newline at end of file +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() From 20b9e48df277ec4167749f4e4cf214c1db2db377 Mon Sep 17 00:00:00 2001 From: Joe Freeman Date: Mon, 11 Jan 2021 08:38:36 -0500 Subject: [PATCH 3/3] northwind only works with graphs of type 'classic' --- northwind/README.md | 41 +++++++++++++++++++++++++++++++---------- northwind/schema.groovy | 1 + 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/northwind/README.md b/northwind/README.md index 127486e..5443c9b 100644 --- a/northwind/README.md +++ b/northwind/README.md @@ -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). @@ -20,22 +23,40 @@ View the live schema visualization