Repository: incubator-s2graph
Updated Branches:
  refs/heads/master 8dcb0f15d -> aeaff3fc6


[S2GRAPH-179]: Add defaultValue on ColumnMeta.


Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/a191ef0a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/a191ef0a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/a191ef0a

Branch: refs/heads/master
Commit: a191ef0a2aaa273095ac6d5aaa80bbba68cfd737
Parents: f1e6be2
Author: DO YUNG YOON <[email protected]>
Authored: Mon Feb 26 18:28:21 2018 +0900
Committer: DO YUNG YOON <[email protected]>
Committed: Mon Feb 26 18:31:08 2018 +0900

----------------------------------------------------------------------
 dev_support/graph_mysql/schema.sql              |  1 +
 .../org/apache/s2graph/core/mysqls/schema.sql   |  1 +
 .../org/apache/s2graph/core/Management.scala    |  6 ++-
 .../s2graph/core/S2EdgePropertyHelper.scala     |  5 +-
 .../apache/s2graph/core/S2GraphFactory.scala    | 48 ++++++++++----------
 .../org/apache/s2graph/core/S2VertexLike.scala  | 17 ++++++-
 .../s2graph/core/S2VertexPropertyHelper.scala   | 42 +++++++++++++++++
 .../apache/s2graph/core/io/Conversions.scala    |  2 +
 .../apache/s2graph/core/mysqls/ColumnMeta.scala | 16 ++++---
 .../s2graph/core/mysqls/ServiceColumn.scala     |  4 ++
 .../core/Integrate/IntegrateCommon.scala        |  9 ++--
 .../core/tinkerpop/S2GraphProvider.scala        | 18 ++++----
 .../rest/play/controllers/AdminController.scala |  2 +-
 13 files changed, 123 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/a191ef0a/dev_support/graph_mysql/schema.sql
----------------------------------------------------------------------
diff --git a/dev_support/graph_mysql/schema.sql 
b/dev_support/graph_mysql/schema.sql
index 48b27df..5781f3b 100644
--- a/dev_support/graph_mysql/schema.sql
+++ b/dev_support/graph_mysql/schema.sql
@@ -76,6 +76,7 @@ CREATE TABLE `column_metas` (
        `name` varchar(64) NOT NULL,
        `seq` tinyint   NOT NULL,
        `data_type` varchar(8) NOT NULL DEFAULT 'string',
+       `default_value` varchar(64) NOT NULL DEFAULT '',
        `store_in_global_index` tinyint NOT NULL DEFAULT 0,
        PRIMARY KEY (`id`),
        UNIQUE KEY `ux_column_id_name` (`column_id`, `name`),

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/a191ef0a/s2core/src/main/resources/org/apache/s2graph/core/mysqls/schema.sql
----------------------------------------------------------------------
diff --git 
a/s2core/src/main/resources/org/apache/s2graph/core/mysqls/schema.sql 
b/s2core/src/main/resources/org/apache/s2graph/core/mysqls/schema.sql
index b66b46b..6b9b71e 100644
--- a/s2core/src/main/resources/org/apache/s2graph/core/mysqls/schema.sql
+++ b/s2core/src/main/resources/org/apache/s2graph/core/mysqls/schema.sql
@@ -65,6 +65,7 @@ CREATE TABLE `column_metas` (
   `name` varchar(64) NOT NULL,
   `seq` tinyint        NOT NULL,
   `data_type` varchar(8) NOT NULL DEFAULT 'string',
+  `default_value` varchar(64) NOT NULL DEFAULT '',
   `store_in_global_index` tinyint NOT NULL DEFAULT 0,
   PRIMARY KEY (`id`),
   UNIQUE KEY `ux_column_id_name` (`column_id`, `name`),

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/a191ef0a/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 c7d2d54..b126e6c 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/Management.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/Management.scala
@@ -105,6 +105,7 @@ object Management {
             Prop(propName, defaultValue, dataType, storeInGlobalIndex) <- props
           } yield {
             ColumnMeta.findOrInsert(serviceColumn.id.get, propName, dataType,
+              defaultValue,
               storeInGlobalIndex = storeInGlobalIndex, useCache = false)
           }
       }
@@ -186,13 +187,14 @@ object Management {
                     columnName: String,
                     propsName: String,
                     propsType: String,
+                    defaultValue: String,
                     storeInGlobalIndex: Boolean = false,
                     schemaVersion: String = DEFAULT_VERSION): ColumnMeta = {
     val result = for {
       service <- Service.findByName(serviceName, useCache = false)
       serviceColumn <- ServiceColumn.find(service.id.get, columnName)
     } yield {
-        ColumnMeta.findOrInsert(serviceColumn.id.get, propsName, propsType, 
storeInGlobalIndex)
+        ColumnMeta.findOrInsert(serviceColumn.id.get, propsName, propsType, 
defaultValue, storeInGlobalIndex)
       }
     result.getOrElse({
       throw new RuntimeException(s"add property on vertex failed")
@@ -365,7 +367,7 @@ class Management(graph: S2GraphLike) {
           for {
             Prop(propName, defaultValue, dataType, storeInGlobalIndex) <- props
           } yield {
-            ColumnMeta.findOrInsert(serviceColumn.id.get, propName, dataType,
+            ColumnMeta.findOrInsert(serviceColumn.id.get, propName, dataType, 
defaultValue,
               storeInGlobalIndex = storeInGlobalIndex, useCache = false)
           }
           serviceColumn

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/a191ef0a/s2core/src/main/scala/org/apache/s2graph/core/S2EdgePropertyHelper.scala
----------------------------------------------------------------------
diff --git 
a/s2core/src/main/scala/org/apache/s2graph/core/S2EdgePropertyHelper.scala 
b/s2core/src/main/scala/org/apache/s2graph/core/S2EdgePropertyHelper.scala
index 0efb851..1e0a95b 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/S2EdgePropertyHelper.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/S2EdgePropertyHelper.scala
@@ -22,7 +22,7 @@ package org.apache.s2graph.core
 import java.util.function.BiConsumer
 
 import org.apache.s2graph.core.S2Edge.Props
-import org.apache.s2graph.core.mysqls.{Label, LabelMeta}
+import org.apache.s2graph.core.mysqls.LabelMeta
 import org.apache.s2graph.core.types.{InnerVal, InnerValLikeWithTs}
 import org.apache.tinkerpop.gremlin.structure.Property
 
@@ -33,6 +33,7 @@ object S2EdgePropertyHelper {
     edge.getPropsWithTs().put(key, newProp)
     newProp
   }
+
   def updatePropsWithTs(edge: S2EdgeLike, others: Props = S2Edge.EmptyProps): 
Props = {
     val emptyProp = S2Edge.EmptyProps
 
@@ -80,10 +81,12 @@ object S2EdgePropertyHelper {
     }
   }
 
+
   def toLabelMetas(edge: S2EdgeLike, keys: Seq[String]): Seq[LabelMeta] = {
     for {
       key <- keys
       labelMeta <- edge.innerLabel.metaPropsInvMap.get(key)
     } yield labelMeta
   }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/a191ef0a/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
index 07a9be1..64108db 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/S2GraphFactory.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/S2GraphFactory.scala
@@ -69,30 +69,30 @@ object S2GraphFactory {
     val DefaultColumn = ServiceColumn.findOrInsert(DefaultService.id.get, 
DefaultColumnName, Some("integer"), HBaseType.DEFAULT_VERSION, useCache = false)
 
     val DefaultColumnMetas = {
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "test", "string", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "name", "string", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "age", "integer", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "lang", "string", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "oid", "integer", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "communityIndex", 
"integer", storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "testing", "string", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "string", "string", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "boolean", "boolean", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "long", "long", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "float", "float", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "double", "double", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "integer", "integer", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "aKey", "string", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "x", "integer", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "y", "integer", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "location", "string", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "status", "string", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "myId", "integer", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "acl", "string", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "some", "string", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "this", "string", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "that", "string", 
storeInGlobalIndex = true, useCache = false)
-      ColumnMeta.findOrInsert(DefaultColumn.id.get, "any", "string", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "test", "string", "-", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "name", "string", "-", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "age", "integer", "0", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "lang", "string", "-", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "oid", "integer", "0", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "communityIndex", 
"integer", "0", storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "testing", "string", "-", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "string", "string", "-", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "boolean", "boolean", 
"true", storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "long", "long", "0", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "float", "float", "0.0", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "double", "double", "0.0", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "integer", "integer", "0", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "aKey", "string", "-", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "x", "integer", "0", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "y", "integer", "0", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "location", "string", "-", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "status", "string", "-", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "myId", "integer", "0", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "acl", "string", "-", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "some", "string", "-", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "this", "string", "-", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "that", "string", "-", 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(DefaultColumn.id.get, "any", "string", "-", 
storeInGlobalIndex = true, useCache = false)
     }
 
     //    Management.deleteLabel("_s2graph")

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/a191ef0a/s2core/src/main/scala/org/apache/s2graph/core/S2VertexLike.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/org/apache/s2graph/core/S2VertexLike.scala 
b/s2core/src/main/scala/org/apache/s2graph/core/S2VertexLike.scala
index 0d898d1..5612525 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/S2VertexLike.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/S2VertexLike.scala
@@ -23,7 +23,7 @@ import java.util.function.{BiConsumer, Consumer}
 
 import org.apache.s2graph.core.S2Vertex.Props
 import org.apache.s2graph.core.mysqls.{ColumnMeta, Label, Service, 
ServiceColumn}
-import org.apache.s2graph.core.types.VertexId
+import org.apache.s2graph.core.types.{InnerValLike, VertexId}
 import org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality
 import org.apache.tinkerpop.gremlin.structure.{Direction, Edge, T, Vertex, 
VertexProperty}
 import play.api.libs.json.Json
@@ -199,4 +199,19 @@ trait S2VertexLike extends Vertex with GraphElement {
       throw Vertex.Exceptions.vertexRemovalNotSupported()
     }
   }
+
+  def propertyValue(key: String): Option[InnerValLike] =
+    S2VertexPropertyHelper.propertyValue(this, key)
+
+  def propertyValueInner(columnMeta: ColumnMeta): InnerValLike =
+    S2VertexPropertyHelper.propertyValueInner(this, columnMeta)
+
+  def propertyValues(keys: Seq[String] = Nil): Map[ColumnMeta, InnerValLike] = 
{
+    S2VertexPropertyHelper.propertyValuesInner(this, 
S2VertexPropertyHelper.toColumnMetas(this, keys))
+  }
+
+  def propertyValuesInner(columnMetas: Seq[ColumnMeta] = Nil): Map[ColumnMeta, 
InnerValLike] = {
+    S2VertexPropertyHelper.propertyValuesInner(this, columnMetas)
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/a191ef0a/s2core/src/main/scala/org/apache/s2graph/core/S2VertexPropertyHelper.scala
----------------------------------------------------------------------
diff --git 
a/s2core/src/main/scala/org/apache/s2graph/core/S2VertexPropertyHelper.scala 
b/s2core/src/main/scala/org/apache/s2graph/core/S2VertexPropertyHelper.scala
new file mode 100644
index 0000000..bed69ef
--- /dev/null
+++ b/s2core/src/main/scala/org/apache/s2graph/core/S2VertexPropertyHelper.scala
@@ -0,0 +1,42 @@
+package org.apache.s2graph.core
+
+import org.apache.s2graph.core.mysqls.ColumnMeta
+import org.apache.s2graph.core.types.InnerValLike
+
+object S2VertexPropertyHelper {
+  def propertyValue(v: S2VertexLike, key: String): Option[InnerValLike] = {
+    key match {
+      case "id" => Option(v.innerId)
+      case _ =>
+        v.serviceColumn.metasInvMap.get(key).map(x => propertyValueInner(v, x))
+    }
+  }
+
+
+  def propertyValuesInner(vertex: S2VertexLike, columnMetas: Seq[ColumnMeta] = 
Nil): Map[ColumnMeta, InnerValLike] = {
+    if (columnMetas.isEmpty) {
+      vertex.serviceColumn.metaPropsDefaultMap.map { case (columnMeta, 
defaultVal) =>
+        columnMeta -> propertyValueInner(vertex, columnMeta)
+      }
+    } else {
+      (ColumnMeta.reservedMetas ++ columnMetas).map { columnMeta =>
+        columnMeta -> propertyValueInner(vertex, columnMeta)
+      }.toMap
+    }
+  }
+
+  def propertyValueInner(vertex: S2VertexLike, columnMeta: ColumnMeta): 
InnerValLike = {
+    if (vertex.props.containsKey(columnMeta.name)) {
+      vertex.props.get(columnMeta.name).innerVal
+    } else {
+      vertex.serviceColumn.metaPropsDefaultMap(columnMeta)
+    }
+  }
+
+  def toColumnMetas(vertex: S2VertexLike, keys: Seq[String]): Seq[ColumnMeta] 
= {
+    for {
+      key <- keys
+      columnMeta <- vertex.serviceColumn.metasInvMap.get(key)
+    } yield columnMeta
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/a191ef0a/s2core/src/main/scala/org/apache/s2graph/core/io/Conversions.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/org/apache/s2graph/core/io/Conversions.scala 
b/s2core/src/main/scala/org/apache/s2graph/core/io/Conversions.scala
index 974965f..83159e2 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/io/Conversions.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/io/Conversions.scala
@@ -92,6 +92,7 @@ object Conversions {
       (JsPath \ "name").read[String] and
       (JsPath \ "seq").read[Byte] and
       (JsPath \ "dataType").read[String] and
+      (JsPath \ "defaultValue").read[String] and
       (JsPath \ "storeGlobalIndex").read[Boolean]
     )(ColumnMeta.apply _)
 
@@ -101,6 +102,7 @@ object Conversions {
       (JsPath \ "name").write[String] and
       (JsPath \ "seq").write[Byte] and
       (JsPath \ "dataType").write[String] and
+      (JsPath \ "defaultValue").write[String] and
       (JsPath \ "storeGlobalIndex").write[Boolean]
     )(unlift(ColumnMeta.unapply))
 

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/a191ef0a/s2core/src/main/scala/org/apache/s2graph/core/mysqls/ColumnMeta.scala
----------------------------------------------------------------------
diff --git 
a/s2core/src/main/scala/org/apache/s2graph/core/mysqls/ColumnMeta.scala 
b/s2core/src/main/scala/org/apache/s2graph/core/mysqls/ColumnMeta.scala
index b764841..cca6d10 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/mysqls/ColumnMeta.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/mysqls/ColumnMeta.scala
@@ -28,16 +28,16 @@ object ColumnMeta extends Model[ColumnMeta] {
 
   val timeStampSeq = -1.toByte
   val lastModifiedAtColumnSeq = 0.toByte
-  val lastModifiedAtColumn = ColumnMeta(Some(0), 0, "lastModifiedAt", 
lastModifiedAtColumnSeq, "long")
+  val lastModifiedAtColumn = ColumnMeta(Some(0), 0, "lastModifiedAt", 
lastModifiedAtColumnSeq, "long", "-1")
   val maxValue = Byte.MaxValue
 
-  val timestamp = ColumnMeta(None, -1, "_timestamp", timeStampSeq.toByte, 
"long")
+  val timestamp = ColumnMeta(None, -1, "_timestamp", timeStampSeq.toByte, 
"long", "-1")
   val reservedMetas = Seq(timestamp, lastModifiedAtColumn)
   val reservedMetaNamesSet = reservedMetas.map(_.name).toSet
 
   def valueOf(rs: WrappedResultSet): ColumnMeta = {
     ColumnMeta(Some(rs.int("id")), rs.int("column_id"), rs.string("name"),
-      rs.byte("seq"), rs.string("data_type").toLowerCase(), 
rs.boolean("store_in_global_index"))
+      rs.byte("seq"), rs.string("data_type").toLowerCase(), 
rs.string("default_value"), rs.boolean("store_in_global_index"))
   }
 
   def findById(id: Int)(implicit session: DBSession = AutoSession) = {
@@ -72,12 +72,12 @@ object ColumnMeta extends Model[ColumnMeta] {
     }
   }
 
-  def insert(columnId: Int, name: String, dataType: String, 
storeInGlobalIndex: Boolean = false)(implicit session: DBSession = AutoSession) 
= {
+  def insert(columnId: Int, name: String, dataType: String, defaultValue: 
String, storeInGlobalIndex: Boolean = false)(implicit session: DBSession = 
AutoSession) = {
     val ls = findAllByColumn(columnId, false)
     val seq = ls.size + 1
     if (seq <= maxValue) {
-      sql"""insert into column_metas(column_id, name, seq, data_type, 
store_in_global_index)
-    select ${columnId}, ${name}, ${seq}, ${dataType}, ${storeInGlobalIndex}"""
+      sql"""insert into column_metas(column_id, name, seq, data_type, 
default_value, store_in_global_index)
+    select ${columnId}, ${name}, ${seq}, ${dataType}, ${defaultValue}, 
${storeInGlobalIndex}"""
         .updateAndReturnGeneratedKey.apply()
     }
   }
@@ -85,12 +85,13 @@ object ColumnMeta extends Model[ColumnMeta] {
   def findOrInsert(columnId: Int,
                    name: String,
                    dataType: String,
+                   defaultValue: String,
                    storeInGlobalIndex: Boolean = false,
                    useCache: Boolean = true)(implicit session: DBSession = 
AutoSession): ColumnMeta = {
     findByName(columnId, name, useCache) match {
       case Some(c) => c
       case None =>
-        insert(columnId, name, dataType, storeInGlobalIndex)
+        insert(columnId, name, dataType, defaultValue, storeInGlobalIndex)
         expireCache(s"columnId=$columnId:name=$name")
         findByName(columnId, name).get
     }
@@ -150,6 +151,7 @@ case class ColumnMeta(id: Option[Int],
                       name: String,
                       seq: Byte,
                       dataType: String,
+                      defaultValue: String,
                       storeInGlobalIndex: Boolean = false) {
   lazy val toJson = Json.obj("name" -> name, "dataType" -> dataType)
   override def equals(other: Any): Boolean = {

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/a191ef0a/s2core/src/main/scala/org/apache/s2graph/core/mysqls/ServiceColumn.scala
----------------------------------------------------------------------
diff --git 
a/s2core/src/main/scala/org/apache/s2graph/core/mysqls/ServiceColumn.scala 
b/s2core/src/main/scala/org/apache/s2graph/core/mysqls/ServiceColumn.scala
index be1ae9a..91133c1 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/mysqls/ServiceColumn.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/mysqls/ServiceColumn.scala
@@ -19,6 +19,7 @@
 
 package org.apache.s2graph.core.mysqls
 
+import org.apache.s2graph.core.JSONParser
 import org.apache.s2graph.core.JSONParser._
 import org.apache.s2graph.core.types.{HBaseType, InnerValLike, 
InnerValLikeWithTs}
 import play.api.libs.json.Json
@@ -106,6 +107,9 @@ case class ServiceColumn(id: Option[Int],
   lazy val metasMap = metas.map { meta => meta.seq.toInt -> meta } toMap
   lazy val metasInvMap = metas.map { meta => meta.name -> meta} toMap
   lazy val metaNamesMap = (ColumnMeta.lastModifiedAtColumn :: metas).map(x => 
(x.seq.toInt, x.name)) toMap
+  lazy val metaPropsDefaultMap = metas.map { meta =>
+    meta -> JSONParser.toInnerVal(meta.defaultValue, meta.dataType, 
schemaVersion)
+  }.toMap
   lazy val toJson = Json.obj("serviceName" -> service.serviceName, 
"columnName" -> columnName, "columnType" -> columnType)
 
   def propsToInnerVals(props: Map[String, Any]): Map[ColumnMeta, InnerValLike] 
= {

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/a191ef0a/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 820f93a..c96231a 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
@@ -92,10 +92,13 @@ trait IntegrateCommon extends FunSuite with Matchers with 
BeforeAndAfterAll {
       }
     }
 
-    val vertexPropsKeys = List("age" -> "integer", "im" -> "string")
+    val vertexPropsKeys = List(
+      ("age", "integer", "0"),
+      ("im", "string", "-")
+    )
 
-    vertexPropsKeys.map { case (key, keyType) =>
-      Management.addVertexProp(testServiceName, testColumnName, key, keyType, 
storeInGlobalIndex = true)
+    vertexPropsKeys.map { case (key, keyType, defaultValue) =>
+      Management.addVertexProp(testServiceName, testColumnName, key, keyType, 
defaultValue, storeInGlobalIndex = true)
     }
 
     // vertex type global index.

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/a191ef0a/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 ca78917..f52f86a 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
@@ -120,30 +120,30 @@ class S2GraphProvider extends AbstractGraphProvider {
     if (testClass.getSimpleName == "PropertyFeatureSupportTest") {
       knowsProp = knowsProp.filterNot(_.name == "aKey")
 
-      val dataType = if (testName.toLowerCase.contains("boolean")) {
+      val (dataType, defaultValue) = if 
(testName.toLowerCase.contains("boolean")) {
         knowsProp = knowsProp.filterNot(_.name == "aKey") :+ Prop("aKey", 
"false", "boolean")
-        "boolean"
+        ("boolean", "false")
       } else if (testName.toLowerCase.contains("integer")) {
         knowsProp = knowsProp.filterNot(_.name == "aKey") :+ Prop("aKey", "0", 
"integer")
-        "integer"
+        ("integer", "0")
       } else if (testName.toLowerCase.contains("long")) {
         knowsProp = knowsProp.filterNot(_.name == "aKey") :+ Prop("aKey", "0", 
"long")
-        "long"
+        ("long", "0")
       } else if (testName.toLowerCase.contains("double")) {
         knowsProp = knowsProp.filterNot(_.name == "aKey") :+ Prop("aKey", 
"0.0", "double")
-        "double"
+        ("double", "0.0")
       } else if (testName.toLowerCase.contains("float")) {
         knowsProp = knowsProp.filterNot(_.name == "aKey") :+ Prop("aKey", 
"0.0", "float")
-        "float"
+        ("float", "0.0")
       } else if (testName.toLowerCase.contains("string")) {
         knowsProp = knowsProp.filterNot(_.name == "aKey") :+ Prop("aKey", "-", 
"string")
-        "string"
+        ("string", "-")
       } else {
-        "string"
+        ("string", "-")
       }
 
       ColumnMeta.findByName(defaultServiceColumn.id.get, "aKey", useCache = 
false).foreach(cm => ColumnMeta.delete(cm.id.get))
-      ColumnMeta.findOrInsert(defaultServiceColumn.id.get, "aKey", dataType, 
storeInGlobalIndex = true, useCache = false)
+      ColumnMeta.findOrInsert(defaultServiceColumn.id.get, "aKey", dataType, 
defaultValue, storeInGlobalIndex = true, useCache = false)
     }
     if (loadGraphWith != null && loadGraphWith.value() == GraphData.MODERN) {
       mnt.createLabel("knows", defaultService.serviceName, "person", 
"integer", defaultService.serviceName, "person", "integer",

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/a191ef0a/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 2ee6395..23bda0a 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
@@ -317,7 +317,7 @@ object AdminController extends Controller {
       serviceColumn <- ServiceColumn.find(service.id.get, columnName)
       prop <- requestParser.toPropElements(js).toOption
     } yield {
-      ColumnMeta.findOrInsert(serviceColumn.id.get, prop.name, prop.dataType, 
storeInGlobalIndex)
+      ColumnMeta.findOrInsert(serviceColumn.id.get, prop.name, prop.dataType, 
prop.defaultValue, storeInGlobalIndex)
     }
   }
 

Reply via email to