我正在使用Java中的Spark,并从一个Row类型的RDD创建一个行数据集(Dataset of Row)。
我使用以下方法创建模式:
Metadata meta = new MetadataBuilder().putString("type", "categorical").build();
StructField s = new StructField(name, IntegerType, true, meta);
StructType t = new StructType(new StructField[]{s});
Encoder<Row> encoder = RowEncoder.apply(t);
我在数据集中使用它,就像这样
ds.flatMap((FlatMapFunction<Row, Row>) this::customFlatMapRow, encoder);
由于某些原因,我在编写表格后检查模式的字段及其元数据为空(尽管我像上面那样创建并设置了它们)。不知何故,我失去了它们。