Skip to content

Commit b4a1b32

Browse files
akudiyarAlexey Kuzin
authored and
Alexey Kuzin
committed
Add tests for row-to-tuple conversion
1 parent b6703b9 commit b4a1b32

File tree

1 file changed

+109
-1
lines changed

1 file changed

+109
-1
lines changed

src/test/scala/org/apache/spark/sql/tarantool/MapFunctionsSpec.scala

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import org.scalatest.flatspec.AnyFlatSpec
1515
import org.scalatest.matchers.should.Matchers
1616

1717
import java.time.Instant
18-
import scala.collection.JavaConverters.{mapAsJavaMapConverter, seqAsJavaListConverter}
18+
import scala.collection.JavaConverters.{
19+
iterableAsScalaIterableConverter,
20+
mapAsJavaMapConverter,
21+
seqAsJavaListConverter
22+
}
1923

2024
/**
2125
*
@@ -153,4 +157,108 @@ class MapFunctionsSpec extends AnyFlatSpec with Matchers {
153157

154158
forAll(row.toSeq.zip(expected.toSeq))(tuple => tuple._1 should equal(tuple._2))
155159
}
160+
161+
it should "convert an empty row to an empty tuple" in {
162+
val row = Row()
163+
val tuple = MapFunctions.rowToTuple(tupleFactory, row)
164+
165+
tuple should not be null
166+
tuple.size should equal(0)
167+
}
168+
169+
it should "convert a row with simple values of different types" in {
170+
val time = Instant.now().getEpochSecond
171+
val row = Row(
172+
"Akakiy",
173+
"Akakievich",
174+
"Ivanov",
175+
null,
176+
38,
177+
new java.math.BigDecimal(200),
178+
0.5f,
179+
Math.PI,
180+
false,
181+
time
182+
)
183+
184+
val tuple = MapFunctions.rowToTuple(tupleFactory, row)
185+
186+
val expected = new TarantoolTupleImpl(
187+
Seq(
188+
"Akakiy",
189+
"Akakievich",
190+
"Ivanov",
191+
null,
192+
38,
193+
new java.math.BigDecimal(200),
194+
0.5f,
195+
Math.PI,
196+
false,
197+
time
198+
).asJava,
199+
defaultMapper,
200+
TestSpaceMetadata()
201+
)
202+
203+
tuple should not be null
204+
tuple.size should equal(simpleSchema.length)
205+
206+
for ((f1, f2) <- tuple.asScala.toSeq.zip(expected.asScala.toSeq)) {
207+
f1 should equal(f2)
208+
}
209+
}
210+
211+
it should "convert a row with array values" in {
212+
val time = Instant.now().getEpochSecond
213+
val row = Row(
214+
null,
215+
List(1, 2, 3, 4).asJava,
216+
time
217+
)
218+
219+
val tuple = MapFunctions.rowToTuple(tupleFactory, row)
220+
val expected = new TarantoolTupleImpl(
221+
Seq(
222+
null,
223+
List(1, 2, 3, 4).asJava,
224+
time
225+
).asJava,
226+
defaultMapper,
227+
TestSpaceWithArrayMetadata()
228+
)
229+
230+
tuple should not be null
231+
tuple.size should equal(simpleSchemaWithArray.length)
232+
233+
for ((f1, f2) <- tuple.asScala.toSeq.zip(expected.asScala.toSeq)) {
234+
f1 should equal(f2)
235+
}
236+
}
237+
238+
it should "convert a row with map values" in {
239+
val time = Instant.now().getEpochSecond
240+
val row = Row(
241+
null,
242+
Map("host" -> "127.0.0.1", "port" -> "3301").asJava,
243+
time
244+
)
245+
246+
val tuple = MapFunctions.rowToTuple(tupleFactory, row)
247+
val expected = new TarantoolTupleImpl(
248+
Seq(
249+
null,
250+
Map("host" -> "127.0.0.1", "port" -> "3301").asJava,
251+
time
252+
).asJava,
253+
defaultMapper,
254+
TestSpaceWithMapMetadata()
255+
)
256+
257+
tuple should not be null
258+
tuple.size should equal(simpleSchemaWithMap.length)
259+
260+
for ((f1, f2) <- tuple.asScala.toSeq.zip(expected.asScala.toSeq)) {
261+
f1 should equal(f2)
262+
}
263+
}
156264
}

0 commit comments

Comments
 (0)