gbe*_*ven 5 python amazon-web-services boto3 aws-glue
我的目标是在 S3 中接收 csv 文件,将它们转换为 avro,并根据 AWS 中的适当架构验证它们。
我根据已有的 .avsc 文件在 AWS Glue Registry 中创建了一系列架构:
{
"namespace": "foo",
"type": "record",
"name": "bar.baz",
"fields": [
{
"name": "column1",
"type": ["string", "null"]
},
{
"name": "column2",
"type": ["string", "null"]
},
{
"name": "column3",
"type": ["string", "null"]
}
]
}
Run Code Online (Sandbox Code Playgroud)
但是,一旦我尝试从 Glue 中提取模式,API 似乎并没有提供定义详细信息:
glue = boto3.client('glue')
glue.get_schema(
SchemaId={
'SchemaArn': schema['SchemaArn']
}
)
Run Code Online (Sandbox Code Playgroud)
返回:
{
'Compatibility': 'BACKWARD',
'CreatedTime': '2021-08-11T21:09:15.312Z',
'DataFormat': 'AVRO',
'LatestSchemaVersion': 2,
'NextSchemaVersion': 3,
'RegistryArn': '[my-registry-arn]',
'RegistryName': '[my-registry-name]',
'ResponseMetadata': {
'HTTPHeaders': {
'connection': 'keep-alive',
'content-length': '854',
'content-type': 'application/x-amz-json-1.1',
},
'HTTPStatusCode': 200,
'RetryAttempts': 0,
},
'SchemaArn': '[my-schema-arn]',
'SchemaCheckpoint': 2,
'SchemaName': '[my-schema-name]',
'SchemaStatus': 'AVAILABLE',
'UpdatedTime': '2021-08-11T21:09:17.312Z',
}
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以以编程方式检索架构的 Glue 架构注册表定义?或者我在尝试做的事情上采取了错误的方法?
经过更多挖掘后,我发现了我一直忽略的名称有点令人困惑的get_schema_version()方法,它返回SchemaDefinition:
{
'SchemaVersionId': 'string',
'SchemaDefinition': 'string',
'DataFormat': 'AVRO'|'JSON',
'SchemaArn': 'string',
'VersionNumber': 123,
'Status': 'AVAILABLE'|'PENDING'|'FAILURE'|'DELETING',
'CreatedTime': 'string'
}
Run Code Online (Sandbox Code Playgroud)