在多个目录中注册您的可互操作表格
重要
使用 Apache XTable™ (Incubating) 在多个目标目录(catalog)之间同步源表,需要通过一个打包好的 jar 在当前数据集上运行目录同步。你可以按照安装页面上的说明创建这个打包 jar。更多详细信息,请阅读 Apache XTable™ 的 GitHub 页面。
在本教程中,我们将展示如何使用 Apache XTable™ (Incubating) 实现不同目录之间的互操作性。例如,你可以将一张 Hudi、Iceberg 或 Delta 表暴露到 Hive Metastore(HMS)中,并使其在 AWS Glue Data Catalog 中可用——而无需手动注册每张表。此外,Apache XTable™ (Incubating) 还允许你转换表格式元数据。比如,HMS 中的 Delta 表可以以 Glue 中的 Iceberg 表形式暴露出来。
前置条件
- 源表(Hudi/Delta/Iceberg)已写入你的本地存储,或 S3/GCS/ADLS 等外部存储位置。如果你尚未将源表写入相应位置,可以按照本教程中的步骤进行设置。
- 克隆 Apache XTable™ (Incubating) 的代码仓库,并按照安装页面上的步骤创建
xtable-utilities_2.12-0.5.0-SNAPSHOT-bundled.jar。 - Hive Metastore 已配置并运行——可以是本地部署,也可以部署在 EMR、Dataproc 或 HDInsight 等平台上。
- 设置从命令行访问 AWS API 的权限。如果你尚未安装 AWSCLIv2,可按照 AWS 文档中的说明进行安装,并按照此处的步骤配置访问凭证。
在接下来的步骤中,我们将介绍如何在本地运行 Apache XTable™ (Incubating),从而将你的表从源目录同步到多个目标目录。
步骤
运行目录同步
在克隆的 xtable 目录中创建 my_config_catalog.yaml。
- sourceCatalog: HMS
- sourceCatalog: GLUE
- sourceCatalog: STORAGE
yaml
sourceCatalog:
catalogId: "source-catalog-id"
catalogType: "HMS"
catalogProperties:
# Ex: thrift://localhost:9083
# Checkout org.apache.xtable.hms.HMSCatalogConfig for advanced configs.
externalCatalog.hms.serverUrl: "hms-server-url"
targetCatalogs:
- catalogId: "target-catalog-id-glue"
catalogSyncClientImpl: "org.apache.xtable.glue.GlueCatalogSyncClient"
catalogProperties:
# Checkout org.apache.xtable.glue.GlueCatalogConfig for advanced configs.
externalCatalog.glue.region: "aws-region"
datasets:
- sourceCatalogTableIdentifier:
tableIdentifier:
hierarchicalId: "db.hudi_table"
# you only need to specify partitionSpec for HUDI sourceFormat
partitionSpec: "cs_sold_date_sk:VALUE"
targetCatalogTableIdentifiers:
- catalogId: "target-catalog-id-hms"
tableFormat: "ICEBERG"
tableIdentifier:
hierarchicalId: "db.iceberg_table"
- catalogId: "target-catalog-id-hms"
tableFormat: "DELTA"
tableIdentifier:
hierarchicalId: "db.delta_table"注意:
catalogId是用户为每个 catalog 定义的唯一标识符,如果你想将一张表同步到多个 glue/hms catalog,这个标识符会很有用。请为
hierarchicalId替换为合适的值,即一个由 2 部分或 3 部分组成的 tableIdentifier。对于存储 catalog,如果你的源表位于 S3/GCS/ADLS,请将
file:///path/to/source/data替换为相应的tableBasePath,即- S3 -
s3://path/to/source/data - GCS -
gs://path/to/source/data或 - ADLS -
abfss://<container-name>@<storage-account-name>.dfs.core.windows.net/<path-to-data>
- S3 -
关于高级配置,请查阅 GlueCatalogConfig 和 HMSCatalogConfig 的 Java 文档。
注意:
AWS 的身份认证由 com.amazonaws.auth.DefaultAWSCredentialsProviderChain 完成。若要覆盖此设置,请通过 --awsCredentialsProvider 选项指定一个不同的实现。
在终端中进入克隆的 Apache XTable™ (Incubating) 目录,运行以下命令。
shell
java -cp xtable-utilities/target/xtable-utilities_2.12-0.5.0-SNAPSHOT-bundled.jar org.apache.xtable.utilities.RunCatalogSync --catalogSyncConfig my_config_catalog.yaml**可选:**现在,如果你查看目标目录,就会发现外部表已经创建完成,可以进行查询了。
结论
在本教程中,我们介绍了如何配置 Apache XTable™ (Incubating),使其自动从源目录读取表,并在目标目录中创建可互操作的外部表。同步完成后,无需手动注册,即可立即从目标目录查询这些表。
评论
登录后参与评论
KnowForge