【问题标题】:Read csv file from S3 into spark in R将 S3 中的 csv 文件读入 R 中的 spark
【发布时间】:2020-04-22 12:27:40
【问题描述】:

我有下面的代码将 s3 中的 csv 读入 spark

test_data <- spark_read_csv(
  sc,
  name = "Invites",
  memory = FALSE,
  path = "s3://xxxx/customer/Sample.csv")


csvcharobj <- rawToChar(test_data)  
con <- textConnection(csvcharobj)  
data <- read.csv(file = con)

但代码失败并出现以下错误

> csvcharobj <- rawToChar(test_data)  
Error in rawToChar(test_data) : argument 'x' must be a raw vector

【问题讨论】:

    标签: r amazon-s3 apache-spark-sql


    【解决方案1】:

    我已将代码更改如下,它确实有效

    test_data <- spark_read_csv(
      sc,
      name = "Invites",
      memory = FALSE,
      path = "s3://xxxx/customer/Sample.csv")
    
    
    test <- as.data.table(test_data)
    
    cols_to_mask <- c("EmailAddress")
    
    anonymize <- function(x, algo="crc32") {
      sapply(x, function(y) if(y == "" | is.na(y)) "" else digest(y, algo = algo))
    }
    
    setDT(test)
    
    test[, (cols_to_mask) := lapply(.SD, anonymize), .SDcols = cols_to_mask]
    
    print(test)
    
    
    

    【讨论】:

      猜你喜欢
      • 2021-11-20
      • 1970-01-01
      • 2016-01-01
      • 2022-01-13
      • 2015-09-24
      • 1970-01-01
      • 2020-08-11
      • 2015-12-04
      • 2023-04-08
      相关资源
      最近更新 更多