-
Notifications
You must be signed in to change notification settings - Fork 624
fix(server): normalize typed DEFAULT_VALUE after JSON reload #3035
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
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fbed962
fix(server): preserve typed DEFAULT_VALUE after JSON reload
dpol1 a0fe682
fix(schema): enforce Set container for SET-cardinality defaults
dpol1 14fa3e3
Merge branch 'master' into fix/3028-preserve-default-value
dpol1 aeb354a
fix(schema): enforce strict validation when converting property key v…
dpol1 dcacd32
test(schema): cover SET defaults through server round trips
dpol1 5481f9e
Address reviewer comments
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
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
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
70 changes: 70 additions & 0 deletions
70
hugegraph-struct/src/test/java/org/apache/hugegraph/struct/schema/PropertyKeyTest.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,70 @@ | ||
| /* | ||
| * 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.struct.schema; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Date; | ||
| import java.util.Set; | ||
|
|
||
| import org.apache.hugegraph.id.IdGenerator; | ||
| import org.apache.hugegraph.type.define.Cardinality; | ||
| import org.apache.hugegraph.type.define.DataType; | ||
| import org.apache.hugegraph.util.DateUtil; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| public class PropertyKeyTest { | ||
|
|
||
| @Test | ||
| public void testDefaultValueNormalizedToDate() { | ||
| // Userdata reloaded from JSON keeps ~default_value as a String; | ||
| // defaultValue() must normalize it to the data type's runtime type | ||
| // (#3028). | ||
| String formatted = "2026-05-14 10:11:12.345"; | ||
| PropertyKey propertyKey = new PropertyKey(null, IdGenerator.of(1), | ||
| "joinDate"); | ||
| propertyKey.dataType(DataType.DATE); | ||
| propertyKey.userdata(Userdata.DEFAULT_VALUE, formatted); | ||
|
|
||
| Object value = propertyKey.defaultValue(); | ||
| Assert.assertTrue("DEFAULT_VALUE should be a Date, was " + | ||
| (value == null ? "null" : value.getClass()), | ||
| value instanceof Date); | ||
| Assert.assertEquals(DateUtil.parse(formatted), value); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetDefaultValueCollapsesDuplicatesAndReturnsSet() { | ||
| String formatted = "2026-05-14 10:11:12.345"; | ||
| PropertyKey propertyKey = new PropertyKey(null, IdGenerator.of(1), | ||
| "joinDate"); | ||
| propertyKey.dataType(DataType.DATE); | ||
| propertyKey.cardinality(Cardinality.SET); | ||
| propertyKey.userdata(Userdata.DEFAULT_VALUE, | ||
| Arrays.asList(formatted, formatted)); | ||
|
|
||
| Object value = propertyKey.defaultValue(); | ||
| Assert.assertTrue("DEFAULT_VALUE should be a Set, was " + | ||
| (value == null ? "null" : value.getClass()), | ||
| value instanceof Set); | ||
|
|
||
| Set<?> values = (Set<?>) value; | ||
| Assert.assertEquals(1, values.size()); | ||
| Assert.assertTrue(values.contains(DateUtil.parse(formatted))); | ||
| } | ||
| } |
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.