在 Apache Spark 中从另一个创建 table 时出错

Error while creating a table from another one in Apache Spark

我正在按以下方式创建 table:

spark.sql("CREATE TABLE IF NOT EXISTS table USING DELTA AS SELECT * FROM origin")

但是我得到这个错误:

Exception in thread "main" org.apache.spark.SparkException: Table implementation does not support writes: table

您会收到此 SparkException 错误,因为未实现使用 SQL 请求作为输入数据来创建增量湖 table 的方法。

如果你想创建一个 delta-lake table 并同时插入数据,你应该使用 DataFrameWriter API,如 databricks documentation:

spark.sql("SELECT * FROM origin")
  .write
  .format("delta")
  .save("/path/to/where/you/want/to/save/your/data")