使用火花2.1
我在里面创建了一个带有MapDataType的DataSet
StructType schema = new StructType(new StructField[]{
new StructField("id", DataTypes.IntegerType, false, Metadata.empty()),
new StructField("words", DataTypes.StringType, false, Metadata.empty()),
new StructField("label", DataTypes.IntegerType, false, Metadata.empty()),
new StructField("features", DataTypes.createMapType(DataTypes.StringType, DataTypes.IntegerType), false, Metadata.empty())
});
Map<String,Integer> abc = new HashMap<String,Integer>();
abc.put("abc", 1);
Row r = RowFactory.create(0, "Hi these are words ", 1, abc);
List<Row> data = Arrays.asList(r);
Dataset<Row> wordDataFrame = spark.createDataFrame(data, schema);
wordDataFrame.show();
Run Code Online (Sandbox Code Playgroud)
以上代码工作正常.
但是当我尝试在这个DataSet上调用map函数(用新的HashMap替换Map DataType条目)时,我收到以下错误.
StructType schema = new StructType(new StructField[]{
new StructField("id", DataTypes.IntegerType, false, Metadata.empty()),
new StructField("words", DataTypes.StringType, false, Metadata.empty()),
new StructField("label", DataTypes.IntegerType, …Run Code Online (Sandbox Code Playgroud)