xml - 使用 Spark 加载 XML 时推断架构中的重复字段
问题描述
我想在这个结构中创建一个模式:
| |-- Features: struct (nullable = true)
| | |-- Feature: array (nullable = true)
| | | |-- element: string (containsNull = true)
这是我的代码:
StructField( "Features", StructType(
Array(
StructField( "Feature", ArrayType(
StructType(
Array(
StructField( "element", StringType, true )
)
)
) )
)
), true )
结果:
| |-- Features: struct (nullable = true)
| | |-- Feature: array (nullable = true)
| | | |-- element: struct (containsNull = true)
| | | | |-- element: string (nullable = true)
有什么想法吗?
解决方案
你应该省略最里面的struct
:
import org.apache.spark.sql.types._
import org.apache.spark.sql.Row
val schema = StructType(Seq(StructField("Features", StructType(Seq(
StructField("Feature", ArrayType(StringType))
)))))
spark.createDataFrame(spark.sparkContext.emptyRDD[Row], schema).printSchema
// root
// |-- Features: struct (nullable = true)
// | |-- Feature: array (nullable = true)
// | | |-- element: string (containsNull = true)
推荐阅读
- r - 单行数据的 PLS-DA 预测返回多个预测
- c# - 如何在 AJAX 成功中访问 viewbag 值?
- firefox - 是否可以获得在 Firefox 浏览器中打开的标签数量?
- android - Android:找不到`androidx.navigation.NavArgs`
- mysql - 将日期显示为列别名
- c - 一个函数在我使用 gcc 时有效,但是当我使用 Microsoft Visual Studio 的编译器时它什么也不做
- angular - ng 格式化表格
- c - 为什么我得到这个代码的错误输出(打印数组中的回文数)?
- r - 如何将数据框中给出的列表转换为 R 数据框中的因子/数字?
- android - 如何使用服务访问广播接收器中的电池电量以给我杀死结果?