1

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

Aureon
  • 141
  • 9
  • I'm struggling to follow your question as the code above appears to have Python, graph-notebook magics, and Groovy all merged in together. I assume this is a follow on question to https://stackoverflow.com/questions/73229622/load-csv-on-gremlin-error-mapping-for-code-not-found ? Did you install the CSVFormat class on the server? – Kelvin Lawrence Aug 10 '22 at 02:24
  • Hi Kelvin, this is a follow-up to the previous question. I installed the `CSVFormat import org.apache.commons.csv.CSVFormat`. The server console shows this error: `[ERROR] o.a.t.g.g.j.GremlinGroovyScriptEngine$GroovyCacheLoader - Script compilation FAILED g = TinkerGraph.open().traversal()` then this `org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script3.groovy: 2: unable to resolve class org.apache.commons.csv.CSVFormat` – Aureon Aug 11 '22 at 02:16
  • It appears that that class is still not being found (in the classpath) on the server side. – Kelvin Lawrence Aug 15 '22 at 15:49

0 Answers0