From 1288b9ec5aed8cd284e85ae6f38aed331b7aa313 Mon Sep 17 00:00:00 2001 From: Stephen Mallette Date: Tue, 28 Jan 2025 08:52:45 -0500 Subject: [PATCH] minor additions for strategies and filtering map keys --- ...Section-Miscellaneous-Queries-Results.adoc | 11 ++++++++++ book/Section-Writing-Gremlin-Queries.adoc | 20 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/book/Section-Miscellaneous-Queries-Results.adoc b/book/Section-Miscellaneous-Queries-Results.adoc index 612c7e1..1d91ca1 100644 --- a/book/Section-Miscellaneous-Queries-Results.adoc +++ b/book/Section-Miscellaneous-Queries-Results.adoc @@ -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 "<>" +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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/book/Section-Writing-Gremlin-Queries.adoc b/book/Section-Writing-Gremlin-Queries.adoc index d520930..0190aee 100644 --- a/book/Section-Writing-Gremlin-Queries.adoc +++ b/book/Section-Writing-Gremlin-Queries.adoc @@ -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