问题描述
使用 AWS :: Glue ::表格,您可以在此处设置雅典娜表格.雅典娜支持基于S3中文件夹结构的分区数据.我想从我的Glue模板中对Athena表进行分区.
Using AWS::Glue::Table, you can set up an Athena table like here. Athena supports partitioning data based on folder structure in S3. I would like to partition my Athena table from my Glue template.
来自 AWS粘合表TableInput,看来我可以使用 PartitionKeys
来对数据进行分区,但是当我尝试使用以下模板时,Athena会失败并且无法获取任何数据.
From AWS Glue Table TableInput, it appears that I can use PartitionKeys
to partition my data, but when I try to use the below template, Athena fails and can't get any data.
Resources:
...
MyGlueTable:
Type: AWS::Glue::Table
Properties:
DatabaseName: !Ref MyGlueDatabase
CatalogId: !Ref AWS::AccountId
TableInput:
Name: my-glue-table
Parameters: { "classification" : "json" }
PartitionKeys:
- {Name: dt, Type: string}
StorageDescriptor:
Location: "s3://elasticmapreduce/samples/hive-ads/tables/impressions/"
InputFormat: "org.apache.hadoop.mapred.TextInputFormat"
OutputFormat: "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat"
SerdeInfo:
Parameters: { "separatorChar" : "," }
SerializationLibrary: "org.apache.hive.hcatalog.data.JsonSerDe"
StoredAsSubDirectories: false
Columns:
- {Name: requestBeginTime, Type: string}
- {Name: adId, Type: string}
- {Name: impressionId, Type: string}
- {Name: referrer, Type: string}
- {Name: userAgent, Type: string}
- {Name: userCookie, Type: string}
- {Name: ip, Type: string}
- {Name: number, Type: string}
- {Name: processId, Type: string}
- {Name: browserCookie, Type: string}
- {Name: requestEndTime, Type: string}
- {Name: timers, Type: "struct<modellookup:string,requesttime:string>"}
- {Name: threadId, Type: string}
- {Name: hostname, Type: string}
- {Name: sessionId, Type: string}
如何在AWS Glue中对数据进行分区?
How do I partition my data in AWS Glue?
推荐答案
知道了!非常痛苦,因为我必须运行Glue Crawler,它会正确创建带有分区的表,然后使用CLI提取正确的模板参数.这是模板,
Got it! Pretty painful, because I had to run Glue Crawler which properly created the table with partitions, and then use the CLI to extract the correct template parameters. Here is the template,
AWSTemplateFormatVersion: 2010-09-09
Description: A partitioned Glue Table
Resources:
MyGlueDatabase:
Type: AWS::Glue::Database
Properties:
DatabaseInput:
Name: my_glue_database
Description: "Glue beats tape"
CatalogId: !Ref AWS::AccountId
MyGlueTable:
Type: AWS::Glue::Table
Properties:
DatabaseName: !Ref MyGlueDatabase
CatalogId: !Ref AWS::AccountId
TableInput:
Name: my_glue_table
TableType: EXTERNAL_TABLE
Parameters:
CrawlerSchemaDeserializerVersion': "1.0"
CrawlerSchemaSerializerVersion': "1.0"
classification': json
compressionType': none
typeOfData': file
PartitionKeys:
- {Name: dt, Type: string}
StorageDescriptor:
BucketColumns: []
Columns:
- {Name: number, Type: string}
- {Name: referrer, Type: string}
- {Name: processid, Type: string}
- {Name: adid, Type: string}
- {Name: browsercookie, Type: string}
- {Name: usercookie, Type: string}
- {Name: requestendtime, Type: string}
- {Name: impressionid, Type: string}
- {Name: useragent, Type: string}
- {Name: timers, Type: 'struct<modelLookup:string,requestTime:string>'}
- {Name: threadid, Type: string}
- {Name: ip, Type: string}
- {Name: modelid, Type: string}
- {Name: hostname, Type: string}
- {Name: sessionid, Type: string}
- {Name: requestbegintime, Type: string}
Compressed: false
InputFormat: org.apache.hadoop.mapred.TextInputFormat
Location: s3://elasticmapreduce/samples/hive-ads/tables/impressions/
NumberOfBuckets: -1
OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
Parameters: {CrawlerSchemaDeserializerVersion: '1.0', CrawlerSchemaSerializerVersion: '1.0',
UPDATED_BY_CRAWLER: test, averageRecordSize: '644', classification: json,
compressionType: none, objectCount: '241', recordCount: '1000109', sizeKey: '648533598',
typeOfData: file}
SerdeInfo:
Parameters: {paths: 'adId,browserCookie,hostname,impressionId,ip,modelId,number,processId,referrer,requestBeginTime,requestEndTime,sessionId,threadId,timers,userAgent,userCookie'}
SerializationLibrary: org.openx.data.jsonserde.JsonSerDe
SortColumns: []
StoredAsSubDirectories: false
然后Cloudformation将部署该表,并且您需要运行.
Then Cloudformation will deploy the table, and you need to run.
MSCK REPAIR TABLE my_glue_table;
这将添加所有分区,您将在输出中看到类似的
That will add all the partitions, which you will see in the output like,
Repair: Added partition to metastore my_glue_table:dt=2009-04-12-13-00
Repair: Added partition to metastore my_glue_table:dt=2009-04-12-13-05
然后,您可以在此分区之上运行SQL,
Then you can run SQL on top of this partitioning like,
%% SELECT * FROM "my_glue_database"."my_glue_table" WHERE dt = '2009-04-14-13-00' LIMIT 10;
1 7663 cartoonnetwork.com 1178 SxRBJCmJBCLcfTS545t6qD1M8L64SC nsdfvfvger 3VCLfFfF75BDgHgDoowHegOpkCivMJ 1239714024000 RTM6Vtrc1O3KX2FlUghUSiAQHiix8F Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB6; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0) {modellookup=0.3538, requesttime=0.7532} 15 37.215.88.35 bxxiuxduad ec2-50-32-48-14.amazon.com BIBIlA7dgXc2eWekUJ6hSXa7p6dQEx 1239714024000 2009-04-14-13-00
2 17646 coursera.org 1255 Fskm4W6JKX6vf7UMaW55KObTJCtm1E xftjotkexc jH6DRWtkeH3tVg6c4mcLW36UW3LvqX 1239714027000 uQqO1fNoeM8KdesiVg86o4iK7FkqLt Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322) {modellookup=0.2986, requesttime=0.9616} 21 37.218.101.204 bxxiuxduad ec2-50-32-48-14.amazon.com OjgTQWOqHJopoWf9LpJ4We1UE7uJao 1239714026000 2009-04-14-13-00
这篇关于从胶水Cloudformation模板对Athena表进行分区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!