amazon-web-services - 从 AWS Glue 作业中引用 Hive View

标签 amazon-web-services apache-spark hive aws-glue

我正在尝试弄清楚如何将用例从 EMR 迁移到涉及 Hive View 的 AWS Glue。

在今天的 EMR 中,我在 S3 中有由 Parquet 支持的 Hive 外部表,我还有其他 View ,例如 create view hive_view as select col from external_table where col = x

然后在 EMR 上的 Spark 中,我可以发出类似 df = spark.sql("select * from hive_view") 的语句来引用我的 Hive View 。

我知道我可以使用 Glue 目录作为 Hive 元存储的直接替代品,但我正在尝试将 Spark 作业本身从 EMR 迁移到 Glue。所以在我的最终状态下,不再有 Hive 端点,只有 Glue。

问题:

  • 如果我不再有 EMR 集群来发出 Hive 命令,我该如何替换 create view ... 语句?什么是等效的 AWS Glue SDK 调用?

  • 如何从 Glue 作业中引用这些 View ?

到目前为止我已经尝试过:使用 boto3 像这样调用 glue.create_table

glue = boto3.client('glue')
glue.create_table(DatabaseName='glue_db_name', 
   TableInput = {'Name': 'hive_view', 
       'TableType': 'VIRTUAL_VIEW',
       'ViewExpandedText': 'select .... from ...'
    })

我可以看到在 Glue 目录中创建的对象,但分类显示为“未知”并且作业中的引用失败并出现相应的错误:

py4j.protocol.Py4JJavaError: An error occurred while calling o56.getCatalogSource. : 
java.lang.Error: No classification or connection in bill_glue_poc.view_test at ...

我已验证我可以在 EMR 中将 Hive View 与 Spark 一起使用,并将 Glue 目录作为元存储——我在 Glue 目录中看到了 View ,并且 Spark SQL 查询成功,但我无法从 Glue 中引用 View 工作。

最佳答案

您可以 create a temporary view in Spark并像 Hive 表 (Scala) 一样查询它:

val dataDyf = glueContext.getSourceWithFormat(
      connectionType = "s3",
      format = "parquet",
      options = JsonOptions(Map(
        "paths" -> Array("s3://bucket/external/folder")
      ))).getDynamicFrame()

// Convert DynamicFrame to Spark's DataFrame and apply filtering
val dataViewDf = dataDyf.toDF().where(...)

dataViewDf.createOrReplaceTempView("hive_view")

val df = spark.sql("select * from hive_view")

关于amazon-web-services - 从 AWS Glue 作业中引用 Hive View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54423899/

相关文章:

apache-spark - 无法访问 Kubernetes 端点

algorithm - 如何在 Scala 中的数据框中获取成对的 x 值?

java - 使用 Spark DataFrame 发展模式

hadoop - Hive - 如何获得每组值的分位数

hadoop - 用Unicode表示法解析Hive DDL

ios - 没有这样的文件位置 - 将图像从 Swift 上传到 S3

python - AWS boto 和 boto3 有什么区别

php - 面临来自 AWS S3 的图像加载问题

amazon-web-services - 如何排查 AWS 目标组中的不健康状态代码

hive - 带有 Hive 1.1 (CDH 5.7.1) 的 Apache NiFi Hive 处理器