I am trying to load a CSV in Gremlin Python, but unfortunately I got this error:
{'error': GremlinServerError('597: startup failed:\r\nScript5.groovy: 2: unable to resolve class org.apache.commons.csv.CSVFormat\n @ line 2, column 1.\r\n import org.apache.commons.csv.CSVFormat\r\n ^\r\n\r\n1 error\r\n')}
I managed to load the CSV into the Gremlin console, both vertices, and edges. The code in Python is as follows:
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.structure.graph import Graph
from gremlin_python import statics
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.process.traversal import *
import sys
from gremlin_python.driver.aiohttp.transport import AiohttpTransport
# Path to our graph (this assumes a locally running Gremlin Server)
# Note how the path is a Web Socket (ws) connection.
endpoint = 'ws://localhost:8182/gremlin'
# Obtain a graph traversal source using a remote connection
graph=Graph()
connection = DriverRemoteConnection(endpoint,'g',
transport_factory=lambda:AiohttpTransport(call_from_event_loop=True))
g = graph.traversal().withRemote(connection)
%%graph_notebook_config
{
"host": "localhost",
"port": 8182,
"ssl": false,
"gremlin": {
"traversal_source": "g"
}
}
%%gremlin
g = TinkerGraph.open().traversal()
import org.apache.commons.csv.CSVFormat
fileReader = new FileReader('C:/airports.csv')
records = CSVFormat.RFC4180.withFirstRecordAsHeader().parse(fileReader);[]
records.each{
c=it.get('code');
d=it.get('desc');
println(it)
g.V().has('code', c).fold().coalesce(
unfold(),
addV('airport').property('code',c).property('desc',d)
).iterate()
}
g.V().count()
In the Gremlin console I configured the server, with this bit:
:remote connect tinkerpop.server conf/remote.yaml
The CSV has two columns, for instance code:TXF, desc:"9 de Maio - Teixeira de Freitas Airport"
Thank you