粘合AWS在boto3 python上创建数据目录表

时间:2018-09-13 17:25:36

标签: amazon-web-services aws-sdk boto3 aws-glue

我一直在尝试使用python API在我们的数据目录中创建一个表。遵循herehere中发布的API文档。我可以理解。但是,我需要不理解如何在创建表时声明字段结构,因为当我查看表here的存储定义时,对于如何为我的表定义这种类型的列有任何解释表。此外。我看不到覆盖的表的分类属性。也许在物业上?我已将boto3 documentation用于此示例

代码:

import boto3


client = boto3.client(service_name='glue', region_name='us-east-1')


response = client.create_table(
        DatabaseName='dbname',
        TableInput={
        'Name': 'tbname',
        'Description': 'tb description',
        'Owner': 'I'm',
        'StorageDescriptor': {
            'Columns': [

                { 'Name': 'agents', 'Type': 'struct','Comment': 'from deserializer'  },
                { 'Name': 'conference_sid', 'Type': 'string','Comment': 'from deserializer'  },
                { 'Name': 'call_sid', 'Type': 'string','Comment': 'from deserializer'  }
            ] ,
        'Location': 's3://bucket/location/', 
        'InputFormat': 'org.apache.hadoop.mapred.TextInputFormat',
        'OutputFormat': 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat',
        'Compressed': False,
        'SerdeInfo': {  'SerializationLibrary': 'org.openx.data.jsonserde.JsonSerDe'}
        },
        'TableType' : "EXTERNAL_TABLE"} )

1 个答案:

答案 0 :(得分:0)

找到这篇文章是因为我遇到了同样的问题,并最终找到了解决方案,因此您可以按以下类型进行操作:

array<struct<id:string,timestamp:bigint,message:string>>

我在使用AWS控制台并单击通过爬网程序创建的现有表的数据类型时发现了此“提示”。它提示:

An ARRAY of scalar type as a top - level column.
ARRAY <STRING>

An ARRAY with elements of complex type (STRUCT).
ARRAY < STRUCT <
  place: STRING,
  start_year: INT
>>

An ARRAY as a field (CHILDREN) within a STRUCT. (The STRUCT is inside another    ARRAY, because it is rare for a STRUCT to be a top-level column.)
ARRAY < STRUCT <
  spouse: STRING,
  children: ARRAY <STRING>
>>

A STRUCT as the element type of an ARRAY.
ARRAY < STRUCT <
  street: STRING,
  city: STRING,
  country: STRING
>>