imbajin commented on code in PR #3209:
URL: https://github.com/apache/hugegraph/pull/3209#discussion_r4148489474
##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/API.java:
##########
@@ -222,14 +224,42 @@ protected static void checkUpdatingBody(Collection<?
extends Checkable> bodies)
}
@SuppressWarnings("unchecked")
+ /**
+ * Convert each plain filter value to the runtime type of its property
+ * key (a JSON fraction arrives as BigDecimal, an integer literal as
+ * Integer or Long): a DECIMAL value keeps every digit, a DOUBLE value
+ * becomes a double as before. Predicates (P.gt(...)), collections and
+ * values of unknown keys are left as they are.
+ */
+ protected static void normalizeProperties(HugeGraph g, Map<String, Object>
props) {
+ for (Map.Entry<String, Object> entry : props.entrySet()) {
+ Object value = entry.getValue();
+ if (value == null || value instanceof Collection || value
instanceof Map ||
+ value instanceof P) {
Review Comment:
⚠️ Important. VertexAPI.list() and EdgeAPI.list() parse P.eq(...) and range
strings into P before calling this normalizer, so this branch skips them.
TraversalUtil.predicateNumber() then parses fractional operands through
JsonUtil.fromJson(..., Number.class), rounding values such as
P.eq(0.100000000000000001) to Double before DECIMAL comparison. Please parse
predicate operands losslessly or normalize each operand using the property key
type. Evidence: exact-head VertexAPI.list() calls parsePredicate() before
normalizeProperties(); predicateNumber() uses default number deserialization.
##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/API.java:
##########
@@ -222,14 +224,42 @@ protected static void checkUpdatingBody(Collection<?
extends Checkable> bodies)
}
@SuppressWarnings("unchecked")
+ /**
+ * Convert each plain filter value to the runtime type of its property
+ * key (a JSON fraction arrives as BigDecimal, an integer literal as
+ * Integer or Long): a DECIMAL value keeps every digit, a DOUBLE value
+ * becomes a double as before. Predicates (P.gt(...)), collections and
+ * values of unknown keys are left as they are.
+ */
+ protected static void normalizeProperties(HugeGraph g, Map<String, Object>
props) {
+ for (Map.Entry<String, Object> entry : props.entrySet()) {
+ Object value = entry.getValue();
+ if (value == null || value instanceof Collection || value
instanceof Map ||
Review Comment:
⚠️ Important. This normalization breaks multi-valued keys in both
directions: array filters are skipped here, leaving integer members as Integer
instead of matching stored BigDecimal members; scalar filters reach
pkey.validValue() below, which rejects LIST/SET keys that require a collection
even though the existing traversal path wraps scalars for membership. Please
make normalization cardinality-aware, converting each DECIMAL member while
preserving scalar membership behavior. Evidence: DECIMAL LIST/SET values are
supported by PropertyKey, and TraversalUtil.validPropertyValue() wraps scalar
filters for multiple cardinalities.
##########
hugegraph-store/hg-store-core/src/main/java/org/apache/hugegraph/store/business/GraphStoreIterator.java:
##########
@@ -255,6 +256,10 @@ private <P extends BaseProperty<?>> List<Graphpb.Property>
buildProperties(
variant.setType(VariantType.VT_DOUBLE)
.setValueDouble((Double) v);
break;
+ case DECIMAL:
Review Comment:
⚠️ Important. For LIST/SET keys, BaseProperty.value() is a Collection, but
this DECIMAL branch casts the whole value to BigDecimal. A Store scan
containing a multi-valued DECIMAL property therefore throws ClassCastException.
Please encode each collection member in the scan response, or reject this
cardinality for scans if the protocol cannot represent it. Evidence: DECIMAL
LIST/SET keys are supported by PropertyKey, and BaseElement stores their values
as collections.
##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/schema/UserdataDeserializer.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.api.schema;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.hugegraph.api.graph.PropertiesDeserializer;
+import org.apache.hugegraph.schema.Userdata;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
+
+/**
+ * The userdata of a property key read like element properties: a JSON
+ * fraction becomes a BigDecimal with every digit, so a DECIMAL
+ * {@code ~default_value} reaches the property key exactly; everything else
+ * keeps Jackson's default types.
+ */
+public class UserdataDeserializer extends StdDeserializer<Userdata> {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final PropertiesDeserializer PROPERTIES = new
PropertiesDeserializer();
+
+ public UserdataDeserializer() {
+ super(Userdata.class);
+ }
+
+ @Override
+ public Userdata deserialize(JsonParser parser, DeserializationContext
context)
+ throws IOException {
+ Map<String, Object> map = PROPERTIES.deserialize(parser, context);
Review Comment:
⚠️ Important. This deserializes the whole user_data map with the
graph-property parser, so fractions outside ~default_value also become
BigDecimal. PropertyKey only normalizes the default-value key, and the new
JsonUtil serializer writes other BigDecimal values as JSON strings; custom
metadata such as {"rate":0.85} is therefore persisted/read back as
{"rate":"0.85"}. Please restrict exact parsing to ~default_value and preserve
existing number types for other metadata. Evidence: UserdataDeserializer
delegates the complete map to PropertiesDeserializer, whose numeric-float
branch returns BigDecimal; JsonUtil registers a BigDecimal string serializer.
--
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]