[
https://issues.apache.org/jira/browse/S2GRAPH-72?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15285861#comment-15285861
]
DOYUNG YOON commented on S2GRAPH-72:
------------------------------------
Currently you can use json and there is util to convert json into edge.
{noformat}
val parser: org.apache.s2graph.core.RequestParser
val edgeJson = Json.obj("timestamp" -> now, "from" -> "a", "to" -> "b", "label"
-> "my_label")
val edge = parser.toEdge(edgeJson)
graph.mutateEdges(Seq(edge))
{noformat}
I agree that json is used more than that it is necessary. In my opinion change
APIs that expect {noformat}Json#Object{noformat} to expeect
{noformat}Map[String, Any]{noformat} to decouple json dependencies.
Not only addEdge, but also generally(more on query part, all we support is
helper to parse json query into inner Query class), I agree that there is no
simple encapsulated layer currently, and also completely agree that it is
necessary.
I think we need to discuss this on seperate thread in more details.
what you suggested is way to go but not sure if making s2graph own API more
usable(adding more helper) need to be done before we start to work on this
issue(support tinkerpop).
P.S. Here is what I have so far with above approach to implement addVertexStep,
addEdgeStep so far. it is very naive since I only spent few days on this, but I
think we can benefit from nice DSL that gremlin provide.
(WIP location:
https://github.com/SteamShon/incubator-s2graph/tree/S2GRAPH-72-WIP-steamshon,
you can find all tinkerpop related experiment codes on
org.apache.s2graph.core.tinkerpop package.
- addVertexStep
{noformat}
test("test S2Graph#addVertexStep.") {
val v = s2.traversal().clone().addV("id", srcId, "serviceName",
label.srcServiceName, "columnName", label.srcColumnName).next()
logger.debug(s"v: ${v.toString}")
/** since traversal for query is not yet implemented, we are using s2graph
native
* graph methods, not TinkerPop Traversal yet. this should be changed.
*/
val checkFuture =
s2.client.getVertices(Seq(v.asInstanceOf[S2Vertex].vertex)).map {
fetchedVertices =>
fetchedVertices.nonEmpty should be(true)
fetchedVertices.head.id should be(v.id())
}
Await.result(checkFuture, timeout)
}
{noformat}
- addEdgeStep
{noformat}
test("test S2Graph#addEdgeStep.") {
val e = s2.traversal().clone().
addV("id", srcId, "serviceName", label.srcServiceName, "columnName",
label.srcColumnName).as("from").
addV("id", tgtId, "serviceName", label.tgtServiceName, "columnName",
label.tgtColumnName).as("to").addE(label.label)
.from("from").to("to").next()
logger.debug(s"v: ${e.toString}")
/** since traversal for query is not yet implemented, we are using s2graph
native
* graph methods, not TinkerPop Traversal yet. this should be changed.
*/
val queryJson = Json.parse(
s"""
|{
| "srcVertices": [{
| "serviceName": "${label.serviceName}",
| "columnName": "${label.srcColumnName}",
| "id": ${srcId}
| }],
| "steps": [{
| "step": [{
| "label": "${label.label}",
| "direction": "out"
| }]
| }]
|}
""".stripMargin)
val query = parser.toQuery(queryJson)
val checkFuture = s2.client.getEdges(query).map { fetchedResult =>
fetchedResult.nonEmpty should be(true)
val result = fetchedResult.head
result.queryResult.edgeWithScoreLs.find(edgeWithScore =>
edgeWithScore.edge.id == e.id())
}
Await.result(checkFuture, timeout)
}
{noformat}
note that I am still using s2graph's own API for getEdges and getVertices,
since I have not implemented necessary steps yet.
Thanks for bring out discussion and please tell us what you think!
> Support Apache TinkerPop and Gremlin
> ------------------------------------
>
> Key: S2GRAPH-72
> URL: https://issues.apache.org/jira/browse/S2GRAPH-72
> Project: S2Graph
> Issue Type: Improvement
> Reporter: Marko A. Rodriguez
>
> I posted a similar ticket when GitHub issues was the issue tracker for this
> project. In short, it would be great if S2Graph leveraged Apache TInkerPop
> (http://tinkerpop.apache.org). You can read the benefits here:
> http://tinkerpop.apache.org/providers.html
> One neat thing is that {{SparkGraphComputer}} would work over S2Graph and it
> would immediately get OLAP support.
> You can read a bit about Gremlin here.
> http://tinkerpop.apache.org/gremlin.html
> S2Graph would create a set of {{TraversalStrategies}} to make use of S2Graph
> specific optimizations such as global indices, local indices, multi-query
> (breadth query), etc.
> If you are interested in this path and have any questions, the Apache
> TinkerPop team is more than happy to help.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)