我在閱讀databricks博客link 我發現內置函數to_json
有問題。 在代碼本教程中自爆,則返回錯誤:to_json不能在selectExpr中使用spark
org.apache.spark.sql.AnalysisException: Undefined function: 'to_json'. This function is neither a registered temporary function nor a permanent function registered in the database 'default'.
這是否意味着這種用法在本教程是錯誤的?並且在selectExpr
中不能使用udf。我可以做一些像註冊這個to_json
函數到默認數據庫嗎?
val deviceAlertQuery = notifydevicesDS
.selectExpr("CAST(dcId AS STRING) AS key", "to_json(struct(*)) AS value")
.writeStream
.format("kafka")
.option("kafka.bootstrap.servers", "host1:port1,host2:port2")
.option("toipic", "device_alerts")
.start()
我試過但沒有工作。任何想法? –
你是否試圖將所有列更改爲json作爲一列並寫入? –
更新了答案:) –