.toMap shuffles my Items around / changes the order they were in, this messes with other parts of my code.
For example:
val seq = Seq("Test" -> DBType.Int, "Test2" -> DBType.Int, "Test3" -> DBType.Int);
val seqMap = seq.toMap;
println(seqMap)
The Output of this will be as expected:
Map(Test -> Int, Test2 -> Int, Test3 -> Int)
However, if I add more elements like this it gets weird:
val seq = Seq("Test" -> DBType.Int, "Test2" -> DBType.Int, "Test3" -> DBType.Int, "Test4" -> DBType.Int, "Test5" -> DBType.Int, "Test6" -> DBType.Int);
val seqMap = seq.toMap;
println(seqMap);
This will, and I really wanna know why, output this (the order has changed):
HashMap(Test3 -> Int, Test6 -> Int, Test5 -> Int, Test -> Int, Test4 -> Int, Test2 -> Int)
What the heck ? Did I not format it correctly ? Did I miss a comma ? I am really at the end of my expertise here.
I tried debugging it for almost an hour and a half but could not fix it. My idea would be that the .toMap function reshuffles the entire thing due to it being a HashMap now rather than a map, maybe the code in the background functions differently.
I am expecting my Seq of Tuples to be matches in order by the Map, as I need the keys to be in a specific (given) order.
I really hope someone can enlighten my why it behaves like this. I also did some google-ing but it just said: Use a Seq ! Well - duh - I am.
If you guys need more information on my code / problem feel free to comment.
EDIT: I am trying to join two tables together. One has a particular order of attributes and the other as well. My task is to join them in a fashion that the attributes of table 2 are being appended to those from table one. This however I have already managed. My problem is that the constructor of the schema class which is required to create a table wants to put these attributes in a map with the type they hold, f.e.: ("grade" -> Double)
So my order matters in that sens that the tests I am trying to full fill require me to have a specific order.