SebastianGruza commented on code in PR #771:
URL:
https://github.com/apache/hugegraph-toolchain/pull/771#discussion_r4165456337
##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/builder/ElementBuilder.java:
##########
@@ -269,7 +317,7 @@ protected Object mappingValue(String fieldName, Object
fieldValue) {
if (this.mapping().mappingValues().isEmpty()) {
return fieldValue;
}
- String fieldStrValue = String.valueOf(fieldValue);
+ String fieldStrValue = DataTypeUtil.mappingKey(fieldValue,
this.struct.input());
Review Comment:
Right, thanks for the jshell table. The double text is now used only for the
lookup: `ElementMapping.mappedValue()` returns null when no entry matches, and
`DataTypeUtil.mapValue()` then returns the original field value itself (an
identity check, not the lookup string). Test
`testMappedStructKeepsUnmappedDecimal`: a struct with a `value_mapping` on
`city` and a 20-digit JSON decimal loaded into a DECIMAL key, expected exactly
`12345678901234567890.10`.
##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/util/DataTypeUtil.java:
##########
@@ -328,6 +353,59 @@ private static Number parseNumber(String key, Object value,
}
}
+ private static boolean fromJsonParser(InputSource source) {
+ if (source instanceof FileSource) {
+ return ((FileSource) source).format() == FileFormat.JSON;
+ }
+ if (source instanceof KafkaSource) {
+ return ((KafkaSource) source).getFormat() == FileFormat.JSON;
+ }
+ return false;
+ }
+
+ private static boolean withinDecimalBounds(BigDecimal decimal) {
+ try {
+ DataType.checkDecimalBounds(decimal);
+ return true;
+ } catch (IllegalArgumentException e) {
+ return false;
+ }
+ }
+
+ /**
+ * The string a JSON fraction had before it was read as BigDecimal: the
+ * shortest double representation ("1.5" for 1.50, "1.0E-7" for 1e-7).
+ * TEXT values and mapping lookups keep the keys they always had.
Review Comment:
Right. New `DataTypeUtil.idText(value, source)` formats a JSON `BigDecimal`
through `jsonNumberText`; `customizeId()`, `olapVertexId()` and `splitField()`
use it. Test `testJsonFractionIdText`: a CUSTOMIZE_STRING id of `1.50` from a
JSON row gives `1.5`, `1e2` gives `100.0`, as before the PR.
--
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]