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


##########
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,
+                                                         "country", "cn");
+        traversal.asAdmin().applyStrategies();
+        Assert.assertFalse(traversal.asAdmin().getSteps().stream()
+                                    
.anyMatch(AddPropertyStep.class::isInstance));
+
+        Vertex vertex = traversal.next();
+        commitTx();
+
+        Assert.assertEquals("marko", vertex.value("name"));
+        Assert.assertEquals("cn", vertex.value("country"));
+        Assert.assertEquals(1L, graph().traversal().V()
+                                           .hasLabel(LABEL).count().next());
+    }
+
+    private void assertMetaPropertiesRejected(
+            GraphTraversal<?, Vertex> traversal) {
+        Assert.assertThrows(UnsupportedOperationException.class,
+                            traversal::next,
+                            e -> Assert.assertEquals(
+                                    "Properties on a vertex property is not " +
+                                    "supported",
+                                    e.getMessage()));

Review Comment:
   The test hard-codes the exact exception message string. This is brittle 
across TinkerPop upgrades/patches (message wording and grammar can change) and 
can cause unrelated failures. Prefer asserting against the library-provided 
exception message instead of duplicating the literal.



##########
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:
   HugePrimaryKeyStrategy now throws metaPropertiesNotSupported() for any 
AddPropertyStep parameter other than T.key/T.value. This also changes the error 
for user-supplied vertex-property IDs (T.id) from HugeVertex.property()'s 
userSuppliedIdsNotSupported() to metaPropertiesNotSupported(), which is 
inconsistent with the runtime behavior when the strategy doesn't fold the step.



-- 
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