ORC SerDe
使用 ORC SerDe 从 ORC 数据中创建 Athena 表。
序列化库名称
ORC SerDe 的序列化库是 org.apache.hadoop.hive.ql.io.orc.OrcSerde
,但在您的 CREATE
TABLE
语句中,您可以使用子句 STORED AS
ORC
指定该库。有关源代码的信息,请参阅 GitHub.com 上的 OrcSerde.java
注意
在 s3://athena-examples-
中,将 myregion
/path/to/data/myregion
替换为您运行 Athena 所在的区域标识符,例如 s3://athena-examples-us-west-1/path/to/data/
。
以下示例为 ORC 中的航班延迟数据创建一个表。该表包括分区:
DROP TABLE flight_delays_orc; CREATE EXTERNAL TABLE flight_delays_orc ( yr INT, quarter INT, month INT, dayofmonth INT, dayofweek INT, flightdate STRING, uniquecarrier STRING, airlineid INT, carrier STRING, tailnum STRING, flightnum STRING, originairportid INT, originairportseqid INT, origincitymarketid INT, origin STRING, origincityname STRING, originstate STRING, originstatefips STRING, originstatename STRING, originwac INT, destairportid INT, destairportseqid INT, destcitymarketid INT, dest STRING, destcityname STRING, deststate STRING, deststatefips STRING, deststatename STRING, destwac INT, crsdeptime STRING, deptime STRING, depdelay INT, depdelayminutes INT, depdel15 INT, departuredelaygroups INT, deptimeblk STRING, taxiout INT, wheelsoff STRING, wheelson STRING, taxiin INT, crsarrtime INT, arrtime STRING, arrdelay INT, arrdelayminutes INT, arrdel15 INT, arrivaldelaygroups INT, arrtimeblk STRING, cancelled INT, cancellationcode STRING, diverted INT, crselapsedtime INT, actualelapsedtime INT, airtime INT, flights INT, distance INT, distancegroup INT, carrierdelay INT, weatherdelay INT, nasdelay INT, securitydelay INT, lateaircraftdelay INT, firstdeptime STRING, totaladdgtime INT, longestaddgtime INT, divairportlandings INT, divreacheddest INT, divactualelapsedtime INT, divarrdelay INT, divdistance INT, div1airport STRING, div1airportid INT, div1airportseqid INT, div1wheelson STRING, div1totalgtime INT, div1longestgtime INT, div1wheelsoff STRING, div1tailnum STRING, div2airport STRING, div2airportid INT, div2airportseqid INT, div2wheelson STRING, div2totalgtime INT, div2longestgtime INT, div2wheelsoff STRING, div2tailnum STRING, div3airport STRING, div3airportid INT, div3airportseqid INT, div3wheelson STRING, div3totalgtime INT, div3longestgtime INT, div3wheelsoff STRING, div3tailnum STRING, div4airport STRING, div4airportid INT, div4airportseqid INT, div4wheelson STRING, div4totalgtime INT, div4longestgtime INT, div4wheelsoff STRING, div4tailnum STRING, div5airport STRING, div5airportid INT, div5airportseqid INT, div5wheelson STRING, div5totalgtime INT, div5longestgtime INT, div5wheelsoff STRING, div5tailnum STRING ) PARTITIONED BY (year String) STORED AS ORC LOCATION 's3://athena-examples-
myregion
/flight/orc/' tblproperties ("orc.compress"="ZLIB");
在该表上运行 MSCK REPAIR TABLE
语句以刷新分区元数据:
MSCK REPAIR TABLE flight_delays_orc;
使用此查询以获取前 10 个延迟超过 1 小时的路线:
SELECT origin, dest, count(*) as delays FROM flight_delays_orc WHERE depdelayminutes > 60 GROUP BY origin, dest ORDER BY 3 DESC LIMIT 10;