【问题标题】:Databricks on Apache Spark AttributeError: 'str' object has no attribute '_jvm'Apache Spark AttributeError 上的 Databricks:“str”对象没有属性“_jvm”
【发布时间】:2022-06-20 04:03:09
【问题描述】:

当尝试使用 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()

有没有人遇到过这个错误并找到了解决办法?

【问题讨论】:

    标签: apache-spark databricks azure-databricks azure-eventhub


    【解决方案1】:

    不应该是sparkContext,而应该是sc

    ehConf['eventhubs.connectionString'] = sc._jvm.org.apache.spark.eventhubs.EventHubsUtils.encrypt(connectionString)
    

    附:但是使用带有 EventHubs 的内置 Kafka 连接器更容易——您不需要安装任何东西,而且它的性能更高......

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-10
    • 2021-10-04
    相关资源
    最近更新 更多