Apache spark Spark:将字符串转换为scala中的Spark.sql.types对象
我在scala中有一个字符串数组Apache spark Spark:将字符串转换为scala中的Spark.sql.types对象,apache-spark,apache-spark-sql,spark-streaming,Apache Spark,Apache Spark Sql,Spark Streaming,我在scala中有一个字符串数组{“StringType”,IntegerType,“LongType”,“StringType”}。 我需要在迭代时将每个字符串转换为spark.sql.types对象 例如: StringType = spark.sql.types.StringType IntegerType = spark.sql.types.IntegerType LongType = spark.sql.types.LongType. 一种解决方案是创建字符串和spark.sql.
{“StringType”,IntegerType,“LongType”,“StringType”}
。
我需要在迭代时将每个字符串转换为spark.sql.types对象
例如:
StringType = spark.sql.types.StringType
IntegerType = spark.sql.types.IntegerType
LongType = spark.sql.types.LongType.
一种解决方案是创建字符串和spark.sql.types的1对1哈希映射,并在迭代数组时使用它。
还有其他更干净的方法吗?我可能只会使用scala模式匹配。比如:
import org.apache.spark.sql.types._
val typeList = inputArray.map(s => {
s match {
case "StringType" => StringType
case "IntegerType" => IntegerType
etc...
case _ => throw new RuntimeException("unknown type")
}
})