

# 将 AWS Glue for Spark 作业迁移到 AWS Glue 版本 5.1
<a name="migrating-version-51"></a>

本主题介绍 AWS Glue 版本 0.9、1.0、2.0、3.0、4.0 和 5.0 之间的变化，允许您将 Spark 应用程序和 ETL 作业迁移到 AWS Glue 5.1。它还介绍了 AWS Glue 5.1 中的功能以及使用它的优点。

要将此功能与 AWS Glue ETL 任务结合使用，请在创建任务时为 `Glue version` 选择 **5.1**。

**Topics**
+ [新特征](#migrating-version-51-features)
+ [用于迁移到 AWS Glue 5.1 的操作](#migrating-version-51-actions)
+ [迁移核对清单](#migrating-version-51-checklist)
+ [从 AWS Glue 5.0 迁移到 AWS Glue 5.1](#migrating-version-51-from-50)
+ [从旧的 AWS Glue 版本迁移到 AWS Glue 5.1](#migrating-older-versions-to-51)
+ [AWS Glue 5.1 的连接器和 JDBC 驱动程序迁移](#migrating-version-51-connector-driver-migration)

## 新特征
<a name="migrating-version-51-features"></a>

此部分介绍 AWS Glue 版本 5.1 的新功能和优势。
+ Apache Spark 从 AWS Glue 5.0 中的 3.5.4 更新到 AWS Glue 5.1 中的 3.5.6。
+ 开放表格式 (OTF) 已更新至 Hudi 1.0.2、Iceberg 1.10.0 和 Delta Lake 3.3.2
+ **Iceberg 实体化视图**：创建和管理 Iceberg 实体化视图（MV）。有关更多信息，请参阅[博客文章](https://aws.amazon.com/blogs/big-data/introducing-apache-iceberg-materialized-views-in-aws-glue-data-catalog/) 
+ **Iceberg 格式版本 3.0**：扩展数据类型和现有元数据结构以添加新功能。有关更多信息，请参阅 [Iceberg Table Spec](https://iceberg.apache.org/spec/)。
+ **Hudi 全表访问**：Apache Spark 中的 Apache Hudi 全表访问（FTA）控制，具体取决于您在 AWS Lake Formation 中定义的策略。当作业角色具有全表访问权限时，您可以借助此功能从 AWS Glue ETL 作业在 AWS Lake Formation 注册的表上执行读写操作。
+ **使用 AWS Lake Formation 的 Spark 原生精细访问控制（FGAC）支持**：对在 AWS Lake Formation 中注册的 Apache Hive、Apache Iceberg 和 Delta Lake 表执行精细访问控制的 DDL/DML 操作（如 CREATE、ALTER、DELETE、DROP）。
+ **Spark 作业的审计上下文**：AWS Glue ETL 作业的审计上下文将可用于 AWS CloudTrail 日志中的 AWS Glue 和 AWS Lake Formation API 调用。

**已知问题和限制**  
请注意以下已知问题和限制：
+ 对用于创建实体化视图、查询重写和增量刷新的视图 SQL 子句的支持有限。更多详情请参阅 [Iceberg 实体化视图功能文档页面](https://docs.aws.amazon.com/lake-formation/latest/dg/materialized-views.html#materialized-views-considerations-limitations) 
+ **Hudi FTA 写入**要求在作业执行期间使用 HoodieCredentialedHadoopStorage 进行凭证下发。运行 Hudi 作业时设置以下配置：

  `hoodie.storage.class=org.apache.spark.sql.hudi.storage.HoodieCredentialedHadoopStorage` 
+ Hudi FTA 写入支持仅适用于默认 Hudi 配置。自定义或非默认 Hudi 设置可能无法完全支持，并可能导致意外行为。在 FTA 写入模式下，也不支持 Hudi 读取时合并（MOR）表的聚类功能。

**重大更改**  
请注意以下重大更改：
+  S3A 文件系统已取代 EMRFS 成为默认 S3 连接器。有关如何迁移的信息，请参阅[从 AWS Glue 5.0 迁移到 AWS Glue 5.1](#migrating-version-51-from-50)。

## 用于迁移到 AWS Glue 5.1 的操作
<a name="migrating-version-51-actions"></a>

对于现有任务，请将 `Glue version` 从以前的版本更改为任务配置中的 `Glue 5.1`。
+ 在 AWS Glue Studio 中，为 `Glue version` 选择 `Glue 5.1 - Supports Spark 3.5.6, Scala 2, Python 3`。
+ 在 API 中，为 [https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-jobs-job.html#aws-glue-api-jobs-job-UpdateJob](https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-jobs-job.html#aws-glue-api-jobs-job-UpdateJob) API 操作中的 `GlueVersion` 参数选择 **5.1**。

对于新任务，请在创建任务时选择 `Glue 5.1`。
+ 在控制台中，为 `Glue version` 选择 `Spark 3.5.6, Python 3 (Glue Version 5.1) or Spark 3.5.6, Scala 2 (Glue Version 5.1)`。
+ 在 AWS Glue Studio 中，为 `Glue version` 选择 `Glue 5.1 - Supports Spark 3.5.6, Scala 2, Python 3`。
+ 在 API 中，为 [https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-jobs-job.html#aws-glue-api-jobs-job-CreateJob](https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-jobs-job.html#aws-glue-api-jobs-job-CreateJob) API 操作中的 `GlueVersion` 参数选择 **5.1**。

要查看 AWS Glue 5.1中来源于 AWS Glue 2.0或更早版本的Spark事件日志，请[使用 CloudFormation 或 Docker 为 AWS Glue 5.1 启动已升级的 Spark 历史记录服务器](https://docs.aws.amazon.com/glue/latest/dg/monitor-spark-ui-history.html)。

## 迁移核对清单
<a name="migrating-version-51-checklist"></a>

查看此核对清单以进行迁移：
+ [Python] 将 boto 引用从 1.34 更新到 1.40。

## 从 AWS Glue 5.0 迁移到 AWS Glue 5.1
<a name="migrating-version-51-from-50"></a>

所有现有任务参数和 AWS Glue 5.0 中存在的主要功能将存在于 AWS Glue 5.1。迁移时，请注意以下更改：
+ 在 AWS Glue 5.1 中，S3A 文件系统已取代 EMRFS 成为默认 S3 连接器。如果 `spark.hadoop.fs.s3a.endpoint` 和 `spark.hadoop.fs.s3a.endpoint.region` 均未设置，则 S3A 使用的默认区域为 `us-east-2`。这可能会导致 S3 上传超时错误等问题，尤其是对于 VPC 作业。要缓解此更改导致的问题，在 AWS Glue 5.1 中使用 S3A 文件系统时，设置 `spark.hadoop.fs.s3a.endpoint.region` Spark 配置。
+ 要继续使用 EMRFS 而不是 S3A，请设置以下 Spark 配置：

  ```
      --conf spark.hadoop.fs.s3.impl=com.amazon.ws.emr.hadoop.fs.EmrFileSystem
      --conf spark.hadoop.fs.s3n.impl=com.amazon.ws.emr.hadoop.fs.EmrFileSystem
      --conf spark.hadoop.fs.AbstractFileSystem.s3.impl=org.apache.hadoop.fs.s3.EMRFSDelegate
  ```

请参阅 Spark 迁移文档：
+ [Migration Guide: Spark Core](https://spark.apache.org/docs/3.5.6/core-migration-guide.html)
+ [Migration Guide: SQL, Datasets and DataFrame](https://spark.apache.org/docs/3.5.6/sql-migration-guide.html)
+ [Migration Guide: Structured Streaming](https://spark.apache.org/docs/3.5.6/ss-migration-guide.html)
+ [Upgrading PySpark](https://spark.apache.org/docs/3.5.6/api/python/migration_guide/pyspark_upgrade.html)

## 从旧的 AWS Glue 版本迁移到 AWS Glue 5.1
<a name="migrating-older-versions-to-51"></a>
+ 有关 AWS Glue 4.0 到 AWS Glue 5.0 的迁移步骤，请参阅[从 AWS Glue 4.0 迁移到 AWS Glue 5.0](https://docs.aws.amazon.com/glue/latest/dg/migrating-version-50.html#migrating-version-50-from-40)。
+ 有关 AWS Glue 3.0 到 AWS Glue 5.0 的迁移步骤，请参阅[从 AWS Glue 3.0 迁移到 AWS Glue 5.0](https://docs.aws.amazon.com/glue/latest/dg/migrating-version-50.html#migrating-version-50-from-30)。
+ 有关 AWS Glue 2.0 到 AWS Glue 5.0 的迁移步骤以及 AWS Glue 版本 2.0 和 4.0 之间的迁移差异列表，请参阅[从 AWS Glue 2.0 迁移到 AWS Glue 5.0](https://docs.aws.amazon.com/glue/latest/dg/migrating-version-50.html#migrating-version-50-from-20)。

## AWS Glue 5.1 的连接器和 JDBC 驱动程序迁移
<a name="migrating-version-51-connector-driver-migration"></a>

有关已升级的 JDBC 和数据湖连接器的版本，请参阅：
+ [附录 B：JDBC 驱动程序升级](#migrating-version-51-appendix-jdbc-driver)
+ [附录 C：连接器升级](#migrating-version-51-appendix-connector)
+ [附录 D：开放表格式升级](#migrating-version-51-appendix-open-table-formats)

以下更改适用于 [附录 D：开放表格式升级](#migrating-version-51-appendix-open-table-formats) 中列出的针对 AWS Glue 5.1的 OTF 版本升级。

**Apache Hudi**  
注意以下更改：
+ 支持对 Lake Formation 注册的表的 FTA 读写访问。

**Apache Iceberg**  
注意以下更改：
+ 支持 Iceberg 格式版本 3。支持以下功能：
  + 用于分区和排序的多参数转换。
  + 行谱系跟踪。
  + 删除向量。在[博客文章](https://aws.amazon.com/blogs/big-data/unlock-the-power-of-apache-iceberg-v3-deletion-vectors-on-amazon-emr/)中了解更多信息 
  + 表加密密钥。
  + 列的默认值支持。
+ 支持对 AWS Lake Formation 注册的表进行 Spark 原生 FGAC 写入。
+ Athena SQL 兼容性：由于错误，无法读取 EMR Spark 创建的 Iceberg V3 表：`GENERIC_INTERNAL_ERROR: Cannot read unsupported version 3`

**Delta Lake**  
注意以下更改：
+ 支持对 Lake Formation 注册的表的 FTA 读写访问。

### 附录 A：显著依赖项升级
<a name="migrating-version-51-appendix-dependencies"></a>

以下是依赖项升级：


| 依赖关系 | AWS Glue 5.1 中的版本 | AWS Glue 5.0 中的版本 | AWS Glue 4.0 中的版本 | AWS Glue 3.0 中的版本 | AWS Glue 2.0 中的版本 | AWS Glue 1.0 中的版本 | 
| --- | --- | --- | --- | --- | --- | --- | 
| Java | 17 | 17 | 8 | 8 | 8 | 8 | 
| Spark | 3.5.6 | 3.5.4 | 3.3.0-amzn-1 | 3.1.1-amzn-0 | 2.4.3 | 2.4.3 | 
| Hadoop | 3.4.1 | 3.4.1 | 3.3.3-amzn-0 | 3.2.1-amzn-3 | 2.8.5-amzn-5 | 2.8.5-amzn-1 | 
| Scala | 2.12.18 | 2.12.18 | 2.12 | 2.12 | 2.1.1 | 2.1.1 | 
| Jackson | 2.15.2 | 2.15.2 | 2.12 | 2.12 | 2.1.1 | 2.1.1 | 
| Hive | 2.3.9-amzn-4 | 2.3.9-amzn-4 | 2.3.9-amzn-2 | 2.3.7-amzn-4 | 1.2 | 1.2 | 
| EMRFS | 2.73.0 | 2.69.0 | 2.54.0 | 2.46.0 | 2.38.0 | 2.30.0 | 
| Json4s | 3.7.0-M11 | 3.7.0-M11 | 3.7.0-M11 | 3.6.6 | 3.5.x | 3.5.x | 
| Arrow | 12.0.1 | 12.0.1 | 7.0.0 | 2.0.0 | 0.10.0 | 0.10.0 | 
| AWS Glue 数据目录客户端 | 4.9.0 | 4.5.0 | 3.7.0 | 3.0.0 | 1.10.0 | 不适用 | 
| AWS SDK for Java | 2.35.5 | 2.29.52 | 1.12 | 1.12 |  |  | 
| Python | 3.11 | 3.11 | 3.10 | 3.7 | 2.7 和 3.6 | 2.7 和 3.6 | 
| Boto | 1.40.61 | 1.34.131 | 1.26 | 1.18 | 1.12 | 不适用 | 
| EMR DynamoDB 连接器 | 5.7.0 | 5.6.0 | 4.16.0 |  |  |  | 

### 附录 B：JDBC 驱动程序升级
<a name="migrating-version-51-appendix-jdbc-driver"></a>

以下是 JDBC 驱动程序升级：


| 驱动程序 | AWS Glue 5.1 中的 JDBC 驱动程序版本 | AWS Glue 5.0 中的 JDBC 驱动程序版本 | AWS Glue 4.0 中的 JDBC 驱动程序版本 | AWS Glue 3.0 中的 JDBC 驱动程序版本 | 过去 AWS Glue 版本中的 JDBC 驱动程序版本 | 
| --- | --- | --- | --- | --- | --- | 
| MySQL | 8.0.33 | 8.0.33 | 8.0.23 | 8.0.23 | 5.1 | 
| Microsoft SQL Server | 10.2.0 | 10.2.0 | 9.4.0 | 7.0.0 | 6.1.0 | 
| Oracle 数据库 | 23.3.0.23.09 | 23.3.0.23.09 | 21.7 | 21.1 | 11.2 | 
| PostgreSQL | 42.7.3 | 42.7.3 | 42.3.6 | 42.2.18 | 42.1.0 | 
| Amazon Redshift |  redshift-jdbc42-2.1.0.29  |  redshift-jdbc42-2.1.0.29  |  redshift-jdbc42-2.1.0.16  |  redshift-jdbc41-1.2.12.1017   |  redshift-jdbc41-1.2.12.1017   | 
| SAP Hana | 2.20.17 | 2.20.17 | 2.17.12 |  |  | 
| Teradata | 20.00.00.33 | 20.00.00.33 | 20.00.00.06 |  |  | 

### 附录 C：连接器升级
<a name="migrating-version-51-appendix-connector"></a>

以下是连接器升级：


| 驱动程序 | AWS Glue 5.1 中的连接器版本 | AWS Glue 5.0 中的连接器版本 | AWS Glue 4.0 中的连接器版本 | AWS Glue 3.0 中的连接器版本 | 
| --- | --- | --- | --- | --- | 
| EMR DynamoDB 连接器 | 5.7.0 | 5.6.0 | 4.16.0 |  | 
| Amazon Redshift | 6.4.2 | 6.4.0 | 6.1.3 |  | 
| OpenSearch | 1.2.0 | 1.2.0 | 1.0.1 |  | 
| MongoDB | 10.3.0 | 10.3.0 | 10.0.4 | 3.0.0 | 
| Snowflake | 3.1.1 | 3.0.0 | 2.12.0 |  | 
| Google BigQuery | 0.32.2 | 0.32.2 | 0.32.2 |  | 
| AzureCosmos | 4.33.0 | 4.33.0 | 4.22.0 |  | 
| AzureSQL | 1.3.0 | 1.3.0 | 1.3.0 |  | 
| Vertica | 3.3.5 | 3.3.5 | 3.3.5 |  | 

### 附录 D：开放表格式升级
<a name="migrating-version-51-appendix-open-table-formats"></a>

下面是开放表格式升级：


| OTF | AWS Glue 5.1 中的连接器版本 | AWS Glue 5.0 中的连接器版本 | AWS Glue 4.0 中的连接器版本 | AWS Glue 3.0 中的连接器版本 | 
| --- | --- | --- | --- | --- | 
| Hudi | 1.0.2 | 0.15.0 | 0.12.1 | 0.10.1 | 
| Delta Lake | 3.3.2 | 3.3.0 | 2.1.0 | 1.0.0 | 
| Iceberg | 1.10.0 | 1.7.1 | 1.0.0 | 0.13.1 | 