This is an automated email from the ASF dual-hosted git repository.
yecol pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-graphar.git
The following commit(s) were added to refs/heads/main by this push:
new 0a44e04a chore(java,info): add default graphInfo prefix and remove
extra '/' (#708)
0a44e04a is described below
commit 0a44e04aef1c0dcf078b77b81f66068942f98fcf
Author: Xiaokang Yang <[email protected]>
AuthorDate: Wed Jul 2 10:45:00 2025 +0800
chore(java,info): add default graphInfo prefix and remove extra '/' (#708)
* remove extra '/'
* add default graphInfo prefix
* add license
---
.../java/org/apache/graphar/info/EdgeInfo.java | 18 +++---
.../java/org/apache/graphar/info/VertexInfo.java | 8 +--
.../graphar/info/loader/LocalYamlGraphLoader.java | 8 ++-
.../java/org/apache/graphar/util/PathUtil.java | 48 ++++++++++++++++
.../org/apache/graphar/info/GraphInfoTest.java | 67 +++++++++++-----------
5 files changed, 102 insertions(+), 47 deletions(-)
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 233313c3..5bcd1937 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
@@ -161,36 +161,36 @@ public class EdgeInfo {
public String getPropertyGroupPrefix(PropertyGroup propertyGroup) {
checkPropertyGroupExist(propertyGroup);
- return getPrefix() + "/" + propertyGroup.getPrefix();
+ return getPrefix() + propertyGroup.getPrefix();
}
public String getPropertyGroupChunkPath(PropertyGroup propertyGroup, long
chunkIndex) {
// PropertyGroup will be checked in getPropertyGroupPrefix
- return getPropertyGroupPrefix(propertyGroup) + "/chunk" + chunkIndex;
+ return getPropertyGroupPrefix(propertyGroup) + "chunk" + chunkIndex;
}
public String getAdjacentListPrefix(AdjListType adjListType) {
- return getPrefix() + "/" + getAdjacentList(adjListType).getPrefix() +
"/adj_list";
+ return getPrefix() + getAdjacentList(adjListType).getPrefix() +
"adj_list/";
}
public String getAdjacentListChunkPath(AdjListType adjListType, long
vertexChunkIndex) {
- return getAdjacentListPrefix(adjListType) + "/chunk" +
vertexChunkIndex;
+ return getAdjacentListPrefix(adjListType) + "chunk" + vertexChunkIndex;
}
public String getOffsetPrefix(AdjListType adjListType) {
- return getAdjacentListPrefix(adjListType) + "/offset";
+ return getAdjacentListPrefix(adjListType) + "offset/";
}
public String getOffsetChunkPath(AdjListType adjListType, long
vertexChunkIndex) {
- return getOffsetPrefix(adjListType) + "/chunk" + vertexChunkIndex;
+ return getOffsetPrefix(adjListType) + "chunk" + vertexChunkIndex;
}
public String getVerticesNumFilePath(AdjListType adjListType) {
- return getAdjacentListPrefix(adjListType) + "/vertex_count";
+ return getAdjacentListPrefix(adjListType) + "vertex_count";
}
public String getEdgesNumFilePath(AdjListType adjListType, long
vertexChunkIndex) {
- return getAdjacentListPrefix(adjListType) + "/edge_count" +
vertexChunkIndex;
+ return getAdjacentListPrefix(adjListType) + "edge_count" +
vertexChunkIndex;
}
public DataType getPropertyType(String propertyName) {
@@ -248,7 +248,7 @@ public class EdgeInfo {
}
public String getEdgePath() {
- return getPrefix() + "/" + getConcat() + ".edge.yaml";
+ return getPrefix() + getConcat() + ".edge.yaml";
}
public Map<AdjListType, AdjacentList> getAdjacentLists() {
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 d3247562..ba1e51a4 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
@@ -98,16 +98,16 @@ public class VertexInfo {
public String getPropertyGroupPrefix(PropertyGroup propertyGroup) {
checkPropertyGroupExist(propertyGroup);
- return getPrefix() + "/" + propertyGroup.getPrefix();
+ return getPrefix() + propertyGroup.getPrefix();
}
public String getPropertyGroupChunkPath(PropertyGroup propertyGroup, long
chunkIndex) {
// PropertyGroup will be checked in getPropertyGroupPrefix
- return getPropertyGroupPrefix(propertyGroup) + "/chunk" + chunkIndex;
+ return getPropertyGroupPrefix(propertyGroup) + "chunk" + chunkIndex;
}
public String getVerticesNumFilePath() {
- return getPrefix() + "/vertex_count";
+ return getPrefix() + "vertex_count";
}
public String dump() {
@@ -133,7 +133,7 @@ public class VertexInfo {
}
public String getVertexPath() {
- return getPrefix() + "/" + getType() + ".vertex.yaml";
+ return getPrefix() + getType() + ".vertex.yaml";
}
private void checkPropertyGroupExist(PropertyGroup propertyGroup) {
diff --git
a/maven-projects/info/src/main/java/org/apache/graphar/info/loader/LocalYamlGraphLoader.java
b/maven-projects/info/src/main/java/org/apache/graphar/info/loader/LocalYamlGraphLoader.java
index 6ca462ed..c8ee8d5c 100644
---
a/maven-projects/info/src/main/java/org/apache/graphar/info/loader/LocalYamlGraphLoader.java
+++
b/maven-projects/info/src/main/java/org/apache/graphar/info/loader/LocalYamlGraphLoader.java
@@ -32,6 +32,7 @@ import org.apache.graphar.info.VertexInfo;
import org.apache.graphar.info.yaml.EdgeYaml;
import org.apache.graphar.info.yaml.GraphYaml;
import org.apache.graphar.info.yaml.VertexYaml;
+import org.apache.graphar.util.PathUtil;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
@@ -47,6 +48,11 @@ public class LocalYamlGraphLoader implements GraphLoader {
final Yaml yamlLoader = new Yaml(new Constructor(GraphYaml.class, new
LoaderOptions()));
final GraphYaml graphYaml = yamlLoader.load(reader);
reader.close();
+ String defaultPrefix = PathUtil.pathToDirectory(graphYamlPath);
+ String prefix = defaultPrefix;
+ if (graphYaml.getPrefix() != null && !graphYaml.getPrefix().isEmpty())
{
+ prefix = graphYaml.getPrefix();
+ }
// load vertices
final String ABSOLUTE_PREFIX = path.getParent().toString();
@@ -59,7 +65,7 @@ public class LocalYamlGraphLoader implements GraphLoader {
for (String edgeYamlName : graphYaml.getEdges()) {
edgeInfos.add(loadEdge(ABSOLUTE_PREFIX + "/" + edgeYamlName));
}
- return new GraphInfo(graphYaml.getName(), vertexInfos, edgeInfos,
graphYaml.getPrefix());
+ return new GraphInfo(graphYaml.getName(), vertexInfos, edgeInfos,
prefix);
}
private VertexInfo loadVertex(String path) throws IOException {
diff --git
a/maven-projects/info/src/main/java/org/apache/graphar/util/PathUtil.java
b/maven-projects/info/src/main/java/org/apache/graphar/util/PathUtil.java
new file mode 100644
index 00000000..7b68c543
--- /dev/null
+++ b/maven-projects/info/src/main/java/org/apache/graphar/util/PathUtil.java
@@ -0,0 +1,48 @@
+/*
+ * 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.util;
+
+public class PathUtil {
+ public static String pathToDirectory(String path) {
+ if (path.startsWith("s3://")) {
+ int t = path.indexOf('?');
+ if (t != -1) {
+ String prefix = path.substring(0, t);
+ String suffix = path.substring(t);
+ int lastSlashIdx = prefix.lastIndexOf('/');
+ if (lastSlashIdx != -1) {
+ return prefix.substring(0, lastSlashIdx + 1) + suffix;
+ }
+ } else {
+ int lastSlashIdx = path.lastIndexOf('/');
+ if (lastSlashIdx != -1) {
+ return path.substring(0, lastSlashIdx + 1);
+ }
+ return path;
+ }
+ } else {
+ int lastSlashIdx = path.lastIndexOf('/');
+ if (lastSlashIdx != -1) {
+ return path.substring(0, lastSlashIdx + 1);
+ }
+ }
+ return path;
+ }
+}
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 55ca737d..28bb69f1 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
@@ -25,6 +25,7 @@ import org.apache.graphar.info.loader.LocalYamlGraphLoader;
import org.apache.graphar.proto.AdjListType;
import org.apache.graphar.proto.DataType;
import org.apache.graphar.proto.FileType;
+import org.apache.graphar.util.PathUtil;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -35,12 +36,13 @@ public class GraphInfoTest {
private static GraphInfo graphInfo;
private static VertexInfo personVertexInfo;
private static EdgeInfo knowsEdgeInfo;
+ private static String GRAPH_PATH;
@BeforeClass
public static void setUp() {
TestUtil.checkTestData();
+ GRAPH_PATH = TestUtil.getLdbcSampleGraphPath();
final GraphLoader graphLoader = new LocalYamlGraphLoader();
- final String GRAPH_PATH = TestUtil.getLdbcSampleGraphPath();
try {
graphInfo = graphLoader.load(GRAPH_PATH);
} catch (IOException e) {
@@ -57,7 +59,7 @@ public class GraphInfoTest {
public void testGraphInfoBasics() {
Assert.assertNotNull(graphInfo);
Assert.assertEquals("ldbc_sample", graphInfo.getName());
- Assert.assertEquals("", graphInfo.getPrefix());
+ Assert.assertEquals(PathUtil.pathToDirectory(GRAPH_PATH),
graphInfo.getPrefix());
Assert.assertNotNull(graphInfo.getEdgeInfos());
Assert.assertEquals(1, graphInfo.getEdgeInfos().size());
Assert.assertNotNull(graphInfo.getVertexInfos());
@@ -71,9 +73,8 @@ public class GraphInfoTest {
Assert.assertEquals(100, personVertexInfo.getChunkSize());
Assert.assertEquals("vertex/person/", personVertexInfo.getPrefix());
Assert.assertEquals(
- "vertex/person//vertex_count",
- personVertexInfo.getVerticesNumFilePath()); // TODO remove
extra '/' issue#698
- Assert.assertEquals("vertex/person//person.vertex.yaml",
personVertexInfo.getVertexPath());
+ "vertex/person/vertex_count",
personVertexInfo.getVerticesNumFilePath());
+ Assert.assertEquals("vertex/person/person.vertex.yaml",
personVertexInfo.getVertexPath());
Assert.assertNotNull(personVertexInfo.getPropertyGroups());
Assert.assertEquals(2, personVertexInfo.getPropertyGroups().size());
}
@@ -85,12 +86,12 @@ public class GraphInfoTest {
Assert.assertEquals("id/", idPropertyGroup.getPrefix());
Assert.assertEquals(FileType.CSV, idPropertyGroup.getFileType());
Assert.assertEquals(
- "vertex/person//id/",
personVertexInfo.getPropertyGroupPrefix(idPropertyGroup));
+ "vertex/person/id/",
personVertexInfo.getPropertyGroupPrefix(idPropertyGroup));
Assert.assertEquals(
- "vertex/person//id//chunk0",
+ "vertex/person/id/chunk0",
personVertexInfo.getPropertyGroupChunkPath(idPropertyGroup,
0));
Assert.assertEquals(
- "vertex/person//id//chunk4",
+ "vertex/person/id/chunk4",
personVertexInfo.getPropertyGroupChunkPath(idPropertyGroup,
4));
Assert.assertNotNull(idPropertyGroup.getPropertyList());
Assert.assertEquals(1, idPropertyGroup.getPropertyList().size());
@@ -105,13 +106,13 @@ public class GraphInfoTest {
Assert.assertEquals("firstName_lastName_gender/",
firstName_lastName_gender.getPrefix());
Assert.assertEquals(FileType.CSV,
firstName_lastName_gender.getFileType());
Assert.assertEquals(
- "vertex/person//firstName_lastName_gender/",
+ "vertex/person/firstName_lastName_gender/",
personVertexInfo.getPropertyGroupPrefix(firstName_lastName_gender));
Assert.assertEquals(
- "vertex/person//firstName_lastName_gender//chunk0",
+ "vertex/person/firstName_lastName_gender/chunk0",
personVertexInfo.getPropertyGroupChunkPath(firstName_lastName_gender, 0));
Assert.assertEquals(
- "vertex/person//firstName_lastName_gender//chunk4",
+ "vertex/person/firstName_lastName_gender/chunk4",
personVertexInfo.getPropertyGroupChunkPath(firstName_lastName_gender, 4));
Assert.assertNotNull(firstName_lastName_gender.getPropertyList());
Assert.assertEquals(3,
firstName_lastName_gender.getPropertyList().size());
@@ -147,7 +148,7 @@ public class GraphInfoTest {
Assert.assertEquals("person_knows_person", knowsEdgeInfo.getConcat());
Assert.assertEquals("edge/person_knows_person/",
knowsEdgeInfo.getPrefix());
Assert.assertEquals(
- "edge/person_knows_person//person_knows_person.edge.yaml",
+ "edge/person_knows_person/person_knows_person.edge.yaml",
knowsEdgeInfo.getEdgePath());
}
@@ -161,31 +162,31 @@ public class GraphInfoTest {
Assert.assertEquals(AdjListType.ORDERED_BY_SOURCE,
adjOrderBySource.getType());
Assert.assertEquals("ordered_by_source/",
adjOrderBySource.getPrefix());
Assert.assertEquals(
-
"edge/person_knows_person//ordered_by_source//adj_list/vertex_count",
+
"edge/person_knows_person/ordered_by_source/adj_list/vertex_count",
knowsEdgeInfo.getVerticesNumFilePath(AdjListType.ORDERED_BY_SOURCE));
Assert.assertEquals(
-
"edge/person_knows_person//ordered_by_source//adj_list/edge_count0",
+
"edge/person_knows_person/ordered_by_source/adj_list/edge_count0",
knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ORDERED_BY_SOURCE, 0));
Assert.assertEquals(
-
"edge/person_knows_person//ordered_by_source//adj_list/edge_count4",
+
"edge/person_knows_person/ordered_by_source/adj_list/edge_count4",
knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ORDERED_BY_SOURCE, 4));
Assert.assertEquals(
- "edge/person_knows_person//ordered_by_source//adj_list",
+ "edge/person_knows_person/ordered_by_source/adj_list/",
knowsEdgeInfo.getAdjacentListPrefix(AdjListType.ORDERED_BY_SOURCE));
Assert.assertEquals(
- "edge/person_knows_person//ordered_by_source//adj_list/chunk0",
+ "edge/person_knows_person/ordered_by_source/adj_list/chunk0",
knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ORDERED_BY_SOURCE, 0));
Assert.assertEquals(
- "edge/person_knows_person//ordered_by_source//adj_list/chunk4",
+ "edge/person_knows_person/ordered_by_source/adj_list/chunk4",
knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ORDERED_BY_SOURCE, 4));
Assert.assertEquals(
- "edge/person_knows_person//ordered_by_source//adj_list/offset",
+ "edge/person_knows_person/ordered_by_source/adj_list/offset/",
knowsEdgeInfo.getOffsetPrefix(AdjListType.ORDERED_BY_SOURCE));
Assert.assertEquals(
-
"edge/person_knows_person//ordered_by_source//adj_list/offset/chunk0",
+
"edge/person_knows_person/ordered_by_source/adj_list/offset/chunk0",
knowsEdgeInfo.getOffsetChunkPath(AdjListType.ORDERED_BY_SOURCE, 0));
Assert.assertEquals(
-
"edge/person_knows_person//ordered_by_source//adj_list/offset/chunk4",
+
"edge/person_knows_person/ordered_by_source/adj_list/offset/chunk4",
knowsEdgeInfo.getOffsetChunkPath(AdjListType.ORDERED_BY_SOURCE, 4));
// test ordered by destination adjacency list
@@ -195,31 +196,31 @@ public class GraphInfoTest {
Assert.assertEquals(AdjListType.ORDERED_BY_DESTINATION,
adjOrderByDestination.getType());
Assert.assertEquals("ordered_by_dest/",
adjOrderByDestination.getPrefix());
Assert.assertEquals(
-
"edge/person_knows_person//ordered_by_dest//adj_list/vertex_count",
+
"edge/person_knows_person/ordered_by_dest/adj_list/vertex_count",
knowsEdgeInfo.getVerticesNumFilePath(AdjListType.ORDERED_BY_DESTINATION));
Assert.assertEquals(
-
"edge/person_knows_person//ordered_by_dest//adj_list/edge_count0",
+
"edge/person_knows_person/ordered_by_dest/adj_list/edge_count0",
knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ORDERED_BY_DESTINATION, 0));
Assert.assertEquals(
-
"edge/person_knows_person//ordered_by_dest//adj_list/edge_count4",
+
"edge/person_knows_person/ordered_by_dest/adj_list/edge_count4",
knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ORDERED_BY_DESTINATION, 4));
Assert.assertEquals(
- "edge/person_knows_person//ordered_by_dest//adj_list",
+ "edge/person_knows_person/ordered_by_dest/adj_list/",
knowsEdgeInfo.getAdjacentListPrefix(AdjListType.ORDERED_BY_DESTINATION));
Assert.assertEquals(
- "edge/person_knows_person//ordered_by_dest//adj_list/chunk0",
+ "edge/person_knows_person/ordered_by_dest/adj_list/chunk0",
knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ORDERED_BY_DESTINATION, 0));
Assert.assertEquals(
- "edge/person_knows_person//ordered_by_dest//adj_list/chunk4",
+ "edge/person_knows_person/ordered_by_dest/adj_list/chunk4",
knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ORDERED_BY_DESTINATION, 4));
Assert.assertEquals(
- "edge/person_knows_person//ordered_by_dest//adj_list/offset",
+ "edge/person_knows_person/ordered_by_dest/adj_list/offset/",
knowsEdgeInfo.getOffsetPrefix(AdjListType.ORDERED_BY_DESTINATION));
Assert.assertEquals(
-
"edge/person_knows_person//ordered_by_dest//adj_list/offset/chunk0",
+
"edge/person_knows_person/ordered_by_dest/adj_list/offset/chunk0",
knowsEdgeInfo.getOffsetChunkPath(AdjListType.ORDERED_BY_DESTINATION, 0));
Assert.assertEquals(
-
"edge/person_knows_person//ordered_by_dest//adj_list/offset/chunk4",
+
"edge/person_knows_person/ordered_by_dest/adj_list/offset/chunk4",
knowsEdgeInfo.getOffsetChunkPath(AdjListType.ORDERED_BY_DESTINATION, 4));
}
@@ -231,13 +232,13 @@ public class GraphInfoTest {
Assert.assertEquals("creationDate/", propertyGroup.getPrefix());
Assert.assertEquals(FileType.CSV, propertyGroup.getFileType());
Assert.assertEquals(
- "edge/person_knows_person//creationDate/",
+ "edge/person_knows_person/creationDate/",
knowsEdgeInfo.getPropertyGroupPrefix(propertyGroup));
Assert.assertEquals(
- "edge/person_knows_person//creationDate//chunk0",
+ "edge/person_knows_person/creationDate/chunk0",
knowsEdgeInfo.getPropertyGroupChunkPath(propertyGroup, 0));
Assert.assertEquals(
- "edge/person_knows_person//creationDate//chunk4",
+ "edge/person_knows_person/creationDate/chunk4",
knowsEdgeInfo.getPropertyGroupChunkPath(propertyGroup, 4));
// edge properties in group 1
Assert.assertNotNull(propertyGroup.getPropertyList());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]