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

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

spmallette commented on code in PR #1843:
URL: https://github.com/apache/tinkerpop/pull/1843#discussion_r1017863078


##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/DetachStrategy.java:
##########
@@ -0,0 +1,186 @@
+/*
+ * 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.strategy.finalization;
+
+import org.apache.commons.configuration2.Configuration;
+import org.apache.commons.configuration2.MapConfiguration;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.ScalarMapStep;
+import 
org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.ProfileSideEffectStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
+import 
org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * A strategy that manages the properties that will be in the result.
+ *
+ * @author Valentyn Kahamlyk
+ */
+public final class DetachStrategy extends 
AbstractTraversalStrategy<TraversalStrategy.FinalizationStrategy> implements 
TraversalStrategy.FinalizationStrategy {
+
+    private static final DetachStrategy INSTANCE = new 
DetachStrategy(DetachMode.ALL, null);
+    private DetachMode detachMode = DetachMode.ALL;
+    private List<String> properties;
+
+    private DetachStrategy() {}
+
+    private DetachStrategy(final DetachMode detachMode, final List<String> 
properties) {
+        this.detachMode = detachMode;
+        this.properties = properties;
+    }
+
+    private DetachStrategy(final Builder builder) {
+        this(builder.detachMode, builder.properties);
+    }
+
+    @Override
+    public void apply(final Traversal.Admin<?, ?> traversal) {
+        if (traversal.getParent() == EmptyStep.instance()) {
+            final Optional<ProfileSideEffectStep> profileStep = 
TraversalHelper.getFirstStepOfAssignableClass(ProfileSideEffectStep.class, 
traversal);
+            final int index = profileStep.map(step -> 
traversal.getSteps().indexOf(step))
+                    .orElseGet(() -> traversal.getSteps().size());
+            traversal.addStep(index,
+                    new DetachElementStep<>(traversal, new 
DetachOptions(detachMode, properties)));
+        }
+    }
+
+    public static DetachStrategy create(final Configuration configuration) {
+        return new 
DetachStrategy(DetachMode.valueOf(configuration.getString(ID_MODE)),
+                new ArrayList<>((Collection<String>) 
configuration.getProperty(ID_PROPERTIES)));
+    }
+
+    /**
+     * Gets the standard configuration of this strategy that will return all 
properties.
+     */
+    public static DetachStrategy instance() {
+        return INSTANCE;
+    }
+
+    public static final String ID_MODE = "detachMode";
+    public static final String ID_PROPERTIES = "properties";
+
+    @Override
+    public Configuration getConfiguration() {
+        final Map<String, Object> map = new HashMap<>();
+        map.put(STRATEGY, DetachStrategy.class.getCanonicalName());
+        map.put(ID_MODE, this.detachMode.toString());
+        map.put(ID_PROPERTIES, this.properties);
+        return new MapConfiguration(map);
+    }
+
+    public enum DetachMode {

Review Comment:
   we do have a precedent for using integer constants for `with()`-step: 
https://github.com/apache/tinkerpop/blob/master/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/WithOptions.java
 
   
   maybe we should follow that pattern here and save the serialization 
expansion. maybe the rule is to save enum for core language elements, like 
`Scope`, `Direction`, etc.





> Properties on Elements
> ----------------------
>
>                 Key: TINKERPOP-2824
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2824
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: dotnet, driver, go, javascript, process, python
>    Affects Versions: 3.5.4
>            Reporter: Valentyn Kahamlyk
>            Assignee: Valentyn Kahamlyk
>            Priority: Major
>             Fix For: 3.7.0
>
>
> Problem: When a user writes `g.V()` they get back a Vertex object. The 
> problem is that depending on the execution context of the traversal, the 
> result could be quite different, with or without properties.
> Solution: Implement new finalization strategy DetachStrategy(detachMode, 
> properties) where mode is one of ALL, NONE or CUSTOM. `properties` is list of 
> properties name, are taken into account only for CUSTOM mode.
> Discussion thread in dev list: [Proposal to handle properties on response 
> Elements-Apache Mail 
> Archives|https://lists.apache.org/thread/l8rw7ydj7kym8vhtwk50nhbp45ng9986]
> Stephen's thread in dev list: [The Issue of Detachment-Apache Mail 
> Archives|https://lists.apache.org/thread/xltcon4zxnwq4fyw2r2126syyrqm8spy]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to