diff --git a/aerospike-scala-example/src/main/scala/ru/tinkoff/aerospikeexamples/example/scheme.scala b/aerospike-scala-example/src/main/scala/ru/tinkoff/aerospikeexamples/example/scheme.scala index 8c274f9..980d174 100644 --- a/aerospike-scala-example/src/main/scala/ru/tinkoff/aerospikeexamples/example/scheme.scala +++ b/aerospike-scala-example/src/main/scala/ru/tinkoff/aerospikeexamples/example/scheme.scala @@ -31,6 +31,7 @@ import scala.collection.mutable.ArrayBuffer import scala.concurrent.{ExecutionContext, Future} import scala.language.experimental.macros import scala.util.matching.Regex +import ru.tinkoff.aerospikemacro.cast.Tuplify._ /** * @author MarinaSigaeva diff --git a/aerospike-scala-macros/src/main/scala/ru/tinkoff/aerospikemacro/cast/Caster.scala b/aerospike-scala-macros/src/main/scala/ru/tinkoff/aerospikemacro/cast/Caster.scala index d55d553..aa3b2ef 100644 --- a/aerospike-scala-macros/src/main/scala/ru/tinkoff/aerospikemacro/cast/Caster.scala +++ b/aerospike-scala-macros/src/main/scala/ru/tinkoff/aerospikemacro/cast/Caster.scala @@ -16,8 +16,6 @@ package ru.tinkoff.aerospikemacro.cast -import shapeless.syntax.std.tuple._ - /** * @author MarinaSigaeva * @since 27.10.16 @@ -43,25 +41,44 @@ object Caster { def cast(elem: Any, desc: String): Any = { elem match { case long: java.lang.Long if desc == "Boolean" => long == 1 - case long: java.lang.Long if desc == "Int" => long.toInt - case long: java.lang.Long if desc == "Short" => long.toShort - case long: java.lang.Long if desc == "Byte" => long.toByte - case dbl: java.lang.Double if desc == "Float" => dbl.toFloat + case long: java.lang.Long if desc == "Int" => long.toInt + case long: java.lang.Long if desc == "Short" => long.toShort + case long: java.lang.Long if desc == "Byte" => long.toByte + case dbl: java.lang.Double if desc == "Float" => dbl.toFloat case str: java.lang.String if desc == "Char" => str.toString.toCharArray.headOption case _ => elem } } - def castTuple(elems: Map[Any, Any], types: List[String]): Option[TP] = { - val casted = types.indices.map(i => cast(elems(i.toString), types(i))).toList - casted.length match { - case l if l > 0 && l < 23 => scala.util.Try(buildTuple(casted)).toOption - case _ => None - } - } - def buildTuple(elems: List[Any]): TP = { - (for (i <- 1 until elems.length) yield Tuple1(elems.head) :+ elems(i)).toList - } } + +object Tuplify { + + val m = Map( + 2 -> { ls: List[Any] => (ls.head, ls(1)) }, + 3 -> { ls: List[Any] => (ls.head, ls(1), ls(2)) }, + 4 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3)) }, + 5 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4)) }, + 6 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4), ls(5)) }, + 7 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4), ls(5), ls(6)) }, + 8 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4), ls(5), ls(6), ls(7)) }, + 9 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4), ls(5), ls(6), ls(7), ls(8)) }, + 10 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4), ls(5), ls(6), ls(7), ls(8), ls(9)) }, + 11 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4), ls(5), ls(6), ls(7), ls(8), ls(9), ls(10)) }, + 12 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4), ls(5), ls(6), ls(7), ls(8), ls(9), ls(10), ls(11)) }, + 13 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4), ls(5), ls(6), ls(7), ls(8), ls(9), ls(10), ls(11), ls(12)) }, + 14 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4), ls(5), ls(6), ls(7), ls(8), ls(9), ls(10), ls(11), ls(12), ls(13)) }, + 15 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4), ls(5), ls(6), ls(7), ls(8), ls(9), ls(10), ls(11), ls(12), ls(13), ls(14)) }, + 16 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4), ls(5), ls(6), ls(7), ls(8), ls(9), ls(10), ls(11), ls(12), ls(13), ls(14), ls(15)) }, + 17 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4), ls(5), ls(6), ls(7), ls(8), ls(9), ls(10), ls(11), ls(12), ls(13), ls(14), ls(15), ls(16)) }, + 18 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4), ls(5), ls(6), ls(7), ls(8), ls(9), ls(10), ls(11), ls(12), ls(13), ls(14), ls(15), ls(16), ls(17)) }, + 19 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4), ls(5), ls(6), ls(7), ls(8), ls(9), ls(10), ls(11), ls(12), ls(13), ls(14), ls(15), ls(16), ls(17), ls(18)) }, + 20 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4), ls(5), ls(6), ls(7), ls(8), ls(9), ls(10), ls(11), ls(12), ls(13), ls(14), ls(15), ls(16), ls(17), ls(18), ls(19)) }, + 21 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4), ls(5), ls(6), ls(7), ls(8), ls(9), ls(10), ls(11), ls(12), ls(13), ls(14), ls(15), ls(16), ls(17), ls(18), ls(19), ls(20)) }, + 22 -> { ls: List[Any] => (ls.head, ls(1), ls(2), ls(3), ls(4), ls(5), ls(6), ls(7), ls(8), ls(9), ls(10), ls(11), ls(12), ls(13), ls(14), ls(15), ls(16), ls(17), ls(18), ls(19), ls(20), ls(21)) } + ) + +} + diff --git a/aerospike-scala-macros/src/main/scala/ru/tinkoff/aerospikemacro/converters/BinWrapper.scala b/aerospike-scala-macros/src/main/scala/ru/tinkoff/aerospikemacro/converters/BinWrapper.scala index c120373..d70ae75 100644 --- a/aerospike-scala-macros/src/main/scala/ru/tinkoff/aerospikemacro/converters/BinWrapper.scala +++ b/aerospike-scala-macros/src/main/scala/ru/tinkoff/aerospikemacro/converters/BinWrapper.scala @@ -20,6 +20,7 @@ import ru.tinkoff.aerospikescala.domain.{ByteSegment, MBin, SingleBin} import scala.language.experimental.macros import scala.reflect.macros.blackbox +import Utils._ /** * @author MarinaSigaeva @@ -33,8 +34,7 @@ trait BinWrapper[BT] { import shapeless.{HList, _} import scala.collection.JavaConverters._ - import scala.collection.immutable.{List, ListMap, Map} - import scala.reflect.ClassTag + import scala.collection.immutable.{List, Map} import scala.reflect.runtime.universe._ import scala.util.{Failure, Success} @@ -44,9 +44,6 @@ trait BinWrapper[BT] { type Multi = MBin[BT] type Out = (Map[String, Option[BT]], Int, Int) - // ToDo Is it needed? - val comma = "," - def apply(many: Many): List[Bin] = many.view.flatMap(one => scala.util.Try(apply(one)).toOption).toList @@ -114,45 +111,7 @@ trait BinWrapper[BT] { } } - def typed[T](x: T)(implicit tag: WeakTypeTag[T]): T = x.asInstanceOf[T] - - def tupleMapped[TPL <: Any with Product](tpl: TPL): Map[String, Any] = { - val i = tpl.productArity - val m = optTuple(tpl).map(mapify(i, _)).getOrElse(Map.empty) - ListMap(m.toSeq.sortBy(_._1): _*).view.map { - case (k, v) => k.toString -> v - }.toMap - } - - def mapify[H <: Any with Product](i: Int, t: H): Map[Int, Any] = { - (for (e <- 0 until i) yield (e, t.productElement(e)))(collection.breakOut) - } - - def fromHList[L <: HList](hList: L, i: Int, maxIndex: Int): Map[String, Any] = { - val h0 = Map(i.toString -> typed(hList.productElement(0))) - hList match { - case _ :: tail if i < maxIndex => - h0 ++ fromHList(tail, i + 1, maxIndex) - case _ => h0 - } - } - - def defaultToValue[T](x: T): Map[String, Any] = { - val clazz = weakTypeOf[T].getClass - val classTag = ClassTag[T](clazz) - val rm = scala.reflect.runtime.currentMirror - val accessors = - rm.classSymbol(x.getClass).toType.decls.sorted.view.collect { - case m: MethodSymbol if m.isGetter && m.isPublic => m - } - val instanceMirror = rm.reflect(x)(classTag) - (for (acc <- accessors.view) yield { - acc.name.toString -> instanceMirror.reflectMethod(acc).apply() - }).toMap - } - - def fetch(any: Any): Option[BT] = - scala.util.Try(any.asInstanceOf[BT]).toOption + def fetch(any: Any): Option[BT] = scala.util.Try(any.asInstanceOf[BT]).toOption def gen(b: One): Bin = new Bin(b._1, toValue(b._2)) @@ -187,33 +146,6 @@ trait BinWrapper[BT] { val all = s.view(1, s.length - 1).mkString.split("\\), ", s.length).view all.dropRight(1).toArray ++ Array(all.last.dropRight(1)) } - - def isTuple[T](x: T): Boolean = x.getClass.getSimpleName.contains("Tuple") - - private def optTuple[TPL <: Any with Product](tpl: TPL) = tpl match { - case t2: Tuple2[_, _] => Option(t2) - case t3: Tuple3[_, _, _] => Option(t3) - case t4: Tuple4[_, _, _, _] => Option(t4) - case t5: Tuple5[_, _, _, _, _] => Option(t5) - case t6: Tuple6[_, _, _, _, _, _] => Option(t6) - case t7: Tuple7[_, _, _, _, _, _, _] => Option(t7) - case t8: Tuple8[_, _, _, _, _, _, _, _] => Option(t8) - case t9: Tuple9[_, _, _, _, _, _, _, _, _] => Option(t9) - case t10: Tuple10[_, _, _, _, _, _, _, _, _, _] => Option(t10) - case t11: Tuple11[_, _, _, _, _, _, _, _, _, _, _] => Option(t11) - case t12: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _] => Option(t12) - case t13: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t13) - case t14: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t14) - case t15: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t15) - case t16: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t16) - case t17: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t17) - case t18: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t18) - case t19: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t19) - case t20: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t20) - case t21: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t21) - case t22: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t22) - case _ => None - } } object BinWrapper { @@ -224,13 +156,22 @@ object BinWrapper { def materializeBinWrapperImpl[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[BinWrapper[T]] = { import c.universe._ val tpe = weakTypeOf[T] -// val one = weakTypeOf[(String, T)] -// val singleton = weakTypeOf[SingleBin[T]] -// val multi = weakTypeOf[MBin[T]] -// val many = weakTypeOf[Map[String, T]] val out = weakTypeOf[(Map[String, Option[T]], Int, Int)] val tpeSt = q"${tpe.toString}" + println("type " + tpe) +/* def castTuple[T](elems: Map[Any, Any], types: List[String])(implicit tf: Tuplify[T]): Option[T] = { + val casted = types.indices.map(i => cast(elems(i.toString), types(i))).toList + casted.length match { + case l if l > 0 && l < 23 => scala.util.Try { + val k = tf.toTuple(casted) + println("buildTupleResult " + k) + k + }.toOption + case _ => None + } + }*/ + def mp(add: Tree) = q"""override def fetch(any: Any): Option[$tpe] = any match { case v: $tpe => Option(v) @@ -244,12 +185,18 @@ object BinWrapper { Value.getFromRecordObject(any) match { case m: MapValue => m.getObject match { case ms: java.util.Map[Any @unchecked, Any @unchecked] => - val res = castTuple(ms.asScala.iterator.toMap, $ts) - res.collect { case t: $tpe => t } + println("tuple from map " + ms.asScala.iterator.toMap) + val elems = ms.asScala.iterator.toMap + val types = $ts + val casted = types.indices.map(i => cast(elems(i.toString), types(i))).toList + val sk = Tuplify.m(casted.length) + scala.util.Try(sk(casted).asInstanceOf[$tpe]).toOption + case _ => None } case _ => None - }""" + } + """ val mh = q"""override def fetch(any: Any): Option[$tpe] = Value.getFromRecordObject(any) match { @@ -262,67 +209,49 @@ object BinWrapper { case _ => None }""" - def typedList(pType: Type): Tree = - q"""override def fetch(any: Any): Option[$tpe] = Try{Value.getFromRecordObject(any) match { + def typedList(pType: Tree): Tree = + q"""override def fetch(any: Any): Option[$tpe] = + Value.getFromRecordObject(any) match { case lv: ListValue => lv.getObject match { - case ls: java.util.List[$pType @unchecked] => ls.asScala.toList - } - } - }.toOption """ - - /* - Example. Remove exception and Try allocation to improve performance. + case ls: java.util.List[$pType @unchecked] => Some(ls.asScala.toList) + case _ => None + } + case _ => None + } + """ - def typedList(pType: Type): Tree = + def typedArray(pType: Tree): Tree = q"""override def fetch(any: Any): Option[$tpe] = - Value.getFromRecordObject(any) match { - case lv: ListValue => lv.getObject match { - case ls: java.util.List[$pType @unchecked] => Some(ls.asScala.toList) - case _ => None - } + Value.getFromRecordObject(any) match { + case lv: ListValue => lv.getObject match { + case ls: java.util.List[$pType @unchecked] => Some(ls.asScala.toArray) + case _ => None } - case _ => None - } - """ - - def typedList(pType: Type): Tree = - q"""override def fetch(any: Any): Option[$tpe] = { - val value = Value.getFromRecordObject(any) - if (value.isInstanceOf[ListValue]) { - val ls = value.getObject - if (ls.isInstanceOf[java.util.List[$pType @unchecked]]) Some(ls.asScala.toList) - else None - } else None + case _ => None } - """*/ + """ - def typedArray(pType: Type): Tree = - q"""override def fetch(any: Any): Option[$tpe] = Try { - Value.getFromRecordObject(any) match { - case lv: ListValue => lv.getObject match { - case ls: java.util.List[$pType @unchecked] => - ls.asScala.toArray - } - } - }.toOption """ - - def streamedArray(pType: Type, to: Tree): Tree = - q"""override def fetch(any: Any): Option[$tpe] = Try { - Value.getFromRecordObject(any) match { - case lv: ListValue => lv.getObject match { - case ls: java.util.List[$pType @unchecked] => - ls.asScala.map($to).toArray - } - } - }.toOption """ + def streamedArray(pType: Tree, to: Tree): Tree = + q"""override def fetch(any: Any): Option[$tpe] = + Value.getFromRecordObject(any) match { + case lv: ListValue => lv.getObject match { + case ls: java.util.List[$pType @unchecked] => Some(ls.asScala.map($to).toArray) + case _ => None + } + case _ => None + } + """ - def typedMap(k: Type, v: Type): Tree = - q""" override def fetch(any: Any): Option[$tpe] = Try{Value.getFromRecordObject(any) match { + def typedMap(k: Tree, v: Tree): Tree = + q""" override def fetch(any: Any): Option[$tpe] = + Value.getFromRecordObject(any) match { case m: MapValue => m.getObject match { - case ms: java.util.Map[$k @unchecked, $v @unchecked] => ms.asScala.iterator.toMap - } - } - }.toOption""" + case ms: java.util.Map[$k @unchecked, $v @unchecked] => Some(ms.asScala.iterator.toMap) + case _ => None + } + case _ => None + } + """ def tupleArity(tpe: Type): Int = { val rex = "Tuple(\\d{1,2})".r @@ -332,79 +261,66 @@ object BinWrapper { } } + + def typedPlain(pType: Tree, cast: Tree): Tree = + q"""override def fetch(any: Any): Option[$tpe] = any match { + case v: $pType => Option($cast) + case _ => None + }""" + + def floatOrDouble(pType: Tree = q"""v""", backup: Tree = q"""java.lang.Double.longBitsToDouble(v)"""): Tree = + q"""override def fetch(any: Any): Option[$tpe] = any match { + case v: java.lang.Double => Option($pType) + case v: java.lang.Long => + Option($backup) + case _ => None + } + """ + val fetchValue = tpe match { case t if t.toString.contains("HNil") || t.toString.contains("HList") => mh case t if t =:= weakTypeOf[String] => q"""override def fetch(any: Any): Option[$tpe] = Try(Value.getFromRecordObject(any).getObject.toString).toOption """ + case t if t =:= weakTypeOf[Boolean] => typedPlain(tq"java.lang.Long", q"v == 1") // ToDo Choose between String and Long. Take storage overhead into account. Implement test. case t if t =:= weakTypeOf[Char] => q"""override def fetch(any: Any): Option[$tpe] = any match { case v: String => v.toString.toCharArray.headOption case _ => None } """ - case t if t =:= weakTypeOf[Boolean] => - q"""override def fetch(any: Any): Option[$tpe] = any match { - case v: java.lang.Long => Option(v == 1) - case _ => None - } """ // ToDo Use strict checking of Value.UseDoubleType. Implement test. - case t if t =:= weakTypeOf[Float] => - q"""override def fetch(any: Any): Option[$tpe] = any match { - case v: java.lang.Double => Option(v.toFloat) - case v: java.lang.Long => - Option(java.lang.Double.longBitsToDouble(v).toFloat) - case _ => None - } """ + case t if t =:= weakTypeOf[Float] => floatOrDouble(q"""v.toFloat""", q"""java.lang.Double.longBitsToDouble(v).toFloat""") // ToDo Use strict checking of Value.UseDoubleType. Implement test. - case t if t =:= weakTypeOf[Double] => - q"""override def fetch(any: Any): Option[$tpe] = any match { - case v: java.lang.Double => Option(v) - case v: java.lang.Long => - Option(java.lang.Double.longBitsToDouble(v)) - case v => None - } """ - case t if t =:= weakTypeOf[Int] => - q"""override def fetch(any: Any): Option[$tpe] = any match { - case v: java.lang.Long => Option(v.toInt) - case _ => None - } """ - case t if t =:= weakTypeOf[Short] => - q"""override def fetch(any: Any): Option[$tpe] = any match { - case v: java.lang.Long => Option(v.toShort) - case _ => None - } """ - case t if t =:= weakTypeOf[Byte] => - q"""override def fetch(any: Any): Option[$tpe] = any match { - case v: java.lang.Long => Option(v.toByte) - case _ => None - }""" - case t if t =:= weakTypeOf[List[String]] => typedList(weakTypeOf[String]) - case t if t =:= weakTypeOf[List[Int]] => typedList(weakTypeOf[Int]) - case t if t =:= weakTypeOf[List[Long]] => typedList(weakTypeOf[Long]) - case t if t =:= weakTypeOf[List[Float]] => typedList(weakTypeOf[Float]) - case t if t =:= weakTypeOf[List[Double]] => typedList(weakTypeOf[Double]) - case t if t =:= weakTypeOf[List[Boolean]] => typedList(weakTypeOf[Boolean]) - case t if t =:= weakTypeOf[Array[String]] => typedArray(weakTypeOf[String]) - case t if t =:= weakTypeOf[Array[Int]] => streamedArray(weakTypeOf[Long], q"_.toInt") - case t if t =:= weakTypeOf[Array[Long]] => typedArray(weakTypeOf[Long]) - case t if t =:= weakTypeOf[Array[Float]] => streamedArray(weakTypeOf[Double], q"_.toFloat") - case t if t =:= weakTypeOf[Array[Double]] => typedArray(weakTypeOf[Double]) - case t if t =:= weakTypeOf[Array[Boolean]] => typedArray(weakTypeOf[Boolean]) - case t if t =:= weakTypeOf[Map[Int, String]] => typedMap(weakTypeOf[Int], weakTypeOf[String]) - case t if t =:= weakTypeOf[Map[String, String]] => typedMap(weakTypeOf[String], weakTypeOf[String]) - case t if t =:= weakTypeOf[Map[String, Int]] => typedMap(weakTypeOf[String], weakTypeOf[Int]) - case t if t =:= weakTypeOf[Map[String, Long]] => typedMap(weakTypeOf[String], weakTypeOf[Long]) - case t if t =:= weakTypeOf[Map[String, Float]] => typedMap(weakTypeOf[String], weakTypeOf[Float]) - case t if t =:= weakTypeOf[Map[String, Double]] => typedMap(weakTypeOf[String], weakTypeOf[Double]) - case t if t =:= weakTypeOf[Map[String, List[Int]]] => - mp(q"""toKVmap[String, List[Int]](any, coll)(_.toString, toLs(_)(_.toInt))""") - case t if t =:= weakTypeOf[Map[String, List[String]]] => - mp(q"""toKVmap[String, List[String]](any, coll)(_.toString, toLs(_))""") - case t if t =:= weakTypeOf[Map[String, Any]] => typedMap(weakTypeOf[String], weakTypeOf[Any]) + case t if t =:= weakTypeOf[Double] => floatOrDouble() + case t if t =:= weakTypeOf[Int] => typedPlain(tq"java.lang.Long", q"v.toInt") + case t if t =:= weakTypeOf[Short] => typedPlain(tq"java.lang.Long", q"v.toShort") + case t if t =:= weakTypeOf[Byte] => typedPlain(tq"java.lang.Long", q"v.toByte") + case t if t =:= weakTypeOf[List[String]] => typedList(tq"String") + case t if t =:= weakTypeOf[List[Int]] => typedList(tq"Int") + case t if t =:= weakTypeOf[List[Long]] => typedList(tq"Long") + case t if t =:= weakTypeOf[List[Float]] => typedList(tq"Float") + case t if t =:= weakTypeOf[List[Double]] => typedList(tq"Double") + case t if t =:= weakTypeOf[List[Boolean]] => typedList(tq"Boolean") + case t if t =:= weakTypeOf[Array[String]] => typedArray(tq"String") + case t if t =:= weakTypeOf[Array[Int]] => streamedArray(tq"Long", q"_.toInt") + case t if t =:= weakTypeOf[Array[Long]] => typedArray(tq"Long") + case t if t =:= weakTypeOf[Array[Float]] => streamedArray(tq"Double", q"_.toFloat") + case t if t =:= weakTypeOf[Array[Double]] => typedArray(tq"Double") + case t if t =:= weakTypeOf[Array[Boolean]] => typedArray(tq"Boolean") + case t if t =:= weakTypeOf[Map[Int, String]] => typedMap(tq"Int", tq"String") + case t if t =:= weakTypeOf[Map[String, String]] => typedMap(tq"String", tq"String") + case t if t =:= weakTypeOf[Map[String, Int]] => typedMap(tq"String", tq"Int") + case t if t =:= weakTypeOf[Map[String, Long]] => typedMap(tq"String", tq"Long") + case t if t =:= weakTypeOf[Map[String, Float]] => typedMap(tq"String", tq"Float") + case t if t =:= weakTypeOf[Map[String, Double]] => typedMap(tq"String", tq"Double") + case t if t =:= weakTypeOf[Map[String, List[Int]]] => mp(q"""toKVmap[String, List[Int]](any, coll)(_.toString, toLs(_)(_.toInt))""") + case t if t =:= weakTypeOf[Map[String, List[String]]] => mp(q"""toKVmap[String, List[String]](any, coll)(_.toString, toLs(_))""") + case t if t =:= weakTypeOf[Map[String, Any]] => typedMap(tq"String", tq"Any") case t if tupleArity(t) != 0 => val tplArity = tupleArity(t) + println("IM IN TUPLE " + t) if (tplArity > 0 && tplArity < 23) tupleFetch(t.typeArgs.map(_.toString)) else q"""None""" case _ => q"""""" @@ -415,7 +331,7 @@ object BinWrapper { import java.util.{List => JList, Map => JMap} import com.aerospike.client.{Bin, Record, Value} - import com.aerospike.client.Value.{BlobValue, ListValue, MapValue, ValueArray} + import com.aerospike.client.Value._ import scala.collection.JavaConverters._ import scala.collection.mutable.{Seq => mSeq} import scala.language.experimental.macros @@ -424,6 +340,8 @@ object BinWrapper { import syntax.std.traversable._ import scala.collection.immutable.ListMap import ru.tinkoff.aerospikemacro.cast.Caster._ + import ru.tinkoff.aerospikemacro.cast.Tuplify._ + import ru.tinkoff.aerospikemacro.cast.Tuplify import ru.tinkoff.aerospikemacro.converters._ import com.aerospike.client.Value import scala.util.Try diff --git a/aerospike-scala-macros/src/main/scala/ru/tinkoff/aerospikemacro/converters/KeyWrapper.scala b/aerospike-scala-macros/src/main/scala/ru/tinkoff/aerospikemacro/converters/KeyWrapper.scala index b0ad2a8..c1fd3d9 100644 --- a/aerospike-scala-macros/src/main/scala/ru/tinkoff/aerospikemacro/converters/KeyWrapper.scala +++ b/aerospike-scala-macros/src/main/scala/ru/tinkoff/aerospikemacro/converters/KeyWrapper.scala @@ -21,7 +21,8 @@ import com.aerospike.client.{Key, Value} import ru.tinkoff.aerospikemacro.domain.{DBCredentials, WrapperException} import scala.language.experimental.macros -import scala.reflect.macros.blackbox.Context +import scala.reflect.macros.blackbox +import Utils._ /** * @author MarinaSigaeva @@ -44,18 +45,17 @@ trait KeyWrapper[KT] { } object KeyWrapper { - import Utils._ implicit def materializeK[T](implicit dbc: DBCredentials): KeyWrapper[T] = macro implK[T] - def implK[T: c.WeakTypeTag](c: Context)(dbc: c.Expr[DBCredentials]): c.Expr[KeyWrapper[T]] = { + def implK[T: c.WeakTypeTag](c: blackbox.Context)(dbc: c.Expr[DBCredentials]): c.Expr[KeyWrapper[T]] = { import c.universe._ val tpe = weakTypeOf[T] val db = reify(dbc.splice.namespace) val tableName = reify(dbc.splice.setname) - val toDBValue = pickValue(c) + val toDBValue = pickValue(c, "KeyWrapper") c.Expr[KeyWrapper[T]] { q""" @@ -64,6 +64,7 @@ object KeyWrapper { import scala.collection.immutable.Seq import ru.tinkoff.aerospikescala.domain.ByteSegment import scala.util.{Failure, Success, Try} + import ru.tinkoff.aerospikemacro.converters.Utils.defaultToValue new KeyWrapper[$tpe] { override val dbName = $db diff --git a/aerospike-scala-macros/src/main/scala/ru/tinkoff/aerospikemacro/converters/Utils.scala b/aerospike-scala-macros/src/main/scala/ru/tinkoff/aerospikemacro/converters/Utils.scala index 55fb682..0fee10b 100644 --- a/aerospike-scala-macros/src/main/scala/ru/tinkoff/aerospikemacro/converters/Utils.scala +++ b/aerospike-scala-macros/src/main/scala/ru/tinkoff/aerospikemacro/converters/Utils.scala @@ -1,22 +1,102 @@ package ru.tinkoff.aerospikemacro.converters +import com.aerospike.client.Value +import com.aerospike.client.Value._ import ru.tinkoff.aerospikescala.domain.ByteSegment +import shapeless.{::, HList} + +import scala.collection.immutable.{List, ListMap, Map} +import scala.reflect.ClassTag +import scala.reflect.macros.blackbox +import scala.util.{Failure, Success} +import scala.reflect.runtime.universe._ +import scala.collection.JavaConverters._ -import scala.reflect.macros.blackbox.Context /** * @author MarinaSigaeva * @since 04.04.17 */ object Utils { - def pickValue[T: c.WeakTypeTag](c: Context): c.universe.Tree = { + + def isTuple[T](x: T) = x.getClass.getSimpleName.contains("Tuple") + + def defaultToValue[T](x: T): Map[String, Any] = { + val clazz = weakTypeOf[T].getClass + val classTag = ClassTag[T](clazz) + val rm = scala.reflect.runtime.currentMirror + val accessors = rm.classSymbol(x.getClass).toType.decls.sorted.view.collect { + case m: MethodSymbol if m.isGetter && m.isPublic => m + } + val instanceMirror = rm.reflect(x)(classTag) + (for (acc <- accessors.view) yield { + acc.name.toString -> instanceMirror.reflectMethod(acc).apply() + }).toMap + } + + def typed[T](x: T)(implicit tag: WeakTypeTag[T]): T = x.asInstanceOf[T] + + def fromHList[L <: HList](hList: L, i: Int, maxIndex: Int): Map[String, Any] = { + val h0 = Map(i.toString -> typed(hList.productElement(0))) + hList match { + case head :: tail if i < maxIndex => h0 ++ fromHList(tail, i + 1, maxIndex) + case _ => h0 + } + } + + def tupleMapped[TPL <: Any with Product](tpl: TPL): Map[String, Any] = { + val i = tpl.productArity + val m = optTuple(tpl).map(mapify(i, _)).getOrElse(Map.empty) + ListMap(m.toSeq.sortBy(_._1): _*).view.map { + case (k, v) => k.toString -> v + }.toMap + } + + def mapify[H <: Any with Product](i: Int, t: H): Map[Int, Any] = { + (for (e <- 0 until i) yield (e, t.productElement(e))) (collection.breakOut) + } + + def optTuple[TPL <: Any with Product](tpl: TPL) = tpl match { + case t2: Tuple2[_, _] => Option(t2) + case t3: Tuple3[_, _, _] => Option(t3) + case t4: Tuple4[_, _, _, _] => Option(t4) + case t5: Tuple5[_, _, _, _, _] => Option(t5) + case t6: Tuple6[_, _, _, _, _, _] => Option(t6) + case t7: Tuple7[_, _, _, _, _, _, _] => Option(t7) + case t8: Tuple8[_, _, _, _, _, _, _, _] => Option(t8) + case t9: Tuple9[_, _, _, _, _, _, _, _, _] => Option(t9) + case t10: Tuple10[_, _, _, _, _, _, _, _, _, _] => Option(t10) + case t11: Tuple11[_, _, _, _, _, _, _, _, _, _, _] => Option(t11) + case t12: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _] => Option(t12) + case t13: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t13) + case t14: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t14) + case t15: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t15) + case t16: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t16) + case t17: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t17) + case t18: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t18) + case t19: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t19) + case t20: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t20) + case t21: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t21) + case t22: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => Option(t22) + case _ => None + } + + + def throwIllegal(w: String, t: String): Tree = { + val tpeName = q"$t" + + q"""throw new IllegalArgumentException( + "You need to write your own toValue function in " + $w + " implicit for type " + $tpeName) """ + } + + def pickValue[T: c.WeakTypeTag](c: blackbox.Context, wrapper: String): c.universe.Tree = { import c.universe._ val tpe = weakTypeOf[T] val tpeName = q"${tpe.typeSymbol.fullName}" val err = q"""throw new IllegalArgumentException( - "You need to write your own toValue function in KeyWrapper implicit for type " + $tpeName) """ + "You need to write your own toValue function in " + $wrapper + " implicit for type " + $tpeName)""" tpe match { case t if t =:= weakTypeOf[ByteSegment] => q"""v match { @@ -24,18 +104,27 @@ object Utils { case _ => $err }""" case t if t =:= weakTypeOf[Int] => q"""new IntegerValue(v)""" + case t if t =:= weakTypeOf[Short] => q"""new IntegerValue(v)""" + case t if t =:= weakTypeOf[Byte] => q"""new IntegerValue(v)""" case t if t =:= weakTypeOf[Long] => q"""new LongValue(v)""" case t if t =:= weakTypeOf[String] => q"""new StringValue(v)""" + case t if t =:= weakTypeOf[Char] => q"""new StringValue(v.toString)""" case t if t =:= weakTypeOf[Boolean] => q"""new BooleanValue(v)""" case t if t =:= weakTypeOf[Float] => q"""new FloatValue(v)""" case t if t =:= weakTypeOf[Double] => q"""new DoubleValue(v)""" + case t if t =:= weakTypeOf[java.util.List[_]] => q"""new ListValue(v)""" + case t if t =:= weakTypeOf[List[_]] => q"""new ListValue(v)""" + case t if t =:= weakTypeOf[Array[_]] => q"""new ListValue(v.toList)""" + case t if t =:= weakTypeOf[java.util.Map[_, _]] => q"""new MapValue(v)""" case t if t =:= weakTypeOf[Array[Byte]] => q"""new BytesValue(v)""" case t if t =:= weakTypeOf[scala.collection.immutable.Seq[_]] => q"""new ListValue(v)""" case t if t =:= weakTypeOf[Map[_, _]] => q"""new MapValue(v)""" - case _ => q"""Try(Value.get(v)) match { - case Failure(th) => $err - case Success(s) => s - }""" + case t: Any with Product if isTuple(t) => q"""new MapValue(tupleMapped($tpe))""" + case yourCaseClass => q""" Value.get(v) match { + case n: NullValue => $err + case other => other + }""" + } } } \ No newline at end of file diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index 28be13a..fcafcf9 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -2,6 +2,6 @@ ru-tinkoff-aerospike-dsl { keyWrapper-namespace = "test" keyWrapper-setName = "test33" - example-host = "127.0.0.1" + example-host = "ds-aerospike01t" example-port = 3000 } \ No newline at end of file diff --git a/src/main/scala/ru/tinkoff/aerospike/dsl/Spike.scala b/src/main/scala/ru/tinkoff/aerospike/dsl/Spike.scala index 5cb0f6d..1d22fb5 100644 --- a/src/main/scala/ru/tinkoff/aerospike/dsl/Spike.scala +++ b/src/main/scala/ru/tinkoff/aerospike/dsl/Spike.scala @@ -17,7 +17,7 @@ package ru.tinkoff.aerospike.dsl import com.aerospike.client.policy._ -import ru.tinkoff.aerospike.dsl.batchread.BatchReadWrapper +//import ru.tinkoff.aerospike.dsl.batchread.BatchReadWrapper import ru.tinkoff.aerospikemacro.converters.KeyWrapper._ import ru.tinkoff.aerospikemacro.converters.{BinWrapper, KeyWrapper} import ru.tinkoff.aerospikescala.domain.ABin @@ -80,9 +80,9 @@ trait Spike { optBP: Option[BatchPolicy] = None): Future[Unit] //note, if you will not change namespace, setName parameters in BatchReadWrapper - default values from application.conf will be used - def getByKeysWithBatchListener[L](kws: List[BatchReadWrapper], +/* def getByKeysWithBatchListener[L](kws: List[BatchReadWrapper], listener: Option[L] = None)( - implicit optBP: Option[BatchPolicy] = None): Future[Unit] + implicit optBP: Option[BatchPolicy] = None): Future[Unit]*/ def deleteK[K](k: K)(implicit kC: KeyWrapper[K], pw: Option[WritePolicy] = None, diff --git a/src/main/scala/ru/tinkoff/aerospike/dsl/SpikeImpl.scala b/src/main/scala/ru/tinkoff/aerospike/dsl/SpikeImpl.scala index e4655d6..a955213 100644 --- a/src/main/scala/ru/tinkoff/aerospike/dsl/SpikeImpl.scala +++ b/src/main/scala/ru/tinkoff/aerospike/dsl/SpikeImpl.scala @@ -21,7 +21,7 @@ import com.aerospike.client.async._ import com.aerospike.client.listener._ import com.aerospike.client.policy._ import com.aerospike.client.query.Statement -import ru.tinkoff.aerospike.dsl.batchread.BatchReadWrapper +//import ru.tinkoff.aerospike.dsl.batchread.BatchReadWrapper import ru.tinkoff.aerospikemacro.converters.{BinWrapper, KeyWrapper} import ru.tinkoff.aerospike.dsl.errors.AerospikeDSLError import ru.tinkoff.aerospikescala.domain.{ABin, MBin, SingleBin} @@ -340,6 +340,9 @@ class SpikeImpl(spikeClient: IAsyncClient)(implicit val ec: ExecutionContext) } } +/* def getByKeysWithBatchListener[L](kws: List[BatchReadWrapper], listener: Option[L] = None)(implicit optBP: Option[BatchPolicy] = None): Future[Unit] = { + val policy = optBP.getOrElse(new BatchPolicy) + val records: java.util.List[BatchRead] = kws.view.map(e => e.apply).toList def getByKeysWithBatchListener[L](kws: List[BatchReadWrapper], listener: Option[L] = None)( implicit optBP: Option[BatchPolicy] = None ): Future[Unit] = { @@ -352,6 +355,6 @@ class SpikeImpl(spikeClient: IAsyncClient)(implicit val ec: ExecutionContext) case None => get(policy, records) case _ => throw AerospikeDSLError(s"Unsupported listener type $listener") } - } + }*/ } diff --git a/src/main/scala/ru/tinkoff/aerospike/dsl/batchread/BatchReadWrapper.scala b/src/main/scala/ru/tinkoff/aerospike/dsl/batchread/BatchReadWrapper.scala index 81a5639..5aa46d2 100644 --- a/src/main/scala/ru/tinkoff/aerospike/dsl/batchread/BatchReadWrapper.scala +++ b/src/main/scala/ru/tinkoff/aerospike/dsl/batchread/BatchReadWrapper.scala @@ -28,6 +28,7 @@ import scala.language.experimental.macros * @author MarinaSigaeva * @since 21.09.16 */ +/* trait BatchReadWrapper { val keyValue: Any val binNames: Array[String] @@ -36,3 +37,4 @@ trait BatchReadWrapper { def applyO[S <: Any](k: S)(implicit kW: KeyWrapper[S]): BatchRead = new BatchRead(kW(k), binNames) def apply = applyO(keyValue) } +*/ diff --git a/src/test/scala/ru/tinkoff/aerospikemacro/converters/BatchReadWrapperTest.scala b/src/test/scala/ru/tinkoff/aerospikemacro/converters/BatchReadWrapperTest.scala index bfa6407..c04ac5b 100644 --- a/src/test/scala/ru/tinkoff/aerospikemacro/converters/BatchReadWrapperTest.scala +++ b/src/test/scala/ru/tinkoff/aerospikemacro/converters/BatchReadWrapperTest.scala @@ -1,3 +1,4 @@ +/* /* * Copyright (c) 2016 Tinkoff * @@ -63,3 +64,4 @@ class BatchReadWrapperTest extends FlatSpec with Matchers { } } +*/ diff --git a/src/test/scala/ru/tinkoff/aerospikemacro/converters/BinTest.scala b/src/test/scala/ru/tinkoff/aerospikemacro/converters/BinTest.scala index 49304a7..72b5acc 100644 --- a/src/test/scala/ru/tinkoff/aerospikemacro/converters/BinTest.scala +++ b/src/test/scala/ru/tinkoff/aerospikemacro/converters/BinTest.scala @@ -31,6 +31,7 @@ import shapeless.HList.hlistOps import syntax.std.traversable._ import ru.tinkoff.aerospikemacro.converters._ import ru.tinkoff.aerospikescala.domain.{MBin, SingleBin} +import ru.tinkoff.aerospikemacro.cast.Tuplify._ /** * @author MarinaSigaeva @@ -73,7 +74,7 @@ class BinTest extends FlatSpec with Matchers with OptionValues { implicit val intM = new BinWrapper[Map[Int, List[Int]]] { override def toValue(m: Map[Int, List[Int]]): MapValue = { val value = m.mapValues { - case ls: List[_] => ls.mkString(comma) + case ls: List[_] => ls.mkString(",") case oth => oth.toString() } new MapValue(value.asJava) @@ -100,144 +101,6 @@ class BinTest extends FlatSpec with Matchers with OptionValues { exp shouldBe 12 } - /* it should "test BinWrapper for getting simple type from aerospike Record" in new fromInsideToBtSimple { - - val (st, gen, exp) = getFromRecord(record2) - st shouldBe Map("name", Some("str")) - gen shouldBe 100 - exp shouldBe 12 - - val (ls, gen2, exp2) = getFromRecord[List[String]](record3)//(BinWrapper.listS) - ls shouldBe Map("name", Some(List("str", "str"))) - gen2 shouldBe 100 - exp2 shouldBe 12 - - val (lsi, geni, expi) = getFromRecord[List[Int]](record8)//(BinWrapper.listS) - lsi shouldBe Map("name", Some(List(8, 9, 7))) - geni shouldBe 100 - expi shouldBe 12 - - val (m, gen3, exp3) = getFromRecord[Map[String, String]](record4) - m shouldBe Map("name", Some(Map("strKey1" -> "strValue1", "strKey2" -> "strValue2"))) - gen3 shouldBe 100 - exp3 shouldBe 12 - - val (m2, gen4, exp4) = getFromRecord[Map[String, Int]](record5) - m2 shouldBe Map("name", Some(Map("k1" -> 4, "k2" -> 5))) - gen4 shouldBe 100 - exp4 shouldBe 12 - - val (m3, gen5, exp5) = getFromRecord[Map[String, List[Int]]](record6) - m3 shouldBe Map("name", Some(Map("k1" -> List(1, 2, 3), "k2" -> List(4, 5, 6)))) - gen5 shouldBe 100 - exp5 shouldBe 12 - - val (m4, gen6, exp6) = getFromRecord[Map[String, Any]](record7) - m4 shouldBe Map("name", Some(Map("k1" -> List(1, 2, 3), "k2" -> 33))) - gen6 shouldBe 100 - exp6 shouldBe 12 - - val (sth, genh, exph) = getFromRecord[Int :: String :: Double :: List[Int] :: List[String]::HNil](recordh) - sth shouldBe Map("name", Some(1 :: "aff" :: 39.0 :: List(1, 2) :: List("a", "z") :: HNil)) - genh shouldBe 100 - exph shouldBe 12 - - val (stt2, gent2, expt2) = getFromRecord[(Int, String)](recordTuple2) - stt2 shouldBe Map("name", Some((1, "aff"))) - - val (stt3, gent3, expt3) = getFromRecord[(Int, String, Double)](recordTuple3) - stt3 shouldBe Map("name", Some((1, "aff", 39.0))) - - val (stt4, gent4, expt4) = getFromRecord[(Int, String, Double, List[Int])](recordTuple4) - stt4 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2)))) - - val (stt5, gent5, expt5) = getFromRecord[(Int, String, Double, List[Int], List[String])](recordTuple5) - stt5 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z")))) - gent5 shouldBe 100 - expt5 shouldBe 12 - - val (stt6, gent6, expt6) = getFromRecord[(Int, String, Double, List[Int], List[String], String)](recordTuple6) - stt6 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z"), "aff"))) - - val (stt7, gent7, expt7) = getFromRecord[(Int, String, Double, List[Int], List[String], Int, String)](recordTuple7) - stt7 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff"))) - - val (stt8, gent8, expt8) = getFromRecord[(Int, String, Double, List[Int], List[String], Int, String, Double)](recordTuple8) - stt8 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", 39.0))) - - val (stt9, gent9, expt9) = getFromRecord[(Int, String, Double, List[Int], List[String], Int, String, Double, List[Int])](recordTuple9) - stt9 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", 39.0, List(1,2)))) - - val (stt10, gent10, expt10) = getFromRecord[(Int, String, Double, List[Int], List[String], - Int, String, Double, List[Int], List[String])](recordTuple10) - stt10 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", 39.0, List(1,2), List("a", "z")))) - - val (stt11, gent11, expt11) = getFromRecord[(Int, String, Double, List[Int], List[String], - Int, String, Double, List[Int], List[String], Int)](recordTuple11) - stt11 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", 39.0, List(1,2), List("a", "z"), 22))) - - val (stt12, gent12, expt12) = getFromRecord[(Int, String, Double, List[Int], List[String], - Int, String, Double, List[Int], List[String], Int, String)](recordTuple12) - stt12 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", - 39.0, List(1,2), List("a", "z"), 22, "www"))) - - val (stt13, gent13, expt13) = getFromRecord[(Int, String, Double, List[Int], List[String], - Int, String, Double, List[Int], List[String], Int, String, Int)](recordTuple13) - stt13 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", - 39.0, List(1,2), List("a", "z"), 22, "www", 3))) - - val (stt14, gent14, expt14) = getFromRecord[(Int, String, Double, List[Int], List[String], - Int, String, Double, List[Int], List[String], Int, String, Int, List[Int])](recordTuple14) - stt14 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", - 39.0, List(1,2), List("a", "z"), 22, "www", 3, List(4,5)))) - - val (stt15, gent15, expt15) = getFromRecord[(Int, String, Double, List[Int], List[String], - Int, String, Double, List[Int], List[String], Int, String, Int, List[Int], String)](recordTuple15) - stt15 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", - 39.0, List(1,2), List("a", "z"), 22, "www", 3, List(4,5), "www"))) - - val (stt16, gent16, expt16) = getFromRecord[(Int, String, Double, List[Int], List[String], - Int, String, Double, List[Int], List[String], Int, String, Int, List[Int], String, Int)](recordTuple16) - stt16 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", - 39.0, List(1,2), List("a", "z"), 22, "www", 3, List(4,5), "www", 4))) - - val (stt17, gent17, expt17) = getFromRecord[(Int, String, Double, List[Int], List[String], - Int, String, Double, List[Int], List[String], Int, String, Int, List[Int], String, Int, String)](recordTuple17) - stt17 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", - 39.0, List(1,2), List("a", "z"), 22, "www", 3, List(4,5), "www", 4, "kkk"))) - - val (stt18, gent18, expt18) = getFromRecord[(Int, String, Double, List[Int], List[String], - Int, String, Double, List[Int], List[String], Int, String, Int, List[Int], - String, Int, String, Int)](recordTuple18) - stt18 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", - 39.0, List(1,2), List("a", "z"), 22, "www", 3, List(4,5), "www", 4, "kkk", 8))) - - val (stt19, gent19, expt19) = getFromRecord[(Int, String, Double, List[Int], List[String], - Int, String, Double, List[Int], List[String], Int, String, Int, List[Int], - String, Int, String, Int, String)](recordTuple19) - stt19 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", - 39.0, List(1,2), List("a", "z"), 22, "www", 3, List(4,5), "www", 4, "kkk", 8, "kkkk"))) - - val (stt20, gent20, expt20) = getFromRecord[(Int, String, Double, List[Int], List[String], - Int, String, Double, List[Int], List[String], Int, String, Int, List[Int], - String, Int, String, Int, String, Double)](recordTuple20) - stt20 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", - 39.0, List(1,2), List("a", "z"), 22, "www", 3, List(4,5), "www", 4, "kkk", 8, "kkkk", 9.0))) - - val (stt21, gent21, expt21) = getFromRecord[(Int, String, Double, List[Int], List[String], - Int, String, Double, List[Int], List[String], Int, String, Int, List[Int], - String, Int, String, Int, String, Double, Boolean)](recordTuple21) - stt21 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", - 39.0, List(1,2), List("a", "z"), 22, "www", 3, List(4,5), "www", 4, "kkk", 8, "kkkk", 9.0, true))) - - val (stt22, gent22, expt22) = getFromRecord[(Int, String, Double, List[Int], List[String], - Int, String, Double, List[Int], List[String], Int, String, Int, List[Int], - String, Int, String, Int, String, Double, Boolean, String)](recordTuple22) - stt22 shouldBe Map("name", Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", - 39.0, List(1,2), List("a", "z"), 22, "www", 3, List(4,5), "www", 4, "kkk", 8, "kkkk", 9.0, true, "www"))) - - }*/ - it should "throw ClassCastException because fromInsideToBt in BinWrapperer is not implemented" in new fromInsideToBtMocks { val duck = Duck("duck", List(1, 2, 3)) val duckValue = getBin[Duck](SingleBin("duckNameBin", duck)).value @@ -282,8 +145,6 @@ trait mocks { new Bin(b.name, new ValueArray(listValue)) } - def getFromRecord[B](r: Record)(implicit bC: BinWrapper[B]): (Map[String, Any], Int, Int) = bC.apply(r) - implicit val tc1 = new BinWrapper[Truck] { import MyJsonProtocol._ @@ -412,136 +273,4 @@ trait RecordMock extends mocks { val booleanRecord: TestRecord[Boolean] = booleanValue.toSingleTestRecord() } -/* -trait fromInsideToBtSimple extends mocks { - val rValue = getBin(SingleBin("name", "str")).value - val rMap: JMap[String, Object] = Map("name", rValue) - val record2 = new Record(rMap, 100, 12) - - val rValue3 = getBin(SingleBin("name", List("str", "str"))).value - val rMap3: JMap[String, Object] = Map("name", rValue3) - val record3 = new Record(rMap3, 100, 12) - - val rValue8 = getBin(SingleBin("name", List(8,9,7))).value - val rMap8: JMap[String, Object] = Map("name", rValue8) - val record8 = new Record(rMap8, 100, 12) - - val rValue4 = getBin(SingleBin("name", Map("strKey1" -> "strValue1", "strKey2" -> "strValue2"))).value - val rMap4: JMap[String, Object] = Map("name", rValue4) - val record4 = new Record(rMap4, 100, 12) - - val rValue5 = getBin(SingleBin("name", Map("k1" -> 4L, "k2" -> 5L))).value - val rMap5: JMap[String, Object] = Map("name", rValue5) - val record5 = new Record(rMap5, 100, 12) - - val rValue6 = getBin(SingleBin("name", Map("k1" -> List(1,2,3), "k2" -> List(4,5,6)))).value - val rMap6: JMap[String, Object] = Map("name", rValue6) - val record6 = new Record(rMap6, 100, 12) - - val rValue7 = getBin(SingleBin("name", Map("k1" -> List(1,2,3), "k2" -> 33))).value - val rMap7: JMap[String, Object] = Map("name", rValue7) - val record7 = new Record(rMap7, 100, 12) - - val rhValue = getBin(SingleBin("name", (1 :: "aff" :: 39.0 :: List(1,2) :: List("a","z") :: HNil))).value - val rhMap: JMap[String, Object] = Map("name", rhValue) - val recordh = new Record(rhMap, 100, 12) - - val rtValue2 = getBin(SingleBin("name", (1, "aff"))).value - val rtMap2: JMap[String, Object] = Map("name", rtValue2) - val recordTuple2 = new Record(rtMap2, 100, 12) - - val rtValue3 = getBin(SingleBin("name", (1, "aff", 39.0))).value - val rtMap3: JMap[String, Object] = Map("name", rtValue3) - val recordTuple3 = new Record(rtMap3, 100, 12) - - val rtValue4 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2)))).value - val rtMap4: JMap[String, Object] = Map("name", rtValue4) - val recordTuple4 = new Record(rtMap4, 100, 12) - - val rtValue5 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z")))).value - val rtMap5: JMap[String, Object] = Map("name", rtValue5) - val recordTuple5 = new Record(rtMap5, 100, 12) - - val rtValue6 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z"), "aff"))).value - val rtMap6: JMap[String, Object] = Map("name", rtValue6) - val recordTuple6 = new Record(rtMap6, 100, 12) - - val rtValue7 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z"), 1, "aff"))).value - val rtMap7: JMap[String, Object] = Map("name", rtValue7) - val recordTuple7 = new Record(rtMap7, 100, 12) - - val rtValue8 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z"), 1, "aff", 39.0))).value - val rtMap8: JMap[String, Object] = Map("name", rtValue8) - val recordTuple8 = new Record(rtMap8, 100, 12) - - val rtValue9 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z"), 1, "aff", 39.0, List(1,2)))).value - val rtMap9: JMap[String, Object] = Map("name", rtValue9) - val recordTuple9 = new Record(rtMap9, 100, 12) - - val rtValue10 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z"), - 1, "aff", 39.0, List(1,2), List("a","z")))).value - val rtMap10: JMap[String, Object] = Map("name", rtValue10) - val recordTuple10 = new Record(rtMap10, 100, 12) - - val rtValue11 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z"), - 1, "aff", 39.0, List(1,2), List("a","z"), 22))).value - val rtMap11: JMap[String, Object] = Map("name", rtValue11) - val recordTuple11 = new Record(rtMap11, 100, 12) - - val rtValue12 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z"), - 1, "aff", 39.0, List(1,2), List("a","z"), 22, "www"))).value - val rtMap12: JMap[String, Object] = Map("name", rtValue12) - val recordTuple12 = new Record(rtMap12, 100, 12) - - val rtValue13 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z"), - 1, "aff", 39.0, List(1,2), List("a","z"), 22, "www", 3))).value - val rtMap13: JMap[String, Object] = Map("name", rtValue13) - val recordTuple13 = new Record(rtMap13, 100, 12) - - val rtValue14 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z"), - 1, "aff", 39.0, List(1,2), List("a","z"), 22, "www", 3, List(4,5)))).value - val rtMap14: JMap[String, Object] = Map("name", rtValue14) - val recordTuple14 = new Record(rtMap14, 100, 12) - - val rtValue15 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z"), - 1, "aff", 39.0, List(1,2), List("a","z"), 22, "www", 3, List(4,5), "www"))).value - val rtMap15: JMap[String, Object] = Map("name", rtValue15) - val recordTuple15 = new Record(rtMap15, 100, 12) - - val rtValue16 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z"), - 1, "aff", 39.0, List(1,2), List("a","z"), 22, "www", 3, List(4,5), "www", 4))).value - val rtMap16: JMap[String, Object] = Map("name", rtValue16) - val recordTuple16 = new Record(rtMap16, 100, 12) - - val rtValue17 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z"), - 1, "aff", 39.0, List(1,2), List("a","z"), 22, "www", 3, List(4,5), "www", 4, "kkk"))).value - val rtMap17: JMap[String, Object] = Map("name", rtValue17) - val recordTuple17 = new Record(rtMap17, 100, 12) - - val rtValue18 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z"), - 1, "aff", 39.0, List(1,2), List("a","z"), 22, "www", 3, List(4,5), "www", 4, "kkk", 8))).value - val rtMap18: JMap[String, Object] = Map("name", rtValue18) - val recordTuple18 = new Record(rtMap18, 100, 12) - - val rtValue19 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z"), - 1, "aff", 39.0, List(1,2), List("a","z"), 22, "www", 3, List(4,5), "www", 4, "kkk", 8, "kkkk"))).value - val rtMap19: JMap[String, Object] = Map("name", rtValue19) - val recordTuple19 = new Record(rtMap19, 100, 12) - - val rtValue20 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z"), - 1, "aff", 39.0, List(1,2), List("a","z"), 22, "www", 3, List(4,5), "www", 4, "kkk", 8, "kkkk", 9.0))).value - val rtMap20: JMap[String, Object] = Map("name", rtValue20) - val recordTuple20 = new Record(rtMap20, 100, 12) - - val rtValue21 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z"), - 1, "aff", 39.0, List(1,2), List("a","z"), 22, "www", 3, List(4,5), "www", 4, "kkk", 8, "kkkk", 9.0, true))).value - val rtMap21: JMap[String, Object] = Map("name", rtValue21) - val recordTuple21 = new Record(rtMap21, 100, 12) - - val rtValue22 = getBin(SingleBin("name", (1, "aff", 39.0, List(1,2), List("a","z"), - 1, "aff", 39.0, List(1,2), List("a","z"), 22, "www", 3, List(4,5), "www", 4, "kkk", 8, "kkkk", 9.0, true, "www"))).value - val rtMap22: JMap[String, Object] = Map("name", rtValue22) - val recordTuple22 = new Record(rtMap22, 100, 12) -} - */ diff --git a/src/test/scala/ru/tinkoff/aerospikemacro/converters/CasterTest.scala b/src/test/scala/ru/tinkoff/aerospikemacro/converters/CasterTest.scala index 488e2ed..48478f8 100644 --- a/src/test/scala/ru/tinkoff/aerospikemacro/converters/CasterTest.scala +++ b/src/test/scala/ru/tinkoff/aerospikemacro/converters/CasterTest.scala @@ -55,7 +55,7 @@ class CasterTest { val hMap: java.util.HashMap[Any, Any] = new java.util.HashMap[Any, Any](Map("0" -> 2, "1" -> "asd").asJava) val tpl = weakTypeOf[Tuple2[Int, String]].typeArgs.map(_.toString) - val expected = Caster.castTuple(hMap.asScala.toMap, tpl) - assertTrue(expected == Option((2, "asd"))) + /* val expected = Caster.castTuple(hMap.asScala.toMap, tpl) + assertTrue(expected == Option((2, "asd")))*/ } } diff --git a/src/test/scala/ru/tinkoff/aerospikemacro/converters/GetFromRecordTest.scala b/src/test/scala/ru/tinkoff/aerospikemacro/converters/GetFromRecordTest.scala new file mode 100644 index 0000000..00d538c --- /dev/null +++ b/src/test/scala/ru/tinkoff/aerospikemacro/converters/GetFromRecordTest.scala @@ -0,0 +1,275 @@ +package ru.tinkoff.aerospikemacro.converters + +import java.util.{List => JList, Map => JMap} + +import com.aerospike.client.Record +import com.aerospike.client.Value.{MapValue, StringValue} +import org.scalatest.{FlatSpec, Matchers, OptionValues} +import ru.tinkoff.aerospikescala.domain.SingleBin +import shapeless.{::, HNil} + +import scala.collection.JavaConverters._ +import ru.tinkoff.aerospikemacro.cast.Caster._ +import ru.tinkoff.aerospikemacro.cast.Tuplify._ +import ru.tinkoff.aerospikemacro.cast.Tuplify + + +/** + * @author MarinaSigaeva + * @since 11.04.17 + */ +class GetFromRecordTest extends FlatSpec with Matchers with OptionValues { + + it should "test BinWrapper for getting simple type from aerospike Record" in new fromInsideToBtSimple { + + val st = getFromRecord[String](record2) + st shouldBe Map("name" -> Some("str")) + + val ls = getFromRecord[List[String]](record3) //(BinWrapper.listS) + ls shouldBe Map("name" -> Some(List("str", "str"))) + + val lsi = getFromRecord[List[Int]](record8) //(BinWrapper.listS) + lsi shouldBe Map("name" -> Some(List(8, 9, 7))) + + val m = getFromRecord[Map[String, String]](record4) + m shouldBe Map("name" -> Some(Map("strKey1" -> "strValue1", "strKey2" -> "strValue2"))) + + val m2 = getFromRecord[Map[String, Int]](record5) + m2 shouldBe Map("name" -> Some(Map("k1" -> 4, "k2" -> 5))) + + val m3 = getFromRecord[Map[String, List[Int]]](record6) + m3 shouldBe Map("name" -> Some(Map("k1" -> List(1, 2, 3), "k2" -> List(4, 5, 6)))) + + val m4 = getFromRecord[Map[String, Any]](record7) + m4 shouldBe Map("name" -> Some(Map("k1" -> List(1, 2, 3), "k2" -> 33))) + + val sth = getFromRecord[Int :: String :: Double :: List[Int] :: List[String] :: HNil](recordh) + sth shouldBe Map("name" -> Some(1 :: "aff" :: 39.0 :: List(1, 2) :: List("a", "z") :: HNil)) + + val stt2 = getFromRecord[(Int, String)](recordTuple2) + stt2 shouldBe Map("name" -> Some((1, "aff"))) + + val stt3 = getFromRecord[(Int, String, Double)](recordTuple3) + stt3 shouldBe Map("name" -> Some((1, "aff2", 39.0))) + + val stt4 = getFromRecord[(Int, String, Double, List[Int])](recordTuple4) + stt4 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2)))) + + val stt5 = getFromRecord[(Int, String, Double, List[Int], List[String])](recordTuple5) + stt5 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z")))) + + val stt6 = getFromRecord[(Int, String, Double, List[Int], List[String], String)](recordTuple6) + stt6 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z"), "aff"))) + + val stt7 = getFromRecord[(Int, String, Double, List[Int], List[String], Int, String)](recordTuple7) + stt7 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff"))) + + val stt8 = getFromRecord[(Int, String, Double, List[Int], List[String], Int, String, Double)](recordTuple8) + stt8 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", 39.0))) + + val stt9 = getFromRecord[(Int, String, Double, List[Int], List[String], Int, String, Double, List[Int])](recordTuple9) + stt9 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", 39.0, List(1, 2)))) + + val stt10 = getFromRecord[(Int, String, Double, List[Int], List[String], + Int, String, Double, List[Int], List[String])](recordTuple10) + stt10 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", 39.0, List(1, 2), List("a", "z")))) + + val stt11 = getFromRecord[(Int, String, Double, List[Int], List[String], + Int, String, Double, List[Int], List[String], Int)](recordTuple11) + stt11 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", 39.0, List(1, 2), List("a", "z"), 22))) + + val stt12 = getFromRecord[(Int, String, Double, List[Int], List[String], + Int, String, Double, List[Int], List[String], Int, String)](recordTuple12) + stt12 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", + 39.0, List(1, 2), List("a", "z"), 22, "www"))) + + val stt13 = getFromRecord[(Int, String, Double, List[Int], List[String], + Int, String, Double, List[Int], List[String], Int, String, Int)](recordTuple13) + stt13 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", + 39.0, List(1, 2), List("a", "z"), 22, "www", 3))) + + val stt14 = getFromRecord[(Int, String, Double, List[Int], List[String], + Int, String, Double, List[Int], List[String], Int, String, Int, List[Int])](recordTuple14) + stt14 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", + 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5)))) + + val stt15 = getFromRecord[(Int, String, Double, List[Int], List[String], + Int, String, Double, List[Int], List[String], Int, String, Int, List[Int], String)](recordTuple15) + stt15 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", + 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5), "www"))) + + val stt16 = getFromRecord[(Int, String, Double, List[Int], List[String], + Int, String, Double, List[Int], List[String], Int, String, Int, List[Int], String, Int)](recordTuple16) + stt16 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", + 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5), "www", 4))) + + val stt17 = getFromRecord[(Int, String, Double, List[Int], List[String], + Int, String, Double, List[Int], List[String], Int, String, Int, List[Int], String, Int, String)](recordTuple17) + stt17 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", + 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5), "www", 4, "kkk"))) + + val stt18 = getFromRecord[(Int, String, Double, List[Int], List[String], + Int, String, Double, List[Int], List[String], Int, String, Int, List[Int], + String, Int, String, Int)](recordTuple18) + stt18 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", + 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5), "www", 4, "kkk", 8))) + + val stt19 = getFromRecord[(Int, String, Double, List[Int], List[String], + Int, String, Double, List[Int], List[String], Int, String, Int, List[Int], + String, Int, String, Int, String)](recordTuple19) + stt19 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", + 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5), "www", 4, "kkk", 8, "kkkk"))) + + val stt20 = getFromRecord[(Int, String, Double, List[Int], List[String], + Int, String, Double, List[Int], List[String], Int, String, Int, List[Int], + String, Int, String, Int, String, Double)](recordTuple20) + stt20 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", + 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5), "www", 4, "kkk", 8, "kkkk", 9.0))) + + val stt21 = getFromRecord[(Int, String, Double, List[Int], List[String], + Int, String, Double, List[Int], List[String], Int, String, Int, List[Int], + String, Int, String, Int, String, Double, Boolean)](recordTuple21) + stt21 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", + 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5), "www", 4, "kkk", 8, "kkkk", 9.0, true))) + + val stt22 = getFromRecord[(Int, String, Double, List[Int], List[String], + Int, String, Double, List[Int], List[String], Int, String, Int, List[Int], + String, Int, String, Int, String, Double, Boolean, String)](recordTuple22) + stt22 shouldBe Map("name" -> Some((1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", + 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5), "www", 4, "kkk", 8, "kkkk", 9.0, true, "www"))) + } +} + +trait fromInsideToBtSimple extends mocks { + + def getFromRecord[B](r: Record)(implicit bC: BinWrapper[B]): Map[String, Option[B]] = bC.apply(r)._1 + + val rMap: JMap[String, Object] = Map[String, Object]("name" -> new StringValue("str")).asJava + val record2 = new Record(rMap, 100, 12) + + val rValue3 = getBin(SingleBin("name", List("str", "str"))).value + val rMap3: JMap[String, Object] = Map[String, Object]("name" -> rValue3).asJava + val record3 = new Record(rMap3, 100, 12) + + val rValue8 = getBin(SingleBin("name", List(8, 9, 7))).value + val rMap8: JMap[String, Object] = Map[String, Object]("name" -> rValue8).asJava + val record8 = new Record(rMap8, 100, 12) + + val rValue4 = getBin(SingleBin("name", Map("strKey1" -> "strValue1", "strKey2" -> "strValue2"))).value + val rMap4: JMap[String, Object] = Map[String, Object]("name" -> rValue4).asJava + val record4 = new Record(rMap4, 100, 12) + + val rValue5 = getBin(SingleBin("name", Map("k1" -> 4L, "k2" -> 5L))).value + val rMap5: JMap[String, Object] = Map[String, Object]("name" -> rValue5).asJava + val record5 = new Record(rMap5, 100, 12) + + val rValue6 = getBin(SingleBin("name", Map("k1" -> List(1, 2, 3), "k2" -> List(4, 5, 6)))).value + val rMap6: JMap[String, Object] = Map[String, Object]("name" -> rValue6).asJava + val record6 = new Record(rMap6, 100, 12) + + val rValue7 = getBin(SingleBin("name", Map("k1" -> List(1, 2, 3), "k2" -> 33))).value + val rMap7: JMap[String, Object] = Map[String, Object]("name" -> rValue7).asJava + val record7 = new Record(rMap7, 100, 12) + + val rhValue = new MapValue(Map(0 -> 1, 1 -> "aff", 2 -> 39.0, 3 -> List(1, 2), 4 -> List("a", "z")).asJava) + val rhMap: JMap[String, Object] = Map[String, Object]("name" -> rhValue).asJava + val recordh = new Record(rhMap, 100, 12) + + val rtValue2 = new MapValue(Map("0" -> 1L, "1" -> "aff").asJava) + val rtMap2: JMap[String, Object] = Map[String, Object]("name" -> rtValue2).asJava + val recordTuple2 = new Record(rtMap2, 100, 12) + + val rtValue3 = new MapValue(Map("0" -> 1, "1" -> "aff2", "2" -> 39.0).asJava) + val rtMap3: JMap[String, Object] = Map[String, Object]("name" -> rtValue3).asJava + val recordTuple3 = new Record(rtMap3, 100, 12) + + val rtValue4 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2)))).value + val rtMap4: JMap[String, Object] = Map[String, Object]("name" -> rtValue4).asJava + val recordTuple4 = new Record(rtMap4, 100, 12) + + val rtValue5 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z")))).value + val rtMap5: JMap[String, Object] = Map[String, Object]("name" -> rtValue5).asJava + val recordTuple5 = new Record(rtMap5, 100, 12) + + val rtValue6 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z"), "aff"))).value + val rtMap6: JMap[String, Object] = Map[String, Object]("name" -> rtValue6).asJava + val recordTuple6 = new Record(rtMap6, 100, 12) + + val rtValue7 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff"))).value + val rtMap7: JMap[String, Object] = Map[String, Object]("name" -> rtValue7).asJava + val recordTuple7 = new Record(rtMap7, 100, 12) + + val rtValue8 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", 39.0))).value + val rtMap8: JMap[String, Object] = Map[String, Object]("name" -> rtValue8).asJava + val recordTuple8 = new Record(rtMap8, 100, 12) + + val rtValue9 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z"), 1, "aff", 39.0, List(1, 2)))).value + val rtMap9: JMap[String, Object] = Map[String, Object]("name" -> rtValue9).asJava + val recordTuple9 = new Record(rtMap9, 100, 12) + + val rtValue10 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z"), + 1, "aff", 39.0, List(1, 2), List("a", "z")))).value + val rtMap10: JMap[String, Object] = Map[String, Object]("name" -> rtValue10).asJava + val recordTuple10 = new Record(rtMap10, 100, 12) + + val rtValue11 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z"), + 1, "aff", 39.0, List(1, 2), List("a", "z"), 22))).value + val rtMap11: JMap[String, Object] = Map[String, Object]("name" -> rtValue11).asJava + val recordTuple11 = new Record(rtMap11, 100, 12) + + val rtValue12 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z"), + 1, "aff", 39.0, List(1, 2), List("a", "z"), 22, "www"))).value + val rtMap12: JMap[String, Object] = Map[String, Object]("name" -> rtValue12).asJava + val recordTuple12 = new Record(rtMap12, 100, 12) + + val rtValue13 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z"), + 1, "aff", 39.0, List(1, 2), List("a", "z"), 22, "www", 3))).value + val rtMap13: JMap[String, Object] = Map[String, Object]("name" -> rtValue13).asJava + val recordTuple13 = new Record(rtMap13, 100, 12) + + val rtValue14 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z"), + 1, "aff", 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5)))).value + val rtMap14: JMap[String, Object] = Map[String, Object]("name" -> rtValue14).asJava + val recordTuple14 = new Record(rtMap14, 100, 12) + + val rtValue15 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z"), + 1, "aff", 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5), "www"))).value + val rtMap15: JMap[String, Object] = Map[String, Object]("name" -> rtValue15).asJava + val recordTuple15 = new Record(rtMap15, 100, 12) + + val rtValue16 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z"), + 1, "aff", 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5), "www", 4))).value + val rtMap16: JMap[String, Object] = Map[String, Object]("name" -> rtValue16).asJava + val recordTuple16 = new Record(rtMap16, 100, 12) + + val rtValue17 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z"), + 1, "aff", 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5), "www", 4, "kkk"))).value + val rtMap17: JMap[String, Object] = Map[String, Object]("name" -> rtValue17).asJava + val recordTuple17 = new Record(rtMap17, 100, 12) + + val rtValue18 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z"), + 1, "aff", 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5), "www", 4, "kkk", 8))).value + val rtMap18: JMap[String, Object] = Map[String, Object]("name" -> rtValue18).asJava + val recordTuple18 = new Record(rtMap18, 100, 12) + + val rtValue19 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z"), + 1, "aff", 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5), "www", 4, "kkk", 8, "kkkk"))).value + val rtMap19: JMap[String, Object] = Map[String, Object]("name" -> rtValue19).asJava + val recordTuple19 = new Record(rtMap19, 100, 12) + + val rtValue20 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z"), + 1, "aff", 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5), "www", 4, "kkk", 8, "kkkk", 9.0))).value + val rtMap20: JMap[String, Object] = Map[String, Object]("name" -> rtValue20).asJava + val recordTuple20 = new Record(rtMap20, 100, 12) + + val rtValue21 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z"), + 1, "aff", 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5), "www", 4, "kkk", 8, "kkkk", 9.0, true))).value + val rtMap21: JMap[String, Object] = Map[String, Object]("name" -> rtValue21).asJava + val recordTuple21 = new Record(rtMap21, 100, 12) + + val rtValue22 = getBin(SingleBin("name", (1, "aff", 39.0, List(1, 2), List("a", "z"), + 1, "aff", 39.0, List(1, 2), List("a", "z"), 22, "www", 3, List(4, 5), "www", 4, "kkk", 8, "kkkk", 9.0, true, "www"))).value + val rtMap22: JMap[String, Object] = Map[String, Object]("name" -> rtValue22).asJava + val recordTuple22 = new Record(rtMap22, 100, 12) + +} \ No newline at end of file