嘗試使用 Apache Spark 上的 Databricks 從 Azure 事件中心讀取流資料時出現錯誤
AttributeError: 'str' object has no attribute '_jvm'
錯誤詳情如下:
----> 8 ehConf['eventhubs.connectionString'] = sparkContext._jvm.org.apache.spark.eventhubs.EventHubsUtils.encrypt(connectionString)
代碼如下:
sparkContext = ""
connectionString = 'Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=both4;SharedAccessKey=adfdMyKeyIGBKYBs=;EntityPath=hubv5'
# Source with default settings
connectionString = connectionString
ehConf = {}
ehConf['eventhubs.connectionString'] = sparkContext._jvm.org.apache.spark.eventhubs.EventHubsUtils.encrypt(connectionString)
streaming_df = spark \
.readStream \
.format("eventhubs") \
.options(**ehConf) \
.load()
有沒有人遇到過這個錯誤并找到了解決方案?
uj5u.com熱心網友回復:
它不應該是sparkContext,而只是sc:
ehConf['eventhubs.connectionString'] = sc._jvm.org.apache.spark.eventhubs.EventHubsUtils.encrypt(connectionString)
PS 但是使用帶有 EventHubs 的內置 Kafka 連接器更容易 - 你不需要安裝任何東西,而且它的性能更高......
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/447326.html
