imbajin commented on code in PR #3178:
URL: https://github.com/apache/hugegraph/pull/3178#discussion_r3888597808


##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugePrimaryKeyStrategy.java:
##########
@@ -76,25 +77,19 @@ public void apply(Traversal.Admin<?, ?> traversal) {
                 || propertyStep.getCardinality() == null) {
 
                 Object[] kvs = new Object[2];
-                List<Object> kvList = new LinkedList<>();
 
                 propertyStep.getParameters().getRaw().forEach((k, v) -> {
                     if (T.key.equals(k)) {
                         kvs[0] = v.get(0);
                     } else if (T.value.equals(k)) {
                         kvs[1] = v.get(0);
                     } else {
-                        kvList.add(k.toString());
-                        kvList.add(v.get(0));
+                        throw 
VertexProperty.Exceptions.metaPropertiesNotSupported();
                     }

Review Comment:
   ⚠️ Throwing from the strategy makes this validation eager for every child 
traversal. TinkerPop applies strategies to `coalesce()`/`choose()` children 
before branch selection, so an unreachable fallback such as `coalesce(unfold(), 
addV(...).property(..., metaKey, metaValue))` now fails even when `unfold()` 
succeeds. Please leave this `AddPropertyStep` unfolded when extra parameters 
are present and let `HugeVertex.property()` reject it only if that branch 
executes; this also keeps validation behavior centralized.



##########
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/PrimaryKeyStrategyCoreTest.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.hugegraph.core;
+
+import org.apache.hugegraph.schema.SchemaManager;
+import org.apache.hugegraph.testutil.Assert;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import 
org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.AddPropertyStep;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.junit.Test;
+
+public class PrimaryKeyStrategyCoreTest extends BaseCoreTest {
+
+    private static final String LABEL = "person";
+
+    private void initSchema() {
+        SchemaManager schema = graph().schema();
+        schema.propertyKey("name").asText().create();
+        schema.propertyKey("country").asText().create();
+        schema.vertexLabel(LABEL)
+              .properties("name", "country")
+              .primaryKeys("name")
+              .nullableKeys("country")
+              .create();
+    }
+
+    @Test
+    public void testStartStepRejectsMetaProperties() {
+        this.initSchema();
+        GraphTraversal<?, Vertex> traversal = graph().traversal()
+                                                   .addV(LABEL)
+                                                   .property("name", "marko",
+                                                             "country", "cn");
+        this.assertMetaPropertiesRejected(traversal);
+    }
+
+    @Test
+    public void testMidTraversalStepRejectsMetaProperties() {
+        this.initSchema();
+        GraphTraversal<?, Vertex> traversal = graph().traversal()
+                                                   .inject(1)
+                                                   .addV(LABEL)
+                                                   .property("name", "marko",
+                                                             "country", "cn");
+        this.assertMetaPropertiesRejected(traversal);
+    }
+
+    @Test
+    public void testFoldsSingleCardinalityProperties() {
+        this.initSchema();
+
+        GraphTraversal<Vertex, Vertex> traversal = graph().traversal()
+                                                       .addV(LABEL)
+                                                       .property(
+                                                         
VertexProperty.Cardinality.single,
+                                                         "name", "marko")
+                                                       .property(
+                                                         
VertexProperty.Cardinality.single,

Review Comment:
   🧹 Several expressions in this test wrap well before the project's 120-column 
limit. For example, each metadata `property(...)` call is about 99 columns as 
one line, each cardinality call is about 116, the helper signature is about 84, 
and the exception text is about 87. Please use the available width so these 
short expressions remain compact and easier to scan.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to