Skip to content

Commit 8e52377

Browse files
committed
ReadMe: add loading examples (Gremlin)
1 parent 38f42af commit 8e52377

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed

README.md

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ docker build -t asterdb:v1.0 .
156156

157157
# Getting Started
158158

159-
## Load Graph Dataset into AsterDB
159+
## Load Graph Dataset into AsterDB (bulkload)
160160

161161
Prepare your dataset for testing, e.g.
162162

@@ -184,6 +184,116 @@ export WRITE_SST_PATH=/udf/sst/file/path
184184
<img src="./assets/session3.gif" alt="build-asterdb">
185185
</p>
186186

187+
188+
## Load Graph Dataset into AsterDB (Gremlin Console)
189+
190+
Please refer to the **"Prepare your dataset for testing"** section above to prepare your dataset.
191+
192+
```bash
193+
# (Optional) Create a mini dataset with first 1000 lines for quick verification
194+
head -n 1000 com-orkut.ungraph.txt > com-orkut.mini.txt
195+
```
196+
197+
Load the mini dataset.
198+
```bash
199+
bin/gremlin.sh
200+
201+
\,,,/
202+
(o o)
203+
-----oOOo-(3)-oOOo-----
204+
plugin activated: tinkerpop.server
205+
plugin activated: tinkerpop.utilities
206+
plugin activated: tinkerpop.tinkergraph
207+
208+
# Configure and Open AsterDB
209+
gremlin> conf = new BaseConfiguration()
210+
==>org.apache.commons.configuration2.BaseConfiguration@576b7c74
211+
gremlin> conf.setProperty("gremlin.tinkergraph.graphLocation", "/tmp/asterdb_orkut")
212+
==>null
213+
gremlin> conf.setProperty("gremlin.tinkergraph.graphFormat", "rocksdb")
214+
==>null
215+
gremlin> conf.setProperty("updatePolicy", 2)
216+
==>null
217+
gremlin> graph = TinkerGraph.open(conf)
218+
using update policy: 2
219+
==>tinkergraph[vertices:0 edges:0]
220+
gremlin> g = graph.traversal()
221+
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
222+
223+
# Define a function for loading
224+
def loadGraphSafe(graph, traversal, filePath) {
225+
def file = new File(filePath)
226+
if (!file.exists()) {
227+
println "Error: File not found -> " + filePath
228+
return
229+
}
230+
231+
println "Start loading from: " + filePath
232+
long counter = 0
233+
long startTime = System.currentTimeMillis()
234+
235+
file.eachLine { line ->
236+
line = line.trim()
237+
// Skip comments and empty lines
238+
if (line.isEmpty() || line.startsWith("#") || line.startsWith("%")) return
239+
240+
try {
241+
def parts = line.split("\\s+")
242+
if (parts.length >= 2) {
243+
// Parse IDs as Long for better compatibility and performance
244+
long id1 = Long.parseLong(parts[0])
245+
long id2 = Long.parseLong(parts[1])
246+
247+
// 1. Upsert Source Vertex
248+
traversal.V(id1).fold().coalesce(
249+
__.unfold(),
250+
__.addV("node").property(T.id, id1)
251+
).iterate()
252+
253+
// 2. Upsert Destination Vertex
254+
traversal.V(id2).fold().coalesce(
255+
__.unfold(),
256+
__.addV("node").property(T.id, id2)
257+
).iterate()
258+
259+
// 3. Add Edge (v1 -> v2)
260+
traversal.V(id1).addE("link").to(__.V(id2)).iterate()
261+
262+
// Progress logging
263+
counter++
264+
if (counter % 1000 == 0) print "."
265+
if (counter % 50000 == 0) println " Loaded ${counter} edges..."
266+
}
267+
} catch (Exception e) {
268+
println "\nSkipping line due to error: ${line}. " + e.getMessage()
269+
}
270+
}
271+
272+
long endTime = System.currentTimeMillis()
273+
println "\nDone! Loaded ${counter} edges in ${(endTime - startTime) / 1000} seconds."
274+
}
275+
==>true
276+
# Execute loading
277+
# The path to the data file is relative to gremlin-console/bin/gremlin.sh.
278+
loadGraphSafe(graph, g, "../../../datasets/com-orkut.mini.txt")
279+
280+
...
281+
Done! Loaded 142 edges in 2.085 seconds.
282+
==>null
283+
284+
# Verify Data
285+
gremlin> println "Total Vertices: " + g.V().count().next()
286+
Total Vertices: 859
287+
==>null
288+
gremlin> println "Total Edges: " + g.E().count().next()
289+
Total Edges: 142
290+
==>null
291+
```
292+
293+
<p align="center">
294+
<img src="./assets/session5.gif" alt="load-grahp-data-gremlin">
295+
</p>
296+
187297
## A Toy Example to Try AsterDB
188298
189299
Try AsterDB with gremlin console in a interactive way:

assets/session5.gif

17.5 MB
Loading

0 commit comments

Comments
 (0)