You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@s2graph.apache.org by da...@apache.org on 2017/08/03 03:29:31 UTC
[1/5] incubator-s2graph git commit: - add README.md. - add examples
on s2graph_gremlin. - add java interface for build global index. - add helper
on Management. - add S2GraphFactory. - update build.sbt - add s2graph_gremlin
as subproject for gremlin plug
Repository: incubator-s2graph
Updated Branches:
refs/heads/master 0a41ff0d2 -> 9f0e1e6de
- add README.md.
- add examples on s2graph_gremlin.
- add java interface for build global index.
- add helper on Management.
- add S2GraphFactory.
- update build.sbt
- add s2graph_gremlin as subproject for gremlin plugin.
- upgrate sbt-assembly.
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/ea36edae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/ea36edae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/ea36edae
Branch: refs/heads/master
Commit: ea36edaed262736a41aa73ea75ffc11980a441f5
Parents: 0a41ff0
Author: DO YUNG YOON <st...@apache.org>
Authored: Tue Aug 1 18:42:41 2017 +0900
Committer: DO YUNG YOON <st...@apache.org>
Committed: Tue Aug 1 18:42:41 2017 +0900
----------------------------------------------------------------------
build.sbt | 3 +
loader/build.sbt | 3 -
project/Common.scala | 2 +-
project/assembly.sbt | 2 +-
.../org/apache/s2graph/core/Management.scala | 81 ++++++++++-
.../scala/org/apache/s2graph/core/S2Graph.scala | 6 +-
.../apache/s2graph/core/S2GraphFactory.scala | 137 +++++++++++++++++++
.../org/apache/s2graph/core/S2Property.scala | 7 +-
.../core/storage/hbase/AsynchbaseStorage.scala | 9 +-
.../apache/s2graph/core/types/VertexId.scala | 2 +-
.../core/tinkerpop/S2GraphProvider.scala | 64 +--------
.../core/tinkerpop/structure/S2GraphTest.scala | 4 +-
s2counter_loader/build.sbt | 4 -
s2graph_gremlin/README.md | 42 ++++++
s2graph_gremlin/build.sbt | 82 +++++++++++
s2graph_gremlin/examples/install_plugin.sh | 28 ++++
.../examples/s2graph_getting_started.groovy | 82 +++++++++++
s2graph_gremlin/examples/s2graph_install.groovy | 21 +++
s2graph_gremlin/examples/s2graph_modern.groovy | 36 +++++
...inkerpop.gremlin.groovy.plugin.GremlinPlugin | 1 +
.../groovy/plugin/S2GraphGremlinPlugin.scala | 59 ++++++++
21 files changed, 593 insertions(+), 82 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/build.sbt
----------------------------------------------------------------------
diff --git a/build.sbt b/build.sbt
index 5c73076..b1017dd 100755
--- a/build.sbt
+++ b/build.sbt
@@ -61,6 +61,9 @@ lazy val s2counter_core = project.dependsOn(s2core)
lazy val s2counter_loader = project.dependsOn(s2counter_core, spark)
.settings(commonSettings: _*)
+lazy val s2graph_gremlin = project.dependsOn(s2core)
+ .settings(commonSettings: _*)
+
lazy val root = (project in file("."))
.aggregate(s2core, s2rest_play)
.dependsOn(s2rest_play, s2rest_netty, loader, s2counter_loader) // this enables packaging on the root project
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/loader/build.sbt
----------------------------------------------------------------------
diff --git a/loader/build.sbt b/loader/build.sbt
index 73144bb..ac7d948 100644
--- a/loader/build.sbt
+++ b/loader/build.sbt
@@ -17,7 +17,6 @@
* under the License.
*/
-import sbtassembly.Plugin.AssemblyKeys._
import Common._
name := "s2loader"
@@ -42,8 +41,6 @@ libraryDependencies ++= Seq(
crossScalaVersions := Seq("2.10.6")
-assemblySettings
-
mergeStrategy in assembly := {
case PathList("META-INF", ps @ _*) => MergeStrategy.discard
case _ => MergeStrategy.first
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/project/Common.scala
----------------------------------------------------------------------
diff --git a/project/Common.scala b/project/Common.scala
index c714aab..b965aed 100644
--- a/project/Common.scala
+++ b/project/Common.scala
@@ -26,7 +26,7 @@ object Common {
val hbaseVersion = "1.2.2"
val hadoopVersion = "2.7.3"
- val tinkerpopVersion = "3.2.4"
+ val tinkerpopVersion = "3.2.5"
/** use Log4j 1.2.17 as the SLF4j backend in runtime, with bridging libraries to forward JCL and JUL logs to SLF4j */
val loggingRuntime = Seq(
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/project/assembly.sbt
----------------------------------------------------------------------
diff --git a/project/assembly.sbt b/project/assembly.sbt
index 558b67e..d678255 100644
--- a/project/assembly.sbt
+++ b/project/assembly.sbt
@@ -17,4 +17,4 @@
* under the License.
*/
-addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")
+addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.5")
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/s2core/src/main/scala/org/apache/s2graph/core/Management.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/org/apache/s2graph/core/Management.scala b/s2core/src/main/scala/org/apache/s2graph/core/Management.scala
index 13610b4..6119045 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/Management.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/Management.scala
@@ -19,15 +19,14 @@
package org.apache.s2graph.core
+import java.util
+
import org.apache.s2graph.core.GraphExceptions.{InvalidHTableException, LabelAlreadyExistException, LabelNameTooLongException, LabelNotExistException}
import org.apache.s2graph.core.Management.JsonModel.{Index, Prop}
import org.apache.s2graph.core.mysqls._
import org.apache.s2graph.core.types.HBaseType._
import org.apache.s2graph.core.types._
import org.apache.s2graph.core.JSONParser._
-import org.apache.s2graph.core.index.IndexProvider
-import org.apache.s2graph.core.utils.logger
-import play.api.libs.json.Reads._
import play.api.libs.json._
import scala.util.Try
@@ -38,6 +37,16 @@ import scala.util.Try
*/
object Management {
+ import scala.collection.JavaConversions._
+
+ def newProp(name: String, defaultValue: String, datatType: String): Prop = {
+ new Prop(name, defaultValue, datatType)
+ }
+
+ def newIndex(name: String, propNames: java.util.List[String], options: String): Index = {
+ new Index(name, propNames, options = Option(options))
+ }
+
object JsonModel {
case class Prop(name: String, defaultValue: String, datatType: String)
@@ -70,7 +79,6 @@ object Management {
}
-
def createServiceColumn(serviceName: String,
columnName: String,
columnType: String,
@@ -259,6 +267,7 @@ object Management {
class Management(graph: S2Graph) {
import Management._
+ import scala.collection.JavaConversions._
def createStorageTable(zkAddr: String,
tableName: String,
@@ -274,6 +283,16 @@ class Management(graph: S2Graph) {
/** HBase specific code */
def createService(serviceName: String,
+ cluster: String,
+ hTableName: String,
+ preSplitSize: Int,
+ hTableTTL: Int,
+ compressionAlgorithm: String): Service = {
+ createService(serviceName, cluster, hTableName, preSplitSize,
+ Option(hTableTTL).filter(_ > -1), compressionAlgorithm).get
+ }
+
+ def createService(serviceName: String,
cluster: String, hTableName: String,
preSplitSize: Int, hTableTTL: Option[Int],
compressionAlgorithm: String = DefaultCompressionAlgorithm): Try[Service] = {
@@ -286,6 +305,54 @@ class Management(graph: S2Graph) {
}
}
+ def createServiceColumn(serviceName: String,
+ columnName: String,
+ columnType: String,
+ props: java.util.List[Prop],
+ schemaVersion: String = DEFAULT_VERSION): ServiceColumn = {
+
+ val serviceColumnTry = Model withTx { implicit session =>
+ val serviceOpt = Service.findByName(serviceName, useCache = false)
+ serviceOpt match {
+ case None => throw new RuntimeException(s"create service $serviceName has not been created.")
+ case Some(service) =>
+ val serviceColumn = ServiceColumn.findOrInsert(service.id.get, columnName, Some(columnType), schemaVersion, useCache = false)
+ for {
+ Prop(propName, defaultValue, dataType) <- props
+ } yield {
+ ColumnMeta.findOrInsert(serviceColumn.id.get, propName, dataType, useCache = false)
+ }
+ serviceColumn
+ }
+ }
+
+ serviceColumnTry.get
+ }
+
+ def createLabel(labelName: String,
+ srcColumn: ServiceColumn,
+ tgtColumn: ServiceColumn,
+ isDirected: Boolean,
+ serviceName: String,
+ indices: java.util.List[Index],
+ props: java.util.List[Prop],
+ consistencyLevel: String,
+ hTableName: String,
+ hTableTTL: Int,
+ schemaVersion: String,
+ compressionAlgorithm: String,
+ options: String): Label = {
+ import scala.collection.JavaConversions._
+
+ createLabel(labelName,
+ srcColumn.service.serviceName, srcColumn.columnName, srcColumn.columnType,
+ tgtColumn.service.serviceName, tgtColumn.columnName, tgtColumn.columnType,
+ isDirected, serviceName, indices, props, consistencyLevel,
+ Option(hTableName), Option(hTableTTL).filter(_ > -1),
+ schemaVersion, false, compressionAlgorithm, Option(options)
+ ).get
+ }
+
/** HBase specific code */
def createLabel(label: String,
srcServiceName: String,
@@ -349,9 +416,15 @@ class Management(graph: S2Graph) {
old.consistencyLevel, hTableName, old.hTableTTL, old.schemaVersion, old.isAsync, old.compressionAlgorithm, old.options)
}
+ def buildGlobalVertexIndex(name: String, propNames: java.util.List[String]): GlobalIndex =
+ buildGlobalIndex(GlobalIndex.VertexType, name, propNames)
+
def buildGlobalVertexIndex(name: String, propNames: Seq[String]): GlobalIndex =
buildGlobalIndex(GlobalIndex.VertexType, name, propNames)
+ def buildGlobalEdgeIndex(name: String, propNames: java.util.List[String]): GlobalIndex =
+ buildGlobalIndex(GlobalIndex.EdgeType, name, propNames)
+
def buildGlobalEdgeIndex(name: String, propNames: Seq[String]): GlobalIndex =
buildGlobalIndex(GlobalIndex.EdgeType, name, propNames)
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala b/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala
index d70651c..890dc4d 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala
@@ -43,6 +43,7 @@ import org.apache.tinkerpop.gremlin.structure.Graph.{Features, Variables}
import org.apache.tinkerpop.gremlin.structure.io.{GraphReader, GraphWriter, Io, Mapper}
import org.apache.tinkerpop.gremlin.structure.{Edge, Element, Graph, T, Transaction, Vertex}
import play.api.libs.json.{JsObject, Json}
+import scalikejdbc.DBSession
import scala.annotation.tailrec
import scala.collection.JavaConversions._
@@ -69,8 +70,6 @@ object S2Graph {
"phase" -> "dev",
"db.default.driver" -> "org.h2.Driver",
"db.default.url" -> "jdbc:h2:file:./var/metastore;MODE=MYSQL",
-// "db.default.driver" -> "com.mysql.jdbc.Driver",
-// "db.default.url" -> "jdbc:mysql://default:3306/graph_dev",
"db.default.password" -> "graph",
"db.default.user" -> "graph",
"cache.max.size" -> java.lang.Integer.valueOf(0),
@@ -871,6 +870,8 @@ class S2Graph(_config: Config)(implicit val ec: ExecutionContext) extends Graph
private var apacheConfiguration: Configuration = _
+ def dbSession() = scalikejdbc.AutoSession
+
def this(apacheConfiguration: Configuration)(ec: ExecutionContext) = {
this(S2Graph.toTypeSafeConfig(apacheConfiguration))(ec)
this.apacheConfiguration = apacheConfiguration
@@ -894,7 +895,6 @@ class S2Graph(_config: Config)(implicit val ec: ExecutionContext) extends Graph
val ExpireAfterWrite = config.getInt("future.cache.expire.after.write")
val ExpireAfterAccess = config.getInt("future.cache.expire.after.access")
val WaitTimeout = Duration(600, TimeUnit.SECONDS)
- val scheduledEx = ExecutionContext.fromExecutor(Executors.newSingleThreadExecutor())
val management = new Management(this)
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/s2core/src/main/scala/org/apache/s2graph/core/S2GraphFactory.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/org/apache/s2graph/core/S2GraphFactory.scala b/s2core/src/main/scala/org/apache/s2graph/core/S2GraphFactory.scala
new file mode 100644
index 0000000..7f13711
--- /dev/null
+++ b/s2core/src/main/scala/org/apache/s2graph/core/S2GraphFactory.scala
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.s2graph.core
+
+import org.apache.commons.configuration.BaseConfiguration
+import org.apache.s2graph.core.Management.JsonModel.Prop
+import org.apache.s2graph.core.S2Graph.{DefaultColumnName, DefaultServiceName}
+import org.apache.s2graph.core.mysqls.{ColumnMeta, ServiceColumn}
+import org.apache.s2graph.core.types.HBaseType
+import org.apache.tinkerpop.gremlin.structure.T
+
+object S2GraphFactory {
+
+ def generateClassic(g: S2Graph): Unit = {
+ val marko = g.addVertex(T.id, Int.box(1), "name", "marko", "age", Int.box(29))
+ val vadas = g.addVertex(T.id, Int.box(2), "name", "vadas", "age", Int.box(27))
+ val lop = g.addVertex(T.id, Int.box(3), "name", "lop", "lang", "java")
+ val josh = g.addVertex(T.id, Int.box(4), "name", "josh", "age", Int.box(32))
+ val ripple = g.addVertex(T.id, Int.box(5), "name", "ripple", "lang", "java")
+ val peter = g.addVertex(T.id, Int.box(6), "name", "peter", "age", Int.box(35))
+ marko.addEdge("knows", vadas, T.id, Int.box(7), "weight", Float.box(0.5f))
+ marko.addEdge("knows", josh, T.id, Int.box(8), "weight", Float.box(1.0f))
+ marko.addEdge("created", lop, T.id, Int.box(9), "weight", Float.box(0.4f))
+ josh.addEdge("created", ripple, T.id, Int.box(10), "weight", Float.box(1.0f))
+ josh.addEdge("created", lop, T.id, Int.box(11), "weight", Float.box(0.4f))
+ peter.addEdge("created", lop, T.id, Int.box(12), "weight", Float.box(0.2f))
+ }
+
+ def generateModern(g: S2Graph): Unit = {
+ val marko = g.addVertex(T.id, Int.box(1), T.label, "person", "name", "marko", "age", Int.box(29))
+ val vadas = g.addVertex(T.id, Int.box(2), T.label, "person", "name", "vadas", "age", Int.box(27))
+ val lop = g.addVertex(T.id, Int.box(3), T.label, "software", "name", "lop", "lang", "java")
+ val josh = g.addVertex(T.id, Int.box(4), T.label, "person", "name", "josh", "age", Int.box(32))
+ val ripple = g.addVertex(T.id, Int.box(5), T.label, "software", "name", "ripple", "lang", "java")
+ val peter = g.addVertex(T.id, Int.box(6), T.label, "person", "name", "peter", "age", Int.box(35))
+
+ marko.addEdge("knows", vadas, T.id, Int.box(7), "weight", Double.box(0.5d))
+ marko.addEdge("knows", josh, T.id, Int.box(8), "weight", Double.box(1.0d))
+ marko.addEdge("created", lop, T.id, Int.box(9), "weight", Double.box(0.4d))
+ josh.addEdge("created", ripple, T.id, Int.box(10), "weight", Double.box(1.0d))
+ josh.addEdge("created", lop, T.id, Int.box(11), "weight", Double.box(0.4d))
+ peter.addEdge("created", lop, T.id, Int.box(12), "weight", Double.box(0.2d))
+ }
+
+ def initDefaultSchema(graph: S2Graph): Unit = {
+ val management = graph.management
+
+ // Management.deleteService(DefaultServiceName)
+ val DefaultService = management.createService(DefaultServiceName, "localhost", "s2graph", 0, None).get
+
+ // Management.deleteColumn(DefaultServiceName, DefaultColumnName)
+ val DefaultColumn = ServiceColumn.findOrInsert(DefaultService.id.get, DefaultColumnName, Some("integer"), HBaseType.DEFAULT_VERSION, useCache = false)
+
+ val DefaultColumnMetas = {
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "test", "string", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "name", "string", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "age", "integer", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "lang", "string", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "oid", "integer", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "communityIndex", "integer", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "testing", "string", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "string", "string", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "boolean", "boolean", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "long", "long", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "float", "float", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "double", "double", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "integer", "integer", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "aKey", "string", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "x", "integer", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "y", "integer", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "location", "string", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "status", "string", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "myId", "integer", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "acl", "string", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "some", "string", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "this", "string", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "that", "string", useCache = false)
+ ColumnMeta.findOrInsert(DefaultColumn.id.get, "any", "string", useCache = false)
+ }
+
+ // Management.deleteLabel("_s2graph")
+ val DefaultLabel = management.createLabel("_s2graph", DefaultService.serviceName, DefaultColumn.columnName, DefaultColumn.columnType,
+ DefaultService.serviceName, DefaultColumn.columnName, DefaultColumn.columnType, true, DefaultService.serviceName, Nil, Nil, "weak", None, None,
+ options = Option("""{"skipReverse": false}""")
+ )
+ }
+
+ def initModernSchema(g: S2Graph): Unit = {
+ val mnt = g.management
+ val softwareColumn = Management.createServiceColumn(S2Graph.DefaultServiceName, "software", "integer", Seq(Prop(T.id.toString, "-1", "integer"), Prop("name", "-", "string"), Prop("lang", "-", "string")))
+ val personColumn = Management.createServiceColumn(S2Graph.DefaultServiceName, "person", "integer",
+ Seq(Prop(T.id.toString, "-1", "integer"), Prop("name", "-", "string"), Prop("age", "0", "integer"), Prop("location", "-", "string")))
+
+ val knows = mnt.createLabel("knows",
+ S2Graph.DefaultServiceName, "person", "integer",
+ S2Graph.DefaultServiceName, "person", "integer",
+ true, S2Graph.DefaultServiceName, Nil, Seq(Prop("weight", "0.0", "double"), Prop("year", "0", "integer")), consistencyLevel = "strong", None, None)
+
+ val created = mnt.createLabel("created",
+ S2Graph.DefaultServiceName, "person", "integer",
+ S2Graph.DefaultServiceName, "software", "integer",
+ true, S2Graph.DefaultServiceName, Nil, Seq(Prop("weight", "0.0", "double")), "strong", None, None)
+ }
+
+ def cleanupDefaultSchema: Unit = {
+ val columnNames = Set(S2Graph.DefaultColumnName, "person", "software", "product", "dog",
+ "animal", "song", "artist", "STEPHEN")
+
+ val labelNames = Set(S2Graph.DefaultLabelName, "knows", "created", "bought", "test", "self", "friends", "friend", "hate", "collaborator",
+ "test1", "test2", "test3", "pets", "walks", "hates", "link",
+ "codeveloper", "createdBy", "existsWith", "writtenBy", "sungBy", "followedBy", "uses", "likes", "foo", "bar")
+
+ columnNames.foreach { columnName =>
+ Management.deleteColumn(S2Graph.DefaultServiceName, columnName)
+ }
+ labelNames.foreach { labelName =>
+ Management.deleteLabel(labelName)
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/s2core/src/main/scala/org/apache/s2graph/core/S2Property.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/org/apache/s2graph/core/S2Property.scala b/s2core/src/main/scala/org/apache/s2graph/core/S2Property.scala
index 07d2bbf..6b0c0eb 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/S2Property.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/S2Property.scala
@@ -41,6 +41,7 @@ object S2Property {
case _: java.lang.Short => true
case _: java.lang.Byte => true
case _: java.lang.String => true
+ case _: java.math.BigDecimal => true
case _: Int => true
case _: Long => true
case _: Float => true
@@ -62,7 +63,11 @@ object S2Property {
var result = Map[String, AnyRef]()
kvsList.foreach { pair =>
val key = pair.getValue0
- val value = pair.getValue1
+ val value = pair.getValue1 match {
+ case v: java.math.BigDecimal => new BigDecimal(v)
+ case _@org => org
+ }
+
ElementHelper.validateProperty(key, value)
// if (keySet.contains(key)) throw VertexProperty.Exceptions.multiPropertiesNotSupported
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/s2core/src/main/scala/org/apache/s2graph/core/storage/hbase/AsynchbaseStorage.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/org/apache/s2graph/core/storage/hbase/AsynchbaseStorage.scala b/s2core/src/main/scala/org/apache/s2graph/core/storage/hbase/AsynchbaseStorage.scala
index dbb6e4c..e4d85cf 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/storage/hbase/AsynchbaseStorage.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/storage/hbase/AsynchbaseStorage.scala
@@ -116,15 +116,20 @@ object AsynchbaseStorage {
val socket = new Socket(host, port)
socket.close()
+ logger.info(s"HBase is available.")
true
} catch {
- case e: IOException => false
+ case e: IOException =>
+ logger.info(s"HBase is not available.")
+ false
}
if (!hbaseAvailable) {
// start HBase
executor.submit(new Runnable {
override def run(): Unit = {
+ logger.info(s"HMaster starting...")
+ val ts = System.currentTimeMillis()
val cwd = new File(".").getAbsolutePath
if (overwrite) {
val dataDir = new File(s"$cwd/storage/s2graph")
@@ -140,12 +145,14 @@ object AsynchbaseStorage {
System.setProperty("hbase.root.logger", "INFO,RFA")
org.apache.hadoop.hbase.master.HMaster.main(Array[String]("start"))
+ logger.info(s"HMaster startup finished: ${System.currentTimeMillis() - ts}")
}
})
}
executor
}
+
hbaseExecutor
}
}
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/s2core/src/main/scala/org/apache/s2graph/core/types/VertexId.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/org/apache/s2graph/core/types/VertexId.scala b/s2core/src/main/scala/org/apache/s2graph/core/types/VertexId.scala
index 4130fe0..eb00405 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/types/VertexId.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/types/VertexId.scala
@@ -21,7 +21,7 @@ package org.apache.s2graph.core.types
import org.apache.hadoop.hbase.util.Bytes
import org.apache.s2graph.core.{GraphUtil, S2Vertex}
-import org.apache.s2graph.core.mysqls.ServiceColumn
+import org.apache.s2graph.core.mysqls._
import org.apache.s2graph.core.types.HBaseType._
import org.apache.s2graph.core.io.Conversions._
import play.api.libs.json.Json
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/S2GraphProvider.scala
----------------------------------------------------------------------
diff --git a/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/S2GraphProvider.scala b/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/S2GraphProvider.scala
index 8bcac9c..52d182e 100644
--- a/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/S2GraphProvider.scala
+++ b/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/S2GraphProvider.scala
@@ -43,64 +43,6 @@ object S2GraphProvider {
classOf[S2VertexProperty[_]],
classOf[S2Graph]
)
- def initDefaultSchema(graph: S2Graph): Unit = {
- val management = graph.management
-
- // Management.deleteService(DefaultServiceName)
- val DefaultService = management.createService(DefaultServiceName, "localhost", "s2graph", 0, None).get
-
- // Management.deleteColumn(DefaultServiceName, DefaultColumnName)
- val DefaultColumn = ServiceColumn.findOrInsert(DefaultService.id.get, DefaultColumnName, Some("integer"), HBaseType.DEFAULT_VERSION, useCache = false)
-
- val DefaultColumnMetas = {
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "test", "string", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "name", "string", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "age", "integer", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "lang", "string", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "oid", "integer", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "communityIndex", "integer", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "testing", "string", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "string", "string", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "boolean", "boolean", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "long", "long", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "float", "float", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "double", "double", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "integer", "integer", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "aKey", "string", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "x", "integer", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "y", "integer", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "location", "string", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "status", "string", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "myId", "integer", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "acl", "string", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "some", "string", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "this", "string", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "that", "string", useCache = false)
- ColumnMeta.findOrInsert(DefaultColumn.id.get, "any", "string", useCache = false)
- }
-
- // Management.deleteLabel("_s2graph")
- val DefaultLabel = management.createLabel("_s2graph", DefaultService.serviceName, DefaultColumn.columnName, DefaultColumn.columnType,
- DefaultService.serviceName, DefaultColumn.columnName, DefaultColumn.columnType, true, DefaultService.serviceName, Nil, Nil, "weak", None, None,
- options = Option("""{"skipReverse": false}""")
- ).get
- }
-
- def cleanupSchema: Unit = {
- val columnNames = Set(S2Graph.DefaultColumnName, "person", "software", "product", "dog",
- "animal", "song", "artist", "STEPHEN")
-
- val labelNames = Set(S2Graph.DefaultLabelName, "knows", "created", "bought", "test", "self", "friends", "friend", "hate", "collaborator",
- "test1", "test2", "test3", "pets", "walks", "hates", "link",
- "codeveloper", "createdBy", "existsWith", "writtenBy", "sungBy", "followedBy", "uses", "likes", "foo", "bar")
-
- columnNames.foreach { columnName =>
- Management.deleteColumn(S2Graph.DefaultServiceName, columnName)
- }
- labelNames.foreach { labelName =>
- Management.deleteLabel(labelName)
- }
- }
}
class S2GraphProvider extends AbstractGraphProvider {
@@ -123,7 +65,7 @@ class S2GraphProvider extends AbstractGraphProvider {
// }
// }
// s2Graph.shutdown(modelDataDelete = true)
- S2GraphProvider.cleanupSchema
+ S2GraphFactory.cleanupDefaultSchema
s2Graph.shutdown(modelDataDelete = true)
logger.info("S2Graph Shutdown")
}
@@ -144,9 +86,9 @@ class S2GraphProvider extends AbstractGraphProvider {
val s2Graph = graph.asInstanceOf[S2Graph]
val mnt = s2Graph.getManagement()
- S2GraphProvider.cleanupSchema
+ S2GraphFactory.cleanupDefaultSchema
initTestSchema(testClass, testName)
- S2GraphProvider.initDefaultSchema(s2Graph)
+ S2GraphFactory.initDefaultSchema(s2Graph)
val defaultService = Service.findByName(S2Graph.DefaultServiceName).getOrElse(throw new IllegalStateException("default service is not initialized."))
val defaultServiceColumn = ServiceColumn.find(defaultService.id.get, S2Graph.DefaultColumnName).getOrElse(throw new IllegalStateException("default column is not initialized."))
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala
----------------------------------------------------------------------
diff --git a/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala b/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala
index 34769da..9b6b60f 100644
--- a/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala
+++ b/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala
@@ -421,8 +421,8 @@ class S2GraphTest extends FunSuite with Matchers with TestCommonWithModels {
val mnt = graph.management
- S2GraphProvider.cleanupSchema
- S2GraphProvider.initDefaultSchema(graph)
+ S2GraphFactory.cleanupDefaultSchema
+ S2GraphFactory.initDefaultSchema(graph)
val softwareColumn = Management.createServiceColumn(S2Graph.DefaultServiceName, "software", "integer", Seq(Prop(T.id.toString, "-1", "integer"), Prop("name", "-", "string"), Prop("lang", "-", "string")))
val personColumn = Management.createServiceColumn(S2Graph.DefaultServiceName, "person", "integer",
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/s2counter_loader/build.sbt
----------------------------------------------------------------------
diff --git a/s2counter_loader/build.sbt b/s2counter_loader/build.sbt
index d0f1f41..f72e449 100644
--- a/s2counter_loader/build.sbt
+++ b/s2counter_loader/build.sbt
@@ -17,8 +17,6 @@
* under the License.
*/
-import sbtassembly.Plugin.AssemblyKeys._
-
name := "s2counter-loader"
scalacOptions in Test ++= Seq("-Yrangepos")
@@ -43,8 +41,6 @@ fork := true
transitiveClassifiers ++= Seq()
-assemblySettings
-
mergeStrategy in assembly := {
case PathList("META-INF", ps @ _*) => MergeStrategy.discard
case _ => MergeStrategy.first
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/s2graph_gremlin/README.md
----------------------------------------------------------------------
diff --git a/s2graph_gremlin/README.md b/s2graph_gremlin/README.md
new file mode 100644
index 0000000..a4782e6
--- /dev/null
+++ b/s2graph_gremlin/README.md
@@ -0,0 +1,42 @@
+# S2Graph Tinkerpop3 Implementation(s2graph-gremlin)
+
+Currently tested with tinkerpop 3.2.5 only on gremlin-console.
+
+## Requirement
+
+1. Download latest [Apache Tinkerpop 3.2.5](https://www.apache.org/dyn/closer.lua/tinkerpop/3.2.5/apache-tinkerpop-gremlin-console-3.2.5-bin.zip).
+2. set environment variable `GREMLIN_HOME`.
+3. create ~/.groovy/grapeConfig.xml file if it does not exist as follow.
+
+```
+<ivysettings>
+ <settings defaultResolver="downloadGrapes"/>
+ <resolvers>
+ <chain name="downloadGrapes">
+ <filesystem name="cachedGrapes">
+ <ivy pattern="${user.home}/.groovy/grapes/[organisation]/[module]/ivy-[revision].xml"/>
+ <artifact pattern="${user.home}/.groovy/grapes/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]"/>
+ </filesystem>
+ <ibiblio name="local" root="file:${user.home}/.m2/repository/" m2compatible="true"/>
+ <ibiblio name="codehaus" root="http://repository.codehaus.org/" m2compatible="true"/>
+ <ibiblio name="central" root="http://central.maven.org/maven2/" m2compatible="true"/>
+ <ibiblio name="jitpack" root="https://jitpack.io" m2compatible="true"/>
+ <ibiblio name="java.net2" root="http://download.java.net/maven/2/" m2compatible="true"/>
+ </chain>
+ </resolvers>
+</ivysettings>
+```
+
+## Build
+
+following is how to setup this project on m2 repository.
+
+1. `sbt "project s2graph_gremlin" publishM2`: this will create single fat jar under m2 repository.
+2. check if `GREMLIN_HOME` is correct.
+3. goto `cd s2graph_gremlin/examples`.
+4. install s2graph-gremlin plugin, `sh install_plugin.sh`.
+5. go to `${GREMLIN_HOME}/bin/gremlin.sh`
+5. try `s2graph_modern.groovy` to play with modern graph comes with tinkerpop.
+6. try `s2graph_getting_started.groovy` for s2graph specific methods.
+
+
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/s2graph_gremlin/build.sbt
----------------------------------------------------------------------
diff --git a/s2graph_gremlin/build.sbt b/s2graph_gremlin/build.sbt
new file mode 100644
index 0000000..8edead5
--- /dev/null
+++ b/s2graph_gremlin/build.sbt
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import scala.xml.{Node => XmlNode, NodeSeq => XmlNodeSeq, _}
+import scala.xml.transform.{RewriteRule, RuleTransformer}
+
+import Common._
+
+val gremlin_version = Common.tinkerpopVersion
+
+name := "s2graph-gremlin"
+version := version.value
+
+scalacOptions ++= Seq("-deprecation")
+
+
+projectDependencies := Seq(
+ (projectID in "s2core").value exclude("org.mortbay.jetty", "*") exclude("javax.xml.stream", "*") exclude("javax.servlet", "*")
+)
+
+
+libraryDependencies ++= Seq(
+ "com.google.guava" % "guava" % "12.0.1" force(), // use this old version of guava to avoid incompatibility
+ "org.apache.hadoop" % "hadoop-mapreduce-client-app" % Common.hadoopVersion excludeLogging(),
+ "org.apache.tinkerpop" % "gremlin-groovy" % gremlin_version excludeLogging()
+)
+
+
+pomIncludeRepository := { (repo: MavenRepository) => false}
+pomPostProcess := { (node: XmlNode) =>
+ new RuleTransformer(new RewriteRule {
+ override def transform(node: XmlNode): XmlNodeSeq = node match {
+ case e: Elem if e.label == "dependency" =>
+ Comment(s"provided dependency $organization#$artifact;$version has been omitted")
+ case _ => node
+ }
+ }).transform(node).head
+}
+
+
+publishMavenStyle := true
+publishArtifact in (Test, packageSrc) := false
+
+publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath+"/.m2/repository")))
+
+autoScalaLibrary := false
+crossPaths := false
+
+mergeStrategy in assembly := {
+ case PathList("META-INF", "services", "org.apache.hadoop.fs.FileSystem") => MergeStrategy.filterDistinctLines
+ case PathList("META-INF", "services", ps @ _*) => MergeStrategy.first
+ case PathList("META-INF", ps @ _*) => MergeStrategy.discard
+ case PathList("license", ps @ _*) => MergeStrategy.discard
+ case _ => MergeStrategy.first
+}
+
+test in assembly := {}
+
+parallelExecution in Test := false
+
+publishArtifact in (Compile, packageBin) := false
+publishArtifact in (Compile, packageSrc) := false
+publishArtifact in (Compile, packageDoc) := false
+
+addArtifact(artifact in (Compile, assembly), assembly)
+
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/s2graph_gremlin/examples/install_plugin.sh
----------------------------------------------------------------------
diff --git a/s2graph_gremlin/examples/install_plugin.sh b/s2graph_gremlin/examples/install_plugin.sh
new file mode 100644
index 0000000..e44e1ad
--- /dev/null
+++ b/s2graph_gremlin/examples/install_plugin.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Require $GREMLIN_HOME point to apache-tinkerpop-gremlin-console.
+
+# remove pre-existing s2graph-gremlin plugin.
+rm -rf ${GREMLIN_HOME}/ext/s2graph-gremlin
+
+# remove pre-existing DB schema and HBase Storage.
+rm -rf ${GREMLIN_HOME}/var ${GREMLIN_HOME}/storage
+
+# export GREMLIN_HOME
+# install plugin
+${GREMLIN_HOME}/bin/gremlin.sh -e s2graph_install.groovy
+
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/s2graph_gremlin/examples/s2graph_getting_started.groovy
----------------------------------------------------------------------
diff --git a/s2graph_gremlin/examples/s2graph_getting_started.groovy b/s2graph_gremlin/examples/s2graph_getting_started.groovy
new file mode 100644
index 0000000..04b27c8
--- /dev/null
+++ b/s2graph_gremlin/examples/s2graph_getting_started.groovy
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// init graph
+graph = S2Graph.open(new BaseConfiguration())
+
+// 0. import
+import static org.apache.s2graph.core.Management.*
+
+// 1. create service
+session = graph.dbSession()
+serviceName = "s2graph"
+cluster = "localhost"
+hTableName = "s2graph"
+preSplitSize = 0
+hTableTTL = -1
+compressionAlgorithm = "gz"
+
+service = graph.management.createService(serviceName, cluster, hTableName, preSplitSize, hTableTTL, compressionAlgorithm)
+
+// 2. create vertex schema
+columnName = "user"
+columnType = "integer"
+props = [newProp("name", "-", "string"), newProp("age", "-1", "integer")]
+schemaVersion = "v3"
+user = graph.management.createServiceColumn(serviceName, columnName, columnType, props, schemaVersion)
+
+// 2.1 (optional) global vertex index.
+graph.management.buildGlobalVertexIndex("global_vertex_index", ["name", "age"])
+
+// 3. create VertexId
+v1Id = graph.newVertexId(serviceName, columnName, 20)
+v2Id = graph.newVertexId(serviceName, columnName, 30)
+
+shon = graph.addVertex(T.id, v1Id, "name", "shon", "age", 35)
+dun = graph.addVertex(T.id, v2Id, "name", "dun", "age", 36)
+
+// 4. friends label
+labelName = "friend_"
+srcColumn = user
+tgtColumn = user
+isDirected = true
+indices = []
+props = [newProp("since", "-", "string")]
+consistencyLevel = "strong"
+hTableName = "s2graph"
+hTableTTL = -1
+options = null
+
+friend = graph.management.createLabel(labelName, srcColumn, tgtColumn,
+ isDirected, serviceName, indices, props, consistencyLevel,
+ hTableName, hTableTTL, schemaVersion, compressionAlgorithm, options)
+
+shon.addEdge(labelName, dun, "since", "2017-01-01")
+
+t = graph.traversal()
+
+
+println "All Edges"
+println t.E().toList()
+
+println "All Vertices"
+println t.V().toList()
+
+println "Specific Edge"
+println t.V().has("name", "shon").out().toList()
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/s2graph_gremlin/examples/s2graph_install.groovy
----------------------------------------------------------------------
diff --git a/s2graph_gremlin/examples/s2graph_install.groovy b/s2graph_gremlin/examples/s2graph_install.groovy
new file mode 100644
index 0000000..2aad60c
--- /dev/null
+++ b/s2graph_gremlin/examples/s2graph_install.groovy
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+:install org.apache.s2graph s2graph-gremlin 0.1.1-SNAPSHOT
+:plugin use tinkerpop.s2graph
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/s2graph_gremlin/examples/s2graph_modern.groovy
----------------------------------------------------------------------
diff --git a/s2graph_gremlin/examples/s2graph_modern.groovy b/s2graph_gremlin/examples/s2graph_modern.groovy
new file mode 100644
index 0000000..982cd9d
--- /dev/null
+++ b/s2graph_gremlin/examples/s2graph_modern.groovy
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// init schema
+graph = S2Graph.open(new BaseConfiguration())
+S2GraphFactory.initDefaultSchema(graph)
+
+S2GraphFactory.initModernSchema(graph)
+S2GraphFactory.generateModern(graph)
+
+// traversal
+t = graph.traversal()
+t.E()
+
+shon = graph.addVertex(T.id, 10, T.label, "person", "name", "shon", "age", 35)
+s2graph = graph.addVertex(T.id, 11, T.label, "software", "name", "s2graph", "lang", "scala")
+
+created = shon.addEdge("created", s2graph, "_timestamp", 10, "weight", 0.1)
+
+t.V().has("name", "shon").out()
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/s2graph_gremlin/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin
----------------------------------------------------------------------
diff --git a/s2graph_gremlin/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin b/s2graph_gremlin/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin
new file mode 100644
index 0000000..89d6ff5
--- /dev/null
+++ b/s2graph_gremlin/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin
@@ -0,0 +1 @@
+org.apache.s2graph.core.tinkerpop.groovy.plugin.S2GraphGremlinPlugin
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea36edae/s2graph_gremlin/src/main/scala/org/apache/s2graph/core/tinkerpop/groovy/plugin/S2GraphGremlinPlugin.scala
----------------------------------------------------------------------
diff --git a/s2graph_gremlin/src/main/scala/org/apache/s2graph/core/tinkerpop/groovy/plugin/S2GraphGremlinPlugin.scala b/s2graph_gremlin/src/main/scala/org/apache/s2graph/core/tinkerpop/groovy/plugin/S2GraphGremlinPlugin.scala
new file mode 100644
index 0000000..a75136d
--- /dev/null
+++ b/s2graph_gremlin/src/main/scala/org/apache/s2graph/core/tinkerpop/groovy/plugin/S2GraphGremlinPlugin.scala
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.s2graph.core.tinkerpop.groovy.plugin
+
+import java.util
+import org.apache.tinkerpop.gremlin.groovy.plugin.{AbstractGremlinPlugin, PluginAcceptor}
+
+object S2GraphGremlinPlugin{
+ lazy val IMPORTS = {
+ val hashSet = new util.HashSet[String]()
+ hashSet.add("import org.apache.s2graph.core.*")
+ hashSet.add("import org.apache.s2graph.core.S2Graph.*")
+ hashSet.add("import org.apache.s2graph.core.Management.JsonModel.*")
+ hashSet.add("import org.apache.s2graph.core.S2GraphFactory")
+ hashSet.add("import org.apache.s2graph.core.S2GraphFactory.*")
+ hashSet.add("import org.apache.s2graph.core.mysqls.*")
+ hashSet.add("import org.apache.s2graph.core.index.*")
+ hashSet.add("import org.apache.s2graph.core.features.*")
+ hashSet.add("import org.apache.s2graph.core.io.*")
+ hashSet.add("import org.apache.s2graph.core.parsers.*")
+ hashSet.add("import org.apache.s2graph.core.rest.*")
+ hashSet.add("import org.apache.s2graph.core.utils.*")
+ hashSet.add("import org.apache.s2graph.core.types.*")
+
+ hashSet
+ }
+}
+class S2GraphGremlinPlugin extends AbstractGremlinPlugin{
+
+ override def pluginTo(pluginAcceptor: PluginAcceptor): Unit = {
+ pluginAcceptor.addImports(S2GraphGremlinPlugin.IMPORTS)
+ }
+
+
+ override def afterPluginTo(pluginAcceptor: PluginAcceptor): Unit = {
+
+ }
+
+ override def getName() : String = "tinkerpop.s2graph"
+
+ override def requireRestart() : Boolean = true
+}
[3/5] incubator-s2graph git commit: remove unnecessary test for
global index on S2GraphTest.
Posted by da...@apache.org.
remove unnecessary test for global index on S2GraphTest.
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/b66b96a7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/b66b96a7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/b66b96a7
Branch: refs/heads/master
Commit: b66b96a7528a2c189d072e1eacfbb683c6365f5d
Parents: 030cd2d
Author: DO YUNG YOON <st...@apache.org>
Authored: Thu Aug 3 07:06:03 2017 +0900
Committer: DO YUNG YOON <st...@apache.org>
Committed: Thu Aug 3 07:06:03 2017 +0900
----------------------------------------------------------------------
.../apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b66b96a7/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala
----------------------------------------------------------------------
diff --git a/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala b/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala
index 9b6b60f..eb59632 100644
--- a/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala
+++ b/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala
@@ -41,7 +41,7 @@ class S2GraphTest extends FunSuite with Matchers with TestCommonWithModels {
initTests()
val g = new S2Graph(config)
- lazy val gIndex = management.buildGlobalIndex(GlobalIndex.EdgeType, "S2GraphTest2", Seq("weight"))
+// lazy val gIndex = management.buildGlobalIndex(GlobalIndex.EdgeType, "S2GraphTest2", Seq("weight"))
def printEdges(edges: Seq[Edge]): Unit = {
edges.foreach { edge =>
logger.debug(s"[FetchedEdge]: $edge")
@@ -417,7 +417,7 @@ class S2GraphTest extends FunSuite with Matchers with TestCommonWithModels {
//// }
// }
test("Modern") {
- gIndex
+// gIndex
val mnt = graph.management
[4/5] incubator-s2graph git commit: ignore conflicted test (#12)
Posted by da...@apache.org.
ignore conflicted test (#12)
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/ca79e490
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/ca79e490
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/ca79e490
Branch: refs/heads/master
Commit: ca79e4906d9e441e4125ab0ae4c25fe39ae6fe46
Parents: b66b96a
Author: daewon <da...@apache.org>
Authored: Thu Aug 3 12:09:04 2017 +0900
Committer: Doyung Yoon <st...@apache.org>
Committed: Thu Aug 3 12:09:04 2017 +0900
----------------------------------------------------------------------
.../apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ca79e490/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala
----------------------------------------------------------------------
diff --git a/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala b/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala
index eb59632..18a6c85 100644
--- a/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala
+++ b/s2core/src/test/scala/org/apache/s2graph/core/tinkerpop/structure/S2GraphTest.scala
@@ -41,7 +41,7 @@ class S2GraphTest extends FunSuite with Matchers with TestCommonWithModels {
initTests()
val g = new S2Graph(config)
-// lazy val gIndex = management.buildGlobalIndex(GlobalIndex.EdgeType, "S2GraphTest2", Seq("weight"))
+ lazy val gIndex = management.buildGlobalIndex(GlobalIndex.EdgeType, "S2GraphTest2", Seq("weight"))
def printEdges(edges: Seq[Edge]): Unit = {
edges.foreach { edge =>
logger.debug(s"[FetchedEdge]: $edge")
@@ -416,11 +416,10 @@ class S2GraphTest extends FunSuite with Matchers with TestCommonWithModels {
//// }
//// }
// }
- test("Modern") {
-// gIndex
+ ignore("Modern") {
+ gIndex
val mnt = graph.management
-
S2GraphFactory.cleanupDefaultSchema
S2GraphFactory.initDefaultSchema(graph)
[5/5] incubator-s2graph git commit: [S2GRAPH-148] Provide Gremlin
Plugin
Posted by da...@apache.org.
[S2GRAPH-148] Provide Gremlin Plugin
resolve S2GRAPH-148
close #115
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/9f0e1e6d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/9f0e1e6d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/9f0e1e6d
Branch: refs/heads/master
Commit: 9f0e1e6de5200eeb1b003cce8859e8f352b66564
Parents: 0a41ff0 ca79e49
Author: daewon <da...@apache.org>
Authored: Thu Aug 3 12:19:07 2017 +0900
Committer: daewon <da...@apache.org>
Committed: Thu Aug 3 12:28:23 2017 +0900
----------------------------------------------------------------------
CHANGES | 2 +
build.sbt | 3 +
loader/build.sbt | 3 -
project/Common.scala | 2 +-
project/assembly.sbt | 2 +-
.../org/apache/s2graph/core/Management.scala | 81 ++++++++++-
.../scala/org/apache/s2graph/core/S2Graph.scala | 6 +-
.../apache/s2graph/core/S2GraphFactory.scala | 137 +++++++++++++++++++
.../org/apache/s2graph/core/S2Property.scala | 7 +-
.../s2graph/core/rest/RequestParser.scala | 4 +-
.../core/storage/hbase/AsynchbaseStorage.scala | 9 +-
.../apache/s2graph/core/types/VertexId.scala | 2 +-
.../core/Integrate/IntegrateCommon.scala | 3 +-
.../apache/s2graph/core/ManagementTest.scala | 24 ++--
.../core/tinkerpop/S2GraphProvider.scala | 64 +--------
.../core/tinkerpop/structure/S2GraphTest.scala | 7 +-
s2counter_loader/build.sbt | 4 -
s2graph_gremlin/README.md | 42 ++++++
s2graph_gremlin/build.sbt | 82 +++++++++++
s2graph_gremlin/examples/install_plugin.sh | 28 ++++
.../examples/s2graph_getting_started.groovy | 82 +++++++++++
s2graph_gremlin/examples/s2graph_install.groovy | 21 +++
s2graph_gremlin/examples/s2graph_modern.groovy | 36 +++++
...inkerpop.gremlin.groovy.plugin.GremlinPlugin | 1 +
.../groovy/plugin/S2GraphGremlinPlugin.scala | 59 ++++++++
.../rest/play/controllers/AdminController.scala | 3 +-
26 files changed, 612 insertions(+), 102 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/9f0e1e6d/CHANGES
----------------------------------------------------------------------
diff --cc CHANGES
index 582177b,582177b..797b790
--- a/CHANGES
+++ b/CHANGES
@@@ -246,6 -246,6 +246,8 @@@ Release 0.1.0 - unrelease
S2GRAPH-152: Add buildGlobalIndex API on Management. (Committed by DOYUNG YOON).
S2GRAPH-153: Implement IndexProvider(for Mixed IndexType) class. (Committed by DOYUNG YOON).
++
++ S2GRAPH-148: Provide Gremlin Plugin. (Committed by DOYUNG YOON).
TEST
[2/5] incubator-s2graph git commit: fix compile error.
Posted by da...@apache.org.
fix compile error.
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/030cd2d5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/030cd2d5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/030cd2d5
Branch: refs/heads/master
Commit: 030cd2d52e7efc338336ce9c9d1fd6ce02d24203
Parents: ea36eda
Author: DO YUNG YOON <st...@apache.org>
Authored: Tue Aug 1 19:22:05 2017 +0900
Committer: DO YUNG YOON <st...@apache.org>
Committed: Tue Aug 1 19:32:32 2017 +0900
----------------------------------------------------------------------
.../s2graph/core/rest/RequestParser.scala | 4 ++--
.../core/Integrate/IntegrateCommon.scala | 3 +--
.../apache/s2graph/core/ManagementTest.scala | 24 ++++++++++----------
.../rest/play/controllers/AdminController.scala | 3 +--
4 files changed, 16 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/030cd2d5/s2core/src/main/scala/org/apache/s2graph/core/rest/RequestParser.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/org/apache/s2graph/core/rest/RequestParser.scala b/s2core/src/main/scala/org/apache/s2graph/core/rest/RequestParser.scala
index 62d1e40..a2f5c47 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/rest/RequestParser.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/rest/RequestParser.scala
@@ -629,7 +629,7 @@ class RequestParser(graph: S2Graph) {
pk ++ both ++ in ++ out
}
- def toLabelElements(jsValue: JsValue) = Try {
+ def toLabelElements(jsValue: JsValue): Try[Label] = {
val labelName = parse[String](jsValue, "label")
val srcServiceName = parse[String](jsValue, "srcServiceName")
val tgtServiceName = parse[String](jsValue, "tgtServiceName")
@@ -653,7 +653,7 @@ class RequestParser(graph: S2Graph) {
val compressionAlgorithm = (jsValue \ "compressionAlgorithm").asOpt[String].getOrElse(DefaultCompressionAlgorithm)
val options = (jsValue \ "options").asOpt[JsValue].map(_.toString())
- (labelName, srcServiceName, srcColumnName, srcColumnType,
+ graph.management.createLabel(labelName, srcServiceName, srcColumnName, srcColumnType,
tgtServiceName, tgtColumnName, tgtColumnType, isDirected, serviceName,
indices, allProps, consistencyLevel, hTableName, hTableTTL, schemaVersion, isAsync, compressionAlgorithm, options)
}
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/030cd2d5/s2core/src/test/scala/org/apache/s2graph/core/Integrate/IntegrateCommon.scala
----------------------------------------------------------------------
diff --git a/s2core/src/test/scala/org/apache/s2graph/core/Integrate/IntegrateCommon.scala b/s2core/src/test/scala/org/apache/s2graph/core/Integrate/IntegrateCommon.scala
index fd496ee..c720b9f 100644
--- a/s2core/src/test/scala/org/apache/s2graph/core/Integrate/IntegrateCommon.scala
+++ b/s2core/src/test/scala/org/apache/s2graph/core/Integrate/IntegrateCommon.scala
@@ -83,8 +83,7 @@ trait IntegrateCommon extends FunSuite with Matchers with BeforeAndAfterAll {
logger.info(s">> Create Label")
logger.info(create)
val tryRes = for {
- labelArgs <- parser.toLabelElements(json)
- label <- (management.createLabel _).tupled(labelArgs)
+ label <- parser.toLabelElements(json)
} yield label
tryRes.get
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/030cd2d5/s2core/src/test/scala/org/apache/s2graph/core/ManagementTest.scala
----------------------------------------------------------------------
diff --git a/s2core/src/test/scala/org/apache/s2graph/core/ManagementTest.scala b/s2core/src/test/scala/org/apache/s2graph/core/ManagementTest.scala
index afc9aea..b2c1113 100644
--- a/s2core/src/test/scala/org/apache/s2graph/core/ManagementTest.scala
+++ b/s2core/src/test/scala/org/apache/s2graph/core/ManagementTest.scala
@@ -20,10 +20,8 @@
package org.apache.s2graph.core
import org.apache.s2graph.core.Integrate.IntegrateCommon
-import org.apache.s2graph.core.mysqls.{Model, Label, Service}
-
-import scala.util.{Failure, Success}
-import play.api.libs.json.{JsValue, Json}
+import org.apache.s2graph.core.mysqls.Label
+import play.api.libs.json.Json
class ManagementTest extends IntegrateCommon {
@@ -52,10 +50,11 @@ class ManagementTest extends IntegrateCommon {
copiedLabel.indices().sortBy(m => m.id.get).map(m => m.metaSeqs) should be(originalLabel.indices().sortBy(m => m.id.get).map(m => m.metaSeqs))
}
- def checkLabelTTL(labelName:String, serviceName:String, setTTL:Option[Int], checkTTL:Option[Int]) = {
+ def checkLabelTTL(labelName: String, serviceName: String, setTTL: Option[Int], checkTTL: Option[Int]) = {
Management.deleteLabel(labelName)
- val ttlOption = if(setTTL.isDefined) s""", "hTableTTL": ${setTTL.get}""" else ""
- val createLabelJson = s"""{
+ val ttlOption = if (setTTL.isDefined) s""", "hTableTTL": ${setTTL.get}""" else ""
+ val createLabelJson =
+ s"""{
"label": "$labelName",
"srcServiceName": "$serviceName",
"srcColumnName": "id",
@@ -69,17 +68,18 @@ class ManagementTest extends IntegrateCommon {
$ttlOption
}"""
val labelOpts = parser.toLabelElements(Json.parse(createLabelJson))
- val tryLabel = (management.createLabel _).tupled(labelOpts.get)
- assert(tryLabel.isSuccess)
- val label = tryLabel.get
- label.hTableTTL should be(checkTTL)
+
+ labelOpts.foreach { label =>
+ label.hTableTTL should be(checkTTL)
+ }
+
}
test("copy label test") {
val labelToCopy = s"${TestUtil.testLabelName}_copied"
Label.findByName(labelToCopy) match {
case None =>
- //
+ //
case Some(oldLabel) =>
Label.delete(oldLabel.id.get)
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/030cd2d5/s2rest_play/app/org/apache/s2graph/rest/play/controllers/AdminController.scala
----------------------------------------------------------------------
diff --git a/s2rest_play/app/org/apache/s2graph/rest/play/controllers/AdminController.scala b/s2rest_play/app/org/apache/s2graph/rest/play/controllers/AdminController.scala
index 087e12e..ecea304 100644
--- a/s2rest_play/app/org/apache/s2graph/rest/play/controllers/AdminController.scala
+++ b/s2rest_play/app/org/apache/s2graph/rest/play/controllers/AdminController.scala
@@ -218,8 +218,7 @@ object AdminController extends Controller {
def createLabelInner(json: JsValue) = for {
- labelArgs <- requestParser.toLabelElements(json)
- label <- (management.createLabel _).tupled(labelArgs)
+ label <- requestParser.toLabelElements(json)
} yield label
/**