带spark 2.4的linesep选件

xdnvmnnf  于 2021-07-14  发布在  Spark
关注(0)|答案(1)|浏览(386)

lineSep 该选项确实适用于spark 2.4版本。

lineSep (default covers all \r, \r\n and \n): defines the line separator that should be used for parsing. Maximum length is 1 character.

我正在向gcs bucket location写入Dataframe,但它总是使用行分隔符作为 '\n' 只是。

df
  .select("COLLECTTIME","SITE","NETWORK")
  .coalesce(1)
  .limit(10)
  .write
  .option("header", false)
  .option("compression", "gzip")
  .option("lineSep","\r\n")
  .csv(tmpOutput)

我在找 CRLF 在每行的末尾。
我也试过了,但没用

df2.withColumn(df2.columns.last,concat(col(df2.columns.last),lit("\r")))
  .write
  .option("header", false)
  .option("compression", "gzip")
  .csv(tmpOutput)

我也试过了,但没有成功。

import org.apache.spark.sql.functions._
df2.withColumn(df2.columns.last,regexp_replace(col(df2.columns.last),"[\\r]","[\\r\\n]"))
  .write
  .option("header", false)
  .option("compression", "gzip")
  .csv(tmpOutput)

现在我想再看一遍 GCS 一旦它被写入并逐行读取,并在每条记录的末尾附加'\r'。是不是有一些简短和简单的 Spark 2.4 . 我只需要 'CRLF' 在每个记录的末尾。
读取和更新也是不可能的,因为gcs存储桶上存储的对象是不可变的。我不能把文件放在缓冲区,因为它们的大小也有点大

vcudknz3

vcudknz31#

很抱歉,不过,恐怕spark允许您在问题中引用不同的分隔符:

lineSep (default covers all \r, \r\n and \n): defines the line separator that should be used for parsing. Maximum length is 1 character.

只为阅读,不为写作;在后一种情况下 \n 是硬编码的,或者,因为spark版本 2.4 以及 3.0 ,可以选择自定义行分隔符,但限制为单个字符。
请考虑阅读这个github问题,它提供了关于这个问题的全部背景。另一个也会有帮助。

相关问题