I know this maybe like basic question, but I searched the web still cannot find the right answer.
I have a list in Spark that looks like:
List[(String,Timestamp,Timestamp)]
I want to retrieve the second element within the first element (ie the first Timestamp that appears in the list above). My understanding is to use something like the following syntax:
a(0)(1)
However, it seems it's not a multi-dimensional List, so I can't use this syntax.
How to get the element I want out of this list?
As mentioned the example list is not multidimensional, So one option to get the value can be iterating through the list.
For eg: Used below list as example
List((StringType,DoubleType,DoubleType,IntegerType))
def main(args: Array[String]): Unit = {
val spark = SparkSession
.builder()
.config("spark.master", "local[1]")
.appName("")
.getOrCreate()
var dataTypeList = List((StringType,DoubleType,DoubleType,IntegerType))
dataTypeList.map { x => println(x._2)}
}
Output
DoubleType
List[(String,Timestamp,Timestamp)]
is a list of Tuple3
.
To get the timestamp, you should:
a(0)._2
instead of:
a(0)(1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.