Re: [PR] [TINKERPOP-2334] Add format() step [tinkerpop]

2023-10-24 Thread via GitHub


vkagamlyk commented on code in PR #2307:
URL: https://github.com/apache/tinkerpop/pull/2307#discussion_r1370831830


##
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/FormatStepTest.java:
##
@@ -0,0 +1,143 @@
+/*
+ * 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.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.step.map;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.StepTest;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.tinkerpop.gremlin.util.CollectionUtil.asMap;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class FormatStepTest extends StepTest {
+
+@Override
+protected List getTraversals() {
+return Collections.singletonList(
+__.format("hello")
+);
+}
+
+private List getVariables(final String format) {
+final FormatStep formatStep = new 
FormatStep(__.inject("test").asAdmin(), format);
+return new ArrayList<>(formatStep.getScopeKeys());
+}
+
+@Test
+public void shouldGetVariablesFromTemplate() {
+assertEquals(Collections.emptyList(), getVariables("Hello world"));
+assertEquals(Collections.emptyList(), getVariables("Hello %{world"));
+assertEquals(Collections.emptyList(), getVariables("Hello %{}"));
+assertEquals(Collections.emptyList(), getVariables("Hello {world}"));
+assertEquals(Collections.emptyList(), getVariables("Hello % {world}"));
+assertEquals(Collections.singletonList(" "), getVariables("Hello %{ 
}"));
+assertEquals(Collections.singletonList("world"), getVariables("Hello 
%{world}"));
+assertEquals(Arrays.asList("Hello", "world"), getVariables("%{Hello} 
%{world}"));
+assertEquals(Arrays.asList("Hello", "world"), getVariables("%{Hello} 
%{Hello} %{world}"));
+assertEquals(Arrays.asList("Hello", "hello", "world"), 
getVariables("%{Hello} %{hello} %{world}"));
+}
+
+@Test
+public void shouldWorkWithoutVariables() {
+assertEquals("Hello world", __.__("test").format("Hello 
world").next());
+}
+
+@Test
+public void shouldWorkWithVertexInput() {
+final VertexProperty mockProperty = mock(VertexProperty.class);
+when(mockProperty.key()).thenReturn("name");
+when(mockProperty.value()).thenReturn("Stephen");
+when(mockProperty.isPresent()).thenReturn(true);
+
+final Vertex mockVertex = mock(Vertex.class);
+when(mockVertex.property("name")).thenReturn(mockProperty);
+
+assertEquals("Hello Stephen", __.__(mockVertex).format("Hello 
%{name}").next());
+}
+
+@Test
+public void shouldWorkWithMultipleVertexInput() {
+final VertexProperty mockProperty1 = mock(VertexProperty.class);
+when(mockProperty1.key()).thenReturn("name");
+when(mockProperty1.value()).thenReturn("Stephen");
+when(mockProperty1.isPresent()).thenReturn(true);
+
+final Vertex mockVertex1 = mock(Vertex.class);
+when(mockVertex1.property("name")).thenReturn(mockProperty1);
+
+final VertexProperty mockProperty2 = mock(VertexProperty.class);
+when(mockProperty2.key()).thenReturn("name");
+when(mockProperty2.value()).thenReturn("Marko");
+when(mockProperty2.isPresent()).thenReturn(true);
+
+final Vertex mockVertex2 = mock(Vertex.class);
+when(mockVertex2.property("name")).thenReturn(mockProperty2);
+
+assertEquals(Arrays.asList("Hello Stephen", "Hello Marko"),
+__.__(mockVertex1, mockVertex2).format("Hello 
%{name}").toList());
+}
+@Test
+public void shouldWorkWithMap() {
+assertEquals("Hello 2", __.__(asMap("name", 2)).format("Hello 
%{name}").next());
+assertE

Re: [PR] [TINKERPOP-2334] Add format() step [tinkerpop]

2023-10-24 Thread via GitHub


vkagamlyk commented on code in PR #2307:
URL: https://github.com/apache/tinkerpop/pull/2307#discussion_r1370820399


##
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/FormatStepTest.java:
##
@@ -0,0 +1,143 @@
+/*
+ * 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.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.step.map;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.StepTest;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.tinkerpop.gremlin.util.CollectionUtil.asMap;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class FormatStepTest extends StepTest {
+
+@Override
+protected List getTraversals() {
+return Collections.singletonList(
+__.format("hello")
+);
+}
+
+private List getVariables(final String format) {
+final FormatStep formatStep = new 
FormatStep(__.inject("test").asAdmin(), format);
+return new ArrayList<>(formatStep.getScopeKeys());
+}
+
+@Test
+public void shouldGetVariablesFromTemplate() {
+assertEquals(Collections.emptyList(), getVariables("Hello world"));
+assertEquals(Collections.emptyList(), getVariables("Hello %{world"));
+assertEquals(Collections.emptyList(), getVariables("Hello %{}"));
+assertEquals(Collections.emptyList(), getVariables("Hello {world}"));
+assertEquals(Collections.emptyList(), getVariables("Hello % {world}"));
+assertEquals(Collections.singletonList(" "), getVariables("Hello %{ 
}"));
+assertEquals(Collections.singletonList("world"), getVariables("Hello 
%{world}"));
+assertEquals(Arrays.asList("Hello", "world"), getVariables("%{Hello} 
%{world}"));
+assertEquals(Arrays.asList("Hello", "world"), getVariables("%{Hello} 
%{Hello} %{world}"));
+assertEquals(Arrays.asList("Hello", "hello", "world"), 
getVariables("%{Hello} %{hello} %{world}"));
+}
+
+@Test
+public void shouldWorkWithoutVariables() {
+assertEquals("Hello world", __.__("test").format("Hello 
world").next());
+}
+
+@Test
+public void shouldWorkWithVertexInput() {
+final VertexProperty mockProperty = mock(VertexProperty.class);
+when(mockProperty.key()).thenReturn("name");
+when(mockProperty.value()).thenReturn("Stephen");
+when(mockProperty.isPresent()).thenReturn(true);
+
+final Vertex mockVertex = mock(Vertex.class);
+when(mockVertex.property("name")).thenReturn(mockProperty);
+
+assertEquals("Hello Stephen", __.__(mockVertex).format("Hello 
%{name}").next());
+}
+
+@Test
+public void shouldWorkWithMultipleVertexInput() {
+final VertexProperty mockProperty1 = mock(VertexProperty.class);
+when(mockProperty1.key()).thenReturn("name");
+when(mockProperty1.value()).thenReturn("Stephen");
+when(mockProperty1.isPresent()).thenReturn(true);
+
+final Vertex mockVertex1 = mock(Vertex.class);
+when(mockVertex1.property("name")).thenReturn(mockProperty1);
+
+final VertexProperty mockProperty2 = mock(VertexProperty.class);
+when(mockProperty2.key()).thenReturn("name");
+when(mockProperty2.value()).thenReturn("Marko");
+when(mockProperty2.isPresent()).thenReturn(true);
+
+final Vertex mockVertex2 = mock(Vertex.class);
+when(mockVertex2.property("name")).thenReturn(mockProperty2);
+
+assertEquals(Arrays.asList("Hello Stephen", "Hello Marko"),
+__.__(mockVertex1, mockVertex2).format("Hello 
%{name}").toList());
+}
+@Test
+public void shouldWorkWithMap() {
+assertEquals("Hello 2", __.__(asMap("name", 2)).format("Hello 
%{name}").next());
+assertE

[tinkerpop] branch master updated (22759b88d3 -> 7bf8cd163d)

2023-10-24 Thread xiazcy
This is an automated email from the ASF dual-hosted git repository.

xiazcy pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


from 22759b88d3 TINKERPOP-2999 3.7.0 Remote Console Sends Incomplete 
Queries (#2297)
 add f28c1db9bf CTR make changelog entry more clear
 new 7bf8cd163d Merge branch '3.6-dev'

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 CHANGELOG.asciidoc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)



[tinkerpop] 01/01: Merge branch '3.6-dev'

2023-10-24 Thread xiazcy
This is an automated email from the ASF dual-hosted git repository.

xiazcy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit 7bf8cd163d04f5553c55e32e1ff8032b174d0809
Merge: 22759b88d3 f28c1db9bf
Author: Yang Xia <55853655+xia...@users.noreply.github.com>
AuthorDate: Tue Oct 24 14:15:14 2023 -0700

Merge branch '3.6-dev'

 CHANGELOG.asciidoc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)




[tinkerpop] branch 3.6-dev updated: CTR make changelog entry more clear

2023-10-24 Thread xiazcy
This is an automated email from the ASF dual-hosted git repository.

xiazcy pushed a commit to branch 3.6-dev
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/3.6-dev by this push:
 new f28c1db9bf CTR make changelog entry more clear
f28c1db9bf is described below

commit f28c1db9bfd010e0eb1b10f0a1cb5b01fbefeb4d
Author: Yang Xia <55853655+xia...@users.noreply.github.com>
AuthorDate: Tue Oct 24 14:14:23 2023 -0700

CTR make changelog entry more clear
---
 CHANGELOG.asciidoc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 2d26ba2747..9e147731a6 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -30,7 +30,7 @@ This release also includes changes from <>.
 * Allowed `io()` to automatically detect ".graphml" as a file extension.
 * Deprecated the `HandshakeInterceptor` in favor of a more generic 
`RequestInterceptor`.
 * Allowed `gremlin-python` to be used over HTTP for experimental purposes.
-* Updated `gremlin-python` translator to enable additional traversals over 
HTTP.
+* Fixed translation of `P`, `TraversalStrategy` and Enums, and added 
translation for `Vertex`, `Edge`, `VertexProperty`, list, set, dict, number, 
binding and lambda in Groovy Translator for Python.
 * Fixed a bug in `StarGraph` where `EdgeFilter` did not remove associated Edge 
Properties.
 * Added translator to the Go GLV.
 * Fixed bug with filtering for `group()` when the side-effect label was 
defined for it.



[tinkerpop] branch master updated: TINKERPOP-2999 3.7.0 Remote Console Sends Incomplete Queries (#2297)

2023-10-24 Thread xiazcy
This is an automated email from the ASF dual-hosted git repository.

xiazcy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/master by this push:
 new 22759b88d3 TINKERPOP-2999 3.7.0 Remote Console Sends Incomplete 
Queries (#2297)
22759b88d3 is described below

commit 22759b88d380e6bd313cd0cae5ad66f20cc78056
Author: Ryan Tan <65996005+r...@users.noreply.github.com>
AuthorDate: Tue Oct 24 13:02:23 2023 -0700

TINKERPOP-2999 3.7.0 Remote Console Sends Incomplete Queries (#2297)

* Add handling for multiline remote console commands

Fixes issue where multiline commands would throw error on the first line, 
caused by upgrade to Groovy 4
Handling pulled from Groovysh.groovy

* Update CHANGELOG.asciidoc
---
 CHANGELOG.asciidoc |  1 +
 .../gremlin/console/GremlinGroovysh.groovy | 77 +-
 2 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index e3d6bc9e18..2c9d2be6a4 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -33,6 +33,7 @@ This release also includes changes from <> and <()`. *(breaking)*
 * Update `concat()` to not special treat `inject` in arguments and use 
`TraversalUtil.apply` on it as with any other child traversals. *(breaking)*
 * Checked graph features for meta-property support before trying to serialize 
them in `VertexPropertySerializer` for GraphBinary.
+* Fixed multiline query bug in console caused by upgrade to Groovy 4.
 * Added date manipulation steps `asDate`, `dateAdd` and `dateDiff`.
 * Added new data type `DT` to represent periods of time.
 * Added Gherkin support for Date.
diff --git 
a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
 
b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
index 63b7e3ac98..2ba5388864 100644
--- 
a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
+++ 
b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
@@ -24,8 +24,10 @@ import org.apache.groovy.groovysh.Groovysh
 import org.apache.groovy.groovysh.ParseCode
 import org.apache.groovy.groovysh.Parser
 import org.apache.groovy.groovysh.util.CommandArgumentParser
+import org.apache.groovy.groovysh.util.ScriptVariableAnalyzer
 import org.apache.tinkerpop.gremlin.console.commands.GremlinSetCommand
 import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.control.MultipleCompilationErrorsException
 import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer
 import org.codehaus.groovy.tools.shell.IO
 
@@ -102,11 +104,40 @@ class GremlinGroovysh extends Groovysh {
 List current = new ArrayList(buffers.current())
 current << line
 
+String importsSpec = this.getImportStatements()
+
 // determine if this script is complete or not - if not it's a 
multiline script
-def status = parser.parse(current)
+def status = parser.parse([importsSpec] + current)
 
 switch (status.code) {
 case ParseCode.COMPLETE:
+if 
(!Boolean.valueOf(getPreference(INTERPRETER_MODE_PREFERENCE_KEY, 'false')) || 
isTypeOrMethodDeclaration(current)) {
+// Evaluate the current buffer w/imports and dummy 
statement
+List buff = [importsSpec] + [ 'true' ] + current
+try {
+interp.evaluate(buff)
+} catch(MultipleCompilationErrorsException t) {
+if (isIncompleteCaseOfAntlr4(t)) {
+// treat like INCOMPLETE case
+buffers.updateSelected(current)
+break
+}
+throw t
+}
+} else {
+// Evaluate Buffer wrapped with code storing 
bounded vars
+try {
+evaluateWithStoredBoundVars(importsSpec, 
current)
+} catch(MultipleCompilationErrorsException t) {
+if (isIncompleteCaseOfAntlr4(t)) {
+// treat like INCOMPLETE case
+buffers.updateSelected(current)
+break
+}
+throw t
+}
+}
+
 // concat script here because commands don't support 
multi-line
 def 

Re: [PR] TINKERPOP-2999 3.7.0 Remote Console Sends Incomplete Queries [tinkerpop]

2023-10-24 Thread via GitHub


xiazcy merged PR #2297:
URL: https://github.com/apache/tinkerpop/pull/2297


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] TINKERPOP-2999 3.7.0 Remote Console Sends Incomplete Queries [tinkerpop]

2023-10-24 Thread via GitHub


xiazcy commented on PR #2297:
URL: https://github.com/apache/tinkerpop/pull/2297#issuecomment-1777939173

   VOTE +1


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [TINKERPOP-2334] Add format() step [tinkerpop]

2023-10-24 Thread via GitHub


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


##
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/FormatStep.java:
##
@@ -0,0 +1,195 @@
+/*
+ * 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.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.step.map;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.tinkerpop.gremlin.process.traversal.Pop;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.step.PathProcessor;
+import org.apache.tinkerpop.gremlin.process.traversal.step.Scoping;
+import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
+import 
org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+import 
org.apache.tinkerpop.gremlin.process.traversal.traverser.util.EmptyTraverser;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalProduct;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalRing;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalUtil;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Reference implementation for String format step, a mid-traversal step which 
will handle result formatting
+ * to string values. If the incoming traverser is a non-String value then an 
{@code IllegalArgumentException}
+ * will be thrown.
+ *
+ * @author Valentyn Kahamlyk
+ */
+public final class FormatStep extends MapStep implements 
TraversalParent, Scoping, PathProcessor {
+
+private String format;
+private Set variables;
+private TraversalRing traversalRing = new TraversalRing<>();
+private Set keepLabels;
+
+public FormatStep(final Traversal.Admin traversal, final String format) {
+super(traversal);
+this.format = format;
+this.variables = getVariables();
+}
+
+@Override
+protected Traverser.Admin processNextStart() {
+final Map values = new HashMap<>();
+
+final Traverser.Admin traverser = this.starts.next();
+
+boolean productive = true;
+for (final String var : variables) {
+final Object current = traverser.get();
+// try to get property value
+if (current instanceof Element) {
+final Property prop = ((Element) current).property(var);
+if (prop != null && prop.isPresent()) {
+values.put(var, prop.value());
+continue;
+}
+}
+
+final TraversalProduct product =
+TraversalUtil.produce((S) 
this.getNullableScopeValue(Pop.last, var, traverser), 
this.traversalRing.next());
+
+if (!product.isProductive() || product.get() == null) {
+productive = false;
+break;
+}
+
+values.put(var, product.get());
+}
+this.traversalRing.reset();
+
+return productive ?
+
PathProcessor.processTraverserPathLabels(traverser.split(evaluate(values), 
this), this.keepLabels) :
+EmptyTraverser.instance();
+}
+
+@Override
+public String toString() {
+return StringFactory.stepString(this, this.format, this.traversalRing);
+}
+
+@Override
+public int hashCode() {
+int result = super.hashCode();
+return Objects.hash(result, format, traversalRing);
+}
+
+@Override
+public List> getLocalChildren() {
+return this.traversalRing.getTraversals();
+}
+
+@Override
+public void reset() {
+super.reset();
+this.traversalRing.reset();
+}
+
+@Override
+public FormatStep clone() {
+

Re: [PR] [TINKERPOP-2334] Add format() step [tinkerpop]

2023-10-24 Thread via GitHub


kenhuuu commented on code in PR #2307:
URL: https://github.com/apache/tinkerpop/pull/2307#discussion_r1370552173


##
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/FormatStep.java:
##
@@ -0,0 +1,195 @@
+/*
+ * 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.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.step.map;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.tinkerpop.gremlin.process.traversal.Pop;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.step.PathProcessor;
+import org.apache.tinkerpop.gremlin.process.traversal.step.Scoping;
+import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
+import 
org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+import 
org.apache.tinkerpop.gremlin.process.traversal.traverser.util.EmptyTraverser;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalProduct;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalRing;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalUtil;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Reference implementation for String format step, a mid-traversal step which 
will handle result formatting
+ * to string values. If the incoming traverser is a non-String value then an 
{@code IllegalArgumentException}
+ * will be thrown.
+ *
+ * @author Valentyn Kahamlyk
+ */
+public final class FormatStep extends MapStep implements 
TraversalParent, Scoping, PathProcessor {
+
+private String format;
+private Set variables;
+private TraversalRing traversalRing = new TraversalRing<>();
+private Set keepLabels;
+
+public FormatStep(final Traversal.Admin traversal, final String format) {
+super(traversal);
+this.format = format;
+this.variables = getVariables();
+}
+
+@Override
+protected Traverser.Admin processNextStart() {
+final Map values = new HashMap<>();
+
+final Traverser.Admin traverser = this.starts.next();
+
+boolean productive = true;
+for (final String var : variables) {
+final Object current = traverser.get();
+// try to get property value
+if (current instanceof Element) {
+final Property prop = ((Element) current).property(var);
+if (prop != null && prop.isPresent()) {
+values.put(var, prop.value());
+continue;
+}
+}
+
+final TraversalProduct product =
+TraversalUtil.produce((S) 
this.getNullableScopeValue(Pop.last, var, traverser), 
this.traversalRing.next());
+
+if (!product.isProductive() || product.get() == null) {
+productive = false;
+break;
+}
+
+values.put(var, product.get());
+}
+this.traversalRing.reset();
+
+return productive ?
+
PathProcessor.processTraverserPathLabels(traverser.split(evaluate(values), 
this), this.keepLabels) :
+EmptyTraverser.instance();
+}
+
+@Override
+public String toString() {
+return StringFactory.stepString(this, this.format, this.traversalRing);
+}
+
+@Override
+public int hashCode() {
+int result = super.hashCode();
+return Objects.hash(result, format, traversalRing);
+}
+
+@Override
+public List> getLocalChildren() {
+return this.traversalRing.getTraversals();
+}
+
+@Override
+public void reset() {
+super.reset();
+this.traversalRing.reset();
+}
+
+@Override
+public FormatStep clone() {
+   

Re: [PR] [TINKERPOP-2334] Add format() step [tinkerpop]

2023-10-24 Thread via GitHub


kenhuuu commented on code in PR #2307:
URL: https://github.com/apache/tinkerpop/pull/2307#discussion_r1370549922


##
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/FormatStep.java:
##
@@ -0,0 +1,195 @@
+/*
+ * 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.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.step.map;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.tinkerpop.gremlin.process.traversal.Pop;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.step.PathProcessor;
+import org.apache.tinkerpop.gremlin.process.traversal.step.Scoping;
+import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
+import 
org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+import 
org.apache.tinkerpop.gremlin.process.traversal.traverser.util.EmptyTraverser;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalProduct;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalRing;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalUtil;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Reference implementation for String format step, a mid-traversal step which 
will handle result formatting
+ * to string values. If the incoming traverser is a non-String value then an 
{@code IllegalArgumentException}
+ * will be thrown.
+ *
+ * @author Valentyn Kahamlyk
+ */
+public final class FormatStep extends MapStep implements 
TraversalParent, Scoping, PathProcessor {
+
+private String format;
+private Set variables;
+private TraversalRing traversalRing = new TraversalRing<>();
+private Set keepLabels;
+
+public FormatStep(final Traversal.Admin traversal, final String format) {
+super(traversal);
+this.format = format;
+this.variables = getVariables();
+}
+
+@Override
+protected Traverser.Admin processNextStart() {
+final Map values = new HashMap<>();
+
+final Traverser.Admin traverser = this.starts.next();
+
+boolean productive = true;
+for (final String var : variables) {
+final Object current = traverser.get();
+// try to get property value
+if (current instanceof Element) {
+final Property prop = ((Element) current).property(var);
+if (prop != null && prop.isPresent()) {
+values.put(var, prop.value());
+continue;
+}
+}
+
+final TraversalProduct product =
+TraversalUtil.produce((S) 
this.getNullableScopeValue(Pop.last, var, traverser), 
this.traversalRing.next());
+
+if (!product.isProductive() || product.get() == null) {
+productive = false;
+break;
+}
+
+values.put(var, product.get());
+}
+this.traversalRing.reset();
+
+return productive ?
+
PathProcessor.processTraverserPathLabels(traverser.split(evaluate(values), 
this), this.keepLabels) :
+EmptyTraverser.instance();
+}
+
+@Override
+public String toString() {
+return StringFactory.stepString(this, this.format, this.traversalRing);
+}
+
+@Override
+public int hashCode() {
+int result = super.hashCode();
+return Objects.hash(result, format, traversalRing);
+}
+
+@Override
+public List> getLocalChildren() {
+return this.traversalRing.getTraversals();
+}
+
+@Override
+public void reset() {
+super.reset();
+this.traversalRing.reset();
+}
+
+@Override
+public FormatStep clone() {
+   

Re: [PR] [TINKERPOP-2334] Add format() step [tinkerpop]

2023-10-24 Thread via GitHub


kenhuuu commented on code in PR #2307:
URL: https://github.com/apache/tinkerpop/pull/2307#discussion_r1370546362


##
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/grammar/DefaultGremlinBaseVisitor.java:
##
@@ -933,6 +933,11 @@ protected void notImplemented(final ParseTree ctx) {
 * {@inheritDoc}
 */
@Override public T visitTraversalMethod_asString_Empty(final 
GremlinParser.TraversalMethod_asString_EmptyContext ctx) { notImplemented(ctx); 
return null; }
+   /**
+* {@inheritDoc}
+*/
+   @Override
+   public T 
visitTraversalMethod_format_String(GremlinParser.TraversalMethod_format_StringContext
 ctx)  { notImplemented(ctx); return null; }

Review Comment:
   Very minor nit: extra space added between ) and {.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] [TINKERPOP-2334] Add format() step [tinkerpop]

2023-10-24 Thread via GitHub


kenhuuu commented on code in PR #2307:
URL: https://github.com/apache/tinkerpop/pull/2307#discussion_r1370543709


##
docs/src/dev/provider/gremlin-semantics.asciidoc:
##
@@ -892,6 +892,36 @@ 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`
+|=
+
+*Arguments:*
+
+Format string. Variables can be represented using `%{variable_name}` notation.
+The variable values are used in the order that the first one will be found: 
Element properties, than Scope values.
+If value for some variable was not found than result for input is skipped.
+
+*Exceptions*
+
+None
+
+*Modulation:*
+
+None
+
+See: 
link:https://github.com/apache/tinkerpop/tree/x.y.z/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/FromatStep.java[source],

Review Comment:
   Typo in "FromatStep.java"



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] TINKERPOP-2995 Create Sample Applications in each GLV [tinkerpop]

2023-10-24 Thread via GitHub


kenhuuu commented on code in PR #2298:
URL: https://github.com/apache/tinkerpop/pull/2298#discussion_r1370515751


##
gremlin-driver/src/main/java/example/Example.java:
##
@@ -0,0 +1,157 @@
+/*
+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.
+*/
+
+package example;
+
+// Common imports
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import 
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+
+import static 
org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
+import static org.apache.tinkerpop.gremlin.process.traversal.P.*;
+import static org.apache.tinkerpop.gremlin.structure.T.*;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.*;
+
+import org.apache.tinkerpop.gremlin.driver.Client;
+import org.apache.tinkerpop.gremlin.driver.Cluster;
+import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.io.AbstractIoRegistry;
+import org.apache.tinkerpop.gremlin.structure.io.IoRegistry;
+import org.apache.tinkerpop.gremlin.structure.io.binary.TypeSerializerRegistry;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.apache.tinkerpop.gremlin.util.MessageSerializer;
+import org.apache.tinkerpop.gremlin.util.ser.GraphBinaryMessageSerializerV1;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+public class Example {
+
+public static void main(String[] args) throws Exception {
+connectionExample();

Review Comment:
   I find this file a bit too "busy". By that I mean there are too many 
examples in one file and I feel it would have made more sense to split these up 
into differrent files with their own main(). This is especially true of the 
connection examples where much of the code is commented out depending on the 
configuration. If these were split into more files, you wouldn't need to do 
that.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[PR] Bump github.com/nicksnyder/go-i18n/v2 from 2.2.1 to 2.2.2 in /gremlin-go [tinkerpop]

2023-10-24 Thread via GitHub


dependabot[bot] opened a new pull request, #2308:
URL: https://github.com/apache/tinkerpop/pull/2308

   Bumps 
[github.com/nicksnyder/go-i18n/v2](https://github.com/nicksnyder/go-i18n) from 
2.2.1 to 2.2.2.
   
   Release notes
   Sourced from https://github.com/nicksnyder/go-i18n/releases";>github.com/nicksnyder/go-i18n/v2's
 releases.
   
   v2.2.2
   New features
   
   extract: support typed string constants by https://github.com/hectorj-thetreep";>@​hectorj-thetreep 
in https://redirect.github.com/nicksnyder/go-i18n/pull/304";>nicksnyder/go-i18n#304
   
   Bug fixes
   
   Fix Localize regression with empty default message by https://github.com/KuSh";>@​KuSh in https://redirect.github.com/nicksnyder/go-i18n/pull/305";>nicksnyder/go-i18n#305
   
   Maintenance
   
   fix misleading comment on MustLoadMessageFile function by https://github.com/ardaozceviz";>@​ardaozceviz in https://redirect.github.com/nicksnyder/go-i18n/pull/298";>nicksnyder/go-i18n#298
   goi18n安装命令更新 by https://github.com/qwxingzhe";>@​qwxingzhe in https://redirect.github.com/nicksnyder/go-i18n/pull/296";>nicksnyder/go-i18n#296
   Fix build by https://github.com/nicksnyder";>@​nicksnyder in https://redirect.github.com/nicksnyder/go-i18n/pull/299";>nicksnyder/go-i18n#299
   Update GitHub actions by https://github.com/nicksnyder";>@​nicksnyder in https://redirect.github.com/nicksnyder/go-i18n/pull/300";>nicksnyder/go-i18n#300
   Tune the Chinese version of README by https://github.com/tengqm";>@​tengqm in https://redirect.github.com/nicksnyder/go-i18n/pull/303";>nicksnyder/go-i18n#303
   
   New Contributors
   
   https://github.com/ardaozceviz";>@​ardaozceviz 
made their first contribution in https://redirect.github.com/nicksnyder/go-i18n/pull/298";>nicksnyder/go-i18n#298
   https://github.com/qwxingzhe";>@​qwxingzhe made 
their first contribution in https://redirect.github.com/nicksnyder/go-i18n/pull/296";>nicksnyder/go-i18n#296
   https://github.com/tengqm";>@​tengqm made their 
first contribution in https://redirect.github.com/nicksnyder/go-i18n/pull/303";>nicksnyder/go-i18n#303
   https://github.com/hectorj-thetreep";>@​hectorj-thetreep 
made their first contribution in https://redirect.github.com/nicksnyder/go-i18n/pull/304";>nicksnyder/go-i18n#304
   https://github.com/KuSh";>@​KuSh made their 
first contribution in https://redirect.github.com/nicksnyder/go-i18n/pull/305";>nicksnyder/go-i18n#305
   
   Full Changelog: https://github.com/nicksnyder/go-i18n/compare/v2.2.1...v2.3.0";>https://github.com/nicksnyder/go-i18n/compare/v2.2.1...v2.3.0
   
   
   
   Commits
   
   https://github.com/nicksnyder/go-i18n/commit/54617eff8617774f6c2deea248cf2f131781f43e";>54617ef
 Fix Localize regression with empty default message (https://redirect.github.com/nicksnyder/go-i18n/issues/305";>#305)
   https://github.com/nicksnyder/go-i18n/commit/5ee16aac4da2284b9be158343f8b4614d539025d";>5ee16aa
 extract: support typed string constants (https://redirect.github.com/nicksnyder/go-i18n/issues/304";>#304)
   https://github.com/nicksnyder/go-i18n/commit/8b7b3cbf0e6179047e15487d513366ec47007d7e";>8b7b3cb
 Tune the Chinese version of README (https://redirect.github.com/nicksnyder/go-i18n/issues/303";>#303)
   https://github.com/nicksnyder/go-i18n/commit/381afe6807f01999bbbcfbc24d67d2bb61221bd9";>381afe6
 Update GitHub actions (https://redirect.github.com/nicksnyder/go-i18n/issues/300";>#300)
   https://github.com/nicksnyder/go-i18n/commit/cdca9f2e7aba75b3d90375cf331e9dacef57ea60";>cdca9f2
 Fix build (https://redirect.github.com/nicksnyder/go-i18n/issues/299";>#299)
   https://github.com/nicksnyder/go-i18n/commit/719fa821c00ac29ea95d30bbad397335ddd300d6";>719fa82
 goi18n安装命令更新 (https://redirect.github.com/nicksnyder/go-i18n/issues/296";>#296)
   https://github.com/nicksnyder/go-i18n/commit/57ba61f1e59e47c0dff18ae9f7e5b36988a1de94";>57ba61f
 fix comment on MustLoadMessageFile function (https://redirect.github.com/nicksnyder/go-i18n/issues/298";>#298)
   https://github.com/nicksnyder/go-i18n/commit/6bb0339bba40dcdda3a822dbe38cf4bd8c0f680c";>6bb0339
 Update install instructions
   See full diff in https://github.com/nicksnyder/go-i18n/compare/v2.2.1...v2.2.2";>compare 
view
   
   
   
   
   
   [![Dependabot compatibility 
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/nicksnyder/go-i18n/v2&package-manager=go_modules&previous-version=2.2.1&new-version=2.2.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
   
   Dependabot will resolve any conflicts with this PR as long as you don't 
alter it yourself. You can also trigger a rebase manually by commenting 
`@dependabot rebase`.
   
   [//]: # (dependabot-automerge-start)
   [//]: # (dependabot-automerge-end)
   
   ---
   
   
   Dependabot commands and options
   
   
   You can trigger Dependabot actions by commenting on this PR:
   - `@dependabot rebase` will rebas

[tinkerpop] branch dependabot/go_modules/gremlin-go/3.5-dev/github.com/nicksnyder/go-i18n/v2-2.2.2 created (now facbda241f)

2023-10-24 Thread github-bot
This is an automated email from the ASF dual-hosted git repository.

github-bot pushed a change to branch 
dependabot/go_modules/gremlin-go/3.5-dev/github.com/nicksnyder/go-i18n/v2-2.2.2
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


  at facbda241f Bump github.com/nicksnyder/go-i18n/v2 from 2.2.1 to 2.2.2 
in /gremlin-go

No new revisions were added by this update.