[
https://issues.apache.org/jira/browse/TINKERPOP-2334?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17780057#comment-17780057
]
ASF GitHub Bot commented on TINKERPOP-2334:
-------------------------------------------
Cole-Greer commented on code in PR #2307:
URL: https://github.com/apache/tinkerpop/pull/2307#discussion_r1373670793
##########
gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/Format.feature:
##########
@@ -0,0 +1,141 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+@StepClassMap @StepFormat
+Feature: Step - format()
+
+ Scenario: g_VX1X_formatXstrX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().has("name", "marko").format("Hello world")
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | Hello world |
+
+ Scenario: g_V_formatXstrX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().format("%{name} is %{age} years old")
+ """
+ When iterated to list
+ # software don't have age, so filtered out
Review Comment:
If a previous step is labelled as "age", would it act here as a default
value for the output? For example would something like
`g.inject(1).as("age").V().format("%{name} is %{age} years old")` produce
results such as`marko is 29 years old` and `lop is 1 years old`?
##########
docs/src/dev/provider/gremlin-semantics.asciidoc:
##########
@@ -1000,6 +1000,38 @@ None
None
+[[format-step]]
+=== format()
+
+*Description:* a mid-traversal step which will handle result formatting to
string values.
+
+*Syntax:* `format(String)`
+
+[width="100%",options="header"]
+|=========================================================
+|Start Step |Mid Step |Modulated |Domain |Range
+|N |Y |N |`any` |`String`
Review Comment:
```suggestion
|N |Y |Y |`any` |`String`
```
##########
gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/Format.feature:
##########
@@ -0,0 +1,141 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+@StepClassMap @StepFormat
+Feature: Step - format()
+
+ Scenario: g_VX1X_formatXstrX
Review Comment:
I second the need for these tests cases. Note however that a list wouldn't
exactly be an unsupported traverser. A list should function fine with `%{_}`
positional tokens and by() modulation. Additionally format should be able to
match scope values regardless of the contents of the traverser.
##########
gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/Format.feature:
##########
@@ -0,0 +1,141 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+@StepClassMap @StepFormat
+Feature: Step - format()
+
+ Scenario: g_VX1X_formatXstrX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().has("name", "marko").format("Hello world")
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | Hello world |
+
+ Scenario: g_V_formatXstrX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().format("%{name} is %{age} years old")
+ """
+ When iterated to list
+ # software don't have age, so filtered out
+ Then the result should be unordered
+ | result |
+ | marko is 29 years old |
+ | vadas is 27 years old |
+ | josh is 32 years old |
+ | peter is 35 years old |
+
+ @GraphComputerVerificationReferenceOnly
+ Scenario: g_V_formatXstrX_byXnameX_byXageX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().format("%{_} is %{_} years
old").by(values("name")).by(values("age"))
Review Comment:
What is the expected result if the number of `%{_}` tokens does not match
the number of `by()` modulators? Could we have tests for both too few and too
many `by()` modulators?
> Add format() step
> -----------------
>
> Key: TINKERPOP-2334
> URL: https://issues.apache.org/jira/browse/TINKERPOP-2334
> Project: TinkerPop
> Issue Type: Improvement
> Components: process
> Affects Versions: 3.4.4
> Reporter: Stephen Mallette
> Assignee: Valentyn Kahamlyk
> Priority: Major
>
> Provide for a {{format()}} step which will handle result formatting to string
> values. This change will help resolve the need for string concatenation
> functions while providing a lot of flexibility to how results can be formed:
> {code}
> gremlin> g.V().hasLabel('person').format("%{n} is %{a} years old.").by('n',
> 'name').by('a', 'age')
> ==>marko is 29 years old.
> ==>vadas is 27 years old.
> ==>josh is 32 years old.
> ==>peter is 35 years old.
> gremlin> g.V().hasLabel('person').format("%{name} is %{age} years old.")
> ==>marko is 29 years old.
> ==>vadas is 27 years old.
> ==>josh is 32 years old.
> ==>peter is 35 years old.
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)