【问题标题】:Reading csv data into SparkR after writing it out from a DataFrame从 DataFrame 写出 csv 数据后将其读入 SparkR
【发布时间】:2017-06-09 17:28:14
【问题描述】:

我按照this post 中的示例将DataFrame 作为csv 写入AWS S3 存储桶。结果不是一个文件,而是一个包含许多 .csv 文件的文件夹。我现在无法在 SparkR 中以 DataFrame 形式读取此文件夹。以下是我尝试过的,但它们不会导致我写出的 DataFrame 相同。

write.df(df, 's3a://bucket/df', source="csv") #Creates a folder named df in S3 bucket

df_in1 <- read.df("s3a://bucket/df", source="csv")
df_in2 <- read.df("s3a://bucket/df/*.csv", source="csv")
#Neither df_in1 or df_in2 result in DataFrames that are the same as df

【问题讨论】:

    标签: sparkr databricks


    【解决方案1】:
    #  Spark 1.4 is used in this example
    # 
    # Download the nyc flights dataset as a CSV from https://s3-us-west-2.amazonaws.com/sparkr-data/nycflights13.csv
    
    # Launch SparkR using 
    # ./bin/sparkR --packages com.databricks:spark-csv_2.10:1.0.3
    
    # The SparkSQL context should already be created for you as sqlContext
    sqlContext
    # Java ref type org.apache.spark.sql.SQLContext id 1
    
    # Load the flights CSV file using `read.df`. Note that we use the CSV reader Spark package here.
    flights <- read.df(sqlContext, "./nycflights13.csv", "com.databricks.spark.csv", header="true")
    
    # Print the first few rows
    head(flights)
    

    希望这个例子有所帮助。

    【讨论】:

      猜你喜欢
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 2015-09-21
      • 2018-11-30
      • 2023-02-21
      • 2014-02-07
      • 2016-02-04
      • 2012-08-10
      相关资源
      最近更新 更多