Skip to content

Commit

Permalink
minor additions for strategies and filtering map keys
Browse files Browse the repository at this point in the history
  • Loading branch information
spmallette committed Jan 28, 2025
1 parent b509968 commit 1288b9e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions book/Section-Miscellaneous-Queries-Results.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4412,6 +4412,17 @@ extremely long time. In many ways the concept of "longest path" can be viewed as
anti pattern. This is especially true in highly connected graphs of which
`air-routes` is an example.

As a final point about the prior example, we recall the "<<traversal-strategies>>"
section, where we learned that TinkerPop applies some changes to the way a traversal
is written just before it is iterated to optimize performance where it can. The prior
example demonstrates a case where certain query patterns will prevent a particular
strategy from being applied. Normally, the 'repeat().times()' pattern will result in
the contents of 'repeat' being expanded, where 'repeat(out()).times(2)' becomes,
'out().out()' which is more efficient for TinkerPop to execute. But the presence of
'dedup()' precludes that transformation to get the query semantics that are
presented. This sort of information can become useful when you are looking for your
own query optimizations.

[[unwantededges]]
Finding unwanted parallel edges
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
20 changes: 20 additions & 0 deletions book/Section-Writing-Gremlin-Queries.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,26 @@ g.V().has('code','AUS').valueMap().select('code','icao','desc')
[code:[AUS],icao:[KAUS],desc:[Austin Bergstrom International Airport]]
----

As an additional example of Gremlin's flexibility, note that you can also restrict
the selected keys to all but those you specify.

[source,groovy]
----
g.V('3').valueMap().as('vm').unfold().
filter(select(keys).is(without('city','desc')))
country=[US]
code=[AUS]
longest=[12250]
elev=[542]
icao=[KAUS]
lon=[-97.6698989868164]
type=[airport]
region=[US-TX]
runways=[2]
lat=[30.1944999694824]
----

If you are reading the output of queries that use 'valueMap' on the Gremlin console,
it is sometimes easier to read the output if you add an 'unfold' step to the end of
the query as follows. The 'unfold' step will unbundle a collection for us. You will
Expand Down

0 comments on commit 1288b9e

Please sign in to comment.