Search code examples
jupyter-notebookgremlinamazon-sagemakeramazon-neptune

Possible to use PartitionStrategy in Gremlin Console in Jupyter?


I'm using aws neptune's jupyter notebook. It provides a gremlin console.

You can issue a Gremlin query using the `%%gremlin` cell magic. Let's add a few vertices and then retrieve them.

%%gremlin

g.addV('person').property('name', 'dan')
 .addV('person').property('name', 'mike')
 .addV('person').property('name', 'saikiran')

In my code I use partition strategy

        const partStrat = new PartitionStrategy({
            partitionKey,
            writePartition: partitionKey,
            readPartitions: [partitionKey]
        });
        return this.graph.traversal().withStrategies(partStrat).withRemote(this.dc);

Is it possible to specify partition with %%gremlin? I get parse errors if I try to do anything other than g.xxx


Solution

  • Yes it can be done. You need to use a syntax that is compatible with the Gremlin Antlr grammar as the notebooks send queries as text strings. Using the air-routes data, for example, you can do something like this:

    %%gremlin
    
    g.withStrategies(new PartitionStrategy(partitionKey: "region", 
                                           writePartition: "x", 
                                           readPartitions: ["US-TX"])).
      V().count()