This question already has answers here:
Dataframe from List<String> in Java
                            
                                (3个答案)
                            
                    
                9个月前关闭。
        

    

由于API的原因,我的测试程序需要获取Dataset<Row>来设置测试,但是我找不到比更简单的方法来使用createDataset()

Dataset<String> datasetString =
    spark.createDataset(Arrays.asList(
        "Country",
        "UK", "US", "UK", "US", "UK",
        "US", "UK", "US", "UK", "US")
        , Encoders.STRING());
Dataset<Row> dfOneCol =
    spark
        .read()
        .format("csv")
        .option("header", "true")
        .csv(datasetString);


有更简单的方法吗?

最佳答案

尝试这个:

List<String> points = Arrays.asList("UK", "US", "Foo", "Bar");
dataset = spark.createDataset(points, Encoders. STRING()).toDF("Country");


希望能帮助到你

关于java - Spark:将createDataset()转换为数据集<行>? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57462478/

10-11 04:54