feat(java,info): update validate and other methods (#769)
* add isValidated method
* add isValidated test cases
* rename prefix or path to uri
* update
* add and fix methods
* update
* update
* update
diff --git a/maven-projects/info/src/main/java/org/apache/graphar/info/AdjacentList.java b/maven-projects/info/src/main/java/org/apache/graphar/info/AdjacentList.java
index b591381..a75b3a6 100644
--- a/maven-projects/info/src/main/java/org/apache/graphar/info/AdjacentList.java
+++ b/maven-projects/info/src/main/java/org/apache/graphar/info/AdjacentList.java
@@ -53,4 +53,23 @@
public URI getBaseUri() {
return baseUri;
}
+
+ public boolean isValidated() {
+ // Check if type is valid
+ if (type == null) {
+ return false;
+ }
+
+ // Check if file type is valid
+ if (fileType == null) {
+ return false;
+ }
+
+ // Check if base URI is not null
+ if (baseUri == null || baseUri.toString().isEmpty()) {
+ return false;
+ }
+
+ return true;
+ }
}
diff --git a/maven-projects/info/src/main/java/org/apache/graphar/info/EdgeInfo.java b/maven-projects/info/src/main/java/org/apache/graphar/info/EdgeInfo.java
index 3df5a0c..57de3c4 100644
--- a/maven-projects/info/src/main/java/org/apache/graphar/info/EdgeInfo.java
+++ b/maven-projects/info/src/main/java/org/apache/graphar/info/EdgeInfo.java
@@ -22,9 +22,11 @@
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -426,6 +428,18 @@
return propertyGroups.hasProperty(propertyName);
}
+ public DataType getPropertyType(String propertyName) {
+ return propertyGroups.getPropertyType(propertyName);
+ }
+
+ public boolean isPrimaryKey(String propertyName) {
+ return propertyGroups.isPrimaryKey(propertyName);
+ }
+
+ public boolean isNullableKey(String propertyName) {
+ return propertyGroups.isNullableKey(propertyName);
+ }
+
public boolean hasPropertyGroup(PropertyGroup propertyGroup) {
return propertyGroups.hasPropertyGroup(propertyGroup);
}
@@ -446,50 +460,38 @@
return propertyGroups.getPropertyGroup(property);
}
- public URI getPropertyGroupPrefix(PropertyGroup propertyGroup) {
+ public URI getPropertyGroupUri(PropertyGroup propertyGroup) {
checkPropertyGroupExist(propertyGroup);
return getBaseUri().resolve(propertyGroup.getBaseUri());
}
- public URI getPropertyGroupChunkPath(PropertyGroup propertyGroup, long chunkIndex) {
+ public URI getPropertyGroupChunkUri(PropertyGroup propertyGroup, long chunkIndex) {
// PropertyGroup will be checked in getPropertyGroupPrefix
- return getPropertyGroupPrefix(propertyGroup).resolve("chunk" + chunkIndex);
+ return getPropertyGroupUri(propertyGroup).resolve("chunk" + chunkIndex);
}
- public URI getAdjacentListPrefix(AdjListType adjListType) {
+ public URI getAdjacentListUri(AdjListType adjListType) {
return getBaseUri().resolve(getAdjacentList(adjListType).getBaseUri()).resolve("adj_list/");
}
- public URI getAdjacentListChunkPath(AdjListType adjListType, long vertexChunkIndex) {
- return getAdjacentListPrefix(adjListType).resolve("chunk" + vertexChunkIndex);
+ public URI getAdjacentListChunkUri(AdjListType adjListType, long vertexChunkIndex) {
+ return getAdjacentListUri(adjListType).resolve("chunk" + vertexChunkIndex);
}
- public URI getOffsetPrefix(AdjListType adjListType) {
- return getAdjacentListPrefix(adjListType).resolve("offset/");
+ public URI getOffsetUri(AdjListType adjListType) {
+ return getAdjacentListUri(adjListType).resolve("offset/");
}
- public URI getOffsetChunkPath(AdjListType adjListType, long vertexChunkIndex) {
- return getOffsetPrefix(adjListType).resolve("chunk" + vertexChunkIndex);
+ public URI getOffsetChunkUri(AdjListType adjListType, long vertexChunkIndex) {
+ return getOffsetUri(adjListType).resolve("chunk" + vertexChunkIndex);
}
- public URI getVerticesNumFilePath(AdjListType adjListType) {
- return getAdjacentListPrefix(adjListType).resolve("vertex_count");
+ public URI getVerticesNumFileUri(AdjListType adjListType) {
+ return getAdjacentListUri(adjListType).resolve("vertex_count");
}
- public URI getEdgesNumFilePath(AdjListType adjListType, long vertexChunkIndex) {
- return getAdjacentListPrefix(adjListType).resolve("edge_count" + vertexChunkIndex);
- }
-
- public DataType getPropertyType(String propertyName) {
- return propertyGroups.getPropertyType(propertyName);
- }
-
- public boolean isPrimaryKey(String propertyName) {
- return propertyGroups.isPrimaryKey(propertyName);
- }
-
- public boolean isNullableKey(String propertyName) {
- return propertyGroups.isNullableKey(propertyName);
+ public URI getEdgesNumFileUri(AdjListType adjListType, long vertexChunkIndex) {
+ return getAdjacentListUri(adjListType).resolve("edge_count" + vertexChunkIndex);
}
public String dump() {
@@ -576,6 +578,56 @@
}
}
+ public boolean isValidated() {
+ // Check if source type, edge type, or destination type is empty
+ if (getSrcType() == null
+ || getSrcType().isEmpty()
+ || getEdgeType() == null
+ || getEdgeType().isEmpty()
+ || getDstType() == null
+ || getDstType().isEmpty()) {
+ return false;
+ }
+
+ // Check if chunk sizes are positive
+ if (chunkSize <= 0 || srcChunkSize <= 0 || dstChunkSize <= 0) {
+ return false;
+ }
+
+ // Check if prefix is null or empty
+ if (baseUri == null || baseUri.toString().isEmpty()) {
+ return false;
+ }
+
+ // Check if adjacent lists are empty
+ if (adjacentLists.isEmpty()) {
+ return false;
+ }
+
+ // Check if all adjacent lists are valid
+ for (AdjacentList adjacentList : adjacentLists.values()) {
+ if (adjacentList == null || !adjacentList.isValidated()) {
+ return false;
+ }
+ }
+
+ // Check if all property groups are valid and property names are unique
+ Set<String> propertyNameSet = new HashSet<>();
+ for (PropertyGroup pg : propertyGroups.getPropertyGroupList()) {
+ if (pg == null || !pg.isValidated()) {
+ return false;
+ }
+
+ for (Property p : pg.getPropertyList()) {
+ if (propertyNameSet.contains(p.getName())) {
+ return false;
+ }
+ propertyNameSet.add(p.getName());
+ }
+ }
+ return true;
+ }
+
private static class EdgeTriplet {
private final String srcType;
private final String edgeType;
diff --git a/maven-projects/info/src/main/java/org/apache/graphar/info/GraphInfo.java b/maven-projects/info/src/main/java/org/apache/graphar/info/GraphInfo.java
index 85322cd..c67a542 100644
--- a/maven-projects/info/src/main/java/org/apache/graphar/info/GraphInfo.java
+++ b/maven-projects/info/src/main/java/org/apache/graphar/info/GraphInfo.java
@@ -167,7 +167,7 @@
}
public boolean hasEdgeInfo(String srcType, String edgeType, String dstType) {
- return edgeConcat2EdgeInfo.containsKey(EdgeInfo.concat(srcType, dstType, edgeType));
+ return edgeConcat2EdgeInfo.containsKey(EdgeInfo.concat(srcType, edgeType, dstType));
}
public VertexInfo getVertexInfo(String type) {
@@ -177,7 +177,7 @@
public EdgeInfo getEdgeInfo(String srcType, String edgeType, String dstType) {
checkEdgeExist(srcType, edgeType, dstType);
- return edgeConcat2EdgeInfo.get(EdgeInfo.concat(srcType, dstType, edgeType));
+ return edgeConcat2EdgeInfo.get(EdgeInfo.concat(srcType, edgeType, dstType));
}
public int getVertexInfoNum() {
@@ -212,6 +212,35 @@
return version;
}
+ public boolean isValidated() {
+ // Check if name is not empty and base URI is not null
+ if (name == null || name.isEmpty() || baseUri == null) {
+ return false;
+ }
+
+ // Check if all vertex infos are valid
+ for (VertexInfo vertexInfo : vertexInfos) {
+ if (vertexInfo == null || !vertexInfo.isValidated()) {
+ return false;
+ }
+ }
+
+ // Check if all edge infos are valid
+ for (EdgeInfo edgeInfo : edgeInfos) {
+ if (edgeInfo == null || !edgeInfo.isValidated()) {
+ return false;
+ }
+ }
+
+ // Check if vertex/edge infos size matches vertex/edge type to index map size
+ if (vertexInfos.size() != vertexType2VertexInfo.size()
+ || edgeInfos.size() != edgeConcat2EdgeInfo.size()) {
+ return false;
+ }
+
+ return true;
+ }
+
private void checkVertexExist(String type) {
if (!hasVertexInfo(type)) {
throw new IllegalArgumentException(
diff --git a/maven-projects/info/src/main/java/org/apache/graphar/info/PropertyGroup.java b/maven-projects/info/src/main/java/org/apache/graphar/info/PropertyGroup.java
index 5da5796..ae1fdc4 100644
--- a/maven-projects/info/src/main/java/org/apache/graphar/info/PropertyGroup.java
+++ b/maven-projects/info/src/main/java/org/apache/graphar/info/PropertyGroup.java
@@ -98,6 +98,49 @@
public URI getBaseUri() {
return baseUri;
}
+
+ public boolean isValidated() {
+ // Check if base URI is not null or empty
+ if (baseUri == null || baseUri.toString().isEmpty()) {
+ return false;
+ }
+
+ // Check if file type is valid
+ if (fileType == null) {
+ return false;
+ }
+
+ // Check if properties are not empty
+ if (propertyList.isEmpty()) {
+ return false;
+ }
+
+ // Check if all properties are valid and have unique names
+ Map<String, Boolean> propertyNameSet = new HashMap<>();
+ for (Property property : propertyList) {
+ // Check if property name is not empty and data type is not null
+ if (property == null
+ || property.getName() == null
+ || property.getName().isEmpty()
+ || property.getDataType() == null) {
+ return false;
+ }
+
+ // Check if property name is unique in the group
+ String propertyName = property.getName();
+ if (propertyNameSet.containsKey(propertyName)) {
+ return false;
+ }
+ propertyNameSet.put(propertyName, true);
+
+ // TODO: support list type in csv file
+ if (property.getDataType() == DataType.LIST && fileType == FileType.CSV) {
+ return false;
+ }
+ }
+
+ return true;
+ }
}
class PropertyGroups {
@@ -192,26 +235,17 @@
return propertyGroupList;
}
- Map<String, PropertyGroup> getPropertyGroupMap() {
- return propertyGroupMap;
- }
-
PropertyGroup getPropertyGroup(String propertyName) {
checkPropertyExist(propertyName);
return propertyGroupMap.get(propertyName);
}
- Map<String, Property> getProperties() {
- return properties;
- }
-
private void checkPropertyExist(String propertyName) {
if (null == propertyName) {
throw new IllegalArgumentException("Property name is null");
}
if (!hasProperty(propertyName)) {
- throw new IllegalArgumentException(
- "Property " + propertyName + " does not exist in the property group " + this);
+ throw new IllegalArgumentException("Property " + propertyName + " does not exist");
}
}
}
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 2ebfb0d..94123a0 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
@@ -20,8 +20,10 @@
package org.apache.graphar.info;
import java.net.URI;
+import java.util.HashSet;
import java.util.List;
import java.util.Optional;
+import java.util.Set;
import org.apache.graphar.info.type.DataType;
import org.apache.graphar.info.yaml.GraphYaml;
import org.apache.graphar.info.yaml.VertexYaml;
@@ -78,7 +80,7 @@
type, chunkSize, newPropertyGroups, baseUri, version));
}
- public int propertyGroupNum() {
+ public int getPropertyGroupNum() {
return propertyGroups.getPropertyGroupNum();
}
@@ -102,17 +104,21 @@
return propertyGroups.hasPropertyGroup(propertyGroup);
}
- public URI getPropertyGroupPrefix(PropertyGroup propertyGroup) {
+ public PropertyGroup getPropertyGroup(String property) {
+ return propertyGroups.getPropertyGroup(property);
+ }
+
+ public URI getPropertyGroupUri(PropertyGroup propertyGroup) {
checkPropertyGroupExist(propertyGroup);
return getBaseUri().resolve(propertyGroup.getBaseUri());
}
- public URI getPropertyGroupChunkPath(PropertyGroup propertyGroup, long chunkIndex) {
+ public URI getPropertyGroupChunkUri(PropertyGroup propertyGroup, long chunkIndex) {
// PropertyGroup will be checked in getPropertyGroupPrefix
- return getPropertyGroupPrefix(propertyGroup).resolve("chunk" + chunkIndex);
+ return getPropertyGroupUri(propertyGroup).resolve("chunk" + chunkIndex);
}
- public URI getVerticesNumFilePath() {
+ public URI getVerticesNumFileUri() {
return getBaseUri().resolve("vertex_count");
}
@@ -135,7 +141,7 @@
}
public String getPrefix() {
- return baseUri.toString();
+ return baseUri == null ? null : baseUri.toString();
}
public URI getBaseUri() {
@@ -158,4 +164,27 @@
+ getType());
}
}
+
+ public boolean isValidated() {
+ // Check if type and baseUri is not empty and chunkSize is positive
+ if (type == null || type.isEmpty() || chunkSize <= 0 || baseUri == null) {
+ return false;
+ }
+ // Check if property groups are valid
+ Set<String> propertyNameSet = new HashSet<>();
+ for (PropertyGroup pg : propertyGroups.getPropertyGroupList()) {
+ // Check if property group is not null and not empty
+ if (pg == null || !pg.isValidated()) {
+ return false;
+ }
+ for (Property p : pg.getPropertyList()) {
+ if (propertyNameSet.contains(p.getName())) {
+ return false;
+ }
+ propertyNameSet.add(p.getName());
+ }
+ }
+
+ return true;
+ }
}
diff --git a/maven-projects/info/src/test/java/org/apache/graphar/info/AdjacentListTest.java b/maven-projects/info/src/test/java/org/apache/graphar/info/AdjacentListTest.java
index b8d60fe..7ea7d42 100644
--- a/maven-projects/info/src/test/java/org/apache/graphar/info/AdjacentListTest.java
+++ b/maven-projects/info/src/test/java/org/apache/graphar/info/AdjacentListTest.java
@@ -205,4 +205,62 @@
Assert.assertEquals(fileType, adjList.getFileType());
Assert.assertEquals(prefix, adjList.getPrefix());
}
+
+ @Test
+ public void testIsValidated() {
+ // Test valid adjacent lists
+ AdjacentList validList =
+ new AdjacentList(AdjListType.unordered_by_source, FileType.CSV, "adj_list/");
+ Assert.assertTrue(validList.isValidated());
+
+ // Test invalid adjacent list with null type
+ AdjacentList nullTypeList = new AdjacentList(null, FileType.CSV, "adj_list/");
+ Assert.assertFalse(nullTypeList.isValidated());
+
+ // Test invalid adjacent list with invalid type values
+ // This test is not needed in Java as AdjListType is an enum
+
+ // Test invalid adjacent list with null file type
+ AdjacentList nullFileTypeList =
+ new AdjacentList(AdjListType.unordered_by_source, null, "adj_list/");
+ Assert.assertFalse(nullFileTypeList.isValidated());
+
+ // Test invalid adjacent list with invalid file type values
+ // This test is not needed in Java as FileType is an enum
+
+ // Test invalid adjacent list with null prefix
+ AdjacentList nullPrefixList =
+ new AdjacentList(AdjListType.unordered_by_source, FileType.CSV, (String) null);
+ Assert.assertFalse(nullPrefixList.isValidated());
+
+ // Test all valid AdjListType values
+ AdjacentList unorderedBySourceList =
+ new AdjacentList(AdjListType.unordered_by_source, FileType.CSV, "unordered_src/");
+ Assert.assertTrue(unorderedBySourceList.isValidated());
+
+ AdjacentList unorderedByDestList =
+ new AdjacentList(AdjListType.unordered_by_dest, FileType.CSV, "unordered_dst/");
+ Assert.assertTrue(unorderedByDestList.isValidated());
+
+ AdjacentList orderedBySourceList =
+ new AdjacentList(AdjListType.ordered_by_source, FileType.CSV, "ordered_src/");
+ Assert.assertTrue(orderedBySourceList.isValidated());
+
+ AdjacentList orderedByDestList =
+ new AdjacentList(AdjListType.ordered_by_dest, FileType.CSV, "ordered_dst/");
+ Assert.assertTrue(orderedByDestList.isValidated());
+
+ // Test all valid FileType values
+ AdjacentList csvList =
+ new AdjacentList(AdjListType.unordered_by_source, FileType.CSV, "csv/");
+ Assert.assertTrue(csvList.isValidated());
+
+ AdjacentList parquetList =
+ new AdjacentList(AdjListType.unordered_by_source, FileType.PARQUET, "parquet/");
+ Assert.assertTrue(parquetList.isValidated());
+
+ AdjacentList orcList =
+ new AdjacentList(AdjListType.unordered_by_source, FileType.ORC, "orc/");
+ Assert.assertTrue(orcList.isValidated());
+ }
}
diff --git a/maven-projects/info/src/test/java/org/apache/graphar/info/EdgeInfoTest.java b/maven-projects/info/src/test/java/org/apache/graphar/info/EdgeInfoTest.java
index caf25bb..7ba683b 100644
--- a/maven-projects/info/src/test/java/org/apache/graphar/info/EdgeInfoTest.java
+++ b/maven-projects/info/src/test/java/org/apache/graphar/info/EdgeInfoTest.java
@@ -20,7 +20,10 @@
package org.apache.graphar.info;
import java.net.URI;
+import java.util.ArrayList;
import java.util.List;
+import org.apache.graphar.info.type.AdjListType;
+import org.apache.graphar.info.type.FileType;
import org.junit.Assert;
import org.junit.Test;
@@ -58,46 +61,49 @@
@Test
public void testUriAndPrefixConflict() {
- try {
- EdgeInfo.builder()
- .srcType("person")
- .edgeType("knows")
- .dstType("person")
- .propertyGroups(new PropertyGroups(List.of(TestUtil.pg3)))
- .adjacentLists(List.of(TestUtil.orderedBySource))
- .chunkSize(1024)
- .srcChunkSize(100)
- .dstChunkSize(100)
- .directed(false)
- .prefix("edge/person_knows_person/")
- .baseUri(URI.create("/person_knows_person/"))
- .version("gar/v1")
- .build();
- } catch (IllegalArgumentException e) {
- Assert.assertEquals(
- "baseUri and prefix conflict: baseUri=/person_knows_person/ prefix=edge/person_knows_person/",
- e.getMessage());
- }
+ IllegalArgumentException illegalArgumentException =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ EdgeInfo.builder()
+ .srcType("person")
+ .edgeType("knows")
+ .dstType("person")
+ .propertyGroups(new PropertyGroups(List.of(TestUtil.pg3)))
+ .adjacentLists(List.of(TestUtil.orderedBySource))
+ .chunkSize(1024)
+ .srcChunkSize(100)
+ .dstChunkSize(100)
+ .directed(false)
+ .prefix("edge/person_knows_person/")
+ .baseUri(URI.create("/person_knows_person/"))
+ .version("gar/v1")
+ .build());
+ Assert.assertEquals(
+ "baseUri and prefix conflict: baseUri=/person_knows_person/ prefix=edge/person_knows_person/",
+ illegalArgumentException.getMessage());
}
@Test
public void testMissingUriAndPrefix() {
- try {
- EdgeInfo.builder()
- .srcType("person")
- .edgeType("knows")
- .dstType("person")
- .propertyGroups(new PropertyGroups(List.of(TestUtil.pg3)))
- .adjacentLists(List.of(TestUtil.orderedBySource))
- .chunkSize(1024)
- .srcChunkSize(100)
- .dstChunkSize(100)
- .directed(false)
- .version("gar/v1")
- .build();
- } catch (IllegalArgumentException e) {
- Assert.assertEquals("baseUri and prefix cannot be both null", e.getMessage());
- }
+ IllegalArgumentException illegalArgumentException =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ EdgeInfo.builder()
+ .srcType("person")
+ .edgeType("knows")
+ .dstType("person")
+ .propertyGroups(new PropertyGroups(List.of(TestUtil.pg3)))
+ .adjacentLists(List.of(TestUtil.orderedBySource))
+ .chunkSize(1024)
+ .srcChunkSize(100)
+ .dstChunkSize(100)
+ .directed(false)
+ .version("gar/v1")
+ .build());
+ Assert.assertEquals(
+ "baseUri and prefix cannot be both null", illegalArgumentException.getMessage());
}
@Test
@@ -158,4 +164,175 @@
Assert.assertEquals(2, edgeInfo.getAdjacentLists().size());
Assert.assertEquals(2, edgeInfo.getPropertyGroups().size());
}
+
+ @Test
+ public void testIsValidated() {
+ // Test valid edge info
+ EdgeInfo edgeInfo =
+ new EdgeInfo(
+ "person",
+ "knows",
+ "person",
+ 1024,
+ 100,
+ 1000,
+ false,
+ URI.create("edge/person_knows_person/"),
+ "gar/v1",
+ List.of(TestUtil.orderedBySource),
+ List.of(TestUtil.pg1));
+ Assert.assertTrue(edgeInfo.isValidated());
+
+ EdgeInfo srcTypeEmptyEdgeInfo =
+ new EdgeInfo(
+ "",
+ "knows",
+ "person",
+ 1024,
+ 100,
+ 100,
+ false,
+ URI.create("edge/person_knows_person/"),
+ "gar/v1",
+ List.of(TestUtil.orderedBySource),
+ List.of(TestUtil.pg3));
+ Assert.assertFalse(srcTypeEmptyEdgeInfo.isValidated());
+
+ EdgeInfo edgeTypeEmptyEdgeInfo =
+ new EdgeInfo(
+ "person",
+ "",
+ "person",
+ 1024,
+ 100,
+ 100,
+ false,
+ URI.create("edge/person_knows_person/"),
+ "gar/v1",
+ List.of(TestUtil.orderedBySource),
+ List.of(TestUtil.pg3));
+ Assert.assertFalse(edgeTypeEmptyEdgeInfo.isValidated());
+
+ EdgeInfo dstTypeEmptyEdgeInfo =
+ new EdgeInfo(
+ "person",
+ "knows",
+ "",
+ 1024,
+ 100,
+ 100,
+ false,
+ URI.create("edge/person_knows_person/"),
+ "gar/v1",
+ List.of(TestUtil.orderedBySource),
+ List.of(TestUtil.pg3));
+ Assert.assertFalse(dstTypeEmptyEdgeInfo.isValidated());
+
+ EdgeInfo chunkSizeIllegalEdgeInfo =
+ new EdgeInfo(
+ "person",
+ "knows",
+ "person",
+ 0,
+ 100,
+ 100,
+ false,
+ URI.create("edge/person_knows_person/"),
+ "gar/v1",
+ List.of(TestUtil.orderedBySource),
+ List.of(TestUtil.pg3));
+ Assert.assertFalse(chunkSizeIllegalEdgeInfo.isValidated());
+
+ EdgeInfo srcChunkSizeIllegalEdgeInfo =
+ new EdgeInfo(
+ "person",
+ "knows",
+ "person",
+ 1024,
+ -1,
+ 100,
+ false,
+ URI.create("edge/person_knows_person/"),
+ "gar/v1",
+ List.of(TestUtil.orderedBySource),
+ List.of(TestUtil.pg3));
+ Assert.assertFalse(srcChunkSizeIllegalEdgeInfo.isValidated());
+
+ EdgeInfo dstChunkSizeIllegalEdgeInfo =
+ new EdgeInfo(
+ "person",
+ "knows",
+ "person",
+ 1024,
+ 100,
+ 0,
+ false,
+ URI.create("edge/person_knows_person/"),
+ "gar/v1",
+ List.of(TestUtil.orderedBySource),
+ List.of(TestUtil.pg3));
+ Assert.assertFalse(dstChunkSizeIllegalEdgeInfo.isValidated());
+
+ EdgeInfo adjListEmptyEdgeInfo =
+ new EdgeInfo(
+ "person",
+ "knows",
+ "person",
+ 1024,
+ 100,
+ 100,
+ false,
+ URI.create(""),
+ "gar/v1",
+ List.of(),
+ List.of(TestUtil.pg3));
+ Assert.assertFalse(adjListEmptyEdgeInfo.isValidated());
+
+ EdgeInfo pgEmptyEdgeInfo =
+ new EdgeInfo(
+ "person",
+ "knows",
+ "person",
+ 1024,
+ 100,
+ 1000,
+ false,
+ URI.create("edge/person_knows_person/"),
+ "gar/v1",
+ List.of(),
+ List.of(TestUtil.pg3));
+ Assert.assertFalse(pgEmptyEdgeInfo.isValidated());
+
+ EdgeInfo adjListPrefixEmptyEdgeInfo =
+ new EdgeInfo(
+ "person",
+ "knows",
+ "person",
+ 1024,
+ 100,
+ 1000,
+ false,
+ URI.create("edge/person_knows_person/"),
+ "gar/v1",
+ List.of(
+ new AdjacentList(
+ AdjListType.ordered_by_source, FileType.PARQUET, "")),
+ List.of(TestUtil.pg3));
+ Assert.assertFalse(adjListPrefixEmptyEdgeInfo.isValidated());
+
+ EdgeInfo pgPrefixEmptyEdgeInfo =
+ new EdgeInfo(
+ "person",
+ "knows",
+ "person",
+ 1024,
+ 100,
+ 1000,
+ false,
+ URI.create("edge/person_knows_person/"),
+ "gar/v1",
+ List.of(TestUtil.orderedBySource),
+ List.of(new PropertyGroup(new ArrayList<>(), FileType.PARQUET, "")));
+ Assert.assertFalse(pgPrefixEmptyEdgeInfo.isValidated());
+ }
}
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 da49754..b4ade71 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
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.apache.graphar.info.loader.GraphInfoLoader;
import org.apache.graphar.info.loader.impl.LocalFileSystemStreamGraphInfoLoader;
@@ -39,6 +40,12 @@
private static VertexInfo personVertexInfo;
private static EdgeInfo knowsEdgeInfo;
private static URI GRAPH_PATH_URI;
+ // test not exist property group
+ private static final PropertyGroup notExistPg =
+ new PropertyGroup(
+ List.of(new Property("not_exist", DataType.INT64, true, false)),
+ FileType.CSV,
+ "not_exist/");
@BeforeClass
public static void setUp() {
@@ -67,9 +74,7 @@
System.out.println(
graphInfo
.getBaseUri()
- .resolve(
- knowsEdgeInfo.getAdjacentListPrefix(
- AdjListType.ordered_by_source)));
+ .resolve(knowsEdgeInfo.getAdjacentListUri(AdjListType.ordered_by_source)));
}
@Test
@@ -83,8 +88,25 @@
Assert.assertNotNull(graphInfo.getEdgeInfos());
Assert.assertEquals(1, graphInfo.getEdgeInfos().size());
+ Assert.assertEquals(1, graphInfo.getEdgeInfoNum());
Assert.assertNotNull(graphInfo.getVertexInfos());
Assert.assertEquals(1, graphInfo.getVertexInfos().size());
+ Assert.assertEquals(1, graphInfo.getVertexInfoNum());
+ Assert.assertEquals(personVertexInfo, graphInfo.getVertexInfo("person"));
+ IllegalArgumentException illegalArgumentException =
+ Assert.assertThrows(
+ IllegalArgumentException.class, () -> graphInfo.getVertexInfo("not_exist"));
+ Assert.assertEquals(
+ "Vertex type not_exist not exist in graph ldbc_sample",
+ illegalArgumentException.getMessage());
+ Assert.assertEquals(knowsEdgeInfo, graphInfo.getEdgeInfo("person", "knows", "person"));
+ illegalArgumentException =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () -> graphInfo.getEdgeInfo("person", "not_knows", "person"));
+ Assert.assertEquals(
+ "Edge type person_not_knows_person not exist in graph ldbc_sample",
+ illegalArgumentException.getMessage());
// test version gar/v1
Assert.assertEquals(1, graphInfo.getVersion().getVersion());
}
@@ -104,27 +126,53 @@
@Test
public void testPersonVertexPropertyGroup() {
// group1 id
+ Assert.assertEquals(2, personVertexInfo.getPropertyGroupNum());
PropertyGroup idPropertyGroup = personVertexInfo.getPropertyGroups().get(0);
Assert.assertEquals("id/", idPropertyGroup.getPrefix());
Assert.assertEquals(URI.create("id/"), idPropertyGroup.getBaseUri());
Assert.assertEquals(FileType.CSV, idPropertyGroup.getFileType());
Assert.assertEquals(
URI.create("vertex/person/id/"),
- personVertexInfo.getPropertyGroupPrefix(idPropertyGroup));
+ personVertexInfo.getPropertyGroupUri(idPropertyGroup));
Assert.assertEquals(
URI.create("vertex/person/id/chunk0"),
- personVertexInfo.getPropertyGroupChunkPath(idPropertyGroup, 0));
+ personVertexInfo.getPropertyGroupChunkUri(idPropertyGroup, 0));
Assert.assertEquals(
URI.create("vertex/person/id/chunk4"),
- personVertexInfo.getPropertyGroupChunkPath(idPropertyGroup, 4));
+ personVertexInfo.getPropertyGroupChunkUri(idPropertyGroup, 4));
+ IllegalArgumentException illegalArgumentException =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () -> personVertexInfo.getPropertyGroupUri(notExistPg));
+ Assert.assertEquals(
+ "Property group "
+ + notExistPg
+ + " does not exist in the vertex "
+ + personVertexInfo.getType(),
+ illegalArgumentException.getMessage());
+ Assert.assertEquals(idPropertyGroup, personVertexInfo.getPropertyGroup("id"));
+ illegalArgumentException =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () -> personVertexInfo.getPropertyGroup("not_exist"));
+ Assert.assertEquals(
+ "Property not_exist does not exist", illegalArgumentException.getMessage());
+ illegalArgumentException =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () -> personVertexInfo.getPropertyGroup(null));
+ Assert.assertEquals("Property name is null", illegalArgumentException.getMessage());
Assert.assertNotNull(idPropertyGroup.getPropertyList());
Assert.assertEquals(1, idPropertyGroup.getPropertyList().size());
Property idProperty = idPropertyGroup.getPropertyList().get(0);
Assert.assertTrue(personVertexInfo.hasProperty("id"));
Assert.assertEquals("id", idProperty.getName());
Assert.assertEquals(DataType.INT64, idProperty.getDataType());
+ Assert.assertEquals(DataType.INT64, personVertexInfo.getPropertyType("id"));
Assert.assertTrue(idProperty.isPrimary());
+ Assert.assertTrue(personVertexInfo.isPrimaryKey("id"));
Assert.assertFalse(idProperty.isNullable());
+ Assert.assertFalse(personVertexInfo.isNullableKey("id"));
// group2 firstName_lastName_gender
PropertyGroup firstName_lastName_gender = personVertexInfo.getPropertyGroups().get(1);
Assert.assertEquals("firstName_lastName_gender/", firstName_lastName_gender.getPrefix());
@@ -133,13 +181,15 @@
Assert.assertEquals(FileType.CSV, firstName_lastName_gender.getFileType());
Assert.assertEquals(
URI.create("vertex/person/firstName_lastName_gender/"),
- personVertexInfo.getPropertyGroupPrefix(firstName_lastName_gender));
+ personVertexInfo.getPropertyGroupUri(firstName_lastName_gender));
Assert.assertEquals(
URI.create("vertex/person/firstName_lastName_gender/chunk0"),
- personVertexInfo.getPropertyGroupChunkPath(firstName_lastName_gender, 0));
+ personVertexInfo.getPropertyGroupChunkUri(firstName_lastName_gender, 0));
Assert.assertEquals(
URI.create("vertex/person/firstName_lastName_gender/chunk4"),
- personVertexInfo.getPropertyGroupChunkPath(firstName_lastName_gender, 4));
+ personVertexInfo.getPropertyGroupChunkUri(firstName_lastName_gender, 4));
+ Assert.assertEquals(
+ URI.create("vertex/person/vertex_count"), personVertexInfo.getVerticesNumFileUri());
Assert.assertNotNull(firstName_lastName_gender.getPropertyList());
Assert.assertEquals(3, firstName_lastName_gender.getPropertyList().size());
Property firstNameProperty = firstName_lastName_gender.getPropertyList().get(0);
@@ -180,6 +230,10 @@
@Test
public void testKnowsEdgeAdjacencyLists() {
Assert.assertEquals(2, knowsEdgeInfo.getAdjacentLists().size());
+ Assert.assertTrue(knowsEdgeInfo.hasAdjListType(AdjListType.ordered_by_source));
+ Assert.assertTrue(knowsEdgeInfo.hasAdjListType(AdjListType.ordered_by_dest));
+ Assert.assertFalse(knowsEdgeInfo.hasAdjListType(AdjListType.unordered_by_source));
+ Assert.assertFalse(knowsEdgeInfo.hasAdjListType(AdjListType.unordered_by_dest));
// test ordered by source adjacency list
AdjacentList adjOrderBySource =
knowsEdgeInfo.getAdjacentList(AdjListType.ordered_by_source);
@@ -189,31 +243,31 @@
Assert.assertEquals(URI.create("ordered_by_source/"), adjOrderBySource.getBaseUri());
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_source/adj_list/vertex_count"),
- knowsEdgeInfo.getVerticesNumFilePath(AdjListType.ordered_by_source));
+ knowsEdgeInfo.getVerticesNumFileUri(AdjListType.ordered_by_source));
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_source/adj_list/edge_count0"),
- knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ordered_by_source, 0));
+ knowsEdgeInfo.getEdgesNumFileUri(AdjListType.ordered_by_source, 0));
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_source/adj_list/edge_count4"),
- knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ordered_by_source, 4));
+ knowsEdgeInfo.getEdgesNumFileUri(AdjListType.ordered_by_source, 4));
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_source/adj_list/"),
- knowsEdgeInfo.getAdjacentListPrefix(AdjListType.ordered_by_source));
+ knowsEdgeInfo.getAdjacentListUri(AdjListType.ordered_by_source));
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_source/adj_list/chunk0"),
- knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ordered_by_source, 0));
+ knowsEdgeInfo.getAdjacentListChunkUri(AdjListType.ordered_by_source, 0));
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_source/adj_list/chunk4"),
- knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ordered_by_source, 4));
+ knowsEdgeInfo.getAdjacentListChunkUri(AdjListType.ordered_by_source, 4));
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_source/adj_list/offset/"),
- knowsEdgeInfo.getOffsetPrefix(AdjListType.ordered_by_source));
+ knowsEdgeInfo.getOffsetUri(AdjListType.ordered_by_source));
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_source/adj_list/offset/chunk0"),
- knowsEdgeInfo.getOffsetChunkPath(AdjListType.ordered_by_source, 0));
+ knowsEdgeInfo.getOffsetChunkUri(AdjListType.ordered_by_source, 0));
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_source/adj_list/offset/chunk4"),
- knowsEdgeInfo.getOffsetChunkPath(AdjListType.ordered_by_source, 4));
+ knowsEdgeInfo.getOffsetChunkUri(AdjListType.ordered_by_source, 4));
// test ordered by destination adjacency list
AdjacentList adjOrderByDestination =
@@ -224,31 +278,31 @@
Assert.assertEquals(URI.create("ordered_by_dest/"), adjOrderByDestination.getBaseUri());
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_dest/adj_list/vertex_count"),
- knowsEdgeInfo.getVerticesNumFilePath(AdjListType.ordered_by_dest));
+ knowsEdgeInfo.getVerticesNumFileUri(AdjListType.ordered_by_dest));
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_dest/adj_list/edge_count0"),
- knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ordered_by_dest, 0));
+ knowsEdgeInfo.getEdgesNumFileUri(AdjListType.ordered_by_dest, 0));
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_dest/adj_list/edge_count4"),
- knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ordered_by_dest, 4));
+ knowsEdgeInfo.getEdgesNumFileUri(AdjListType.ordered_by_dest, 4));
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_dest/adj_list/"),
- knowsEdgeInfo.getAdjacentListPrefix(AdjListType.ordered_by_dest));
+ knowsEdgeInfo.getAdjacentListUri(AdjListType.ordered_by_dest));
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_dest/adj_list/chunk0"),
- knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ordered_by_dest, 0));
+ knowsEdgeInfo.getAdjacentListChunkUri(AdjListType.ordered_by_dest, 0));
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_dest/adj_list/chunk4"),
- knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ordered_by_dest, 4));
+ knowsEdgeInfo.getAdjacentListChunkUri(AdjListType.ordered_by_dest, 4));
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_dest/adj_list/offset/"),
- knowsEdgeInfo.getOffsetPrefix(AdjListType.ordered_by_dest));
+ knowsEdgeInfo.getOffsetUri(AdjListType.ordered_by_dest));
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_dest/adj_list/offset/chunk0"),
- knowsEdgeInfo.getOffsetChunkPath(AdjListType.ordered_by_dest, 0));
+ knowsEdgeInfo.getOffsetChunkUri(AdjListType.ordered_by_dest, 0));
Assert.assertEquals(
URI.create("edge/person_knows_person/ordered_by_dest/adj_list/offset/chunk4"),
- knowsEdgeInfo.getOffsetChunkPath(AdjListType.ordered_by_dest, 4));
+ knowsEdgeInfo.getOffsetChunkUri(AdjListType.ordered_by_dest, 4));
}
@Test
@@ -256,18 +310,39 @@
Assert.assertEquals(1, knowsEdgeInfo.getPropertyGroupNum());
// edge properties group 1
PropertyGroup propertyGroup = knowsEdgeInfo.getPropertyGroups().get(0);
+ IllegalArgumentException illegalArgumentException =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () -> knowsEdgeInfo.getPropertyGroupUri(notExistPg));
+ Assert.assertEquals(
+ "Property group "
+ + notExistPg
+ + " does not exist in the edge "
+ + knowsEdgeInfo.getConcat(),
+ illegalArgumentException.getMessage());
+ Assert.assertEquals(propertyGroup, knowsEdgeInfo.getPropertyGroup("creationDate"));
+ illegalArgumentException =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () -> knowsEdgeInfo.getPropertyGroup("not_exist"));
+ Assert.assertEquals(
+ "Property not_exist does not exist", illegalArgumentException.getMessage());
+ illegalArgumentException =
+ Assert.assertThrows(
+ IllegalArgumentException.class, () -> knowsEdgeInfo.getPropertyGroup(null));
+ Assert.assertEquals("Property name is null", illegalArgumentException.getMessage());
Assert.assertEquals("creationDate/", propertyGroup.getPrefix());
Assert.assertEquals(URI.create("creationDate/"), propertyGroup.getBaseUri());
Assert.assertEquals(FileType.CSV, propertyGroup.getFileType());
Assert.assertEquals(
URI.create("edge/person_knows_person/creationDate/"),
- knowsEdgeInfo.getPropertyGroupPrefix(propertyGroup));
+ knowsEdgeInfo.getPropertyGroupUri(propertyGroup));
Assert.assertEquals(
URI.create("edge/person_knows_person/creationDate/chunk0"),
- knowsEdgeInfo.getPropertyGroupChunkPath(propertyGroup, 0));
+ knowsEdgeInfo.getPropertyGroupChunkUri(propertyGroup, 0));
Assert.assertEquals(
URI.create("edge/person_knows_person/creationDate/chunk4"),
- knowsEdgeInfo.getPropertyGroupChunkPath(propertyGroup, 4));
+ knowsEdgeInfo.getPropertyGroupChunkUri(propertyGroup, 4));
// edge properties in group 1
Assert.assertNotNull(propertyGroup.getPropertyList());
Assert.assertEquals(1, propertyGroup.getPropertyList().size());
@@ -275,8 +350,11 @@
Assert.assertTrue(knowsEdgeInfo.hasProperty("creationDate"));
Assert.assertEquals("creationDate", property.getName());
Assert.assertEquals(DataType.STRING, property.getDataType());
+ Assert.assertEquals(DataType.STRING, knowsEdgeInfo.getPropertyType("creationDate"));
Assert.assertFalse(property.isPrimary());
+ Assert.assertFalse(knowsEdgeInfo.isPrimaryKey("creationDate"));
Assert.assertTrue(property.isNullable());
+ Assert.assertTrue(knowsEdgeInfo.isNullableKey("creationDate"));
}
@Test
@@ -307,4 +385,66 @@
Assert.assertEquals(List.of("t1", "t2"), versionInfo.getUserDefinedTypes());
Assert.assertEquals("gar/v2 (t1,t2)", versionInfo.toString());
}
+
+ @Test
+ public void testIsValidated() {
+ // Test valid graph info from real test data
+ Assert.assertTrue(graphInfo.isValidated());
+
+ // Test invalid graph info with empty name
+ GraphInfo emptyNameGraphInfo =
+ new GraphInfo(
+ "",
+ graphInfo.getVertexInfos(),
+ graphInfo.getEdgeInfos(),
+ graphInfo.getBaseUri(),
+ graphInfo.getVersion().toString());
+ Assert.assertFalse(emptyNameGraphInfo.isValidated());
+
+ // Test invalid graph info with null base URI
+ GraphInfo nullBaseUriGraphInfo =
+ new GraphInfo(
+ "test",
+ graphInfo.getVertexInfos(),
+ graphInfo.getEdgeInfos(),
+ (URI) null,
+ graphInfo.getVersion().toString());
+ Assert.assertFalse(nullBaseUriGraphInfo.isValidated());
+
+ // Test invalid graph info with invalid vertex info
+ VertexInfo invalidVertexInfo =
+ new VertexInfo("", 100, Arrays.asList(TestUtil.pg1), "vertex/person/", "gar/v1");
+ GraphInfo invalidVertexGraphInfo =
+ new GraphInfo(
+ "test",
+ Arrays.asList(invalidVertexInfo),
+ graphInfo.getEdgeInfos(),
+ graphInfo.getBaseUri(),
+ graphInfo.getVersion().toString());
+ Assert.assertFalse(invalidVertexGraphInfo.isValidated());
+
+ // Test invalid graph info with invalid edge info
+ EdgeInfo invalidEdgeInfo =
+ EdgeInfo.builder()
+ .srcType("")
+ .edgeType("knows")
+ .dstType("person")
+ .propertyGroups(new PropertyGroups(List.of(TestUtil.pg3)))
+ .adjacentLists(List.of(TestUtil.orderedBySource))
+ .chunkSize(1024)
+ .srcChunkSize(100)
+ .dstChunkSize(100)
+ .directed(false)
+ .prefix("edge/person_knows_person/")
+ .version("gar/v1")
+ .build();
+ GraphInfo invalidEdgeGraphInfo =
+ new GraphInfo(
+ "test",
+ graphInfo.getVertexInfos(),
+ Arrays.asList(invalidEdgeInfo),
+ graphInfo.getBaseUri(),
+ graphInfo.getVersion().toString());
+ Assert.assertFalse(invalidEdgeGraphInfo.isValidated());
+ }
}
diff --git a/maven-projects/info/src/test/java/org/apache/graphar/info/GraphInfoUriTest.java b/maven-projects/info/src/test/java/org/apache/graphar/info/GraphInfoUriTest.java
index dc3cc83..2607376 100644
--- a/maven-projects/info/src/test/java/org/apache/graphar/info/GraphInfoUriTest.java
+++ b/maven-projects/info/src/test/java/org/apache/graphar/info/GraphInfoUriTest.java
@@ -41,11 +41,11 @@
// absolute paths
Assert.assertEquals(
URI.create("vertex/person/id/"),
- vertexInfo.getPropertyGroupPrefix(vertexInfo.getPropertyGroups().get(0)));
+ vertexInfo.getPropertyGroupUri(vertexInfo.getPropertyGroups().get(0)));
// relative paths
Assert.assertEquals(
URI.create("/tmp/vertex/person/firstName_lastName_gender/chunk0"),
- vertexInfo.getPropertyGroupChunkPath(vertexInfo.getPropertyGroups().get(1), 0));
+ vertexInfo.getPropertyGroupChunkUri(vertexInfo.getPropertyGroups().get(1), 0));
}
@Test
@@ -58,11 +58,11 @@
// absolute paths
Assert.assertEquals(
URI.create("s3://graphar/vertex/person/id/"),
- vertexInfo.getPropertyGroupPrefix(vertexInfo.getPropertyGroups().get(0)));
+ vertexInfo.getPropertyGroupUri(vertexInfo.getPropertyGroups().get(0)));
// relative paths
Assert.assertEquals(
URI.create("s3://tmp/vertex/person/firstName_lastName_gender/chunk0"),
- vertexInfo.getPropertyGroupChunkPath(vertexInfo.getPropertyGroups().get(1), 0));
+ vertexInfo.getPropertyGroupChunkUri(vertexInfo.getPropertyGroups().get(1), 0));
}
@Test
@@ -75,11 +75,11 @@
// absolute paths
Assert.assertEquals(
URI.create("hdfs://graphar/vertex/person/id/"),
- vertexInfo.getPropertyGroupPrefix(vertexInfo.getPropertyGroups().get(0)));
+ vertexInfo.getPropertyGroupUri(vertexInfo.getPropertyGroups().get(0)));
// relative paths
Assert.assertEquals(
URI.create("hdfs://tmp/vertex/person/firstName_lastName_gender/chunk0"),
- vertexInfo.getPropertyGroupChunkPath(vertexInfo.getPropertyGroups().get(1), 0));
+ vertexInfo.getPropertyGroupChunkUri(vertexInfo.getPropertyGroups().get(1), 0));
}
@Test
@@ -92,10 +92,10 @@
// absolute paths
Assert.assertEquals(
URI.create("file:///graphar/vertex/person/id/"),
- vertexInfo.getPropertyGroupPrefix(vertexInfo.getPropertyGroups().get(0)));
+ vertexInfo.getPropertyGroupUri(vertexInfo.getPropertyGroups().get(0)));
// relative paths
Assert.assertEquals(
URI.create("file:///tmp/vertex/person/firstName_lastName_gender/chunk0"),
- vertexInfo.getPropertyGroupChunkPath(vertexInfo.getPropertyGroups().get(1), 0));
+ vertexInfo.getPropertyGroupChunkUri(vertexInfo.getPropertyGroups().get(1), 0));
}
}
diff --git a/maven-projects/info/src/test/java/org/apache/graphar/info/PropertyGroupTest.java b/maven-projects/info/src/test/java/org/apache/graphar/info/PropertyGroupTest.java
index d98fb89..eaa0cc3 100644
--- a/maven-projects/info/src/test/java/org/apache/graphar/info/PropertyGroupTest.java
+++ b/maven-projects/info/src/test/java/org/apache/graphar/info/PropertyGroupTest.java
@@ -261,4 +261,56 @@
Assert.assertEquals(DataType.BOOL, pg.getPropertyMap().get("flag").getDataType());
Assert.assertEquals(DataType.DOUBLE, pg.getPropertyMap().get("score").getDataType());
}
+
+ @Test
+ public void testIsValidated() {
+ // Test valid property group
+ Assert.assertTrue(basicGroup.isValidated());
+ Assert.assertTrue(singlePropertyGroup.isValidated());
+
+ // Test invalid property group with null prefix
+ PropertyGroup nullPrefixGroup =
+ TestDataFactory.createPropertyGroup(
+ Arrays.asList(idProperty, nameProperty), FileType.CSV, null);
+ Assert.assertFalse(nullPrefixGroup.isValidated());
+
+ // Test invalid property group with empty prefix
+ PropertyGroup emptyPrefixGroup =
+ TestDataFactory.createPropertyGroup(
+ Arrays.asList(idProperty, nameProperty), FileType.CSV, "");
+ Assert.assertFalse(emptyPrefixGroup.isValidated());
+
+ // Test invalid property group with null file type
+ PropertyGroup nullFileTypeGroup =
+ new PropertyGroup(Arrays.asList(idProperty, nameProperty), null, "test/");
+ Assert.assertFalse(nullFileTypeGroup.isValidated());
+
+ // Test invalid property group with invalid file type values
+ // This test is not applicable in Java as FileType is an enum and cannot have invalid values
+
+ // Test invalid property group with empty property list
+ Assert.assertFalse(emptyGroup.isValidated());
+
+ // Test invalid property group with property having empty name
+ Property emptyNameProperty =
+ TestDataFactory.createProperty("", DataType.STRING, false, true);
+ PropertyGroup groupWithEmptyNameProperty =
+ new PropertyGroup(
+ Arrays.asList(idProperty, emptyNameProperty), FileType.CSV, "test/");
+ Assert.assertFalse(groupWithEmptyNameProperty.isValidated());
+
+ // Test invalid property group with property having null data type
+ Property nullDataTypeProperty = new Property("nullType", null, false, true);
+ PropertyGroup groupWithNullDataTypeProperty =
+ new PropertyGroup(
+ Arrays.asList(idProperty, nullDataTypeProperty), FileType.CSV, "test/");
+ Assert.assertFalse(groupWithNullDataTypeProperty.isValidated());
+
+ // Test invalid property group with CSV file type and LIST data type
+ Property listProperty =
+ TestDataFactory.createProperty("listProp", DataType.LIST, false, true);
+ PropertyGroup csvWithListGroup =
+ new PropertyGroup(Arrays.asList(listProperty), FileType.CSV, "test/");
+ Assert.assertFalse(csvWithListGroup.isValidated());
+ }
}
diff --git a/maven-projects/info/src/test/java/org/apache/graphar/info/VertexInfoTest.java b/maven-projects/info/src/test/java/org/apache/graphar/info/VertexInfoTest.java
new file mode 100644
index 0000000..4cf486a
--- /dev/null
+++ b/maven-projects/info/src/test/java/org/apache/graphar/info/VertexInfoTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.net.URI;
+import java.util.Arrays;
+import org.apache.graphar.info.type.DataType;
+import org.apache.graphar.info.type.FileType;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class VertexInfoTest {
+
+ @Test
+ public void testBuildWithPrefix() {
+ try {
+ VertexInfo vertexInfo =
+ new VertexInfo(
+ "person", 100, Arrays.asList(TestUtil.pg1), "vertex/person/", "gar/v1");
+ Assert.assertEquals(URI.create("vertex/person/"), vertexInfo.getBaseUri());
+ } catch (Exception e) {
+ Assert.fail("Should not throw exception: " + e.getMessage());
+ }
+ }
+
+ @Test
+ public void testIsValidated() {
+ // Test valid vertex info
+ VertexInfo validVertexInfo =
+ new VertexInfo(
+ "person", 100, Arrays.asList(TestUtil.pg1), "vertex/person/", "gar/v1");
+ Assert.assertTrue(validVertexInfo.isValidated());
+
+ // Test invalid vertex info with empty type
+ VertexInfo emptyTypeVertexInfo =
+ new VertexInfo("", 100, Arrays.asList(TestUtil.pg1), "vertex/person/", "gar/v1");
+ Assert.assertFalse(emptyTypeVertexInfo.isValidated());
+
+ // Test invalid vertex info with zero chunk size
+ VertexInfo zeroChunkSizeVertexInfo =
+ new VertexInfo(
+ "person", 0, Arrays.asList(TestUtil.pg1), "vertex/person/", "gar/v1");
+ Assert.assertFalse(zeroChunkSizeVertexInfo.isValidated());
+
+ // Test invalid vertex info with null prefix
+ VertexInfo nullPrefixVertexInfo =
+ new VertexInfo("person", 100, Arrays.asList(TestUtil.pg1), (URI) null, "gar/v1");
+ Assert.assertFalse(nullPrefixVertexInfo.isValidated());
+
+ // Test invalid vertex info with invalid property group
+ Property invalidProperty = new Property("", DataType.STRING, false, true);
+ PropertyGroup invalidPropertyGroup =
+ new PropertyGroup(Arrays.asList(invalidProperty), FileType.CSV, "invalid/");
+ VertexInfo invalidPropertyGroupVertexInfo =
+ new VertexInfo(
+ "person",
+ 100,
+ Arrays.asList(invalidPropertyGroup),
+ "vertex/person/",
+ "gar/v1");
+ Assert.assertFalse(invalidPropertyGroupVertexInfo.isValidated());
+ }
+}
diff --git a/testing b/testing
index 12b4b17..8286724 160000
--- a/testing
+++ b/testing
@@ -1 +1 @@
-Subproject commit 12b4b17561ca3e414366b176a8760b7ee825f7d9
+Subproject commit 8286724cd898047de833f0304dbddd2831afdf9f