dosubot[bot] commented on issue #3028: URL: https://github.com/apache/hugegraph/issues/3028#issuecomment-4459779067
<!-- Answer --> Good question. Here's what `hugegraph-struct`'s `PropertyKey` / `Userdata` actually does and where normalization should live: **Role in the architecture:** `hugegraph-struct`'s `PropertyKey` is used by **hugegraph-store** (the distributed storage layer) to reconstruct schema metadata retrieved from hugegraph-pd. Schema elements are not protobuf messages — they flow as **JSON** through PD's generic KV service [[1]](https://github.com/apache/hugegraph/blob/9126c80e414c073b60fc074361b211cfb409e0eb/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/meta/managers/SchemaMetaManager.java#L73-L122). The store deserializes them via `PropertyKey.fromMap()` [[2]](https://github.com/apache/hugegraph/blob/9126c80e414c073b60fc074361b211cfb409e0eb/hugegraph-struct/src/main/java/org/apache/hugegraph/struct/schema/PropertyKey.java#L591-L627) and then uses the reconstructed `PropertyKey` as a **codec descriptor** to guide binary encoding/decoding of property *values* in RocksDB [[3]](https://github.com/apache/hugegraph/blob/9126c80e414c073b60fc074361b211cfb409e0eb/hugegraph-struct/src/main/java/org/apach e/hugegraph/serializer/BytesBuffer.java#L553-L563). **The conversion path:** ``` hugegraph-core PropertyKey → asMap() → JSON → PD KV store ↓ hugegraph-struct PropertyKey ← fromMap() ← JSON ← PD retrieval ``` There is no direct converter between the two `PropertyKey` classes — conversion is implicit through JSON [[4]](https://github.com/apache/hugegraph/blob/9126c80e414c073b60fc074361b211cfb409e0eb/hugegraph-struct/src/main/java/org/apache/hugegraph/struct/schema/PropertyKey.java#L567-L627). This is the exact point where type information is lost: `fromMap()` stores userdata values as-is from the deserialized `Map<String, Object>`, with no type-aware normalization [[5]](https://github.com/apache/hugegraph/blob/9126c80e414c073b60fc074361b211cfb409e0eb/hugegraph-struct/src/main/java/org/apache/hugegraph/struct/schema/PropertyKey.java#L610-L613). **Where normalization is needed:** Both sides need it, but for different reasons: 1. **hugegraph-core** (server-side): Needed when the server itself reloads schema from backend storage or PD after cache invalidation. The existing serializers (Text/Binary/MySQL/Cassandra) all deserialize userdata into raw maps [[6]](https://github.com/apache/hugegraph/blob/9126c80e414c073b60fc074361b211cfb409e0eb/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BinarySerializer.java#L1230-L1245). This is the same path that causes the `~create_time` issue in #3013. 2. **hugegraph-struct** (store-side): Needed because `PropertyKey.fromMap()` reconstructs from JSON with no type conversion on userdata [[7]](https://github.com/apache/hugegraph/blob/9126c80e414c073b60fc074361b211cfb409e0eb/hugegraph-struct/src/main/java/org/apache/hugegraph/struct/schema/PropertyKey.java#L122-L130). If the store ever calls `defaultValue()` and uses the result — for example to fill missing property values during binary encoding — it would get a raw `String` instead of the expected typed value. **Recommendation:** The normalization should exist in **both** modules, ideally as a shared pattern. The natural location is in `PropertyKey.defaultValue()` itself (or immediately after `fromMap()` sets the data type), since that's where `dataType` is known and can drive the conversion. The struct version already has `validValue()` / `convValue()` methods that do type conversion [[8]](https://github.com/apache/hugegraph/blob/9126c80e414c073b60fc074361b211cfb409e0eb/hugegraph-struct/src/main/java/org/apache/hugegraph/struct/schema/PropertyKey.java#L289-L297) — those could be reused: ```java public Object defaultValue() { Object val = this.userdata().get(Userdata.DEFAULT_VALUE); if (val != null) { val = this.validValue(val); // normalize using dataType } return val; } ``` This avoids duplicating conversion logic and keeps both modules consistent. Since the two `PropertyKey` classes have nearly identical implementations, the same fix pattern applies to both [[9]](https://github.com/apache/hugegraph/blob/9126c80e414c073b60fc074361b211cfb409e0eb/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/schema/PropertyKey.java) [[10]](https://github.com/apache/hugegraph/blob/9126c80e414c073b60fc074361b211cfb409e0eb/hugegraph-struct/src/main/java/org/apache/hugegraph/struct/schema/PropertyKey.java). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fhugegraph).* --- Share context across your team and agents. Try [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-tagline&utm_term=apache%2Fhugegraph). [](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-feedback&utm_term=apache%2Fhugegraph&message_id=1feade92-61dd-43db-927e-c2491d86fd50) [](https://github.dosu.com/apache/hugegraph?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-learn-repo&utm_term=apache%2Fhugegraph) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-add-team&utm_term=apache%2Fhugegraph) -- 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]
