提问人:LearneR 提问时间:11/16/2023 最后编辑:LearneR 更新时间:11/16/2023 访问量:31
如何从 Azure Databricks 输出“基础 SQLException”而不是一般异常消息?
How to output the 'Underlying SQLException' from Azure Databricks instead of the generic exception message?
问:
我们从数据工厂管道调用 Azure Databricks 笔记本,该管道将引入到 Azure Synapse 中。但是,每当笔记本运行失败时,它只会显示以下错误消息:
com.databricks.spark.sqldw.SqlDWSideException: Azure Synapse Analytics failed to execute the JDBC query produced by the connector.
但是,当我们进入运行日志并向下滚动到此异常消息时,在此消息的正下方,将有
Underlying SQLException(s):
- com.microsoft.sqlserver.jdbc.SQLServerException: HdfsBridge::recordReaderFillBuffer - Unexpected error encountered filling record reader buffer: HadoopExecutionException: The column [4] is not nullable and also USE_DEFAULT_VALUE is false, thus empty input is not allowed. [ErrorCode = 107090] [SQLState = S0001]
或者有时它会像:
Underlying SQLException(s):
- com.microsoft.sqlserver.jdbc.SQLServerException: HdfsBridge::recordReaderFillBuffer - Unexpected error encountered filling record reader buffer: HadoopExecutionException: String or Binary would be truncated
我们用于引入数据的代码是:
try:
data.write.format('com.databricks.spark.sqldw').option("url", connection_string).option("dbTable", table) \
.option("driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver") \
.option("tempDir", Connection.storageaccount_path + 'store/dataload')
.save(mode="append")
except Exception as e:
raise Exception("error took place for table: " + table + " : " + str(e))
因此,这是实际的错误消息,说明出了什么问题。但它永远不会显示在我们在 ADF 管道上看到的输出中。因此,我们无法使用 .我们总是必须手动向下滚动到错误日志中,一个接一个地失败。Underlying SQLException(s):
runError
Azure Log Analytics
我们每天在生产环境中进行数千次运行,许多管道经常出现故障。但是,由于在查看确切错误消息方面的限制,我们无法有效地监视故障。
有没有办法让 Databricks 输出而不是泛型消息:Underlying SQLException(s):
com.databricks.spark.sqldw.SqlDWSideException: Azure Synapse Analytics failed to execute the JDBC query produced by the connector.
答:
要获取实际错误消息而不是通用错误消息,您需要使用适当的分隔符将其拆分,并根据索引号获取实际错误消息。
try:
df1.write.format('com.databricks.spark.sqldw').option("url", "URL").option("dbTable", "demo4") \
.option("driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver") \
.option("tempDir", "tempdir") \
.option("forwardSparkAzureStorageCredentials", "true") \
.save(mode="append")
except Exception as e:
error_message = str(e)
error_parts = error_message.split('\n')
print("Error occurred:",error_parts[2],error_parts[3],error_parts[4])
在这里,我将错误消息与(新行)一起溢出到数组中,为了获得预期的结果,我调用了拆分数组的第 2、3、4 个索引元素。\n
我的执行:
评论
try / except
"error took place for table:"