[ 
https://issues.apache.org/jira/browse/TINKERPOP-3274?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18154328#comment-18154328
 ] 

ASF GitHub Bot commented on TINKERPOP-3274:
-------------------------------------------

Cole-Greer commented on code in PR #3762:
URL: https://github.com/apache/tinkerpop/pull/3762#discussion_r4759552595


##########
docs/src/dev/provider/gremlin-semantics.asciidoc:
##########
@@ -1885,9 +1885,8 @@ property entries specified by propertyKeys. If the list 
is empty, then all prope
 *Considerations:*
 
 The label format in the map is controlled by source-level `with("multilabel")` 
and `with("singlelabel")` options, not
-by the number of labels the graph permits per element. When `"multilabel"` is 
present, the label value is a
-`SET<STRING>`. Likewise when
-`"singlelabel"` is present, it is a single `STRING`. The two options are 
mutually exclusive. Configuring both
+by the number of labels the graph permits per element. When `"multilabel"` is 
present, the element's full label set is emitted under a `labels` key as a
+`SET<STRING>`. When `"singlelabel"` is present, a single `label` key is 
emitted as a `STRING`. The two options are mutually exclusive. Configuring both

Review Comment:
   Nit:
   
   ```suggestion
   by the number of labels the graph permits per element. When `"multilabel"` 
is present, the element's full label set is emitted under a `T.labels` key as a
   `SET<STRING>`. When `"singlelabel"` is present, a single `T.label` key is 
emitted as a `STRING`. The two options are mutually exclusive. Configuring both
   ```



##########
docs/src/dev/provider/gremlin-semantics.asciidoc:
##########
@@ -2109,6 +2108,8 @@ None
 
 * `has(key)` filters to elements that have the specified property (existence 
check).
 * `has(T.label, value)` is equivalent to `hasLabel(value)`. `has(T.id, value)` 
is equivalent to `hasId(value)`.
+* `has(T.labels, value)` is equivalent to `has(T.label, value)` and 
`hasLabel(value)`, matching when any of the
+  element's labels satisfies the comparison.

Review Comment:
   Nit:
   
   ```suggestion
   * `has(T.labels, value)` is equivalent to `has(T.label, value)` and 
`hasLabel(value)`.
   ```
   



##########
gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/Labels.feature:
##########
@@ -156,3 +156,54 @@ Feature: Step - labels()
       | m[{"name":"bitsy","labels":"l[animal,mammal,nocturnal]"}] |
       | 
m[{"name":"splash","labels":"l[animal,aquatic,endangered,mammal,nocturnal]"}] |
       | m[{"name":"tinker","labels":"l[animal,endangered,mammal,nocturnal]"}] |
+
+  Scenario: g_V_hasXname_markoX_projectXlabelsX_byXT_labelsX

Review Comment:
   Nit: None of these new cases actually use the `labels()` step. They should 
be relocated based on whatever step is receiving a `T.labels` (project, has...)



##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AbstractAddVertexStepPlaceholder.java:
##########
@@ -55,6 +55,13 @@ protected String getDefaultLabel() {
 
     @Override
     public void setLabel(Object label) {
+        // An explicit empty label collection means "no label provided": leave 
the label unset so vertex
+        // creation applies the graph's LabelCardinality default (no labels 
under ZERO_OR_MORE), matching the
+        // concrete step and graph.addVertex(). Flipping userProvidedLabel 
here would instead materialize the
+        // default label.
+        if (label instanceof Collection && ((Collection<?>) label).isEmpty()) {
+            return;
+        }

Review Comment:
   I'm not sure I agree with this logic. It's sort of assuming that 
`setLabel()` will only be called once. We shouldn't try and reason about how 
this method may be called. Who knows what provider strategies might want to do 
with these steps.
   
   If we want to treat empty collections as "no label provided", then that 
needs to overwrite any existing label state in the step.



##########
docs/src/reference/the-traversal.asciidoc:
##########
@@ -1206,8 +1206,9 @@ 
g.V().group().by(labels().fold()).by(values('name').fold())  <2>
 <1> `atlas` carries the "animal", "reptile", "aquatic", and "endangered" 
labels, but is grouped under only one of
 them, chosen non-deterministically, so this grouping is not reliable for 
multi-label vertices.
 <2> Grouping by the full set of labels instead keeps each animal under its own 
distinct combination of labels.
-Prefer this pattern with the <<labels-step,`labels()`>> step over `by(label)` 
for graphs that support multiple
-labels per vertex.
+Prefer this pattern with the <<labels-step,`labels()`>> step, or 
<<t-labels-token,`by(T.labels)`>>, over `by(label)`
+for graphs that support multiple labels per vertex. The two differ only in the 
type of the group key: `labels().fold()`
+produces a `List` in label iteration order, while `T.labels` produces a `Set`.

Review Comment:
   There should be a corresponding 
`g.V().group().by(labels).by(values('name').fold())` traversal in the above 
example.



##########
gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/MergeEdge.feature:
##########
@@ -1202,3 +1202,153 @@ Feature: Step - mergeE()
     Then the result should have a count of 1
     And the graph should return 7 for count of "g.E()"
     And the graph should return 1 for count of 
"g.V().has(\"name\",\"marko\").out(\"knows\").has(\"name\",\"peter\")"
+  # edges accept T.labels like T.label, given as a String or a one-element set
+  Scenario: g_mergeEXlabels_knows_out_marko_in_vadasX
+    Given the empty graph
+    And the graph initializer of
+      """
+      g.addV("person").property("name", "marko").
+        addV("person").property("name", "vadas")
+      """
+    And using the parameter xx1 defined as "m[{\"t[labels]\": \"s[knows]\", 
\"D[OUT]\":\"v[marko].id\", \"D[IN]\":\"v[vadas].id\"}]"
+    And the traversal of
+      """
+      g.mergeE(xx1)
+      """
+    When iterated to list
+    Then the result should have a count of 1
+    And the graph should return 1 for count of 
"g.V().has(\"person\",\"name\",\"marko\").out(\"knows\").has(\"person\",\"name\",\"vadas\")"
+
+  Scenario: g_mergeEXlabels_knows_out_marko_in_vadasX_exists
+    Given the empty graph
+    And the graph initializer of
+      """
+      g.addV("person").property("name", "marko").as("a").
+        addV("person").property("name", "vadas").as("b").
+        addE("knows").from("a").to("b")
+      """
+    And using the parameter xx1 defined as "m[{\"t[labels]\": \"knows\", 
\"D[OUT]\":\"v[marko].id\", \"D[IN]\":\"v[vadas].id\"}]"
+    And the traversal of
+      """
+      g.mergeE(xx1)
+      """
+    When iterated to list
+    Then the result should have a count of 1
+    And the graph should return 1 for count of "g.E()"
+
+  # an empty label set is treated as an omitted label, so it does not 
constrain the search
+  Scenario: g_mergeEXlabels_empty_out_marko_in_vadasX_exists
+    Given the empty graph
+    And the graph initializer of
+      """
+      g.addV("person").property("name", "marko").as("a").
+        addV("person").property("name", "vadas").as("b").
+        addE("knows").from("a").to("b")
+      """
+    And using the parameter xx1 defined as "m[{\"t[labels]\": \"s[]\", 
\"D[OUT]\":\"v[marko].id\", \"D[IN]\":\"v[vadas].id\"}]"
+    And the traversal of
+      """
+      g.mergeE(xx1)
+      """
+    When iterated to list
+    Then the result should have a count of 1
+    And the graph should return 1 for count of "g.E()"
+    And the graph should return 1 for count of "g.E().hasLabel(\"knows\")"
+
+  Scenario: g_mergeEXout_marko_in_vadasX_optionXonCreate_labels_knowsX
+    Given the empty graph
+    And the graph initializer of
+      """
+      g.addV("person").property("name", "marko").
+        addV("person").property("name", "vadas")
+      """
+    And using the parameter xx1 defined as "m[{\"D[OUT]\":\"v[marko].id\", 
\"D[IN]\":\"v[vadas].id\"}]"
+    And using the parameter xx2 defined as "m[{\"t[labels]\": \"s[knows]\"}]"
+    And the traversal of
+      """
+      g.mergeE(xx1).option(Merge.onCreate, xx2)
+      """
+    When iterated to list
+    Then the result should have a count of 1
+    And the graph should return 1 for count of "g.E().hasLabel(\"knows\")"
+
+  Scenario: g_mergeEXlabels_knows_likes_out_marko_in_vadasX
+    Given the empty graph
+    And the graph initializer of
+      """
+      g.addV("person").property("name", "marko").
+        addV("person").property("name", "vadas")
+      """
+    And using the parameter xx1 defined as "m[{\"t[id]\": \"v[marko].id\"}]"
+    And using the parameter xx2 defined as "m[{\"t[id]\": \"v[vadas].id\"}]"
+    And the traversal of
+      """
+      g.mergeE([(T.labels): {"knows", "likes"}, (OUT): Merge.outV, (IN): 
Merge.inV]).option(Merge.outV, xx1).option(Merge.inV, xx2)
+      """
+    When iterated to list
+    Then the traversal will raise an error with message containing text of "An 
edge has exactly one label"
+
+  Scenario: g_V_addEXedgeX_propertyXT_labels_knows_likesX
+    Given the empty graph
+    And the graph initializer of
+      """
+      g.addV("person").property("name", "marko")
+      """
+    And the traversal of
+      """
+      g.V().addE("edge").to(__.V()).property(T.labels, {"knows", "likes"})
+      """
+    When iterated to list
+    Then the traversal will raise an error with message containing text of "An 
edge has exactly one label"

Review Comment:
   This isn't a mergeE() test, this is an addE() test. This also appears to be 
the lone motivation for all the new validation added to `setLabel()` in addE(), 
which I'm not sure is justified. The reason this is using `addE("edge")`, which 
is a pretty odd label to pass, is it's essentially the only code path to reach 
`setLabel()` in AddEdgeStepPlaceholder. This can only be reached if the current 
label equals the default edge label, as edge labels are immutable.
   
   All of this is pointing to a limitation in our current edge label 
immutability check, not really justification to add a bunch of additional label 
validation logic into addEdgeStep (which is also independent from the addition 
of a T.labels alias). I think we can drop all that new AddEdgeStepPlaceholder 
label validation logic, and just track this minor edge immutability check 
failure separately. It's probably within scope of an errand in TinkerBeads.





> Add T.labels as an analogue for labels()
> ----------------------------------------
>
>                 Key: TINKERPOP-3274
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-3274
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: process
>    Affects Versions: 4.0.0
>            Reporter: Cole Greer
>            Priority: Major
>
> Following the introduction of optional multilabel vertices to the TinkerPop 
> data model, and the corresponding introduction of a `labels()` step to 
> replace the old `label()` step, we should also introduce a new `T.labels` 
> token for complete symmetry.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to