首页 > 解决方案 > AWS Glue 搜索选项

问题描述

我目前正在使用 AWS Glue 数据目录来组织我的数据库。一旦我建立了连接并发送了我的爬虫来收集信息,我就能够看到制定的元数据。

一个很好的功能是能够在一个列名上搜索整个数据目录。例如,如果我的数据目录中有 5 个表,其中一个表恰好有一个字段“年龄”。我希望能够看到那张桌子。

我还想知道是否可以搜索 AWS Glue 数据目录表中每列的“评论”字段

希望能得到一些帮助!

标签: pythonrestaws-glueaws-glue-data-catalog

解决方案


您可以使用 AWS Glue API 做到这一点。例如,您可以使用 python SDKboto3get_tables()方法来检索有关特定数据库中表的所有元信息。看看调用返回的响应语法get_tables(),然后你只需要解析它,例如:

import boto3

glue_client = boto3.client('glue')

response = glue_client.get_tables(
    DatabaseName='__SOME_NAME__'
)

for table in response['TableList']:
    columns = table['StorageDescriptor']['Columns']
    for col in columns:
        col_name = col['Name']
        col_comment = col['Comment']

        # Here you do search for what you need

注意:如果您有一个带有分区(人工列)的表,那么您都需要搜索

columns_as_partitions = table['PartitionKeys']
for col in columns_as_partitions:
    col_name = col['Name']
    col_comment = col['Comment']

    # Here you do search for what you need

推荐阅读