Skip to content

Instantly share code, notes, and snippets.

@mzsima
Last active May 9, 2020 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzsima/501b01c5b9b232e6950193ec6baec455 to your computer and use it in GitHub Desktop.
Save mzsima/501b01c5b9b232e6950193ec6baec455 to your computer and use it in GitHub Desktop.
find 3+likes

image

snapshot

gremlin code

schema

schema.vertexLabel("User").
    ifNotExists().
    partitionBy("uid", Text).
    property("name", Text).
    create();
    
schema.vertexLabel("Tweet").
    ifNotExists().
    partitionBy("text", Text).
    create();
    
schema.edgeLabel("like").
    ifNotExists().
    from('User').to('Tweet').
    create();

generate

users = []
for(i=0; i<5; i++) {
    user = g.addV("User").
        property("uid", "user" + i).
        property("name", "Taro").
        next();
    users.push(user)
}

tweets = []
for(i=0;i<20; i++) {
    tweet = g.addV("Tweet").
        property("text", "hello" + i).
        next();
    tweets.push(tweet)
}

rnd = new Random(2)
for(tweet in tweets) {
    for(user in users) {
        if (rnd.nextInt() > 0) {
            g.addE('like').
              from(user).
              to(tweet).
              next();
        }
    }
}

show result

dev.V().hasLabel('Tweet').where(inE('like').count().is(gt(2L))).bothE()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment