'How to join several ArrayBuffer mutable in scala?
I have three 3 csv files. I put them in their ArrayBuffer collection.
How can I join one collection to another, and then the third file with this last one created?
val file_1_csv = Source.fromFile("./inputs/file_1.csv")
val file_2_csv = Source.fromFile("./inputs/file_2.csv")
val file_3_csv = Source.fromFile("./inputs/file_3.csv")
var collection_file1: ArrayBuffer[Model1] = ArrayBuffer()
var collection_file2: ArrayBuffer[Model2] = ArrayBuffer()
var collection_file3: ArrayBuffer[Model3] = ArrayBuffer()
var collection4: ArrayBuffer[Model4] = ArrayBuffer()
with models :
Model1(
"FK_ID" -> String,
"key1_f1" -> String,
"key2_f1" -> String,
"key3_f1" -> String,
)
Model2(
"FK_ID" -> String,
"FK_NUMBER" -> Int,
"key1_f2" -> String,
"key2_f2" -> String,
"key3_f2" -> String,
)
Model3(
"FK_ID" -> String,
"FK_NUMBER" -> Int,
"key1_f3" -> String,
"key2_f3" -> String,
"key3_f3" -> String,
)
Model4(
"FK_ID" -> String, => common for all models
"FK_NUMBER" -> Int, => common for all models
"key1_f1" -> String, => provide Model1
"key2_f2" -> String, => provide Model2
"key3_f3" -> String, => provide Model3
)
I use "for" to fill the collections of csv files
Return :
Model1("fkid", "fknumber", "value1", "value2", "value3")
Model2("fkid", "fknumber", "value4", "value5", "value6")
Model3("fkid", "fknumber", "value7", "value8", "value9")
Consolidate Collection4 information following rules::
Join file_1.FK_ID to file_2.FK_ID and to file_3.FK_ID => ID Join file_1.FK_NUMBER to file_2.FK_NUMBER and to file_3.FK_NUMBER => NUMBER
I must have a single collection which is the join of the 3 files.
I would like to get this result after the joins:
Model4("fkid", "fknumber", "value1", "value5", "value9")
the join is made with FK_ID and FK_NUMBER
Thanks for your answers.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
