This is an automated email from the ASF dual-hosted git repository.

ssinchenko 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 0bf48c1f Remove Hadoop dependency and update tests / Local (#665)
0bf48c1f is described below

commit 0bf48c1f4a254a06ced3dff1f5c116272bb4b11a
Author: Sem <ssinche...@apache.org>
AuthorDate: Tue Mar 4 07:53:00 2025 +0100

    Remove Hadoop dependency and update tests / Local (#665)
---
 maven-projects/info/pom.xml                        |  6 +-
 .../graphar/info/loader/LocalYamlGraphLoader.java  | 43 +++++++-------
 .../graphar/info/saver/LocalYamlGraphSaver.java    | 67 ++++++++++++----------
 3 files changed, 60 insertions(+), 56 deletions(-)

diff --git a/maven-projects/info/pom.xml b/maven-projects/info/pom.xml
index 7c0ba74c..2bc9db5f 100644
--- a/maven-projects/info/pom.xml
+++ b/maven-projects/info/pom.xml
@@ -63,11 +63,7 @@
             <groupId>org.yaml</groupId>
             <artifactId>snakeyaml</artifactId>
             <version>2.0</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.hadoop</groupId>
-            <artifactId>hadoop-common</artifactId>
-            <version>3.4.0</version>
+            <scope>compile</scope>
         </dependency>
     </dependencies>
 
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 f2936fb4..939b1836 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
@@ -19,38 +19,37 @@
 
 package org.apache.graphar.info.loader;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
 import org.apache.graphar.info.EdgeInfo;
 import org.apache.graphar.info.GraphInfo;
 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.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.FSDataInputStream;
-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 LocalYamlGraphLoader implements GraphLoader {
-    private static FileSystem fileSystem = null;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
 
-    public LocalYamlGraphLoader() {}
+public class LocalYamlGraphLoader implements GraphLoader {
+    public LocalYamlGraphLoader() {
+    }
 
     @Override
     public GraphInfo load(String graphYamlPath) throws IOException {
-        if (fileSystem == null) {
-            fileSystem = FileSystem.get(new Configuration());
-        }
+        final Path path = FileSystems.getDefault().getPath(graphYamlPath);
         // load graph itself
-        final Path path = new Path(graphYamlPath);
-        final FSDataInputStream inputStream = fileSystem.open(path);
+        final BufferedReader reader = Files.newBufferedReader(path);
         final Yaml yamlLoader = new Yaml(new Constructor(GraphYaml.class, new 
LoaderOptions()));
-        final GraphYaml graphYaml = yamlLoader.load(inputStream);
+        final GraphYaml graphYaml = yamlLoader.load(reader);
+        reader.close();
+
         // load vertices
         final String ABSOLUTE_PREFIX = path.getParent().toString();
         List<VertexInfo> vertexInfos = new 
ArrayList<>(graphYaml.getVertices().size());
@@ -66,16 +65,20 @@ public class LocalYamlGraphLoader implements GraphLoader {
     }
 
     private VertexInfo loadVertex(String path) throws IOException {
-        FSDataInputStream inputStream = fileSystem.open(new Path(path));
+        final Path vertexPath = FileSystems.getDefault().getPath(path);
+        final BufferedReader reader = Files.newBufferedReader(vertexPath);
         Yaml vertexYamlLoader = new Yaml(new Constructor(VertexYaml.class, new 
LoaderOptions()));
-        VertexYaml vertexYaml = vertexYamlLoader.load(inputStream);
+        VertexYaml vertexYaml = vertexYamlLoader.load(reader);
+        reader.close();
         return vertexYaml.toVertexInfo();
     }
 
     private EdgeInfo loadEdge(String path) throws IOException {
-        FSDataInputStream inputStream = fileSystem.open(new Path(path));
+        final Path edgePath = FileSystems.getDefault().getPath(path);
+        final BufferedReader reader = Files.newBufferedReader(edgePath);
         Yaml edgeYamlLoader = new Yaml(new Constructor(EdgeYaml.class, new 
LoaderOptions()));
-        EdgeYaml edgeYaml = edgeYamlLoader.load(inputStream);
+        EdgeYaml edgeYaml = edgeYamlLoader.load(reader);
+        reader.close();
         return edgeYaml.toEdgeInfo();
     }
 }
diff --git 
a/maven-projects/info/src/main/java/org/apache/graphar/info/saver/LocalYamlGraphSaver.java
 
b/maven-projects/info/src/main/java/org/apache/graphar/info/saver/LocalYamlGraphSaver.java
index 500268d1..7e464c1e 100644
--- 
a/maven-projects/info/src/main/java/org/apache/graphar/info/saver/LocalYamlGraphSaver.java
+++ 
b/maven-projects/info/src/main/java/org/apache/graphar/info/saver/LocalYamlGraphSaver.java
@@ -19,51 +19,56 @@
 
 package org.apache.graphar.info.saver;
 
-import java.io.IOException;
 import org.apache.graphar.info.EdgeInfo;
 import org.apache.graphar.info.GraphInfo;
 import org.apache.graphar.info.VertexInfo;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.FSDataOutputStream;
-import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.Path;
 
-public class LocalYamlGraphSaver implements GraphSaver {
-    private static final FileSystem fileSystem;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
 
-    static {
-        try {
-            fileSystem = FileSystem.get(new Configuration());
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
-    }
+public class LocalYamlGraphSaver implements GraphSaver {
 
     @Override
     public void save(String path, GraphInfo graphInfo) throws IOException {
-        try (FSDataOutputStream outputStream =
-                fileSystem.create(new Path(path + "/" + graphInfo.getName() + 
".graph.yaml"))) {
-            outputStream.writeBytes(graphInfo.dump());
-            for (VertexInfo vertexInfo : graphInfo.getVertexInfos()) {
-                saveVertex(path, vertexInfo);
-            }
-            for (EdgeInfo edgeInfo : graphInfo.getEdgeInfos()) {
-                saveEdge(path, edgeInfo);
-            }
+        final Path outputPath = FileSystems
+            .getDefault()
+            .getPath(path + FileSystems.getDefault().getSeparator() + 
graphInfo.getName() + ".graph.yaml");
+        Files.createDirectories(outputPath.getParent());
+        Files.createFile(outputPath);
+        final BufferedWriter writer = Files.newBufferedWriter(outputPath);
+        writer.write(graphInfo.dump());
+        writer.close();
+
+        for (VertexInfo vertexInfo : graphInfo.getVertexInfos()) {
+            saveVertex(path, vertexInfo);
+        }
+        for (EdgeInfo edgeInfo : graphInfo.getEdgeInfos()) {
+            saveEdge(path, edgeInfo);
         }
     }
 
     private void saveVertex(String path, VertexInfo vertexInfo) throws 
IOException {
-        try (FSDataOutputStream outputStream =
-                fileSystem.create(new Path(path + "/" + vertexInfo.getType() + 
".vertex.yaml"))) {
-            outputStream.writeBytes(vertexInfo.dump());
-        }
+        final Path outputPath = FileSystems
+            .getDefault()
+            .getPath(path + FileSystems.getDefault().getSeparator() + 
vertexInfo.getType() + ".vertex.yaml");
+        Files.createDirectories(outputPath.getParent());
+        Files.createFile(outputPath);
+        final BufferedWriter writer = Files.newBufferedWriter(outputPath);
+        writer.write(vertexInfo.dump());
+        writer.close();
     }
 
     private void saveEdge(String path, EdgeInfo edgeInfo) throws IOException {
-        try (FSDataOutputStream outputStream =
-                fileSystem.create(new Path(path + "/" + edgeInfo.getConcat() + 
".edge.yaml"))) {
-            outputStream.writeBytes(edgeInfo.dump());
-        }
+        final Path outputPath = FileSystems
+            .getDefault()
+            .getPath(path + FileSystems.getDefault().getSeparator() + 
edgeInfo.getConcat() + ".edge.yaml");
+        Files.createDirectories(outputPath.getParent());
+        Files.createFile(outputPath);
+        final BufferedWriter writer = Files.newBufferedWriter(outputPath);
+        writer.write(edgeInfo.dump());
+        writer.close();
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@graphar.apache.org
For additional commands, e-mail: commits-h...@graphar.apache.org

Reply via email to