【问题标题】:Postgres JAR with EMR and Jupyter Notebooks带有 EMR 和 Jupyter Notebooks 的 Postgres JAR
【发布时间】:2021-07-02 08:13:06
【问题描述】:

我正在尝试启动一个包含 Postgres 驱动程序 JAR 文件的 EMR 集群,以便我可以从 Postgres 加载数据并使用 PySpark 对其进行分析。我有我想包含在 S3 中的 JAR。我尝试了以下方法:

1 - 输入以下配置:

[
  {
    "Classification": "presto-connector-postgresql",
    "Properties": {
      "connection-url": "jdbc:postgresql://example.net:5432/database",
      "connection-user": "MYUSER",
      "connection-password": "MYPASS"
    },
    "Configurations": []
  }
]

2 - 添加 JAR 作为自定义步骤(从 S3 中选择 JAR)

3 - 将 JAR 添加为自定义引导操作(从 S3 中选择 JAR)

这些都不起作用,我不知道如何在 Jupyter 中的第 1 步中使用连接器,并且当我启动集群时,自定义步骤/引导操作都失败了。如何启动安装了 Postgres 驱动程序的 EMR 集群,以便在 Jupyter 中查询数据?

编辑:

我使用以下引导脚本将 JAR 复制到我的主/工作节点:

#!/bin/bash
aws s3 cp s3://BUCKETNAME/postgresql-42.2.8.jar /mnt1/myfolder

但还是报如下错误:

An error was encountered:
An error occurred while calling o90.load.
: java.lang.ClassNotFoundException: org.postgresql.Driver

使用以下代码:

df = spark.read \
    .format("jdbc") \
    .option("url", "jdbcURL") \
    .option("user", "user") \
    .option("password", "password") \
    .option("driver", "org.postgresql.Driver") \
    .option("query", "select * from slm_files limit 100") \
    .load()

df.count()

【问题讨论】:

    标签: postgresql amazon-web-services jupyter-notebook amazon-emr


    【解决方案1】:

    在我的 Jupyter 笔记本的第一个单元格中使用此代码为我解决了这个问题:

    %%configure -f
    { "conf":{
              "spark.jars": "s3://JAR-LOCATION/postgresql-42.2.8.jar"
             }
    }
    
    

    【讨论】:

    • 谢谢伙计,我被困在这个问题上很久了。这是一个救世主
    • 这适用于 Postgres。你知道如何为 Redshift 做这件事吗?我遇到了同样的红移错误
    • 尝试将 redshift jar 添加到 S3 中的该位置,并使 spark.jars 值成为包含两者的列表。虽然这对我来说也适用于 redshift,因为它使用 Postgres 语法
    • 无法以列表格式同时添加spark.jars。它一次只接受一个。但它以其他方式起作用。我直接将 jar 复制到 EMR 集群,它直接从那里提取。
    猜你喜欢
    • 2019-12-19
    • 1970-01-01
    • 2019-04-11
    • 2018-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-11
    相关资源
    最近更新 更多