This is an automated email from the ASF dual-hosted git repository.
xiaokang 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 676d301f feat(java,info): revert java info to pre protobuf version
(#727)
676d301f is described below
commit 676d301f254405419c593634a9569cc03a4d7d0e
Author: Xiaokang Yang <[email protected]>
AuthorDate: Thu Aug 14 17:34:52 2025 +0800
feat(java,info): revert java info to pre protobuf version (#727)
* revert to the pre-protobuf version
* format
* remove extra util class
* format
* fix
---
maven-projects/info/pom.xml | 79 +----
.../java/org/apache/graphar/info/AdjacentList.java | 40 ++-
.../java/org/apache/graphar/info/EdgeInfo.java | 318 +++++++++++++++------
.../java/org/apache/graphar/info/GraphInfo.java | 258 +++++++++++------
.../java/org/apache/graphar/info/Property.java | 42 ++-
.../org/apache/graphar/info/PropertyGroup.java | 117 +++-----
.../java/org/apache/graphar/info/VertexInfo.java | 135 ++++++---
.../org/apache/graphar/info/type/AdjListType.java | 50 ++++
.../org/apache/graphar/info/type/DataType.java | 69 +++++
.../org/apache/graphar/info/type/FileType.java | 42 +++
.../apache/graphar/info/yaml/AdjacentListYaml.java | 22 +-
.../org/apache/graphar/info/yaml/EdgeYaml.java | 8 +-
.../apache/graphar/info/yaml/EnumTransferUtil.java | 130 ---------
.../org/apache/graphar/info/yaml/GraphYaml.java | 5 +
.../graphar/info/yaml/PropertyGroupYaml.java | 5 +-
.../org/apache/graphar/info/yaml/PropertyYaml.java | 5 +-
.../org/apache/graphar/info/GraphInfoTest.java | 56 ++--
.../java/org/apache/graphar/info/TestUtil.java | 11 +-
18 files changed, 797 insertions(+), 595 deletions(-)
diff --git a/maven-projects/info/pom.xml b/maven-projects/info/pom.xml
index 3df2b5ba..52c85867 100644
--- a/maven-projects/info/pom.xml
+++ b/maven-projects/info/pom.xml
@@ -42,17 +42,9 @@
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <protobuf-maven-plugin.version>2.3.0</protobuf-maven-plugin.version>
- <protobuf.version>4.27.1</protobuf.version>
</properties>
<dependencies>
- <dependency>
- <groupId>com.google.protobuf</groupId>
- <artifactId>protobuf-java</artifactId>
- <version>${protobuf.version}</version>
- <scope>compile</scope>
- </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -65,28 +57,15 @@
<version>2.0</version>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-common</artifactId>
+ <version>3.4.0</version>
+ </dependency>
</dependencies>
<build>
<plugins>
- <plugin>
- <groupId>io.github.ascopes</groupId>
- <artifactId>protobuf-maven-plugin</artifactId>
- <version>${protobuf-maven-plugin.version}</version>
- <configuration>
- <sourceDirectories>
-
<sourceDirectory>${project.basedir}/../../format</sourceDirectory>
- </sourceDirectories>
- <protocVersion>${protobuf.version}</protocVersion>
- </configuration>
- <executions>
- <execution>
- <goals>
- <goal>generate</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
@@ -100,54 +79,6 @@
</java>
</configuration>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <version>3.6.0</version>
- <configuration>
- <shadedArtifactAttached>false</shadedArtifactAttached>
- <shadeTestJar>false</shadeTestJar>
- <artifactSet>
- <includes>
- <include>com.google.protobuf:*</include>
- <include>org.yaml:*</include>
- </includes>
- </artifactSet>
- <relocations>
- <relocation>
- <pattern>com.google.protobuf</pattern>
- <shadedPattern>org.graphar.protobuf</shadedPattern>
- <includes>
- <include>com.google.protobuf.**</include>
- </includes>
- </relocation>
- <relocation>
- <pattern>org.yaml</pattern>
- <shadedPattern>org.graphar.yaml</shadedPattern>
- <includes>
- <include>org.yaml.**</include>
- </includes>
- </relocation>
- </relocations>
- <filters>
- <filter>
- <artifact>*:*</artifact>
- <excludes>
- <exclude>google/protobuf/**</exclude>
- <exclude>yaml/snakeyaml/**</exclude>
- </excludes>
- </filter>
- </filters>
- </configuration>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
</plugins>
</build>
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 161eac27..ddf285de 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
@@ -19,42 +19,38 @@
package org.apache.graphar.info;
-import org.apache.graphar.proto.AdjListType;
-import org.apache.graphar.proto.FileType;
+import org.apache.graphar.info.type.AdjListType;
+import org.apache.graphar.info.type.FileType;
+import org.apache.graphar.info.yaml.AdjacentListYaml;
public class AdjacentList {
- private final org.apache.graphar.proto.AdjacentList protoAdjacentList;
+ private final AdjListType type;
+ private final FileType fileType;
+ private final String prefix;
public AdjacentList(AdjListType type, FileType fileType, String prefix) {
- protoAdjacentList =
- org.apache.graphar.proto.AdjacentList.newBuilder()
- .setType(type)
- .setFileType(fileType)
- .setPrefix(prefix)
- .build();
+ this.type = type;
+ this.fileType = fileType;
+ this.prefix = prefix;
}
- private AdjacentList(org.apache.graphar.proto.AdjacentList
protoAdjacentList) {
- this.protoAdjacentList = protoAdjacentList;
- }
-
- public static AdjacentList ofProto(org.apache.graphar.proto.AdjacentList
protoAdjacentList) {
- return new AdjacentList(protoAdjacentList);
+ AdjacentList(AdjacentListYaml yamlParser) {
+ this.type =
+ AdjListType.fromOrderedAndAlignedBy(
+ yamlParser.isOrdered(), yamlParser.getAligned_by());
+ this.fileType = FileType.fromString(yamlParser.getFile_type());
+ this.prefix = yamlParser.getPrefix();
}
public AdjListType getType() {
- return protoAdjacentList.getType();
+ return type;
}
public FileType getFileType() {
- return protoAdjacentList.getFileType();
+ return fileType;
}
public String getPrefix() {
- return protoAdjacentList.getPrefix();
- }
-
- org.apache.graphar.proto.AdjacentList getProto() {
- return protoAdjacentList;
+ return prefix;
}
}
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 141aeae1..07ecf619 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
@@ -19,28 +19,42 @@
package org.apache.graphar.info;
+import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.apache.graphar.info.type.AdjListType;
+import org.apache.graphar.info.type.DataType;
import org.apache.graphar.info.yaml.EdgeYaml;
import org.apache.graphar.info.yaml.GraphYaml;
-import org.apache.graphar.proto.AdjListType;
-import org.apache.graphar.proto.DataType;
import org.apache.graphar.util.GeneralParams;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.constructor.Constructor;
public class EdgeInfo {
- private final org.apache.graphar.proto.EdgeInfo protoEdgeInfo;
- private final Map<AdjListType, AdjacentList> cachedAdjacentLists;
- private final PropertyGroups cachedPropertyGroups;
+ private final EdgeTriplet edgeTriplet;
+ private final long chunkSize;
+ private final long srcChunkSize;
+ private final long dstChunkSize;
+ private final boolean directed;
+ private final String prefix;
+ private final Map<AdjListType, AdjacentList> adjacentLists;
+ private final PropertyGroups propertyGroups;
+ private final VersionInfo version;
public EdgeInfo(
- String srcLabel,
- String edgeLabel,
- String dstLabel,
+ String srcType,
+ String edgeType,
+ String dstType,
long chunkSize,
long srcChunkSize,
long dstChunkSize,
@@ -49,56 +63,128 @@ public class EdgeInfo {
String version,
List<AdjacentList> adjacentListsAsList,
List<PropertyGroup> propertyGroupsAsList) {
- this.cachedAdjacentLists =
+ this(
+ srcType,
+ edgeType,
+ dstType,
+ chunkSize,
+ srcChunkSize,
+ dstChunkSize,
+ directed,
+ prefix,
+ VersionParser.getVersion(version),
+ adjacentListsAsList,
+ propertyGroupsAsList);
+ }
+
+ public EdgeInfo(
+ String srcType,
+ String edgeType,
+ String dstType,
+ long chunkSize,
+ long srcChunkSize,
+ long dstChunkSize,
+ boolean directed,
+ String prefix,
+ VersionInfo version,
+ List<AdjacentList> adjacentListsAsList,
+ List<PropertyGroup> propertyGroupsAsList) {
+ this.edgeTriplet = new EdgeTriplet(srcType, edgeType, dstType);
+ this.chunkSize = chunkSize;
+ this.srcChunkSize = srcChunkSize;
+ this.dstChunkSize = dstChunkSize;
+ this.directed = directed;
+ this.prefix = prefix;
+ this.adjacentLists =
adjacentListsAsList.stream()
.collect(
Collectors.toUnmodifiableMap(
AdjacentList::getType,
Function.identity()));
- this.cachedPropertyGroups = new PropertyGroups(propertyGroupsAsList);
- this.protoEdgeInfo =
- org.apache.graphar.proto.EdgeInfo.newBuilder()
- .setSourceVertexType(srcLabel)
- .setType(edgeLabel)
- .setDestinationVertexChunkSize(dstChunkSize)
- .setChunkSize(chunkSize)
- .setSourceVertexChunkSize(srcChunkSize)
- .setDestinationVertexType(dstLabel)
- .setIsDirected(directed)
- .setPrefix(prefix)
- .setVersion(version)
- .addAllAdjacentList(
- adjacentListsAsList.stream()
- .map(AdjacentList::getProto)
-
.collect(Collectors.toUnmodifiableList()))
- .addAllProperties(
- propertyGroupsAsList.stream()
- .map(PropertyGroup::getProto)
-
.collect(Collectors.toUnmodifiableList()))
- .build();
- }
-
- public EdgeInfo(org.apache.graphar.proto.EdgeInfo protoEdgeInfo) {
- this.protoEdgeInfo = protoEdgeInfo;
- this.cachedAdjacentLists =
- protoEdgeInfo.getAdjacentListList().stream()
- .map(AdjacentList::ofProto)
- .collect(
- Collectors.toUnmodifiableMap(
- AdjacentList::getType,
Function.identity()));
- this.cachedPropertyGroups =
PropertyGroups.ofProto(protoEdgeInfo.getPropertiesList());
+ this.propertyGroups = new PropertyGroups(propertyGroupsAsList);
+ this.version = version;
+ }
+
+ private EdgeInfo(EdgeYaml yamlParser) {
+ this(
+ yamlParser.getSrc_type(),
+ yamlParser.getEdge_type(),
+ yamlParser.getDst_type(),
+ yamlParser.getChunk_size(),
+ yamlParser.getSrc_chunk_size(),
+ yamlParser.getDst_chunk_size(),
+ yamlParser.isDirected(),
+ yamlParser.getPrefix(),
+ yamlParser.getVersion(),
+ yamlParser.getAdj_lists().stream()
+ .map(AdjacentList::new)
+ .collect(Collectors.toUnmodifiableList()),
+ yamlParser.getProperty_groups().stream()
+ .map(PropertyGroup::new)
+ .collect(Collectors.toUnmodifiableList()));
}
private EdgeInfo(
- org.apache.graphar.proto.EdgeInfo protoEdgeInfo,
- Map<AdjListType, AdjacentList> cachedAdjacentLists,
- PropertyGroups cachedPropertyGroups) {
- this.protoEdgeInfo = protoEdgeInfo;
- this.cachedAdjacentLists = cachedAdjacentLists;
- this.cachedPropertyGroups = cachedPropertyGroups;
+ EdgeTriplet edgeTriplet,
+ long chunkSize,
+ long srcChunkSize,
+ long dstChunkSize,
+ boolean directed,
+ String prefix,
+ String version,
+ Map<AdjListType, AdjacentList> adjacentLists,
+ PropertyGroups propertyGroups) {
+ this(
+ edgeTriplet,
+ chunkSize,
+ srcChunkSize,
+ dstChunkSize,
+ directed,
+ prefix,
+ VersionParser.getVersion(version),
+ adjacentLists,
+ propertyGroups);
+ }
+
+ private EdgeInfo(
+ EdgeTriplet edgeTriplet,
+ long chunkSize,
+ long srcChunkSize,
+ long dstChunkSize,
+ boolean directed,
+ String prefix,
+ VersionInfo version,
+ Map<AdjListType, AdjacentList> adjacentLists,
+ PropertyGroups propertyGroups) {
+ this.edgeTriplet = edgeTriplet;
+ this.chunkSize = chunkSize;
+ this.srcChunkSize = srcChunkSize;
+ this.dstChunkSize = dstChunkSize;
+ this.directed = directed;
+ this.prefix = prefix;
+ this.adjacentLists = adjacentLists;
+ this.propertyGroups = propertyGroups;
+ this.version = version;
+ }
+
+ public static EdgeInfo load(String edgeInfoPath) throws IOException {
+ return load(edgeInfoPath, new Configuration());
+ }
+
+ public static EdgeInfo load(String edgeInfoPath, Configuration conf)
throws IOException {
+ if (conf == null) {
+ throw new IllegalArgumentException("Configuration is null");
+ }
+ return load(edgeInfoPath, FileSystem.get(conf));
}
- org.apache.graphar.proto.EdgeInfo getProto() {
- return protoEdgeInfo;
+ public static EdgeInfo load(String edgeInfoPath, FileSystem fileSystem)
throws IOException {
+ if (fileSystem == null) {
+ throw new IllegalArgumentException("FileSystem is null");
+ }
+ FSDataInputStream inputStream = fileSystem.open(new
Path(edgeInfoPath));
+ Yaml edgeInfoYamlLoader = new Yaml(new Constructor(EdgeYaml.class, new
LoaderOptions()));
+ EdgeYaml edgeInfoYaml = edgeInfoYamlLoader.load(inputStream);
+ return new EdgeInfo(edgeInfoYaml);
}
public static String concat(String srcLabel, String edgeLabel, String
dstLabel) {
@@ -110,39 +196,56 @@ public class EdgeInfo {
}
public Optional<EdgeInfo> addAdjacentListAsNew(AdjacentList adjacentList) {
- if (adjacentList == null ||
cachedAdjacentLists.containsKey(adjacentList.getType())) {
+ if (adjacentList == null ||
adjacentLists.containsKey(adjacentList.getType())) {
return Optional.empty();
}
Map<AdjListType, AdjacentList> newAdjacentLists =
Stream.concat(
- cachedAdjacentLists.entrySet().stream(),
+ adjacentLists.entrySet().stream(),
Map.of(adjacentList.getType(),
adjacentList).entrySet().stream())
.collect(
Collectors.toUnmodifiableMap(
Map.Entry::getKey,
Map.Entry::getValue));
- return Optional.of(new EdgeInfo(protoEdgeInfo, newAdjacentLists,
cachedPropertyGroups));
+ return Optional.of(
+ new EdgeInfo(
+ edgeTriplet,
+ chunkSize,
+ srcChunkSize,
+ dstChunkSize,
+ directed,
+ prefix,
+ version,
+ newAdjacentLists,
+ propertyGroups));
}
public Optional<EdgeInfo> addPropertyGroupAsNew(PropertyGroup
propertyGroup) {
- // do not need check property group exist, because PropertyGroups will
check it
- return cachedPropertyGroups
+ return propertyGroups
.addPropertyGroupAsNew(propertyGroup)
.map(
newPropertyGroups ->
new EdgeInfo(
- protoEdgeInfo, cachedAdjacentLists,
newPropertyGroups));
+ edgeTriplet,
+ chunkSize,
+ srcChunkSize,
+ dstChunkSize,
+ directed,
+ prefix,
+ version,
+ adjacentLists,
+ newPropertyGroups));
}
public boolean hasAdjListType(AdjListType adjListType) {
- return cachedAdjacentLists.containsKey(adjListType);
+ return adjacentLists.containsKey(adjListType);
}
public boolean hasProperty(String propertyName) {
- return cachedPropertyGroups.hasProperty(propertyName);
+ return propertyGroups.hasProperty(propertyName);
}
public boolean hasPropertyGroup(PropertyGroup propertyGroup) {
- return cachedPropertyGroups.hasPropertyGroup(propertyGroup);
+ return propertyGroups.hasPropertyGroup(propertyGroup);
}
public AdjacentList getAdjacentList(AdjListType adjListType) {
@@ -150,15 +253,15 @@ public class EdgeInfo {
// other methods which get adjacent list in this class should call
this method first,
// so we don't check AdjListType in other methods.
checkAdjListTypeExist(adjListType);
- return cachedAdjacentLists.get(adjListType);
+ return adjacentLists.get(adjListType);
}
public int getPropertyGroupNum() {
- return cachedPropertyGroups.getPropertyGroupNum();
+ return propertyGroups.getPropertyGroupNum();
}
public PropertyGroup getPropertyGroup(String property) {
- return cachedPropertyGroups.getPropertyGroup(property);
+ return propertyGroups.getPropertyGroup(property);
}
public String getPropertyGroupPrefix(PropertyGroup propertyGroup) {
@@ -196,15 +299,35 @@ public class EdgeInfo {
}
public DataType getPropertyType(String propertyName) {
- return cachedPropertyGroups.getPropertyType(propertyName);
+ return propertyGroups.getPropertyType(propertyName);
}
public boolean isPrimaryKey(String propertyName) {
- return cachedPropertyGroups.isPrimaryKey(propertyName);
+ return propertyGroups.isPrimaryKey(propertyName);
}
public boolean isNullableKey(String propertyName) {
- return cachedPropertyGroups.isNullableKey(propertyName);
+ return propertyGroups.isNullableKey(propertyName);
+ }
+
+ public void save(String filePath) throws IOException {
+ save(filePath, new Configuration());
+ }
+
+ public void save(String filePath, Configuration conf) throws IOException {
+ if (conf == null) {
+ throw new IllegalArgumentException("Configuration is null");
+ }
+ save(filePath, FileSystem.get(conf));
+ }
+
+ public void save(String fileName, FileSystem fileSystem) throws
IOException {
+ if (fileSystem == null) {
+ throw new IllegalArgumentException("FileSystem is null");
+ }
+ FSDataOutputStream outputStream = fileSystem.create(new
Path(fileName));
+ outputStream.writeBytes(dump());
+ outputStream.close();
}
public String dump() {
@@ -214,39 +337,39 @@ public class EdgeInfo {
}
public String getConcat() {
- return concat(getSrcLabel(), getEdgeLabel(), getDstLabel());
+ return edgeTriplet.getConcat();
}
- public String getSrcLabel() {
- return protoEdgeInfo.getSourceVertexType();
+ public String getSrcType() {
+ return edgeTriplet.getSrcType();
}
- public String getEdgeLabel() {
- return protoEdgeInfo.getType();
+ public String getEdgeType() {
+ return edgeTriplet.getEdgeType();
}
- public String getDstLabel() {
- return protoEdgeInfo.getDestinationVertexType();
+ public String getDstType() {
+ return edgeTriplet.getDstType();
}
public long getChunkSize() {
- return protoEdgeInfo.getChunkSize();
+ return chunkSize;
}
public long getSrcChunkSize() {
- return protoEdgeInfo.getSourceVertexChunkSize();
+ return srcChunkSize;
}
public long getDstChunkSize() {
- return protoEdgeInfo.getDestinationVertexChunkSize();
+ return dstChunkSize;
}
public boolean isDirected() {
- return protoEdgeInfo.getIsDirected();
+ return directed;
}
public String getPrefix() {
- return protoEdgeInfo.getPrefix();
+ return prefix;
}
public String getEdgePath() {
@@ -254,27 +377,27 @@ public class EdgeInfo {
}
public VersionInfo getVersion() {
- return VersionParser.getVersion(protoEdgeInfo.getVersion());
+ return version;
}
public Map<AdjListType, AdjacentList> getAdjacentLists() {
- return cachedAdjacentLists;
+ return adjacentLists;
}
public List<PropertyGroup> getPropertyGroups() {
- return cachedPropertyGroups.getPropertyGroupList();
+ return propertyGroups.getPropertyGroupList();
}
private void checkAdjListTypeExist(AdjListType adjListType) {
if (adjListType == null) {
throw new IllegalArgumentException("The adjacency list type is
null");
}
- if (!cachedAdjacentLists.containsKey(adjListType)) {
+ if (!adjacentLists.containsKey(adjListType)) {
throw new IllegalArgumentException(
"The adjacency list type "
+ adjListType
+ " does not exist in the edge info "
- + getConcat());
+ + this.edgeTriplet.getConcat());
}
}
@@ -290,4 +413,37 @@ public class EdgeInfo {
+ getConcat());
}
}
+
+ private static class EdgeTriplet {
+ private final String srcType;
+ private final String edgeType;
+ private final String dstType;
+
+ public EdgeTriplet(String srcType, String edgeType, String dstType) {
+ this.srcType = srcType;
+ this.edgeType = edgeType;
+ this.dstType = dstType;
+ }
+
+ public String getConcat() {
+ return EdgeInfo.concat(srcType, edgeType, dstType);
+ }
+
+ @Override
+ public String toString() {
+ return getConcat();
+ }
+
+ public String getSrcType() {
+ return srcType;
+ }
+
+ public String getEdgeType() {
+ return edgeType;
+ }
+
+ public String getDstType() {
+ return dstType;
+ }
+ }
}
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 0578d32e..ddad1a88 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
@@ -19,6 +19,8 @@
package org.apache.graphar.info;
+import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -26,15 +28,23 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.graphar.info.yaml.GraphYaml;
-import org.apache.graphar.util.GeneralParams;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.constructor.Constructor;
public class GraphInfo {
- private final org.apache.graphar.proto.GraphInfo protoGraphInfo;
- private final List<VertexInfo> cachedVertexInfoList;
- private final List<EdgeInfo> cachedEdgeInfoList;
- private final Map<String, VertexInfo> cachedVertexInfoMap;
- private final Map<String, EdgeInfo> cachedEdgeInfoMap;
+ private final String name;
+ private final List<VertexInfo> vertexInfos;
+ private final List<EdgeInfo> edgeInfos;
+ private final String prefix;
+ private final Map<String, VertexInfo> vertexType2VertexInfo;
+ private final Map<String, EdgeInfo> edgeConcat2EdgeInfo;
+ private final VersionInfo version;
public GraphInfo(
String name,
@@ -42,46 +52,108 @@ public class GraphInfo {
List<EdgeInfo> edgeInfos,
String prefix,
String version) {
- this.cachedVertexInfoList = List.copyOf(vertexInfos);
- this.cachedEdgeInfoList = List.copyOf(edgeInfos);
- this.cachedVertexInfoMap =
+ this.name = name;
+ this.vertexInfos = List.copyOf(vertexInfos);
+ this.edgeInfos = List.copyOf(edgeInfos);
+ this.prefix = prefix;
+ this.version = VersionParser.getVersion(version);
+ this.vertexType2VertexInfo =
vertexInfos.stream()
.collect(
Collectors.toUnmodifiableMap(
VertexInfo::getType,
Function.identity()));
- this.cachedEdgeInfoMap =
+ this.edgeConcat2EdgeInfo =
edgeInfos.stream()
.collect(
Collectors.toUnmodifiableMap(
EdgeInfo::getConcat,
Function.identity()));
- this.protoGraphInfo =
- org.apache.graphar.proto.GraphInfo.newBuilder()
- .setName(name)
- .addAllVertices(
- vertexInfos.stream()
- .map(VertexInfo::getVertexPath)
- .collect(Collectors.toList()))
- .addAllEdges(
- edgeInfos.stream()
- .map(EdgeInfo::getEdgePath)
- .collect(Collectors.toList()))
- .setPrefix(prefix)
- .setVersion(version)
- .build();
+ }
+
+ private GraphInfo(GraphYaml graphYaml, Configuration conf) throws
IOException {
+ this(
+ graphYaml.getName(),
+ vertexFileNames2VertexInfos(graphYaml.getVertices(), conf),
+ edgeFileNames2EdgeInfos(graphYaml.getEdges(), conf),
+ graphYaml.getPrefix(),
+ graphYaml.getVersion());
+ }
+
+ private GraphInfo(
+ String name,
+ List<VertexInfo> vertexInfos,
+ List<EdgeInfo> edgeInfos,
+ String prefix,
+ String version,
+ Map<String, VertexInfo> vertexType2VertexInfo,
+ Map<String, EdgeInfo> edgeConcat2EdgeInfo) {
+ this(
+ name,
+ vertexInfos,
+ edgeInfos,
+ prefix,
+ VersionParser.getVersion(version),
+ vertexType2VertexInfo,
+ edgeConcat2EdgeInfo);
}
private GraphInfo(
- org.apache.graphar.proto.GraphInfo protoGraphInfo,
- List<VertexInfo> cachedVertexInfoList,
- List<EdgeInfo> cachedEdgeInfoList,
- Map<String, VertexInfo> cachedVertexInfoMap,
- Map<String, EdgeInfo> cachedEdgeInfoMap) {
+ String name,
+ List<VertexInfo> vertexInfos,
+ List<EdgeInfo> edgeInfos,
+ String prefix,
+ VersionInfo version,
+ Map<String, VertexInfo> vertexType2VertexInfo,
+ Map<String, EdgeInfo> edgeConcat2EdgeInfo) {
+ this.name = name;
+ this.vertexInfos = vertexInfos;
+ this.edgeInfos = edgeInfos;
+ this.prefix = prefix;
+ this.version = version;
+ this.vertexType2VertexInfo = vertexType2VertexInfo;
+ this.edgeConcat2EdgeInfo = edgeConcat2EdgeInfo;
+ }
- this.protoGraphInfo = protoGraphInfo;
- this.cachedVertexInfoList = cachedVertexInfoList;
- this.cachedEdgeInfoList = cachedEdgeInfoList;
- this.cachedVertexInfoMap = cachedVertexInfoMap;
- this.cachedEdgeInfoMap = cachedEdgeInfoMap;
+ public static GraphInfo load(String graphPath) throws IOException {
+ return load(graphPath, new Configuration());
+ }
+
+ public static GraphInfo load(String graphPath, FileSystem fileSystem)
throws IOException {
+ if (fileSystem == null) {
+ throw new IllegalArgumentException("FileSystem is null");
+ }
+ return load(graphPath, fileSystem.getConf());
+ }
+
+ public static GraphInfo load(String graphPath, Configuration conf) throws
IOException {
+ if (conf == null) {
+ throw new IllegalArgumentException("Configuration is null");
+ }
+ Path path = new Path(graphPath);
+ FileSystem fileSystem = path.getFileSystem(conf);
+ FSDataInputStream inputStream = fileSystem.open(path);
+ Yaml graphYamlLoader = new Yaml(new Constructor(GraphYaml.class, new
LoaderOptions()));
+ GraphYaml graphYaml = graphYamlLoader.load(inputStream);
+ return new GraphInfo(graphYaml, conf);
+ }
+
+ public void save(String filePath) throws IOException {
+ save(filePath, new Configuration());
+ }
+
+ public void save(String filePath, Configuration conf) throws IOException {
+ if (conf == null) {
+ throw new IllegalArgumentException("Configuration is null");
+ }
+ save(filePath, FileSystem.get(conf));
+ }
+
+ public void save(String fileName, FileSystem fileSystem) throws
IOException {
+ if (fileSystem == null) {
+ throw new IllegalArgumentException("FileSystem is null");
+ }
+ FSDataOutputStream outputStream = fileSystem.create(new
Path(fileName));
+ outputStream.writeBytes(dump());
+ outputStream.close();
}
public String dump() {
@@ -94,121 +166,129 @@ public class GraphInfo {
if (vertexInfo == null || hasVertexInfo(vertexInfo.getType())) {
return Optional.empty();
}
- final org.apache.graphar.proto.GraphInfo newProtoGraphInfo =
- org.apache.graphar.proto.GraphInfo.newBuilder(protoGraphInfo)
- .addVertices(vertexInfo.getVertexPath())
- .build();
- final List<VertexInfo> newVertexInfoList =
- Stream.concat(cachedVertexInfoList.stream(),
Stream.of(vertexInfo))
+ List<VertexInfo> newVertexInfos =
+ Stream.concat(vertexInfos.stream(), Stream.of(vertexInfo))
.collect(Collectors.toList());
- final Map<String, VertexInfo> newVertexInfoMap =
+ Map<String, VertexInfo> newVertexType2VertexInfo =
Stream.concat(
- cachedVertexInfoMap.entrySet().stream(),
+ vertexType2VertexInfo.entrySet().stream(),
Stream.of(Map.entry(vertexInfo.getType(),
vertexInfo)))
.collect(
Collectors.toUnmodifiableMap(
Map.Entry::getKey,
Map.Entry::getValue));
return Optional.of(
new GraphInfo(
- newProtoGraphInfo,
- newVertexInfoList,
- cachedEdgeInfoList,
- newVertexInfoMap,
- cachedEdgeInfoMap));
+ name,
+ newVertexInfos,
+ edgeInfos,
+ prefix,
+ version,
+ newVertexType2VertexInfo,
+ edgeConcat2EdgeInfo));
}
public Optional<GraphInfo> addEdgeAsNew(EdgeInfo edgeInfo) {
if (edgeInfo == null
|| hasEdgeInfo(
- edgeInfo.getSrcLabel(), edgeInfo.getEdgeLabel(),
edgeInfo.getDstLabel())) {
+ edgeInfo.getSrcType(), edgeInfo.getEdgeType(),
edgeInfo.getDstType())) {
return Optional.empty();
}
- final org.apache.graphar.proto.GraphInfo newProtoGraphInfo =
- org.apache.graphar.proto.GraphInfo.newBuilder(protoGraphInfo)
- .addEdges(edgeInfo.getEdgePath())
- .build();
- final List<EdgeInfo> newEdgeInfos =
- Stream.concat(cachedEdgeInfoList.stream(), Stream.of(edgeInfo))
- .collect(Collectors.toList());
- final Map<String, EdgeInfo> newEdgeConcat2EdgeInfo =
+ List<EdgeInfo> newEdgeInfos =
+ Stream.concat(edgeInfos.stream(),
Stream.of(edgeInfo)).collect(Collectors.toList());
+ Map<String, EdgeInfo> newEdgeConcat2EdgeInfo =
Stream.concat(
- cachedEdgeInfoMap.entrySet().stream(),
+ edgeConcat2EdgeInfo.entrySet().stream(),
Stream.of(Map.entry(edgeInfo.getConcat(),
edgeInfo)))
.collect(
Collectors.toUnmodifiableMap(
Map.Entry::getKey,
Map.Entry::getValue));
return Optional.of(
new GraphInfo(
- newProtoGraphInfo,
- cachedVertexInfoList,
+ name,
+ vertexInfos,
newEdgeInfos,
- cachedVertexInfoMap,
+ prefix,
+ version,
+ vertexType2VertexInfo,
newEdgeConcat2EdgeInfo));
}
- public boolean hasVertexInfo(String label) {
- return cachedVertexInfoMap.containsKey(label);
+ public boolean hasVertexInfo(String type) {
+ return vertexType2VertexInfo.containsKey(type);
}
- public boolean hasEdgeInfo(String srcLabel, String edgeLabel, String
dstLabel) {
- return cachedEdgeInfoMap.containsKey(EdgeInfo.concat(srcLabel,
edgeLabel, dstLabel));
+ public boolean hasEdgeInfo(String srcType, String edgeType, String
dstType) {
+ return edgeConcat2EdgeInfo.containsKey(EdgeInfo.concat(srcType,
dstType, edgeType));
}
- public VertexInfo getVertexInfo(String label) {
- checkVertexExist(label);
- return cachedVertexInfoMap.get(label);
+ public VertexInfo getVertexInfo(String type) {
+ checkVertexExist(type);
+ return vertexType2VertexInfo.get(type);
}
- public EdgeInfo getEdgeInfo(String srcLabel, String edgeLabel, String
dstLabel) {
- checkEdgeExist(srcLabel, edgeLabel, dstLabel);
- return cachedEdgeInfoMap.get(EdgeInfo.concat(srcLabel, edgeLabel,
dstLabel));
+ public EdgeInfo getEdgeInfo(String srcType, String edgeType, String
dstType) {
+ checkEdgeExist(srcType, edgeType, dstType);
+ return edgeConcat2EdgeInfo.get(EdgeInfo.concat(srcType, dstType,
edgeType));
}
public int getVertexInfoNum() {
- return cachedVertexInfoList.size();
+ return vertexInfos.size();
}
public int getEdgeInfoNum() {
- return cachedEdgeInfoList.size();
+ return edgeInfos.size();
}
public String getName() {
- return protoGraphInfo.getName();
+ return name;
}
public List<VertexInfo> getVertexInfos() {
- return cachedVertexInfoList;
+ return vertexInfos;
}
public List<EdgeInfo> getEdgeInfos() {
- return cachedEdgeInfoList;
+ return edgeInfos;
}
public String getPrefix() {
- return protoGraphInfo.getPrefix();
+ return prefix;
}
public VersionInfo getVersion() {
- return VersionParser.getVersion(protoGraphInfo.getVersion());
+ return version;
+ }
+
+ private static List<VertexInfo> vertexFileNames2VertexInfos(
+ List<String> vertexFileNames, Configuration conf) throws
IOException {
+ ArrayList<VertexInfo> tempVertices = new
ArrayList<>(vertexFileNames.size());
+ for (String vertexFileName : vertexFileNames) {
+ tempVertices.add(VertexInfo.load(vertexFileName, conf));
+ }
+ return List.copyOf(tempVertices);
+ }
+
+ private static List<EdgeInfo> edgeFileNames2EdgeInfos(
+ List<String> edgeFileNames, Configuration conf) throws IOException
{
+ ArrayList<EdgeInfo> tempEdges = new ArrayList<>(edgeFileNames.size());
+ for (String edgeFileName : edgeFileNames) {
+ tempEdges.add(EdgeInfo.load(edgeFileName, conf));
+ }
+ return List.copyOf(tempEdges);
}
- private void checkVertexExist(String label) {
- if (!hasVertexInfo(label)) {
+ private void checkVertexExist(String type) {
+ if (!hasVertexInfo(type)) {
throw new IllegalArgumentException(
- "Vertex label " + label + " not exist in graph " +
getName());
+ "Vertex type " + type + " not exist in graph " +
getName());
}
}
- private void checkEdgeExist(String srcLabel, String dstLabel, String
edgeLabel) {
- if (!hasEdgeInfo(srcLabel, dstLabel, edgeLabel)) {
+ private void checkEdgeExist(String srcType, String dstType, String
edgeType) {
+ if (!hasEdgeInfo(srcType, dstType, edgeType)) {
throw new IllegalArgumentException(
- "Edge label"
- + srcLabel
- + GeneralParams.regularSeparator
- + GeneralParams.regularSeparator
- + edgeLabel
- + GeneralParams.regularSeparator
- + dstLabel
+ "Edge type "
+ + EdgeInfo.concat(srcType, dstType, edgeType)
+ " not exist in graph "
+ getName());
}
diff --git
a/maven-projects/info/src/main/java/org/apache/graphar/info/Property.java
b/maven-projects/info/src/main/java/org/apache/graphar/info/Property.java
index 09ce2361..1221ebc1 100644
--- a/maven-projects/info/src/main/java/org/apache/graphar/info/Property.java
+++ b/maven-projects/info/src/main/java/org/apache/graphar/info/Property.java
@@ -19,46 +19,42 @@
package org.apache.graphar.info;
-import org.apache.graphar.proto.DataType;
+import org.apache.graphar.info.type.DataType;
+import org.apache.graphar.info.yaml.PropertyYaml;
public class Property {
- private final org.apache.graphar.proto.Property protoProperty;
+ private final String name;
+ private final DataType dataType;
+ private final boolean primary;
+ private final boolean nullable;
public Property(String name, DataType dataType, boolean primary, boolean
nullable) {
- protoProperty =
- org.apache.graphar.proto.Property.newBuilder()
- .setName(name)
- .setType(dataType)
- .setIsPrimaryKey(primary)
- .setIsNullable(nullable)
- .build();
+ this.name = name;
+ this.dataType = dataType;
+ this.primary = primary;
+ this.nullable = nullable;
}
- private Property(org.apache.graphar.proto.Property protoProperty) {
- this.protoProperty = protoProperty;
- }
-
- public static Property ofProto(org.apache.graphar.proto.Property
protoProperty) {
- return new Property(protoProperty);
+ Property(PropertyYaml yamlParser) {
+ this.name = yamlParser.getName();
+ this.dataType = DataType.fromString(yamlParser.getData_type());
+ this.primary = yamlParser.getIs_primary();
+ this.nullable = yamlParser.getIs_nullable();
}
public String getName() {
- return protoProperty.getName();
+ return name;
}
public DataType getDataType() {
- return protoProperty.getType();
+ return dataType;
}
public boolean isPrimary() {
- return protoProperty.getIsPrimaryKey();
+ return primary;
}
public boolean isNullable() {
- return protoProperty.getIsNullable();
- }
-
- org.apache.graphar.proto.Property getProto() {
- return protoProperty;
+ return nullable;
}
}
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 87b8d5bd..c00ce3f5 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
@@ -27,109 +27,80 @@ import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import org.apache.graphar.proto.DataType;
-import org.apache.graphar.proto.FileType;
+import org.apache.graphar.info.type.DataType;
+import org.apache.graphar.info.type.FileType;
+import org.apache.graphar.info.yaml.PropertyGroupYaml;
import org.apache.graphar.util.GeneralParams;
public class PropertyGroup implements Iterable<Property> {
- private final org.apache.graphar.proto.PropertyGroup protoPropertyGroup;
- private final List<Property> cachedPropertyList;
- private final Map<String, Property> cachedPropertyMap;
-
- public PropertyGroup(List<Property> propertyList, FileType fileType,
String prefix) {
- this.cachedPropertyList = List.copyOf(propertyList);
- this.cachedPropertyMap =
- cachedPropertyList.stream()
- .collect(
- Collectors.toUnmodifiableMap(
- Property::getName,
Function.identity()));
- this.protoPropertyGroup =
- org.apache.graphar.proto.PropertyGroup.newBuilder()
- .addAllProperties(
- cachedPropertyList.stream()
- .map(Property::getProto)
- .collect(Collectors.toList()))
- .setFileType(fileType)
- .setPrefix(prefix)
- .build();
- }
-
- private PropertyGroup(org.apache.graphar.proto.PropertyGroup
protoPropertyGroup) {
- this.protoPropertyGroup = protoPropertyGroup;
- this.cachedPropertyList =
- protoPropertyGroup.getPropertiesList().stream()
- .map(Property::ofProto)
- .collect(Collectors.toUnmodifiableList());
- this.cachedPropertyMap =
- cachedPropertyList.stream()
+ private final List<Property> propertyList;
+ private final Map<String, Property> propertyMap;
+ private final FileType fileType;
+ private final String prefix;
+
+ public PropertyGroup(List<Property> propertyMap, FileType fileType, String
prefix) {
+ this.propertyList = List.copyOf(propertyMap);
+ this.propertyMap =
+ propertyMap.stream()
.collect(
Collectors.toUnmodifiableMap(
Property::getName,
Function.identity()));
+ this.fileType = fileType;
+ this.prefix = prefix;
}
- public static PropertyGroup ofProto(org.apache.graphar.proto.PropertyGroup
protoPropertyGroup) {
- return new PropertyGroup(protoPropertyGroup);
+ PropertyGroup(PropertyGroupYaml yamlParser) {
+ this(
+ yamlParser.getProperties().stream()
+ .map(Property::new)
+ .collect(Collectors.toUnmodifiableList()),
+ FileType.fromString(yamlParser.getFile_type()),
+ yamlParser.getPrefix());
}
public Optional<PropertyGroup> addPropertyAsNew(Property property) {
- if (property == null ||
cachedPropertyMap.containsKey(property.getName())) {
+ if (property == null || propertyMap.containsKey(property.getName())) {
return Optional.empty();
}
- List<Property> newPropertyList =
- Stream.concat(
- protoPropertyGroup.getPropertiesList().stream()
- .map(Property::ofProto),
- Stream.of(property))
+ List<Property> newPropertyMap =
+ Stream.concat(propertyMap.values().stream(),
Stream.of(property))
.collect(Collectors.toUnmodifiableList());
- return Optional.of(
- new PropertyGroup(
- newPropertyList,
- protoPropertyGroup.getFileType(),
- protoPropertyGroup.getPrefix()));
+ return Optional.of(new PropertyGroup(newPropertyMap, fileType,
prefix));
}
@Override
public Iterator<Property> iterator() {
- return cachedPropertyList.iterator();
+ return propertyList.iterator();
}
@Override
public String toString() {
- return cachedPropertyList.stream()
+ return propertyList.stream()
.map(Property::getName)
.collect(Collectors.joining(GeneralParams.regularSeparator));
}
public int size() {
- return cachedPropertyList.size();
+ return propertyList.size();
}
public List<Property> getPropertyList() {
- return cachedPropertyList;
+ return propertyList;
}
- public Map<String, Property> getCachedPropertyMap() {
- return cachedPropertyMap;
+ public Map<String, Property> getPropertyMap() {
+ return propertyMap;
}
public FileType getFileType() {
- return protoPropertyGroup.getFileType();
+ return fileType;
}
public String getPrefix() {
- return protoPropertyGroup.getPrefix();
- }
-
- org.apache.graphar.proto.PropertyGroup getProto() {
- return protoPropertyGroup;
+ return prefix;
}
}
-/**
- * PropertyGroups is a helper class to manage a list of PropertyGroup objects,
which can be used by
- * {@link org.apache.graphar.info.VertexInfo} and {@link
org.apache.graphar.info.EdgeInfo}
- * conveniently. but should not be exposed to outer side of the package.
- */
class PropertyGroups {
private final List<PropertyGroup> propertyGroupList;
private final Map<String, PropertyGroup> propertyGroupMap;
@@ -139,9 +110,7 @@ class PropertyGroups {
this.propertyGroupList = List.copyOf(propertyGroupList);
this.properties =
propertyGroupList.stream()
- .flatMap(
- propertyGroup ->
-
propertyGroup.getCachedPropertyMap().values().stream())
+ .flatMap(propertyGroup ->
propertyGroup.getPropertyMap().values().stream())
.collect(
Collectors.toUnmodifiableMap(
Property::getName,
Function.identity()));
@@ -163,14 +132,6 @@ class PropertyGroups {
this.properties = properties;
}
- static PropertyGroups ofProto(
- List<org.apache.graphar.proto.PropertyGroup> protoPropertyGroups) {
- return new PropertyGroups(
- protoPropertyGroups.stream()
- .map(PropertyGroup::ofProto)
- .collect(Collectors.toList()));
- }
-
Optional<PropertyGroups> addPropertyGroupAsNew(PropertyGroup
propertyGroup) {
if (propertyGroup == null || propertyGroup.size() == 0 ||
hasPropertyGroup(propertyGroup)) {
return Optional.empty();
@@ -183,20 +144,22 @@ class PropertyGroups {
List<PropertyGroup> newPropertyGroupsAsList =
Stream.concat(propertyGroupList.stream(),
Stream.of(propertyGroup))
.collect(Collectors.toUnmodifiableList());
- Map<String, PropertyGroup> tempPropertyGroupMap = new
HashMap<>(propertyGroupMap);
+ Map<String, PropertyGroup> tempPropertyGroupAsMap = new
HashMap<>(propertyGroupMap);
for (Property property : propertyGroup) {
- tempPropertyGroupMap.put(property.getName(), propertyGroup);
+ tempPropertyGroupAsMap.put(property.getName(), propertyGroup);
}
Map<String, Property> newProperties =
Stream.concat(
properties.values().stream(),
-
propertyGroup.getCachedPropertyMap().values().stream())
+
propertyGroup.getPropertyMap().values().stream())
.collect(
Collectors.toUnmodifiableMap(
Property::getName,
Function.identity()));
return Optional.of(
new PropertyGroups(
- newPropertyGroupsAsList,
Map.copyOf(tempPropertyGroupMap), newProperties));
+ newPropertyGroupsAsList,
+ Map.copyOf(tempPropertyGroupAsMap),
+ newProperties));
}
boolean hasProperty(String propertyName) {
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 c7c2ef65..45eb4f04 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
@@ -19,17 +19,28 @@
package org.apache.graphar.info;
+import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
+import org.apache.graphar.info.type.DataType;
import org.apache.graphar.info.yaml.GraphYaml;
import org.apache.graphar.info.yaml.VertexYaml;
-import org.apache.graphar.proto.DataType;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.constructor.Constructor;
public class VertexInfo {
- private final org.apache.graphar.proto.VertexInfo protoVertexInfo;
- private final PropertyGroups cachedPropertyGroups;
+ private final String type;
+ private final long chunkSize;
+ private final PropertyGroups propertyGroups;
+ private final String prefix;
+ private final VersionInfo version;
public VertexInfo(
String type,
@@ -37,69 +48,87 @@ public class VertexInfo {
List<PropertyGroup> propertyGroups,
String prefix,
String version) {
- this.cachedPropertyGroups = new PropertyGroups(propertyGroups);
- this.protoVertexInfo =
- org.apache.graphar.proto.VertexInfo.newBuilder()
- .setType(type)
- .setChunkSize(chunkSize)
- .addAllProperties(
- propertyGroups.stream()
- .map(PropertyGroup::getProto)
- .collect(Collectors.toList()))
- .setPrefix(prefix)
- .setVersion(version)
- .build();
+ this(type, chunkSize, propertyGroups, prefix,
VersionParser.getVersion(version));
}
- private VertexInfo(org.apache.graphar.proto.VertexInfo protoVertexInfo) {
- this.protoVertexInfo = protoVertexInfo;
- this.cachedPropertyGroups =
PropertyGroups.ofProto(protoVertexInfo.getPropertiesList());
+ public VertexInfo(
+ String type,
+ long chunkSize,
+ List<PropertyGroup> propertyGroups,
+ String prefix,
+ VersionInfo version) {
+ this.type = type;
+ this.chunkSize = chunkSize;
+ this.propertyGroups = new PropertyGroups(propertyGroups);
+ this.prefix = prefix;
+ this.version = version;
}
- public static VertexInfo ofProto(org.apache.graphar.proto.VertexInfo
protoVertexInfo) {
- return new VertexInfo(protoVertexInfo);
+ private VertexInfo(VertexYaml parser) {
+ this(
+ parser.getType(),
+ parser.getChunk_size(),
+ parser.getProperty_groups().stream()
+ .map(PropertyGroup::new)
+ .collect(Collectors.toUnmodifiableList()),
+ parser.getPrefix(),
+ parser.getVersion());
}
- org.apache.graphar.proto.VertexInfo getProto() {
- return protoVertexInfo;
+ public static VertexInfo load(String vertexInfoPath) throws IOException {
+ return load(vertexInfoPath, new Configuration());
+ }
+
+ public static VertexInfo load(String vertexInfoPath, Configuration conf)
throws IOException {
+ if (conf == null) {
+ throw new IllegalArgumentException("Configuration is null");
+ }
+ return load(vertexInfoPath, FileSystem.get(conf));
+ }
+
+ public static VertexInfo load(String vertexInfoPath, FileSystem
fileSystem) throws IOException {
+ if (fileSystem == null) {
+ throw new IllegalArgumentException("FileSystem is null");
+ }
+ FSDataInputStream inputStream = fileSystem.open(new
Path(vertexInfoPath));
+ Yaml vertexInfoYamlLoader =
+ new Yaml(new Constructor(VertexYaml.class, new
LoaderOptions()));
+ VertexYaml vertexInfoYaml = vertexInfoYamlLoader.load(inputStream);
+ return new VertexInfo(vertexInfoYaml);
}
public Optional<VertexInfo> addPropertyGroupAsNew(PropertyGroup
propertyGroup) {
- // do not need check property group exist, because PropertyGroups will
check it
- return cachedPropertyGroups
+ return propertyGroups
.addPropertyGroupAsNew(propertyGroup)
+ .map(PropertyGroups::getPropertyGroupList)
.map(
newPropertyGroups ->
new VertexInfo(
- protoVertexInfo.getType(),
- protoVertexInfo.getChunkSize(),
-
newPropertyGroups.getPropertyGroupList(),
- protoVertexInfo.getPrefix(),
- protoVertexInfo.getVersion()));
+ type, chunkSize, newPropertyGroups,
prefix, version));
}
public int propertyGroupNum() {
- return cachedPropertyGroups.getPropertyGroupNum();
+ return propertyGroups.getPropertyGroupNum();
}
public DataType getPropertyType(String propertyName) {
- return cachedPropertyGroups.getPropertyType(propertyName);
+ return propertyGroups.getPropertyType(propertyName);
}
public boolean hasProperty(String propertyName) {
- return cachedPropertyGroups.hasProperty(propertyName);
+ return propertyGroups.hasProperty(propertyName);
}
public boolean isPrimaryKey(String propertyName) {
- return cachedPropertyGroups.isPrimaryKey(propertyName);
+ return propertyGroups.isPrimaryKey(propertyName);
}
public boolean isNullableKey(String propertyName) {
- return cachedPropertyGroups.isNullableKey(propertyName);
+ return propertyGroups.isNullableKey(propertyName);
}
public boolean hasPropertyGroup(PropertyGroup propertyGroup) {
- return cachedPropertyGroups.hasPropertyGroup(propertyGroup);
+ return propertyGroups.hasPropertyGroup(propertyGroup);
}
public String getPropertyGroupPrefix(PropertyGroup propertyGroup) {
@@ -116,6 +145,26 @@ public class VertexInfo {
return getPrefix() + "vertex_count";
}
+ public void save(String filePath) throws IOException {
+ save(filePath, new Configuration());
+ }
+
+ public void save(String filePath, Configuration conf) throws IOException {
+ if (conf == null) {
+ throw new IllegalArgumentException("Configuration is null");
+ }
+ save(filePath, FileSystem.get(conf));
+ }
+
+ public void save(String fileName, FileSystem fileSystem) throws
IOException {
+ if (fileSystem == null) {
+ throw new IllegalArgumentException("FileSystem is null");
+ }
+ FSDataOutputStream outputStream = fileSystem.create(new
Path(fileName));
+ outputStream.writeBytes(dump());
+ outputStream.close();
+ }
+
public String dump() {
Yaml yaml = new Yaml(GraphYaml.getRepresenter(),
GraphYaml.getDumperOptions());
VertexYaml vertexYaml = new VertexYaml(this);
@@ -123,27 +172,27 @@ public class VertexInfo {
}
public String getType() {
- return protoVertexInfo.getType();
+ return type;
}
public long getChunkSize() {
- return protoVertexInfo.getChunkSize();
+ return chunkSize;
}
public List<PropertyGroup> getPropertyGroups() {
- return cachedPropertyGroups.getPropertyGroupList();
+ return propertyGroups.getPropertyGroupList();
}
public String getPrefix() {
- return protoVertexInfo.getPrefix();
+ return prefix;
}
- public String getVertexPath() {
- return getPrefix() + getType() + ".vertex.yaml";
+ public VersionInfo getVersion() {
+ return version;
}
- public VersionInfo getVersion() {
- return VersionParser.getVersion(protoVertexInfo.getVersion());
+ public String getVertexPath() {
+ return getPrefix() + getType() + ".vertex.yaml";
}
private void checkPropertyGroupExist(PropertyGroup propertyGroup) {
diff --git
a/maven-projects/info/src/main/java/org/apache/graphar/info/type/AdjListType.java
b/maven-projects/info/src/main/java/org/apache/graphar/info/type/AdjListType.java
new file mode 100644
index 00000000..a077d870
--- /dev/null
+++
b/maven-projects/info/src/main/java/org/apache/graphar/info/type/AdjListType.java
@@ -0,0 +1,50 @@
+/*
+ * 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.type;
+
+public enum AdjListType {
+ /** collection of edges by source, but unordered, can represent COO format
*/
+ unordered_by_source,
+ /** collection of edges by destination, but unordered, can represent COO */
+ unordered_by_dest,
+ /** collection of edges by source, ordered by source, can represent CSR
format */
+ ordered_by_source,
+ /** collection of edges by destination, ordered by destination, can
represent CSC format */
+ ordered_by_dest;
+
+ public static AdjListType fromOrderedAndAlignedBy(boolean ordered, String
alignedBy) {
+ switch (alignedBy) {
+ case "src":
+ return ordered ? ordered_by_source : unordered_by_source;
+ case "dst":
+ return ordered ? ordered_by_dest : unordered_by_dest;
+ default:
+ throw new IllegalArgumentException("Invalid alignedBy: " +
alignedBy);
+ }
+ }
+
+ public boolean isOrdered() {
+ return this == ordered_by_source || this == ordered_by_dest;
+ }
+
+ public String getAlignedBy() {
+ return this == ordered_by_source || this == unordered_by_source ?
"src" : "dst";
+ }
+}
diff --git
a/maven-projects/info/src/main/java/org/apache/graphar/info/type/DataType.java
b/maven-projects/info/src/main/java/org/apache/graphar/info/type/DataType.java
new file mode 100644
index 00000000..83c31aec
--- /dev/null
+++
b/maven-projects/info/src/main/java/org/apache/graphar/info/type/DataType.java
@@ -0,0 +1,69 @@
+/*
+ * 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.type;
+
+public enum DataType {
+ /** Boolean */
+ BOOL,
+
+ /** Signed 32-bit integer */
+ INT32,
+
+ /** Signed 64-bit integer */
+ INT64,
+
+ /** 4-byte floating point value */
+ FLOAT,
+
+ /** 8-byte floating point value */
+ DOUBLE,
+
+ /** UTF8 variable-length string */
+ STRING,
+
+ /** List of same type */
+ LIST;
+
+ public static DataType fromString(String s) {
+ switch (s) {
+ case "bool":
+ return BOOL;
+ case "int32":
+ return INT32;
+ case "int64":
+ return INT64;
+ case "float":
+ return FLOAT;
+ case "double":
+ return DOUBLE;
+ case "string":
+ return STRING;
+ case "list":
+ return LIST;
+ default:
+ throw new IllegalArgumentException("Unknown data type: " + s);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return name().toLowerCase();
+ }
+}
diff --git
a/maven-projects/info/src/main/java/org/apache/graphar/info/type/FileType.java
b/maven-projects/info/src/main/java/org/apache/graphar/info/type/FileType.java
new file mode 100644
index 00000000..b45038b8
--- /dev/null
+++
b/maven-projects/info/src/main/java/org/apache/graphar/info/type/FileType.java
@@ -0,0 +1,42 @@
+/*
+ * 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.type;
+
+public enum FileType {
+ CSV,
+ PARQUET,
+ ORC;
+
+ public static FileType fromString(String fileType) {
+ if (fileType == null) {
+ return null;
+ }
+ switch (fileType) {
+ case "csv":
+ return CSV;
+ case "parquet":
+ return PARQUET;
+ case "orc":
+ return ORC;
+ default:
+ throw new IllegalArgumentException("Unknown file type: " +
fileType);
+ }
+ }
+}
diff --git
a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/AdjacentListYaml.java
b/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/AdjacentListYaml.java
index b65da68d..cb6ee2a8 100644
---
a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/AdjacentListYaml.java
+++
b/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/AdjacentListYaml.java
@@ -20,7 +20,8 @@
package org.apache.graphar.info.yaml;
import org.apache.graphar.info.AdjacentList;
-import org.apache.graphar.proto.AdjListType;
+import org.apache.graphar.info.type.AdjListType;
+import org.apache.graphar.info.type.FileType;
public class AdjacentListYaml {
private boolean ordered;
@@ -36,23 +37,16 @@ public class AdjacentListYaml {
}
public AdjacentListYaml(org.apache.graphar.info.AdjacentList adjacentList)
{
- final var adjListType = adjacentList.getType();
- this.ordered =
- adjListType == AdjListType.ORDERED_BY_SOURCE
- || adjListType == AdjListType.ORDERED_BY_DESTINATION;
- this.aligned_by =
- adjListType == AdjListType.ORDERED_BY_SOURCE
- || adjListType ==
AdjListType.UNORDERED_BY_SOURCE
- ? "src"
- : "dst";
- this.file_type =
EnumTransferUtil.fileType2String(adjacentList.getFileType());
+ this.ordered = adjacentList.getType().isOrdered();
+ this.aligned_by = adjacentList.getType().getAlignedBy();
+ this.file_type = adjacentList.getFileType().toString();
this.prefix = adjacentList.getPrefix();
}
public AdjacentList toAdjacentList() {
return new AdjacentList(
- EnumTransferUtil.orderedAndAlignedBy2AdjListType(ordered,
aligned_by),
- EnumTransferUtil.string2FileType(file_type),
+ AdjListType.fromOrderedAndAlignedBy(ordered, aligned_by),
+ FileType.fromString(file_type),
prefix);
}
@@ -64,7 +58,7 @@ public class AdjacentListYaml {
this.ordered = ordered;
}
- public String isAligned_by() {
+ public String getAligned_by() {
return aligned_by;
}
diff --git
a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/EdgeYaml.java
b/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/EdgeYaml.java
index 1bc78f47..5ef06d33 100644
---
a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/EdgeYaml.java
+++
b/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/EdgeYaml.java
@@ -50,13 +50,13 @@ public class EdgeYaml {
this.prefix = "";
this.adj_lists = new ArrayList<>();
this.property_groups = new ArrayList<>();
- this.version = "v1";
+ this.version = "";
}
public EdgeYaml(EdgeInfo edgeInfo) {
- this.src_type = edgeInfo.getSrcLabel();
- this.edge_type = edgeInfo.getSrcLabel();
- this.dst_type = edgeInfo.getDstLabel();
+ this.src_type = edgeInfo.getSrcType();
+ this.edge_type = edgeInfo.getEdgeType();
+ this.dst_type = edgeInfo.getDstType();
this.chunk_size = edgeInfo.getChunkSize();
this.src_chunk_size = edgeInfo.getSrcChunkSize();
this.dst_chunk_size = edgeInfo.getDstChunkSize();
diff --git
a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/EnumTransferUtil.java
b/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/EnumTransferUtil.java
deleted file mode 100644
index 2c484da8..00000000
---
a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/EnumTransferUtil.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * 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.yaml;
-
-import org.apache.graphar.proto.AdjListType;
-import org.apache.graphar.proto.FileType;
-
-public class EnumTransferUtil {
- static String fileType2String(FileType fileType) {
- switch (fileType) {
- case CSV:
- return "csv";
- case PARQUET:
- return "parquet";
- case ORC:
- return "orc";
- case JSON:
- return "json";
- case AVRO:
- return "avro";
- case HDF5:
- return "hdf5";
- default:
- throw new IllegalArgumentException("Invalid fileType: " +
fileType);
- }
- }
-
- static FileType string2FileType(String fileType) {
- switch (fileType) {
- case "csv":
- return FileType.CSV;
- case "parquet":
- return FileType.PARQUET;
- case "orc":
- return FileType.ORC;
- case "json":
- return FileType.JSON;
- case "avro":
- return FileType.AVRO;
- case "hdf5":
- return FileType.HDF5;
- default:
- throw new IllegalArgumentException("Invalid fileType: " +
fileType);
- }
- }
-
- static String dataType2String(org.apache.graphar.proto.DataType dataType) {
- switch (dataType) {
- case BOOL:
- return "bool";
- case INT32:
- return "int32";
- case INT64:
- return "int64";
- case FLOAT:
- return "float";
- case DOUBLE:
- return "double";
- case STRING:
- return "string";
- case LIST:
- return "list";
- case DATE:
- return "date";
- case TIMESTAMP:
- return "timestamp";
- case TIME:
- return "time";
- default:
- throw new IllegalArgumentException("Invalid dataType: " +
dataType);
- }
- }
-
- static org.apache.graphar.proto.DataType string2DataType(String dataType) {
- switch (dataType) {
- case "bool":
- return org.apache.graphar.proto.DataType.BOOL;
- case "int32":
- return org.apache.graphar.proto.DataType.INT32;
- case "int64":
- return org.apache.graphar.proto.DataType.INT64;
- case "float":
- return org.apache.graphar.proto.DataType.FLOAT;
- case "double":
- return org.apache.graphar.proto.DataType.DOUBLE;
- case "string":
- return org.apache.graphar.proto.DataType.STRING;
- case "list":
- return org.apache.graphar.proto.DataType.LIST;
- case "date":
- return org.apache.graphar.proto.DataType.DATE;
- case "timestamp":
- return org.apache.graphar.proto.DataType.TIMESTAMP;
- case "time":
- return org.apache.graphar.proto.DataType.TIME;
- default:
- throw new IllegalArgumentException("Invalid dataType: " +
dataType);
- }
- }
-
- public static AdjListType orderedAndAlignedBy2AdjListType(boolean ordered,
String alignedBy) {
- switch (alignedBy) {
- case "src":
- return ordered ? AdjListType.ORDERED_BY_SOURCE :
AdjListType.UNORDERED_BY_SOURCE;
- case "dst":
- return ordered
- ? AdjListType.ORDERED_BY_DESTINATION
- : AdjListType.UNORDERED_BY_DESTINATION;
- default:
- throw new IllegalArgumentException("Invalid alignedBy: " +
alignedBy);
- }
- }
-}
diff --git
a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/GraphYaml.java
b/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/GraphYaml.java
index 0f57b8f2..bf665dcd 100644
---
a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/GraphYaml.java
+++
b/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/GraphYaml.java
@@ -92,6 +92,11 @@ public class GraphYaml {
graphInfo.getEdgeInfos().stream()
.map(edgeInfo -> edgeInfo.getConcat() + ".edge.yaml")
.collect(Collectors.toList());
+ this.version =
+ Optional.of(graphInfo)
+ .map(GraphInfo::getVersion)
+ .map(VersionInfo::toString)
+ .orElse(null);
}
public static DumperOptions getDumperOptions() {
diff --git
a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/PropertyGroupYaml.java
b/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/PropertyGroupYaml.java
index 1e992539..457d4175 100644
---
a/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/PropertyGroupYaml.java
+++
b/maven-projects/info/src/main/java/org/apache/graphar/info/yaml/PropertyGroupYaml.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.graphar.info.PropertyGroup;
+import org.apache.graphar.info.type.FileType;
public class PropertyGroupYaml {
private List<PropertyYaml> properties;
@@ -40,14 +41,14 @@ public class PropertyGroupYaml {
propertyGroup.getPropertyList().stream()
.map(PropertyYaml::new)
.collect(Collectors.toList());
- this.file_type =
EnumTransferUtil.fileType2String(propertyGroup.getFileType());
+ this.file_type = propertyGroup.getFileType().toString();
this.prefix = propertyGroup.getPrefix();
}
PropertyGroup toPropertyGroup() {
return new PropertyGroup(
properties.stream().map(PropertyYaml::toProperty).collect(Collectors.toList()),
- EnumTransferUtil.string2FileType(file_type),
+ FileType.fromString(file_type),
prefix);
}
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 89fa87a0..ee98a339 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
@@ -21,6 +21,7 @@ package org.apache.graphar.info.yaml;
import java.util.Optional;
import org.apache.graphar.info.Property;
+import org.apache.graphar.info.type.DataType;
public class PropertyYaml {
private String name;
@@ -37,7 +38,7 @@ public class PropertyYaml {
public PropertyYaml(Property property) {
this.name = property.getName();
- this.data_type =
EnumTransferUtil.dataType2String(property.getDataType());
+ this.data_type = property.getDataType().toString();
this.is_primary = property.isPrimary();
this.is_nullable = Optional.of(property.isNullable());
}
@@ -45,7 +46,7 @@ public class PropertyYaml {
Property toProperty() {
return new Property(
name,
- EnumTransferUtil.string2DataType(data_type),
+ DataType.fromString(data_type),
is_primary,
is_nullable.orElseGet(() -> !is_primary));
}
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 8f873851..20cae797 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
@@ -24,9 +24,9 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.graphar.info.loader.GraphLoader;
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.info.type.AdjListType;
+import org.apache.graphar.info.type.DataType;
+import org.apache.graphar.info.type.FileType;
import org.apache.graphar.util.PathUtil;
import org.junit.AfterClass;
import org.junit.Assert;
@@ -143,11 +143,11 @@ public class GraphInfoTest {
@Test
public void testKnowEdgeInfoBasic() {
- Assert.assertEquals("knows", knowsEdgeInfo.getEdgeLabel());
+ Assert.assertEquals("knows", knowsEdgeInfo.getEdgeType());
Assert.assertEquals(1024, knowsEdgeInfo.getChunkSize());
- Assert.assertEquals("person", knowsEdgeInfo.getSrcLabel());
+ Assert.assertEquals("person", knowsEdgeInfo.getSrcType());
Assert.assertEquals(100, knowsEdgeInfo.getSrcChunkSize());
- Assert.assertEquals("person", knowsEdgeInfo.getDstLabel());
+ Assert.assertEquals("person", knowsEdgeInfo.getDstType());
Assert.assertEquals(100, knowsEdgeInfo.getDstChunkSize());
Assert.assertFalse(knowsEdgeInfo.isDirected());
Assert.assertEquals("person_knows_person", knowsEdgeInfo.getConcat());
@@ -163,71 +163,71 @@ public class GraphInfoTest {
Assert.assertEquals(2, knowsEdgeInfo.getAdjacentLists().size());
// test ordered by source adjacency list
AdjacentList adjOrderBySource =
- knowsEdgeInfo.getAdjacentList(AdjListType.ORDERED_BY_SOURCE);
+ knowsEdgeInfo.getAdjacentList(AdjListType.ordered_by_source);
Assert.assertEquals(FileType.CSV, adjOrderBySource.getFileType());
- Assert.assertEquals(AdjListType.ORDERED_BY_SOURCE,
adjOrderBySource.getType());
+ 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",
-
knowsEdgeInfo.getVerticesNumFilePath(AdjListType.ORDERED_BY_SOURCE));
+
knowsEdgeInfo.getVerticesNumFilePath(AdjListType.ordered_by_source));
Assert.assertEquals(
"edge/person_knows_person/ordered_by_source/adj_list/edge_count0",
-
knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ORDERED_BY_SOURCE, 0));
+
knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ordered_by_source, 0));
Assert.assertEquals(
"edge/person_knows_person/ordered_by_source/adj_list/edge_count4",
-
knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ORDERED_BY_SOURCE, 4));
+
knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ordered_by_source, 4));
Assert.assertEquals(
"edge/person_knows_person/ordered_by_source/adj_list/",
-
knowsEdgeInfo.getAdjacentListPrefix(AdjListType.ORDERED_BY_SOURCE));
+
knowsEdgeInfo.getAdjacentListPrefix(AdjListType.ordered_by_source));
Assert.assertEquals(
"edge/person_knows_person/ordered_by_source/adj_list/chunk0",
-
knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ORDERED_BY_SOURCE, 0));
+
knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ordered_by_source, 0));
Assert.assertEquals(
"edge/person_knows_person/ordered_by_source/adj_list/chunk4",
-
knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ORDERED_BY_SOURCE, 4));
+
knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ordered_by_source, 4));
Assert.assertEquals(
"edge/person_knows_person/ordered_by_source/adj_list/offset/",
- knowsEdgeInfo.getOffsetPrefix(AdjListType.ORDERED_BY_SOURCE));
+ knowsEdgeInfo.getOffsetPrefix(AdjListType.ordered_by_source));
Assert.assertEquals(
"edge/person_knows_person/ordered_by_source/adj_list/offset/chunk0",
-
knowsEdgeInfo.getOffsetChunkPath(AdjListType.ORDERED_BY_SOURCE, 0));
+
knowsEdgeInfo.getOffsetChunkPath(AdjListType.ordered_by_source, 0));
Assert.assertEquals(
"edge/person_knows_person/ordered_by_source/adj_list/offset/chunk4",
-
knowsEdgeInfo.getOffsetChunkPath(AdjListType.ORDERED_BY_SOURCE, 4));
+
knowsEdgeInfo.getOffsetChunkPath(AdjListType.ordered_by_source, 4));
// test ordered by destination adjacency list
AdjacentList adjOrderByDestination =
-
knowsEdgeInfo.getAdjacentList(AdjListType.ORDERED_BY_DESTINATION);
+ knowsEdgeInfo.getAdjacentList(AdjListType.ordered_by_dest);
Assert.assertEquals(FileType.CSV, adjOrderByDestination.getFileType());
- Assert.assertEquals(AdjListType.ORDERED_BY_DESTINATION,
adjOrderByDestination.getType());
+ Assert.assertEquals(AdjListType.ordered_by_dest,
adjOrderByDestination.getType());
Assert.assertEquals("ordered_by_dest/",
adjOrderByDestination.getPrefix());
Assert.assertEquals(
"edge/person_knows_person/ordered_by_dest/adj_list/vertex_count",
-
knowsEdgeInfo.getVerticesNumFilePath(AdjListType.ORDERED_BY_DESTINATION));
+
knowsEdgeInfo.getVerticesNumFilePath(AdjListType.ordered_by_dest));
Assert.assertEquals(
"edge/person_knows_person/ordered_by_dest/adj_list/edge_count0",
-
knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ORDERED_BY_DESTINATION, 0));
+ knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ordered_by_dest,
0));
Assert.assertEquals(
"edge/person_knows_person/ordered_by_dest/adj_list/edge_count4",
-
knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ORDERED_BY_DESTINATION, 4));
+ knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ordered_by_dest,
4));
Assert.assertEquals(
"edge/person_knows_person/ordered_by_dest/adj_list/",
-
knowsEdgeInfo.getAdjacentListPrefix(AdjListType.ORDERED_BY_DESTINATION));
+
knowsEdgeInfo.getAdjacentListPrefix(AdjListType.ordered_by_dest));
Assert.assertEquals(
"edge/person_knows_person/ordered_by_dest/adj_list/chunk0",
-
knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ORDERED_BY_DESTINATION, 0));
+
knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ordered_by_dest, 0));
Assert.assertEquals(
"edge/person_knows_person/ordered_by_dest/adj_list/chunk4",
-
knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ORDERED_BY_DESTINATION, 4));
+
knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ordered_by_dest, 4));
Assert.assertEquals(
"edge/person_knows_person/ordered_by_dest/adj_list/offset/",
-
knowsEdgeInfo.getOffsetPrefix(AdjListType.ORDERED_BY_DESTINATION));
+ knowsEdgeInfo.getOffsetPrefix(AdjListType.ordered_by_dest));
Assert.assertEquals(
"edge/person_knows_person/ordered_by_dest/adj_list/offset/chunk0",
-
knowsEdgeInfo.getOffsetChunkPath(AdjListType.ORDERED_BY_DESTINATION, 0));
+ knowsEdgeInfo.getOffsetChunkPath(AdjListType.ordered_by_dest,
0));
Assert.assertEquals(
"edge/person_knows_person/ordered_by_dest/adj_list/offset/chunk4",
-
knowsEdgeInfo.getOffsetChunkPath(AdjListType.ORDERED_BY_DESTINATION, 4));
+ knowsEdgeInfo.getOffsetChunkPath(AdjListType.ordered_by_dest,
4));
}
@Test
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 d683f03b..899f6a78 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
@@ -20,9 +20,9 @@
package org.apache.graphar.info;
import java.util.List;
-import org.apache.graphar.proto.AdjListType;
-import org.apache.graphar.proto.DataType;
-import org.apache.graphar.proto.FileType;
+import org.apache.graphar.info.type.AdjListType;
+import org.apache.graphar.info.type.DataType;
+import org.apache.graphar.info.type.FileType;
import org.junit.Assume;
public class TestUtil {
@@ -106,10 +106,9 @@ public class TestUtil {
// is_primary: false
// version: gar/v1
AdjacentList orderedBySource =
- new AdjacentList(AdjListType.ORDERED_BY_SOURCE, FileType.CSV,
"ordered_by_source/");
+ new AdjacentList(AdjListType.ordered_by_source, FileType.CSV,
"ordered_by_source/");
AdjacentList orderedByDest =
- new AdjacentList(
- AdjListType.ORDERED_BY_DESTINATION, FileType.CSV,
"ordered_by_dest/");
+ new AdjacentList(AdjListType.ordered_by_dest, FileType.CSV,
"ordered_by_dest/");
Property creationDate = new Property("creationDate", DataType.STRING,
false, false);
PropertyGroup pg3 = new PropertyGroup(List.of(creationDate),
FileType.CSV, "creationDate/");
EdgeInfo knows =
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]