@@ -5421,6 +5421,9 @@ have not attempted to give an example of every single operator being used but th
5421
5421
examples provided should provide all of the basic building blocks you will need to
5422
5422
incorporate mathematical operators into your own Gremlin queries.
5423
5423
5424
+ TIP: These features require that the graph database system you are using supports a
5425
+ TinkerPop version of 3.3.1 or higher.
5426
+
5424
5427
[[arithmentic]]
5425
5428
Performing simple arithmetic
5426
5429
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -6682,6 +6685,67 @@ g.V().has('code','XYZ').as('a').V().has('code','DFW').addE('route').to('a')
6682
6685
You will see a bigger example that uses 'as' to name steps in the "<<testgraph>>"
6683
6686
section that is coming up soon.
6684
6687
6688
+ [[addlabeldynamic]]
6689
+ Using a traversal to determine a new label name
6690
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6691
+
6692
+ In TinkerPop 3.3.1 a new capability was added to the 'addV' and 'addE' steps. This
6693
+ new capability allows us to use a traversal to determine what the label used by a new
6694
+ vertex or edge should be. Take a look at the query below. We have seen this type of
6695
+ query used earlier in the book. It simply tells us what label the vertex representing
6696
+ the Austin (AUS) airport has.
6697
+
6698
+ [source,groovy]
6699
+ ----
6700
+ g.V().has('code','AUS').label()
6701
+
6702
+ airport
6703
+ ----
6704
+
6705
+ What the new capability added in TinkerPop 3.3.1 allows us to do is include the
6706
+ traversal above inside of an 'addV' step as shown below. The first string result
6707
+ returned by the provided traversal will be used as the label name.
6708
+
6709
+ [source,groovy]
6710
+ ----
6711
+ g.addV(V().has('code','AUS').label()).property('code','XYZ')
6712
+
6713
+ v[53768]
6714
+ ----
6715
+
6716
+ We can inspect the new vertex using 'valueMap' to make sure that our label was
6717
+ correctly assigned.
6718
+
6719
+ [source,groovy]
6720
+ ----
6721
+ g.V(53768).valueMap(true)
6722
+
6723
+ [id:53768,code:[XYZ],label:airport]
6724
+ ----
6725
+
6726
+ TIP: These features require that the graph database system you are using to supports
6727
+ a TinkerPop version of 3.3.1 or higher.
6728
+
6729
+ We can now do something similar to dynamically work out what the label should be for
6730
+ an edge between our new airport and Austin.
6731
+
6732
+ [source,groovy]
6733
+ ----
6734
+ g.V(53768).addE(V().has('code','AUS').outE().limit(1).label()).
6735
+ to(V().has('code','AUS'))
6736
+
6737
+ e[53770][53768-route->3]
6738
+ ----
6739
+
6740
+ Again, we can use a 'valueMap' step to make sure our new edge label looks OK.
6741
+
6742
+ [source,groovy]
6743
+ ----
6744
+ g.E(53770).valueMap(true)
6745
+
6746
+ [id:53770,label:route]
6747
+ ----
6748
+
6685
6749
[[proptraversal]]
6686
6750
Using a traversal to seed a property with a list
6687
6751
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0 commit comments