简体   繁体   English

Python Azure Databricks 创建增量表异常:不存在事务日志

[英]Python Azure Databricks create delta table exception: no transaction log present

I am using Azure Databricks and I am trying to create a Delta table.我正在使用 Azure Databricks,并且正在尝试创建一个 Delta 表。

Python code: Python代码:

delta_save_path = "/mnt/ops/test/alerts"
try: 
  sqlContext.sql("CREATE TABLE ops.test_alerts USING DELTA LOCATION '" + delta_save_path + "'")
except Exception as e:
  print(str(e))

Error message:错误信息:

You are trying to create an external table `ops`.`test_alerts`
from `/mnt/ops/test/alerts` using Databricks Delta, but there is no transaction log present at
`/mnt/ops/test/alerts/_delta_log`. Check the upstream job to make sure that it is writing using
format("delta") and that the path is the root of the table.

What am I doing wrong?我究竟做错了什么?

The syntax that you're using is when you want to create a table from the existing data.您使用的语法是当您想要从现有数据创建表时。 But it looks like that you're creating an empty table, so in this case you need to provide a schema for your table, like this (schema is fictious):但看起来您正在创建一个空表,因此在这种情况下,您需要为您的表提供一个架构,如下所示(架构是虚构的):

CREATE TABLE ops.test_alerts (
  id int,
  metric_nam string,
  timestamp timestamp
) USING DELTA 
LOCATION '<some location>'

See CREATE TABLE documentation for more details有关更多详细信息,请参阅CREATE TABLE 文档

delta_save_path = "/mnt/ops/test/alerts"

df = spark.read.format("csv").option("header", "false").load(delta_save_path)

df.write.format("delta").mode("overwrite").saveAsTable("ops.test_alerts")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM