passed all before GraphTest.
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/450171de Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/450171de Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/450171de Branch: refs/heads/master Commit: 450171dee04b8872704fb201d5f19d806d247c22 Parents: bfc05ba Author: DO YUNG YOON <[email protected]> Authored: Fri Apr 14 23:57:26 2017 +0900 Committer: DO YUNG YOON <[email protected]> Committed: Fri Apr 14 23:57:26 2017 +0900 ---------------------------------------------------------------------- .../org/apache/s2graph/core/JSONParser.scala | 1 + .../scala/org/apache/s2graph/core/S2Edge.scala | 2 + .../scala/org/apache/s2graph/core/S2Graph.scala | 62 ++++++++++---------- .../org/apache/s2graph/core/S2Property.scala | 34 ++++++++++- .../org/apache/s2graph/core/S2Vertex.scala | 2 + .../core/features/S2DataTypeFeatures.scala | 2 +- .../features/S2VertexPropertyFeatures.scala | 18 +++--- 7 files changed, 77 insertions(+), 44 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/450171de/s2core/src/main/scala/org/apache/s2graph/core/JSONParser.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/org/apache/s2graph/core/JSONParser.scala b/s2core/src/main/scala/org/apache/s2graph/core/JSONParser.scala index 9d10dc7..90574f2 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/JSONParser.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/JSONParser.scala @@ -235,6 +235,7 @@ object JSONParser { } } } + def jsValueToInnerVal(jsValue: JsValue, dataType: String, version: String): Option[InnerValLike] = { val ret = try { val dType = InnerVal.toInnerDataType(dataType.toLowerCase()) http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/450171de/s2core/src/main/scala/org/apache/s2graph/core/S2Edge.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/org/apache/s2graph/core/S2Edge.scala b/s2core/src/main/scala/org/apache/s2graph/core/S2Edge.scala index 3b000f6..27d0b42 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/S2Edge.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/S2Edge.scala @@ -116,6 +116,8 @@ case class SnapshotEdge(graph: S2Graph, } def property[V](key: String, value: V, ts: Long): S2Property[V] = { + S2Property.assertValidProp(key, value) + val labelMeta = label.metaPropsInvMap.getOrElse(key, throw new RuntimeException(s"$key is not configured on IndexEdge.")) val newProps = new S2Property(edge, labelMeta, key, value, ts) propsWithTs.put(key, newProps) http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/450171de/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 8b48064..8856a8c 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala @@ -35,7 +35,8 @@ import org.apache.s2graph.core.utils.{DeferCache, Extensions, logger} import org.apache.tinkerpop.gremlin.process.computer.GraphComputer import org.apache.tinkerpop.gremlin.structure import org.apache.tinkerpop.gremlin.structure.Graph.{Features, Variables} -import org.apache.tinkerpop.gremlin.structure.{Edge, Element, Graph, T, Transaction, Vertex} +import org.apache.tinkerpop.gremlin.structure.util.ElementHelper +import org.apache.tinkerpop.gremlin.structure.{Edge, Element, Graph, Property, T, Transaction, Vertex} import play.api.libs.json.{JsObject, Json} import scala.annotation.tailrec @@ -533,37 +534,37 @@ object S2Graph { @Graph.OptIn(Graph.OptIn.SUITE_STRUCTURE_STANDARD) @Graph.OptOuts(value = Array( // new Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.EdgeTest", method="*", reason="no"), -// // passed: all, failed: none -// + // passed: all, failed: none + // new Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.GraphConstructionTest", method="*", reason="no"), -// // passed: all, failed: none -// + // passed: all, failed: none + // new Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.PropertyTest", method="*", reason="no"), -// // passed: all, failed: none -// + // passed: all, failed: none + // new Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.VertexPropertyTest", method="*", reason="no"), -// // passed: all, failed: none -// + // passed: all, failed: none + // new Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.FeatureSupportTest", method="*", reason="no"), -// // passed: all, failed: none -// + // passed: all, failed: none + new Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.VertexTest$BasicVertexTest", method="shouldHaveExceptionConsistencyWhenAssigningSameIdOnEdge", reason="S2Vertex.addEdge behave as upsert."), -// // passed: , failed: shouldHaveExceptionConsistencyWhenAssigningSameIdOnEdge -// + // passed: , failed: shouldHaveExceptionConsistencyWhenAssigningSameIdOnEdge + new Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdgeTest", method="shouldNotEvaluateToEqualDifferentId", reason="reference equals is not supported."), -// // passed: all, failed: shouldNotEvaluateToEqualDifferentId -// + // passed: all, failed: shouldNotEvaluateToEqualDifferentId + // new Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexTest", method="*", reason="no"), -// // passed: all, failed: none -// + // passed: all, failed: none + // new Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.util.detached.DetachedGraphTest", method="*", reason="no"), -// // passed: all, failed: none, all ignored -// + // passed: all, failed: none, all ignored + new Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.util.detached.DetachedPropertyTest", method="shouldNotBeEqualPropertiesAsThereIsDifferentKey", reason="reference equals is not supported."), // // passed: , failed: shouldNotBeEqualPropertiesAsThereIsDifferentKey -// + // new Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexPropertyTest", method="*", reason="no"), -// // passed: all, failed: none + // passed: all, failed: none new Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.GraphTest", method="*", reason="no"), // passed: , failed: @@ -1614,22 +1615,19 @@ class S2Graph(_config: Config)(implicit val ec: ExecutionContext) extends Graph } } - def validType(t: Any): Boolean = t match { - case _: VertexId => true - case _: String => true - case _: java.lang.Integer => true - case _: java.lang.Long => true - case _: scala.Long => true - case _: scala.Int => true - case _ => false - } - override def addVertex(kvs: AnyRef*): structure.Vertex = { if (!features().vertex().supportsUserSuppliedIds() && kvs.contains(T.id)) { throw Vertex.Exceptions.userSuppliedIdsNotSupported } val kvsMap = S2Property.kvsToProps(kvs) + kvsMap.get(T.id.name()) match { + case Some(idValue) if !S2Property.validType(idValue) => + throw Vertex.Exceptions.userSuppliedIdsOfThisTypeNotSupported() + case _ => + } + + kvsMap.foreach { case (k, v) => S2Property.assertValidProp(k, v) } if (kvsMap.contains(T.label.name()) && kvsMap(T.label.name).toString.isEmpty) throw Element.Exceptions.labelCanNotBeEmpty @@ -1638,7 +1636,7 @@ class S2Graph(_config: Config)(implicit val ec: ExecutionContext) extends Graph case None => // do nothing val id = Random.nextLong makeVertex(Long.box(id), kvsMap) - case Some(idValue) if validType(idValue) => + case Some(idValue) if S2Property.validType(idValue) => makeVertex(idValue, kvsMap) case _ => throw Vertex.Exceptions.userSuppliedIdsOfThisTypeNotSupported http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/450171de/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 bca1303..aca9826 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/S2Property.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/S2Property.scala @@ -21,7 +21,7 @@ package org.apache.s2graph.core import org.apache.s2graph.core.mysqls.LabelMeta -import org.apache.s2graph.core.types.{CanInnerValLike, InnerValLikeWithTs} +import org.apache.s2graph.core.types.{CanInnerValLike, InnerValLikeWithTs, VertexId} import org.apache.tinkerpop.gremlin.structure.Graph.Features import org.apache.tinkerpop.gremlin.structure.util.ElementHelper import org.apache.tinkerpop.gremlin.structure._ @@ -29,6 +29,29 @@ import org.apache.tinkerpop.gremlin.structure._ import scala.util.hashing.MurmurHash3 object S2Property { + + def validType(t: Any): Boolean = t match { + case _: VertexId => true + case _: java.lang.Integer => true + case _: java.lang.Long => true + case _: java.lang.Float => true + case _: java.lang.Double => true + case _: java.lang.Boolean => true + case _: java.lang.Short => true + case _: java.lang.Byte => true + case _: java.lang.String => true + case _: Int => true + case _: Long => true + case _: Float => true + case _: Double => true + case _: Boolean => true + case _: Short => true + case _: Byte => true + case _: String => true + case _: BigDecimal => true + case _ => false + } + def kvsToProps(kvs: Seq[AnyRef]): Map[String, AnyRef] = { import scala.collection.JavaConverters._ @@ -42,7 +65,7 @@ object S2Property { ElementHelper.validateProperty(key, value) // if (keySet.contains(key)) throw VertexProperty.Exceptions.multiPropertiesNotSupported - assertValidProp(key, value) +// assertValidProp(key, value) keySet.add(key) result = result + (key -> value) @@ -56,6 +79,13 @@ object S2Property { if (!key.isInstanceOf[String]) throw Element.Exceptions.providedKeyValuesMustHaveALegalKeyOnEvenIndices() if (value == null) throw Property.Exceptions.propertyValueCanNotBeNull() + if (!validType(value)) { + value match { + case _: java.io.Serializable => throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value) + case _ => + } + } + if (value.isInstanceOf[Iterable[_]]) throw new java.lang.IllegalArgumentException("not supported data type") if (value.isInstanceOf[Array[_]]) throw new java.lang.IllegalArgumentException("not supported data type") if (value.isInstanceOf[java.util.List[_]]) throw new java.lang.IllegalArgumentException("not supported data type") http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/450171de/s2core/src/main/scala/org/apache/s2graph/core/S2Vertex.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/org/apache/s2graph/core/S2Vertex.scala b/s2core/src/main/scala/org/apache/s2graph/core/S2Vertex.scala index 7d6433d..529ece4 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/S2Vertex.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/S2Vertex.scala @@ -196,6 +196,8 @@ case class S2Vertex(graph: S2Graph, val props = S2Property.kvsToProps(kvs) + props.foreach { case (k, v) => S2Property.assertValidProp(k, v) } + //TODO: direction, operation, _timestamp need to be reserved property key. try { http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/450171de/s2core/src/main/scala/org/apache/s2graph/core/features/S2DataTypeFeatures.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/org/apache/s2graph/core/features/S2DataTypeFeatures.scala b/s2core/src/main/scala/org/apache/s2graph/core/features/S2DataTypeFeatures.scala index 3db4930..a3ff088 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/features/S2DataTypeFeatures.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/features/S2DataTypeFeatures.scala @@ -36,7 +36,7 @@ case class S2DataTypeFeatures() extends Features.DataTypeFeatures { override def supportsLongArrayValues(): Boolean = false - override def supportsSerializableValues(): Boolean = true + override def supportsSerializableValues(): Boolean = false override def supportsStringValues(): Boolean = true http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/450171de/s2core/src/main/scala/org/apache/s2graph/core/features/S2VertexPropertyFeatures.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/org/apache/s2graph/core/features/S2VertexPropertyFeatures.scala b/s2core/src/main/scala/org/apache/s2graph/core/features/S2VertexPropertyFeatures.scala index fe74c85..b354561 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/features/S2VertexPropertyFeatures.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/features/S2VertexPropertyFeatures.scala @@ -4,21 +4,21 @@ import org.apache.tinkerpop.gremlin.structure.Graph.Features class S2VertexPropertyFeatures extends S2PropertyFeatures with Features.VertexPropertyFeatures { - override def supportsStringIds(): Boolean = true + override def supportsStringIds(): Boolean = false - override def supportsUserSuppliedIds(): Boolean = true - - override def supportsAddProperty(): Boolean = true + override def supportsCustomIds(): Boolean = true - override def willAllowId(id: scala.Any): Boolean = true + override def supportsUuidIds(): Boolean = false - override def supportsNumericIds(): Boolean = false + override def supportsAddProperty(): Boolean = true override def supportsRemoveProperty(): Boolean = true - override def supportsUuidIds(): Boolean = false - - override def supportsCustomIds(): Boolean = true + override def supportsUserSuppliedIds(): Boolean = true override def supportsAnyIds(): Boolean = false + + override def supportsNumericIds(): Boolean = false + + override def willAllowId(id: scala.Any): Boolean = true }
