针对这个问题,有一个解决方案是手动定义表架构,而不是依赖 Glue 爬虫自动获取。下面是一个 Python 示例代码,其中创建了一个名为 table_name 的表,并手动定义了其字段和类型。
import boto3
client = boto3.client('glue', region_name='your-region-name')
response = client.create_table(
DatabaseName='your-database-name',
TableInput={
'Name': 'table_name',
'Description': 'description',
'StorageDescriptor': {
'Location': 's3://bucket-name/path/to/data',
'InputFormat': 'org.apache.hadoop.mapred.TextInputFormat',
'OutputFormat': 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat',
'SerdeInfo': {
'SerializationLibrary': 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe',
'Parameters': {
'field.delim': ','
}
},
'Columns': [
{
'Name': 'id',
'Type': 'int'
},
{
'Name': 'name',
'Type': 'string'
},
{
'Name': 'date_field',
'Type': 'timestamp'
}
]
}
}
)
在此示例中,我们定义了三个列:id(int)、name(string)和date_field(timestamp)。您可以根据您的需要定义更多的列。请注意,其中包含 “org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe” 的部分将 SerDe 序列化库设置为处理 CSV 文件。
通过手动定义表架构,您可以确保 Glue 作业将正确识别和解析包含字符串和时间戳/日期值的 CSV 文件。
上一篇:AWSGlue:读/写Parquet文件(文件>50,000)
下一篇:AWSGlue:SCRAMauthenticationrequireslibpqversion10orabove[UsingCockroachDB]