从结构体获取结构体阵列

时间:2018-07-11 16:41:48

标签: scala apache-spark-sql

我有以下Spark SQL模式:

 |-- route: struct (nullable = true)
 |    |-- originCode: string (nullable = true)
 |    |-- originName: string (nullable = true)
 |    |-- originCountry: string (nullable = true)
 .    .   .
 .    .   .
 |    |-- actualTimeAverage: double (nullable = true)
 |    |-- legs: array (nullable = true)
 |    |    |-- element: array (containsNull = true)
 |    |    |    |-- element: struct (containsNull = true)
 |    |    |    |    |-- tenantId: string (nullable = true)
 |    |    |    |    |-- originCode: string (nullable = true)
 |    |    |    |    |-- originName: string (nullable = true)
 .    .    .    .    .
 .    .    .    .    .
 .    .    .    .    .

route的实例开始,我试图获取legs数组并在定义val时声明其类型。

我尝试过:

val atlLegs: Array[Array[Row]] = atlRoute.getAs[Array[Array[Row]]](atlRoute.fieldIndex("legs"))

但是,出现此运行时错误:

scala.collection.mutable.WrappedArray$ofRef cannot be cast to [[Lorg.apache.spark.sql.Row;
java.lang.ClassCastException: scala.collection.mutable.WrappedArray$ofRef cannot be cast to [[Lorg.apache.spark.sql.Row;

我应该给什么作为atlLegs类型?

0 个答案:

没有答案