From e4a41a97f16abf1c0c8ddc72bb59de63b5fc3603 Mon Sep 17 00:00:00 2001 From: yxk485490 <1320342065@qq.com> Date: Mon, 29 Sep 2025 15:00:50 +0800 Subject: [PATCH 1/6] add multi labels --- .../org/apache/graphar/info/VertexInfo.java | 39 +++- .../info/loader/BaseGraphInfoLoader.java | 1 + .../info/saver/BaseGraphInfoSaver.java | 14 ++ .../graphar/info/yaml/PropertyYaml.java | 10 + .../apache/graphar/info/yaml/VertexYaml.java | 14 ++ .../apache/graphar/info/GraphInfoTest.java | 1 + .../org/apache/graphar/info/TestUtil.java | 9 + .../graphar/info/TestVerificationUtils.java | 2 + .../graphar/info/VertexInfoLabelsTest.java | 180 ++++++++++++++++++ 9 files changed, 267 insertions(+), 3 deletions(-) create mode 100644 maven-projects/info/src/test/java/org/apache/graphar/info/VertexInfoLabelsTest.java diff --git a/maven-projects/info/src/main/java/org/apache/graphar/info/VertexInfo.java b/maven-projects/info/src/main/java/org/apache/graphar/info/VertexInfo.java index b4a14c5ee..b46d9997b 100644 --- a/maven-projects/info/src/main/java/org/apache/graphar/info/VertexInfo.java +++ b/maven-projects/info/src/main/java/org/apache/graphar/info/VertexInfo.java @@ -21,6 +21,7 @@ import java.io.Writer; import java.net.URI; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Optional; @@ -34,6 +35,7 @@ public class VertexInfo { private final String type; private final long chunkSize; private final PropertyGroups propertyGroups; + private final List labels; private final URI baseUri; private final VersionInfo version; @@ -43,22 +45,43 @@ public VertexInfo( List propertyGroups, String prefix, String version) { - this(type, chunkSize, propertyGroups, URI.create(prefix), version); + this(type, chunkSize, propertyGroups, Collections.emptyList(), URI.create(prefix), version); } public VertexInfo( String type, long chunkSize, List propertyGroups, + List labels, + String prefix, + String version) { + this(type, chunkSize, propertyGroups, labels, URI.create(prefix), version); + } + + public VertexInfo( + String type, + long chunkSize, + List propertyGroups, + URI baseUri, + String version) { + this(type, chunkSize, propertyGroups, Collections.emptyList(), baseUri, version); + } + + public VertexInfo( + String type, + long chunkSize, + List propertyGroups, + List labels, URI baseUri, String version) { - this(type, chunkSize, propertyGroups, baseUri, VersionParser.getVersion(version)); + this(type, chunkSize, propertyGroups, labels, baseUri, VersionParser.getVersion(version)); } public VertexInfo( String type, long chunkSize, List propertyGroups, + List labels, URI baseUri, VersionInfo version) { if (chunkSize < 0) { @@ -67,6 +90,7 @@ public VertexInfo( this.type = type; this.chunkSize = chunkSize; this.propertyGroups = new PropertyGroups(propertyGroups); + this.labels = labels == null ? Collections.emptyList() : List.copyOf(labels); this.baseUri = baseUri; this.version = version; } @@ -78,7 +102,12 @@ public Optional addPropertyGroupAsNew(PropertyGroup propertyGroup) { .map( newPropertyGroups -> new VertexInfo( - type, chunkSize, newPropertyGroups, baseUri, version)); + type, + chunkSize, + newPropertyGroups, + labels, + baseUri, + version)); } public int getPropertyGroupNum() { @@ -143,6 +172,10 @@ public long getChunkSize() { return chunkSize; } + public List getLabels() { + return labels; + } + public List getPropertyGroups() { return propertyGroups.getPropertyGroupList(); } diff --git a/maven-projects/info/src/main/java/org/apache/graphar/info/loader/BaseGraphInfoLoader.java b/maven-projects/info/src/main/java/org/apache/graphar/info/loader/BaseGraphInfoLoader.java index 504633736..e5767b946 100644 --- a/maven-projects/info/src/main/java/org/apache/graphar/info/loader/BaseGraphInfoLoader.java +++ b/maven-projects/info/src/main/java/org/apache/graphar/info/loader/BaseGraphInfoLoader.java @@ -76,6 +76,7 @@ protected VertexInfo buildVertexInfoFromVertexYaml(VertexYaml vertexYaml) { vertexYaml.getProperty_groups().stream() .map(PropertyGroupYaml::toPropertyGroup) .collect(Collectors.toList()), + vertexYaml.getLabels(), vertexYaml.getPrefix(), vertexYaml.getVersion()); } diff --git a/maven-projects/info/src/main/java/org/apache/graphar/info/saver/BaseGraphInfoSaver.java b/maven-projects/info/src/main/java/org/apache/graphar/info/saver/BaseGraphInfoSaver.java index a59bdcc7b..5da7f3454 100644 --- a/maven-projects/info/src/main/java/org/apache/graphar/info/saver/BaseGraphInfoSaver.java +++ b/maven-projects/info/src/main/java/org/apache/graphar/info/saver/BaseGraphInfoSaver.java @@ -32,6 +32,11 @@ public abstract class BaseGraphInfoSaver implements GraphInfoSaver { @Override public void save(URI graphInfoUri, GraphInfo graphInfo) throws IOException { + // if graphInfoUri is a directory then save to ${graphInfo.name}.graph.yml + if (graphInfoUri.getPath().endsWith("/")) { + graphInfoUri = + URI.create(graphInfoUri.toString() + graphInfo.getName() + ".graph.yaml"); + } Writer writer = writeYaml(graphInfoUri); graphInfo.dump(graphInfoUri, writer); writer.close(); @@ -48,6 +53,11 @@ public void save(URI graphInfoUri, GraphInfo graphInfo) throws IOException { @Override public void save(URI vertexInfoUri, VertexInfo vertexInfo) throws IOException { + // if vertexInfoUri is a directory then save to ${vertexInfo.type}.vertex.yml + if (vertexInfoUri.getPath().endsWith("/")) { + vertexInfoUri = + URI.create(vertexInfoUri.toString() + vertexInfo.getType() + ".vertex.yaml"); + } Writer vertexWriter = writeYaml(vertexInfoUri); vertexInfo.dump(vertexWriter); vertexWriter.close(); @@ -55,6 +65,10 @@ public void save(URI vertexInfoUri, VertexInfo vertexInfo) throws IOException { @Override public void save(URI edgeInfoUri, EdgeInfo edgeInfo) throws IOException { + // if edgeInfoUri is a directory then save to ${edgeInfo.getConcat()}.edge.yml + if (edgeInfoUri.getPath().endsWith("/")) { + edgeInfoUri = URI.create(edgeInfoUri.toString() + edgeInfo.getConcat() + ".edge.yaml"); + } Writer edgeWriter = writeYaml(edgeInfoUri); edgeInfo.dump(edgeWriter); edgeWriter.close(); diff --git a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/PropertyYaml.java b/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/PropertyYaml.java index ee98a339d..8e63263a9 100644 --- a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/PropertyYaml.java +++ b/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/PropertyYaml.java @@ -28,12 +28,14 @@ public class PropertyYaml { private String data_type; private boolean is_primary; private Optional is_nullable; + private String cardinality; public PropertyYaml() { this.name = ""; this.data_type = ""; this.is_primary = false; this.is_nullable = Optional.empty(); + this.cardinality = "single"; // Default to single } public PropertyYaml(Property property) { @@ -82,4 +84,12 @@ public boolean getIs_nullable() { public void setIs_nullable(boolean is_nullable) { this.is_nullable = Optional.of(is_nullable); } + + public String getCardinality() { + return this.cardinality; + } + + public void setCardinality(String cardinality) { + this.cardinality = cardinality; + } } diff --git a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/VertexYaml.java b/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/VertexYaml.java index 345e0369e..eaa8a91e9 100644 --- a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/VertexYaml.java +++ b/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/VertexYaml.java @@ -30,6 +30,7 @@ public class VertexYaml { private String type; private long chunk_size; private List property_groups; + private List labels; private String prefix; private String version; @@ -37,6 +38,7 @@ public VertexYaml() { this.type = ""; this.chunk_size = 0; this.property_groups = new ArrayList<>(); + this.labels = null; this.prefix = ""; this.version = ""; } @@ -48,6 +50,7 @@ public VertexYaml(VertexInfo vertexInfo) { vertexInfo.getPropertyGroups().stream() .map(PropertyGroupYaml::new) .collect(Collectors.toList()); + this.labels = vertexInfo.getLabels(); this.prefix = vertexInfo.getPrefix(); this.version = Optional.of(vertexInfo) @@ -80,6 +83,17 @@ public void setProperty_groups(List property_groups) { this.property_groups = property_groups; } + public List getLabels() { + if (labels == null) { + return null; + } + return labels.isEmpty() ? null : labels; + } + + public void setLabels(List labels) { + this.labels = labels; + } + public String getPrefix() { return prefix; } diff --git a/maven-projects/info/src/test/java/org/apache/graphar/info/GraphInfoTest.java b/maven-projects/info/src/test/java/org/apache/graphar/info/GraphInfoTest.java index b4ade7188..2d1a82eca 100644 --- a/maven-projects/info/src/test/java/org/apache/graphar/info/GraphInfoTest.java +++ b/maven-projects/info/src/test/java/org/apache/graphar/info/GraphInfoTest.java @@ -115,6 +115,7 @@ public void testGraphInfoBasics() { public void testPersonVertexInfoBasics() { VertexInfo personVertexInfo = graphInfo.getVertexInfos().get(0); Assert.assertEquals("person", personVertexInfo.getType()); + Assert.assertTrue(personVertexInfo.getLabels().isEmpty()); Assert.assertEquals(100, personVertexInfo.getChunkSize()); Assert.assertEquals("vertex/person/", personVertexInfo.getPrefix()); Assert.assertEquals(URI.create("vertex/person/"), personVertexInfo.getBaseUri()); diff --git a/maven-projects/info/src/test/java/org/apache/graphar/info/TestUtil.java b/maven-projects/info/src/test/java/org/apache/graphar/info/TestUtil.java index 880c60053..0b7033437 100644 --- a/maven-projects/info/src/test/java/org/apache/graphar/info/TestUtil.java +++ b/maven-projects/info/src/test/java/org/apache/graphar/info/TestUtil.java @@ -38,6 +38,7 @@ public class TestUtil { System.getProperty("test.output.dir", "target/test-output") + "/"; private static final String LDBC_SAMPLE_GRAPH_PATH = "/ldbc_sample/csv/ldbc_sample.graph.yml"; + private static final String LDBC_GRAPH_PATH = "/ldbc/parquet/ldbc.graph.yml"; public static String getTestData() { return GAR_TEST_DATA; @@ -56,6 +57,14 @@ public static URI getLdbcSampleGraphURI() { return URI.create(getLdbcSampleGraphPath()); } + public static String getLdbcGraphPath() { + return getTestData() + "/" + LDBC_GRAPH_PATH; + } + + public static URI getLdbcGraphURI() { + return URI.create(getLdbcGraphPath()); + } + public static VertexInfo buildVertexInfoFromYaml(VertexYaml vertexYaml) { return new VertexInfo( vertexYaml.getType(), diff --git a/maven-projects/info/src/test/java/org/apache/graphar/info/TestVerificationUtils.java b/maven-projects/info/src/test/java/org/apache/graphar/info/TestVerificationUtils.java index fe09e6e62..b4063f20e 100644 --- a/maven-projects/info/src/test/java/org/apache/graphar/info/TestVerificationUtils.java +++ b/maven-projects/info/src/test/java/org/apache/graphar/info/TestVerificationUtils.java @@ -234,6 +234,8 @@ public static boolean equalsVertexInfo(VertexInfo expected, VertexInfo actual) { return false; } + Assert.assertEquals("VertexInfo labels mismatch", expected.getLabels(), actual.getLabels()); + Assert.assertEquals("VertexInfo type mismatch", expected.getType(), actual.getType()); Assert.assertEquals( "VertexInfo chunk size mismatch", expected.getChunkSize(), actual.getChunkSize()); diff --git a/maven-projects/info/src/test/java/org/apache/graphar/info/VertexInfoLabelsTest.java b/maven-projects/info/src/test/java/org/apache/graphar/info/VertexInfoLabelsTest.java new file mode 100644 index 000000000..4c99475b9 --- /dev/null +++ b/maven-projects/info/src/test/java/org/apache/graphar/info/VertexInfoLabelsTest.java @@ -0,0 +1,180 @@ +/* + * 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.graphar.info; + +import java.io.IOException; +import java.net.URI; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.apache.graphar.info.loader.GraphInfoLoader; +import org.apache.graphar.info.loader.impl.LocalFileSystemStringGraphInfoLoader; +import org.apache.graphar.info.saver.GraphInfoSaver; +import org.apache.graphar.info.saver.impl.LocalFileSystemYamlGraphSaver; +import org.apache.graphar.info.type.DataType; +import org.apache.graphar.info.type.FileType; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class VertexInfoLabelsTest extends BaseFileSystemTest { + + private String testSaveDirectory; + private GraphInfoSaver graphInfoSaver; + private GraphInfoLoader graphInfoLoader; + + @Before + public void setUp() { + testSaveDirectory = createCleanTestDirectory("ldbc_multi_labels_sample/"); + graphInfoSaver = new LocalFileSystemYamlGraphSaver(); + graphInfoLoader = new LocalFileSystemStringGraphInfoLoader(); + } + + @After + public void tearDown() { + // Test data will be preserved for debugging - cleanup happens before next test run + System.out.println("Test data saved in: " + testSaveDirectory); + } + + @Test + public void testVertexInfoWithLabels() throws IOException { + // Create property group + Property property = new Property("id", DataType.INT32, true, false); + PropertyGroup propertyGroup = + new PropertyGroup(Collections.singletonList(property), FileType.PARQUET, "test/"); + + // Create labels + List labels = Arrays.asList("Person", "Employee", "User"); + + // Create vertex info with labels + VertexInfo vertexInfo = + new VertexInfo( + "person", + 100L, + Collections.singletonList(propertyGroup), + labels, + "vertex/person/", + "gar/v1"); + + // Test getters + Assert.assertEquals("person", vertexInfo.getType()); + Assert.assertEquals(100L, vertexInfo.getChunkSize()); + Assert.assertEquals(labels, vertexInfo.getLabels()); + Assert.assertEquals("vertex/person/", vertexInfo.getPrefix()); + Assert.assertEquals("gar/v1", vertexInfo.getVersion().toString()); + + // Test property group related methods + Assert.assertEquals(1, vertexInfo.getPropertyGroupNum()); + Assert.assertTrue(vertexInfo.hasProperty("id")); + Assert.assertTrue(vertexInfo.isPrimaryKey("id")); + Assert.assertFalse(vertexInfo.isNullableKey("id")); + + // Test validation + Assert.assertTrue(vertexInfo.isValidated()); + + // Test dump + graphInfoSaver.save(URI.create(testSaveDirectory), vertexInfo); + // test load + VertexInfo loadedVertexInfo = + graphInfoLoader.loadVertexInfo( + URI.create(testSaveDirectory + "person.vertex.yaml")); + Assert.assertTrue(TestVerificationUtils.equalsVertexInfo(vertexInfo, loadedVertexInfo)); + } + + @Test + public void testVertexInfoWithoutLabels() throws IOException { + // Create property group + Property property = new Property("id", DataType.INT32, true, false); + PropertyGroup propertyGroup = + new PropertyGroup(Collections.singletonList(property), FileType.PARQUET, "test/"); + + // Create vertex info without labels (using old constructor) + VertexInfo vertexInfo = + new VertexInfo( + "person", + 100L, + Collections.singletonList(propertyGroup), + "vertex/person/", + "gar/v1"); + + // Test that labels list is empty but not null + Assert.assertEquals("person", vertexInfo.getType()); + Assert.assertEquals(100L, vertexInfo.getChunkSize()); + Assert.assertNotNull(vertexInfo.getLabels()); + Assert.assertTrue(vertexInfo.getLabels().isEmpty()); + Assert.assertEquals("vertex/person/", vertexInfo.getPrefix()); + + // Test validation + Assert.assertTrue(vertexInfo.isValidated()); + // Test dump + graphInfoSaver.save(URI.create(testSaveDirectory), vertexInfo); + // test load + VertexInfo loadedVertexInfo = + graphInfoLoader.loadVertexInfo( + URI.create(testSaveDirectory + "person.vertex.yaml")); + Assert.assertTrue(TestVerificationUtils.equalsVertexInfo(vertexInfo, loadedVertexInfo)); + } + + @Test + public void testVertexInfoWithEmptyLabels() throws IOException { + // Create property group + Property property = new Property("id", DataType.INT32, true, false); + PropertyGroup propertyGroup = + new PropertyGroup(Collections.singletonList(property), FileType.PARQUET, "test/"); + + // Create vertex info with empty labels + VertexInfo vertexInfo = + new VertexInfo( + "person", + 100L, + Collections.singletonList(propertyGroup), + Collections.emptyList(), + "vertex/person/", + "gar/v1"); + + // Test that labels list is empty but not null + Assert.assertEquals("person", vertexInfo.getType()); + Assert.assertEquals(100L, vertexInfo.getChunkSize()); + Assert.assertNotNull(vertexInfo.getLabels()); + Assert.assertTrue(vertexInfo.getLabels().isEmpty()); + Assert.assertEquals("vertex/person/", vertexInfo.getPrefix()); + + // Test validation + Assert.assertTrue(vertexInfo.isValidated()); // Test dump + graphInfoSaver.save(URI.create(testSaveDirectory), vertexInfo); + // test load + VertexInfo loadedVertexInfo = + graphInfoLoader.loadVertexInfo( + URI.create(testSaveDirectory + "person.vertex.yaml")); + Assert.assertTrue(TestVerificationUtils.equalsVertexInfo(vertexInfo, loadedVertexInfo)); + } + + @Test + public void testLoadFromTestData() throws IOException { + URI GRAPH_PATH_URI = TestUtil.getLdbcGraphURI(); + GraphInfo graphInfo = graphInfoLoader.loadGraphInfo(GRAPH_PATH_URI); + VertexInfo placeInfo = graphInfo.getVertexInfo("place"); + VertexInfo organisationInfo = graphInfo.getVertexInfo("organisation"); + Assert.assertEquals(List.of("city", "country", "continent"), placeInfo.getLabels()); + Assert.assertEquals( + List.of("university", "company", "public"), organisationInfo.getLabels()); + } +} From db726f79ff7e1b1d31102853b13afc6aef63301a Mon Sep 17 00:00:00 2001 From: yxk485490 <1320342065@qq.com> Date: Fri, 17 Oct 2025 15:00:13 +0800 Subject: [PATCH 2/6] fix --- .../org/apache/graphar/info/VertexInfo.java | 55 +++++++++++++------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/maven-projects/info/src/main/java/org/apache/graphar/info/VertexInfo.java b/maven-projects/info/src/main/java/org/apache/graphar/info/VertexInfo.java index 6c6565e7e..9c1072f4e 100644 --- a/maven-projects/info/src/main/java/org/apache/graphar/info/VertexInfo.java +++ b/maven-projects/info/src/main/java/org/apache/graphar/info/VertexInfo.java @@ -50,9 +50,11 @@ public static class VertexInfoBuilder { private PropertyGroups propertyGroups; private URI baseUri; private VersionInfo version; + private List labels; private List propertyGroupsAsListTemp; - private VertexInfoBuilder() {} + private VertexInfoBuilder() { + } public VertexInfoBuilder type(String type) { this.type = type; @@ -88,6 +90,19 @@ public VertexInfoBuilder version(String version) { return this; } + public VertexInfoBuilder labels(List labels) { + this.labels = labels; + return this; + } + + public VertexInfoBuilder addLabel(String label) { + if (labels == null) { + labels = new ArrayList<>(); + } + labels.add(label); + return this; + } + public VertexInfoBuilder addPropertyGroup(PropertyGroup propertyGroup) { if (propertyGroupsAsListTemp == null) { propertyGroupsAsListTemp = new ArrayList<>(); @@ -110,16 +125,23 @@ public VertexInfoBuilder propertyGroups(PropertyGroups propertyGroups) { } public VertexInfo build() { + if (type == null || type.isEmpty()) { + throw new IllegalArgumentException("Type cannot be null or empty"); + } + + if (labels == null) { + labels = Collections.emptyList(); + } + if (propertyGroups == null && propertyGroupsAsListTemp != null) { propertyGroups = new PropertyGroups(propertyGroupsAsListTemp); } else if (propertyGroupsAsListTemp != null) { - propertyGroups = - propertyGroupsAsListTemp.stream() - .map(propertyGroups::addPropertyGroupAsNew) - .filter(Optional::isPresent) - .map(Optional::get) - .reduce((first, second) -> second) - .orElse(new PropertyGroups(new ArrayList<>())); + propertyGroups = propertyGroupsAsListTemp.stream() + .map(propertyGroups::addPropertyGroupAsNew) + .filter(Optional::isPresent) + .map(Optional::get) + .reduce((first, second) -> second) + .orElse(new PropertyGroups(new ArrayList<>())); } if (chunkSize < 0) { @@ -128,6 +150,7 @@ public VertexInfo build() { if (baseUri == null) { throw new IllegalArgumentException("Base URI cannot be null"); } + return new VertexInfo(this); } } @@ -135,6 +158,7 @@ public VertexInfo build() { private VertexInfo(VertexInfoBuilder builder) { this.type = builder.type; this.chunkSize = builder.chunkSize; + this.labels = builder.labels; this.propertyGroups = builder.propertyGroups; this.baseUri = builder.baseUri; this.version = builder.version; @@ -201,14 +225,13 @@ public Optional addPropertyGroupAsNew(PropertyGroup propertyGroup) { .addPropertyGroupAsNew(propertyGroup) .map(PropertyGroups::getPropertyGroupList) .map( - newPropertyGroups -> - new VertexInfo( - type, - chunkSize, - newPropertyGroups, - labels, - baseUri, - version)); + newPropertyGroups -> new VertexInfo( + type, + chunkSize, + newPropertyGroups, + labels, + baseUri, + version)); } public int getPropertyGroupNum() { From 59c6a80fda8420bd01047d56ef19ffbd1795164a Mon Sep 17 00:00:00 2001 From: yxk485490 <1320342065@qq.com> Date: Fri, 17 Oct 2025 15:01:14 +0800 Subject: [PATCH 3/6] format --- .../org/apache/graphar/info/VertexInfo.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/maven-projects/info/src/main/java/org/apache/graphar/info/VertexInfo.java b/maven-projects/info/src/main/java/org/apache/graphar/info/VertexInfo.java index 9c1072f4e..f74d612e7 100644 --- a/maven-projects/info/src/main/java/org/apache/graphar/info/VertexInfo.java +++ b/maven-projects/info/src/main/java/org/apache/graphar/info/VertexInfo.java @@ -53,8 +53,7 @@ public static class VertexInfoBuilder { private List labels; private List propertyGroupsAsListTemp; - private VertexInfoBuilder() { - } + private VertexInfoBuilder() {} public VertexInfoBuilder type(String type) { this.type = type; @@ -136,12 +135,13 @@ public VertexInfo build() { if (propertyGroups == null && propertyGroupsAsListTemp != null) { propertyGroups = new PropertyGroups(propertyGroupsAsListTemp); } else if (propertyGroupsAsListTemp != null) { - propertyGroups = propertyGroupsAsListTemp.stream() - .map(propertyGroups::addPropertyGroupAsNew) - .filter(Optional::isPresent) - .map(Optional::get) - .reduce((first, second) -> second) - .orElse(new PropertyGroups(new ArrayList<>())); + propertyGroups = + propertyGroupsAsListTemp.stream() + .map(propertyGroups::addPropertyGroupAsNew) + .filter(Optional::isPresent) + .map(Optional::get) + .reduce((first, second) -> second) + .orElse(new PropertyGroups(new ArrayList<>())); } if (chunkSize < 0) { @@ -225,13 +225,14 @@ public Optional addPropertyGroupAsNew(PropertyGroup propertyGroup) { .addPropertyGroupAsNew(propertyGroup) .map(PropertyGroups::getPropertyGroupList) .map( - newPropertyGroups -> new VertexInfo( - type, - chunkSize, - newPropertyGroups, - labels, - baseUri, - version)); + newPropertyGroups -> + new VertexInfo( + type, + chunkSize, + newPropertyGroups, + labels, + baseUri, + version)); } public int getPropertyGroupNum() { From 546ee66b525a8569a33bbbfdf6e78fa0013b6af4 Mon Sep 17 00:00:00 2001 From: yxk485490 <1320342065@qq.com> Date: Mon, 8 Dec 2025 19:04:01 +0800 Subject: [PATCH 4/6] update --- .../main/java/org/apache/graphar/info/yaml/PropertyYaml.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/PropertyYaml.java b/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/PropertyYaml.java index 8e63263a9..ea586b392 100644 --- a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/PropertyYaml.java +++ b/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/PropertyYaml.java @@ -35,7 +35,7 @@ public PropertyYaml() { this.data_type = ""; this.is_primary = false; this.is_nullable = Optional.empty(); - this.cardinality = "single"; // Default to single + this.cardinality = null; } public PropertyYaml(Property property) { From 52506dd0d8cfafbde8929773fc9c257da6bbe70a Mon Sep 17 00:00:00 2001 From: yxk485490 <1320342065@qq.com> Date: Mon, 8 Dec 2025 19:08:38 +0800 Subject: [PATCH 5/6] fix --- .../graphar/info/saver/BaseGraphInfoSaver.java | 7 +++---- .../apache/graphar/info/VertexInfoLabelsTest.java | 12 +++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/maven-projects/info/src/main/java/org/apache/graphar/info/saver/BaseGraphInfoSaver.java b/maven-projects/info/src/main/java/org/apache/graphar/info/saver/BaseGraphInfoSaver.java index 5da7f3454..680b877b7 100644 --- a/maven-projects/info/src/main/java/org/apache/graphar/info/saver/BaseGraphInfoSaver.java +++ b/maven-projects/info/src/main/java/org/apache/graphar/info/saver/BaseGraphInfoSaver.java @@ -34,8 +34,7 @@ public abstract class BaseGraphInfoSaver implements GraphInfoSaver { public void save(URI graphInfoUri, GraphInfo graphInfo) throws IOException { // if graphInfoUri is a directory then save to ${graphInfo.name}.graph.yml if (graphInfoUri.getPath().endsWith("/")) { - graphInfoUri = - URI.create(graphInfoUri.toString() + graphInfo.getName() + ".graph.yaml"); + graphInfoUri = URI.create(graphInfoUri.toString() + graphInfo.getName() + ".graph.yml"); } Writer writer = writeYaml(graphInfoUri); graphInfo.dump(graphInfoUri, writer); @@ -56,7 +55,7 @@ public void save(URI vertexInfoUri, VertexInfo vertexInfo) throws IOException { // if vertexInfoUri is a directory then save to ${vertexInfo.type}.vertex.yml if (vertexInfoUri.getPath().endsWith("/")) { vertexInfoUri = - URI.create(vertexInfoUri.toString() + vertexInfo.getType() + ".vertex.yaml"); + URI.create(vertexInfoUri.toString() + vertexInfo.getType() + ".vertex.yml"); } Writer vertexWriter = writeYaml(vertexInfoUri); vertexInfo.dump(vertexWriter); @@ -67,7 +66,7 @@ public void save(URI vertexInfoUri, VertexInfo vertexInfo) throws IOException { public void save(URI edgeInfoUri, EdgeInfo edgeInfo) throws IOException { // if edgeInfoUri is a directory then save to ${edgeInfo.getConcat()}.edge.yml if (edgeInfoUri.getPath().endsWith("/")) { - edgeInfoUri = URI.create(edgeInfoUri.toString() + edgeInfo.getConcat() + ".edge.yaml"); + edgeInfoUri = URI.create(edgeInfoUri.toString() + edgeInfo.getConcat() + ".edge.yml"); } Writer edgeWriter = writeYaml(edgeInfoUri); edgeInfo.dump(edgeWriter); diff --git a/maven-projects/info/src/test/java/org/apache/graphar/info/VertexInfoLabelsTest.java b/maven-projects/info/src/test/java/org/apache/graphar/info/VertexInfoLabelsTest.java index 4c99475b9..ed331b900 100644 --- a/maven-projects/info/src/test/java/org/apache/graphar/info/VertexInfoLabelsTest.java +++ b/maven-projects/info/src/test/java/org/apache/graphar/info/VertexInfoLabelsTest.java @@ -94,8 +94,7 @@ public void testVertexInfoWithLabels() throws IOException { graphInfoSaver.save(URI.create(testSaveDirectory), vertexInfo); // test load VertexInfo loadedVertexInfo = - graphInfoLoader.loadVertexInfo( - URI.create(testSaveDirectory + "person.vertex.yaml")); + graphInfoLoader.loadVertexInfo(URI.create(testSaveDirectory + "person.vertex.yml")); Assert.assertTrue(TestVerificationUtils.equalsVertexInfo(vertexInfo, loadedVertexInfo)); } @@ -128,8 +127,7 @@ public void testVertexInfoWithoutLabels() throws IOException { graphInfoSaver.save(URI.create(testSaveDirectory), vertexInfo); // test load VertexInfo loadedVertexInfo = - graphInfoLoader.loadVertexInfo( - URI.create(testSaveDirectory + "person.vertex.yaml")); + graphInfoLoader.loadVertexInfo(URI.create(testSaveDirectory + "person.vertex.yml")); Assert.assertTrue(TestVerificationUtils.equalsVertexInfo(vertexInfo, loadedVertexInfo)); } @@ -158,12 +156,12 @@ public void testVertexInfoWithEmptyLabels() throws IOException { Assert.assertEquals("vertex/person/", vertexInfo.getPrefix()); // Test validation - Assert.assertTrue(vertexInfo.isValidated()); // Test dump + Assert.assertTrue(vertexInfo.isValidated()); + // Test dump graphInfoSaver.save(URI.create(testSaveDirectory), vertexInfo); // test load VertexInfo loadedVertexInfo = - graphInfoLoader.loadVertexInfo( - URI.create(testSaveDirectory + "person.vertex.yaml")); + graphInfoLoader.loadVertexInfo(URI.create(testSaveDirectory + "person.vertex.yml")); Assert.assertTrue(TestVerificationUtils.equalsVertexInfo(vertexInfo, loadedVertexInfo)); } From db65619ec9b9855f1d53f072dac30f73a76f1e68 Mon Sep 17 00:00:00 2001 From: yxk485490 <1320342065@qq.com> Date: Mon, 8 Dec 2025 19:15:29 +0800 Subject: [PATCH 6/6] update --- .../src/main/java/org/apache/graphar/info/yaml/VertexYaml.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/VertexYaml.java b/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/VertexYaml.java index eaa8a91e9..773423243 100644 --- a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/VertexYaml.java +++ b/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/VertexYaml.java @@ -87,6 +87,9 @@ public List getLabels() { if (labels == null) { return null; } + // Returns the labels list, or null if the list is null or empty. Returning null for empty + // lists ensures that the labels field is omitted from YAML output when no labels are + // defined. return labels.isEmpty() ? null : labels; }