내용으로 건너뛰기

如何在EMR上使用 Spark SQL 读取 Aurora Postgress 表

0

【以下的问题经过翻译处理】 使用 EMR 上的 Spark 读取 Aurora Postgres 表。已成功抓取 Aurora Postgres 表,并已创建 Glue 数据目录中的相应表。 EMR 集群已经配置了 Glue Data Catalog for Spark 以及以下文档中提到的配置。 https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-spark-glue.html

但是,当在 Spark 中对表运行查询时,出现以下错误。

scala> spark.sql("SELECT * FROM `aurora-glue`.`glue_public_distributors`")
18/09/11 14:17:40 WARN CredentialsLegacyConfigLocationProvider: Found the legacy config profiles file at [/home/hadoop/.aws/config]. Please move it to the latest default location [~/.aws/credentials].
org.apache.spark.sql.AnalysisException: org.apache.hadoop.hive.ql.metadata.HiveException: Unable to fetch table glue_public_distributors. StorageDescriptor#InputFormat cannot be null for table: glue_public_distributors (Service: null; Status Code: 0; Error Code: null; Request ID: null);
  at org.apache.spark.sql.hive.HiveExternalCatalog.withClient(HiveExternalCatalog.scala:106)
  at org.apache.spark.sql.hive.HiveExternalCatalog.tableExists(HiveExternalCatalog.scala:808)
  at org.apache.spark.sql.catalyst.catalog.SessionCatalog.tableExists(SessionCatalog.scala:385)
  at org.apache.spark.sql.catalyst.analysis.Analyzer$ResolveRelations$.isRunningDirectlyOnFiles(Analyzer.scala:682)
...

这里做错了什么吗?

전문가
질문됨 2년 전115회 조회
1개 답변
0

【以下的回答经过翻译处理】 这里不能使用 Glue Catalog 作为元数据存储在 Aurora Postgres 上运行 Spark SQL。就像 Athena 一样,Spark SQL 只能对 S3 中的表使用 Glue Catalog。要在 Aurora Postgres 上运行 Spark SQL,需要使用 Spark JDBC 包来直接查询数据库。

properties = {
    ...
    "driver": "org.postgresql.Driver"
}
jdbc_url='<jdbc-url>'
df=spark.read.jdbc(url=jdbc_url, table='<tablename>', properties=properties)
전문가
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.