-
Notifications
You must be signed in to change notification settings - Fork 608
fix(server): keep schema ~create_time as Date after reload #3026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
imbajin
merged 6 commits into
apache:master
from
dpol1:fix/3013-create-time-userdata-roundtrip
May 19, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
62680de
fix(server): restore schema create_time Date
dpol1 11adabf
fix(schema): preserve typed userdata values in struct and default values
dpol1 bc48eec
Merge branch 'master' into fix/3013-create-time-userdata-roundtrip
dpol1 dccc0f0
test(schema): cover userdata constructor normalization
dpol1 8110bc4
refactor(schema): centralize userdata create_time normalization in …
dpol1 1977a44
fix(schema): skip create_time normalization for blank eliminate place…
dpol1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
212 changes: 212 additions & 0 deletions
212
...server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/core/SchemaElementTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,212 @@ | ||
| /* | ||
| * 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.unit.core; | ||
|
|
||
| import java.util.Date; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import org.apache.hugegraph.backend.id.IdGenerator; | ||
| import org.apache.hugegraph.schema.PropertyKey; | ||
| import org.apache.hugegraph.schema.SchemaElement; | ||
| import org.apache.hugegraph.schema.Userdata; | ||
| import org.apache.hugegraph.schema.VertexLabel; | ||
| import org.apache.hugegraph.testutil.Assert; | ||
| import org.apache.hugegraph.unit.FakeObjects; | ||
| import org.apache.hugegraph.util.DateUtil; | ||
| import org.junit.Test; | ||
|
|
||
| public class SchemaElementTest { | ||
|
|
||
| private static SchemaElement newSchema() { | ||
| return new PropertyKey(null, IdGenerator.of(1L), "test"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSingleSetterNormalizesCreateTimeStringToDate() { | ||
| SchemaElement schema = newSchema(); | ||
| String formatted = "2026-05-14 10:11:12.345"; | ||
|
|
||
| schema.userdata(Userdata.CREATE_TIME, formatted); | ||
|
|
||
| Object value = schema.userdata().get(Userdata.CREATE_TIME); | ||
| Assert.assertTrue("CREATE_TIME should be a Date, was " + | ||
| (value == null ? "null" : value.getClass()), | ||
| value instanceof Date); | ||
| Assert.assertEquals(DateUtil.parse(formatted), value); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSingleSetterKeepsCreateTimeDateUnchanged() { | ||
| SchemaElement schema = newSchema(); | ||
| Date now = DateUtil.now(); | ||
|
|
||
| schema.userdata(Userdata.CREATE_TIME, now); | ||
|
|
||
| Assert.assertSame(now, schema.userdata().get(Userdata.CREATE_TIME)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSingleSetterRejectsInvalidCreateTimeString() { | ||
| SchemaElement schema = newSchema(); | ||
|
|
||
| Assert.assertThrows(IllegalArgumentException.class, () -> { | ||
| schema.userdata(Userdata.CREATE_TIME, "not-a-date"); | ||
| }, e -> { | ||
| Assert.assertContains(Userdata.CREATE_TIME, e.getMessage()); | ||
| Assert.assertContains("not-a-date", e.getMessage()); | ||
| Assert.assertNotNull(e.getCause()); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSingleSetterRejectsNullCreateTime() { | ||
| SchemaElement schema = newSchema(); | ||
|
|
||
| Assert.assertThrows(IllegalArgumentException.class, () -> { | ||
| schema.userdata(Userdata.CREATE_TIME, null); | ||
| }, e -> { | ||
| Assert.assertContains("userdata value", e.getMessage()); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSingleSetterPassesThroughBlankCreateTime() { | ||
| // "" is the key-only placeholder for the eliminate()/DELETE builder | ||
| // flow (.userdata(CREATE_TIME, "").eliminate()); it must not be parsed. | ||
| SchemaElement schema = newSchema(); | ||
|
|
||
| schema.userdata(Userdata.CREATE_TIME, ""); | ||
|
|
||
| Object value = schema.userdata().get(Userdata.CREATE_TIME); | ||
| Assert.assertEquals("", value); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSingleSetterLeavesOtherStringKeysUntouched() { | ||
| SchemaElement schema = newSchema(); | ||
|
dpol1 marked this conversation as resolved.
|
||
|
|
||
| schema.userdata("note", "2026-05-14 10:11:12.345"); | ||
|
|
||
| Object value = schema.userdata().get("note"); | ||
| Assert.assertTrue(value instanceof String); | ||
| Assert.assertEquals("2026-05-14 10:11:12.345", value); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUserdataConstructorNormalizesCreateTimeString() { | ||
| String formatted = "2026-05-14 10:11:12.345"; | ||
| Map<String, Object> map = new HashMap<>(); | ||
| map.put(Userdata.CREATE_TIME, formatted); | ||
|
|
||
| Userdata userdata = new Userdata(map); | ||
|
|
||
| Object createTime = userdata.get(Userdata.CREATE_TIME); | ||
| Assert.assertTrue(createTime instanceof Date); | ||
| Assert.assertEquals(DateUtil.parse(formatted), | ||
| createTime); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUserdataConstructorLeavesOtherEntriesUntouched() { | ||
| Map<String, Object> map = new HashMap<>(); | ||
| map.put("note", "2026-05-14 10:11:12.345"); | ||
| map.put("count", 42); | ||
|
|
||
| Userdata userdata = new Userdata(map); | ||
|
|
||
| Assert.assertEquals("2026-05-14 10:11:12.345", | ||
| userdata.get("note")); | ||
| Assert.assertEquals(42, userdata.get("count")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUserdataConstructorRejectsInvalidCreateTimeString() { | ||
| Map<String, Object> map = new HashMap<>(); | ||
| map.put(Userdata.CREATE_TIME, "not-a-date"); | ||
|
|
||
| Assert.assertThrows(IllegalArgumentException.class, () -> { | ||
| new Userdata(map); | ||
| }, e -> { | ||
| Assert.assertContains(Userdata.CREATE_TIME, e.getMessage()); | ||
| Assert.assertContains("not-a-date", e.getMessage()); | ||
| Assert.assertNotNull(e.getCause()); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBulkSetterNormalizesCreateTimeAndKeepsOtherEntries() { | ||
| SchemaElement schema = newSchema(); | ||
| Userdata bulk = new Userdata(); | ||
| String formatted = "2026-05-14 10:11:12.345"; | ||
| bulk.put(Userdata.CREATE_TIME, formatted); | ||
| bulk.put("note", "hello"); | ||
| bulk.put("count", 42); | ||
|
|
||
| schema.userdata(bulk); | ||
|
|
||
| Object createTime = schema.userdata().get(Userdata.CREATE_TIME); | ||
| Assert.assertTrue(createTime instanceof Date); | ||
| Assert.assertEquals(DateUtil.parse(formatted), createTime); | ||
| Assert.assertEquals("hello", schema.userdata().get("note")); | ||
| Assert.assertEquals(42, schema.userdata().get("count")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBulkSetterKeepsCreateTimeDateUnchanged() { | ||
| SchemaElement schema = newSchema(); | ||
| Userdata bulk = new Userdata(); | ||
| Date now = DateUtil.now(); | ||
| bulk.put(Userdata.CREATE_TIME, now); | ||
|
|
||
| schema.userdata(bulk); | ||
|
|
||
| Assert.assertSame(now, schema.userdata().get(Userdata.CREATE_TIME)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testVertexLabelFromMapNormalizesCreateTimeString() { | ||
| String formatted = "2026-05-14 10:11:12.345"; | ||
| Map<String, Object> userdata = new HashMap<>(); | ||
| userdata.put(Userdata.CREATE_TIME, formatted); | ||
|
|
||
| Map<String, Object> map = new HashMap<>(); | ||
| map.put(VertexLabel.P.ID, 1); | ||
| map.put(VertexLabel.P.NAME, "person"); | ||
| map.put(VertexLabel.P.USERDATA, userdata); | ||
|
|
||
| VertexLabel vertexLabel = VertexLabel.fromMap(map, | ||
| new FakeObjects().graph()); | ||
|
|
||
| Object createTime = vertexLabel.userdata().get(Userdata.CREATE_TIME); | ||
| Assert.assertTrue(createTime instanceof Date); | ||
| Assert.assertEquals(DateUtil.parse(formatted), | ||
| createTime); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBulkSetterRejectsNullUserdata() { | ||
| SchemaElement schema = newSchema(); | ||
|
|
||
| Assert.assertThrows(IllegalArgumentException.class, () -> { | ||
| schema.userdata(null); | ||
| }, e -> { | ||
| Assert.assertContains("userdata", e.getMessage()); | ||
| }); | ||
| } | ||
|
dpol1 marked this conversation as resolved.
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.