Dataframe保存模式

示例代码:

val dataframe =  sqlContext.read.parquet("读取路径")

dataframe.write.mode("overwrite").parquet("写入路径")


overwrite是dataframe写入的一种模式,dataframe写入的模式一共有4中

def mode(saveMode: String): DataFrameWriter = {
    this.mode = saveMode.toLowerCase match {
      case "overwrite" => SaveMode.Overwrite              // 覆盖已经存在的文件
      case "append" => SaveMode.Append                    // 向存在的文件追加
      case "ignore" => SaveMode.Ignore                    // 如果文件已存在,则忽略保存操作
      case "error" | "default" => SaveMode.ErrorIfExists  // 如果文件存在,则报错
      case _ => throw new IllegalArgumentException(s"Unknown save mode: $saveMode. " +
        "Accepted modes are 'overwrite', 'append', 'ignore', 'error'.")
    }
    this
  }


你可能感兴趣的:(Dataframe保存模式)