imbajin commented on code in PR #771:
URL:
https://github.com/apache/hugegraph-toolchain/pull/771#discussion_r4174109401
##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/util/DataTypeUtil.java:
##########
@@ -200,7 +203,17 @@ private static Object parseSingleValue(String key, Object
rawValue,
}
} else if (dataType.isUUID()) {
return parseUUID(key, value);
+ } else if (dataType.isDecimal()) {
+ return parseDecimal(key, value);
} else if (dataType.isText()) {
+ if (value instanceof BigDecimal && fromJsonParser(source)) {
Review Comment:
⚠️ Blocking: yes. Summary: Fractional replacement values in value_mapping
are parsed from the JSON struct as BigDecimal, but this branch decides legacy
text formatting from the row source. With CSV/JDBC input, a configured 1.50
therefore reaches TEXT conversion or idText() as "1.50" instead of the previous
"1.5", changing existing text values and CUSTOMIZE_STRING IDs. Evidence:
JsonValueDeser returns BigDecimal, ElementMapping.mappedValue() returns the
configured object, and fromJsonParser(source) is false for non-JSON row
sources. Please preserve legacy numeric text for mapped TEXT/ID outputs while
keeping DECIMAL outputs exact.
##########
hugegraph-client/src/main/java/org/apache/hugegraph/serializer/BigDecimalSerializer.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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.serializer;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+
+import org.apache.hugegraph.structure.constant.DataType;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+
+/**
+ * Write a BigDecimal as a plain JSON number ("1.10", never "1.1E+2").
+ * Jackson's default is the scientific form of BigDecimal.toString(); the
+ * plain form carries every digit, so a server that reads fractions as
+ * BigDecimal (apache/hugegraph#3209) stores a DECIMAL value exactly, and a
+ * server that reads them as double behaves as it always did. The value stays
+ * a number, so numeric keys (DOUBLE, FLOAT, LONG, INT) accept it too.
+ */
+public class BigDecimalSerializer extends StdSerializer<BigDecimal> {
+
+ private static final long serialVersionUID = 1L;
+
+ public BigDecimalSerializer() {
+ super(BigDecimal.class);
+ }
+
+ @Override
+ public void serialize(BigDecimal value, JsonGenerator generator,
+ SerializerProvider provider) throws IOException {
+ generator.writeNumber(exactString(value));
+ }
+
+ /**
+ * The plain form while the value is within the DECIMAL bounds the server
+ * accepts, else the scientific form: still exact and still a JSON number,
+ * but a value such as 1E+999999999 is not expanded into a billion
+ * characters on the client before the server rejects it.
+ */
+ public static String exactString(BigDecimal value) {
+ int scale = value.scale();
+ if (value.precision() <= DataType.DECIMAL_MAX_PRECISION &&
+ scale >= -DataType.DECIMAL_MAX_SCALE && scale <=
DataType.DECIMAL_MAX_SCALE) {
+ return value.toPlainString();
Review Comment:
⚠️ Blocking: yes. Summary: 1E+128 passes this bound check (precision 1,
scale -128), but toPlainString() emits a 129-digit integer; the server reads
integer tokens as BigInteger and rejects precision 129. Evidence: the client
DataType.valueToDecimal() accepts 1E+128, while apache/hugegraph#3209
PropertiesDeserializer uses getNumberValue() for VALUE_NUMBER_INT and server
DataType.checkDecimalBounds() enforces the 128-digit cap. Please preserve
exponent notation whenever plain expansion exceeds the server precision limit
and add an upper-bound REST serialization test.
--
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]