简体   繁体   English

以编程方式检索AWS Glue动态框架字段名称和数据类型

[英]Programatically retrieving AWS Glue Dynamic Frame field names and data types

New to PySpark and AWS Glue. PySpark和AWS Glue的新功能。 I need to retrieve fields names and data types to use them in a program. 我需要检索字段名称和数据类型以在程序中使用它们。 I could print the results of DynamicFrame.schema(), which appear to be a JSON-like structure. 我可以打印DynamicFrame.schema()的结果,该结果似乎是一个类似于JSON的结构。 I tried json.loads to see if the structure can be converted to Python dictionary, so I could iterate through it, but got this error - TypeError: expected string or buffer ------------------------------* 我尝试了json.loads来查看该结构是否可以转换为Python字典,所以我可以对其进行迭代,但是遇到了此错误-TypeError:期望的字符串或缓冲区--------------- --------------- *

AWS Glue documentation doesn't indicate the return type of schema(). AWS Glue文档没有指出schema()的返回类型。 Thank you. 谢谢。

You can use DynamicFrame.schema().field_map to get a dictionary of all the fields and their types: 您可以使用DynamicFrame.schema().field_map获取所有字段及其类型的字典:

 {'field_map': 
   {'PersonId': Field(PersonId, IntegerType({}), {}),
    'ChangeId': Field(ChangeId, LongType({}), {}),
    'CreateDate': Field(CreateDate, TimestampType({}), {}),)},
 'fields': 
    [Field(PersonId, IntegerType({}), {}),
    Field(ChangeId, LongType({}), {}),
    Field(CreateDate, TimestampType({}), {})],
    'properties'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM