I am a new developer on Spark & Scala and I want to do an easy thing (I think..) :
So, my code looks like this :
var a
var b
var c
def myfunction() : (Int, Int, Int) = {
val tmp = spark.sql(""" select col1, col2, col3 from table
LIMIT 1
""")
return (tmp.collect(0)(0), tmp.collect(0)(1), tmp.collect(0)(2))
}
So, the idea if to call my function like this :
a, b, c = myfunction()
I tried a lot of configurations but I get many different errors each time, so, I got confused.
You could just use destructuring bind. Since your method returns tuple you can unpack it using pattern matching:
val (a, b, c) = myfunction()
a, b and c will contain consecutive elements of the tuple.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With