【发布时间】:2019-01-30 10:19:50
【问题描述】:
这是使用表达式(字符串)的评估(Eval 或类似的东西)将数据帧写入 Scala 中的 csv 文件。
import org.apache.spark.sql.{SaveMode, SparkSession, SQLContext, Row, DataFrame, Column}
import scala.reflect.runtime.universe._
import scala.tools.reflect.ToolBox
import scala.reflect.runtime.currentMirror
val df = Seq(("a", "b", "c"), ("a1", "b1", "c1")).toDF("A", "B", "C")
val df_write = """df.coalesce(1).write.option("delimiter", "\u001F").csv("file:///var/tmp/test")"""
// This is one of my failed attempts - I have tried using the interpreter as well (code not shown here).
val tb = runtimeMirror(getClass.getClassLoader).mkToolBox()
toolbox.eval(toolbox.parse(df_write))
Errors are:
object coalesce is not a member of package df ....
【问题讨论】:
标签: scala csv dataframe expression eval