Skip to content

Commit d05cd51

Browse files
committed
Fix formatting and small edits
1 parent 2903ca6 commit d05cd51

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

book/Section-Getting-Started.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ at version 11 or higher.
102102
NOTE: For more information on the compatability of Gremlin with versions of Java and
103103
other languages, please see the https://tinkerpop.apache.org/docs/current/upgrade/[official documentation].
104104

105-
The Console download also includes all of the JAR files that are needed to write a
105+
The console download also includes all of the JAR files that are needed to write a
106106
standalone Java or Groovy TinkerPop application but that is a topic for later!
107107

108108
When you start the console you will be presented with a banner/logo and a prompt that

book/Section-Writing-Gremlin-Queries.adoc

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ data in a single table called 'airports'. In a very simple case (the air routes
4040
graph actually stores a lot more data than this about each airport) we could setup
4141
our airports table so that it had entries for each airport as follows.
4242

43+
[source,text]
4344
----
4445
ID CODE ICAO CITY COUNTRY
4546
--- ---- ---- --------------- ----------
@@ -51,13 +52,14 @@ ID CODE ICAO CITY COUNTRY
5152
51 CDG LFPG Paris FR
5253
52 FRA EDDF Frankfurt DE
5354
55 SYD YSSY Sydney AU
55+
----
5456

55-
We could then use a SQL query to count the
56-
distribution of airports in each country as follows.
57+
We could then use a SQL query to count the distribution of airports in each country
58+
as follows.
5759

5860
[source,sql]
5961
----
60-
select country,count(country) from airports group by country;
62+
SELECT country,count(country) FROM airports GROUP BY country;
6163
----
6264

6365
We can do this in Gremlin using the 'air-routes' graph with a query like the one
@@ -75,7 +77,7 @@ is in no way required to learn Gremlin.
7577
One thing you will not find when working with a graph using Gremlin is the concept of
7678
a SQL 'join'. Graph databases by their very nature avoid the need to join things
7779
together (as things that need to be connected already are connected) and this is a
78-
core reason why, for many use cases, Graph databases are a very good choice and can
80+
core reason why, for many use cases, graph databases are a very good choice and can
7981
be more performant than relational databases.
8082

8183
Graph databases are usually a good choice for storing and modelling networks. The
@@ -91,6 +93,7 @@ destination airport and the distance between them in miles (SRC,DEST and DIST).
9193
would contain entries that looked like this (the real table would of course have
9294
thousands of rows but this gives a good idea of what the table would look like).
9395

96+
[source,text]
9497
----
9598
SRC DEST DIST
9699
--- ---- ----
@@ -109,18 +112,19 @@ LHR BOM 4479
109112
LHR FRA 406
110113
YYZ FRA 3938
111114
YYZ LHR 3544
115+
----
112116

113117
If we wanted to write a SQL query to calculate the ways of travelling from Austin
114118
(AUS) to Agra (AGR) with two stops, we would end up writing a query that looked
115119
something like this:
116120

117121
[source,sql]
118122
----
119-
select a1.code,r1.dest,r2.dest,r3.dest from airports a1
120-
join routes r1 on a1.code=r1.src
121-
join routes r2 on r1.dest=r2.src
122-
join routes r3 on r2.dest=r3.src
123-
where a1.code='AUS' and r3.dest='AGR';
123+
SELECT a1.code,r1.dest,r2.dest,r3.dest FROM airports a1
124+
JOIN routes r1 ON a1.code=r1.src
125+
JOIN routes r2 ON r1.dest=r2.src
126+
JOIN routes r3 ON r2.dest=r3.src
127+
WHERE a1.code='AUS' AND r3.dest='AGR';
124128
----
125129

126130
Using our 'air-routes' graph database the query can be expressed quite simply as
@@ -153,7 +157,7 @@ take to get there.
153157

154158
Again, don't worry if some of the Gremlin steps shown here are confusing, we will
155159
cover them all in detail a bit later. The key point to take away from this discussion
156-
of SQL and Gremlin is that for data that is very connected, Graph databases provide a
160+
of SQL and Gremlin is that for data that is very connected, graph databases provide a
157161
very good way to store that data and Gremlin provides a nice and fairly intuitive way
158162
to traverse that data efficiently.
159163

@@ -177,14 +181,13 @@ doing. We are traversing the graph from a starting point to an ending point.
177181
Traversals consist of one or more 'steps' (essentially methods) that are chained
178182
together.
179183

180-
As we start to look at some simple traversals here are a few 'steps' that you will
184+
As we start to look at some simple traversals, here are a few 'steps' that you will
181185
see used a lot. Firstly, you will notice that almost all traversals start with either
182186
a 'g.V()' or a 'g.E()'. Sometimes there will be parameters specified along with those
183187
steps but we will get into that a little later. You may remember from when we looked
184188
at how to load the 'air-routes' graph in Section 2 we used the following instruction
185189
to create a graph traversal source object for our loaded 'graph'.
186190

187-
188191
[source,groovy]
189192
----
190193
g = traversal().with(graph)
@@ -259,10 +262,10 @@ v[8]
259262
So, what we actually got back from these queries was a TinkerPop 'Vertex' data
260263
structure. Later in this book we will look at ways to store that value into a
261264
variable for additional processing. Remember that even though we are working with a
262-
Groovy environment while inside the Gremlin Console, everything we are working with
263-
here, at its core, is Java code. So we can use the 'getClass' method from Java to
264-
introspect the object. Note the call to 'next' which turns the result of the
265-
traversal into an object we can work with further.
265+
Groovy environment while inside the console, everything we are working with here, at
266+
its core, is Java code. So we can use the 'getClass' method from Java to introspect
267+
the object. Note the call to 'next' which turns the result of the traversal into an
268+
object we can work with further.
266269

267270
[source,groovy]
268271
----
@@ -597,7 +600,7 @@ value 'AUS'). Having found that vertex we then go 'out' from there. This will fi
597600
all of the vertices connected to Austin by an outgoing edge. Having found those
598601
airports we then ask for the values of their 'code' properties using the 'values'
599602
step. Finally the 'fold' step puts all of the results into a list for us. This just
600-
makes it easier for us to inspect the results in the console.
603+
makes it easier for us to inspect the results in Gremlin Console.
601604

602605
[source,groovy]
603606
----
@@ -1941,7 +1944,7 @@ the Austin airport vertex.
19411944
g.V().has('code','AUS').valueMap().unfold()
19421945
----
19431946

1944-
If you are using the Gremlin console, the output from running the previous command
1947+
If you are using the Gremlin Console, the output from running the previous command
19451948
should look something like this. The unfold step at the end of the query is used
19461949
to make the results easier to read.
19471950

@@ -2040,10 +2043,10 @@ runways=[2]
20402043
lat=[30.1944999694824]
20412044
----
20422045

2043-
If you are reading the output of queries that use 'valueMap' on the Gremlin console,
2044-
it is sometimes easier to read the output if you add an 'unfold' step to the end of
2045-
the query as follows. The 'unfold' step will unbundle a collection for us. You will
2046-
see it used in many parts of this book.
2046+
If you are reading the output of queries that use 'valueMap' from the console, it is
2047+
sometimes easier to read the output if you add an 'unfold' step to the end of the
2048+
query as follows. The 'unfold' step will unbundle a collection for us. You will see
2049+
it used in many parts of this book.
20472050

20482051
[source,groovy]
20492052
----

0 commit comments

Comments
 (0)