pietermartin / sqlg

TinkerPop graph over sql
MIT License
244 stars 51 forks source link

casting MapValues() or working the type when using gremlin with sqlg #278

Closed bshambaugh closed 6 years ago

bshambaugh commented 6 years ago

http://sql2gremlin.com/ has an example for

SELECT * FROM Categories

expressed as

g.V().hasLabel("category").valueMap()

in gremlin

I fiddled around in Java and tried to write::

List persons = g.traversal().V().hasLabel("Software").valueMap().toList();

and got an error: Type mismatch: cannot convert from List<Map<String,Object>> to List

Is there a way to reduce this valueMap to get an object, or is this not even possible due to MapValues not being implemented as a vertex property feature?

pietermartin commented 6 years ago

Are you using java 8? And can you show the stack trace please.

    @Test
    public void test() {
        this.sqlgGraph.addVertex(T.label, "Software", "name", "a");
        this.sqlgGraph.addVertex(T.label, "Software", "name", "a");
        this.sqlgGraph.tx().commit();
        List softwares = this.sqlgGraph.traversal().V().hasLabel("Software").valueMap().toList();
        Assert.assertEquals(2, softwares.size());
        System.out.println(softwares.get(0));
    }

result,

{name=[a]}
bshambaugh commented 6 years ago

Thanks, this helped a lot. I looked at what you wrote and realized I was in the github comment in a way that it would not produce an error message in Eclipse.

e.g. List software = g.traversal().V().hasLabel("Software").valueMap().toList();

Whereas, in Eclipse I had it written as something like:

List<Object> software = g.traversal().V().hasLabel("Software").valueMap().toList(); which gave "Type mismatch: cannot convert from List<Map<String,Object>> to List"

pietermartin commented 6 years ago

Ok, I normally prefer to write it out fully, i.e.

List<Map<String,Object>> software = g.traversal().V().hasLabel("Software").valueMap().toList();