gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 08:01:21 26 4
gpt4 key购买 nike

我正在尝试弄清楚如何将用例从 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com