選取您的 Cookie 偏好設定

我們使用提供自身網站和服務所需的基本 Cookie 和類似工具。我們使用效能 Cookie 收集匿名統計資料,以便了解客戶如何使用我們的網站並進行改進。基本 Cookie 無法停用,但可以按一下「自訂」或「拒絕」以拒絕效能 Cookie。

如果您同意,AWS 與經核准的第三方也會使用 Cookie 提供實用的網站功能、記住您的偏好設定,並顯示相關內容,包括相關廣告。若要接受或拒絕所有非必要 Cookie,請按一下「接受」或「拒絕」。若要進行更詳細的選擇,請按一下「自訂」。

Avro SerDe

焦點模式
Avro SerDe - Amazon Athena

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 Avro SerDe 從 Avro 資料建立 Athena 資料表。

序列化程式庫名稱

Avro SerDe 的序列化程式庫名稱為 org.apache.hadoop.hive.serde2.avro.AvroSerDe。如需技術資訊,請參閱 Apache 文件中的 AvroSerDe

使用 Avro SerDe

基於安全考量,Athena 不支援使用 avro.schema.url來指定資料表結構描述;請avro.schema.literal改用 。

若要從 Avro 格式的資料中擷取結構描述,請使用安裝在已安裝 Avro 版本java子目錄中的 Apache avro-tools-<version>.jar 檔案。使用 getschema 參數來傳回您可以在WITH SERDEPROPERTIES陳述式中使用的結構描述,如下列範例所示。

java -jar avro-tools-1.8.2.jar getschema my_data.avro

若要下載 Avro,請參閱 Apache Avro 版本。若要直接下載 Apache Avro 工具,請參閱 Apache Avro 工具 Maven 儲存庫

取得結構描述後,請使用 CREATE TABLE陳述式,根據存放在 Amazon S3 中的基礎 Avro 資料來建立 Athena 資料表。若要在CREATE TABLE陳述式中指定 Avro SerDe,請使用 ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe'。使用 WITH SERDEPROPERTIES子句指定結構描述,如下列範例所示。

注意

s3://athena-examples-myregion/path/to/data/ 中,以您執行 Athena 之處的區域識別符 (例如 s3://athena-examples-us-west-1/path/to/data/) 取代 myregion

CREATE EXTERNAL TABLE flights_avro_example ( yr INT, flightdate STRING, uniquecarrier STRING, airlineid INT, carrier STRING, flightnum STRING, origin STRING, dest STRING, depdelay INT, carrierdelay INT, weatherdelay INT ) PARTITIONED BY (year STRING) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe' WITH SERDEPROPERTIES ('avro.schema.literal'=' { "type" : "record", "name" : "flights_avro_subset", "namespace" : "default", "fields" : [ { "name" : "yr", "type" : [ "null", "int" ], "default" : null }, { "name" : "flightdate", "type" : [ "null", "string" ], "default" : null }, { "name" : "uniquecarrier", "type" : [ "null", "string" ], "default" : null }, { "name" : "airlineid", "type" : [ "null", "int" ], "default" : null }, { "name" : "carrier", "type" : [ "null", "string" ], "default" : null }, { "name" : "flightnum", "type" : [ "null", "string" ], "default" : null }, { "name" : "origin", "type" : [ "null", "string" ], "default" : null }, { "name" : "dest", "type" : [ "null", "string" ], "default" : null }, { "name" : "depdelay", "type" : [ "null", "int" ], "default" : null }, { "name" : "carrierdelay", "type" : [ "null", "int" ], "default" : null }, { "name" : "weatherdelay", "type" : [ "null", "int" ], "default" : null } ] } ') STORED AS AVRO LOCATION 's3://athena-examples-myregion/flight/avro/';

對資料表執行 MSCK REPAIR TABLE 陳述式,以重新整理分割區中繼資料。

MSCK REPAIR TABLE flights_avro_example;

透過出境總數查詢 10 大出境城市。

SELECT origin, count(*) AS total_departures FROM flights_avro_example WHERE year >= '2000' GROUP BY origin ORDER BY total_departures DESC LIMIT 10;
注意

航班資料表資料來自美國運輸部交通統計局提供的航班。從原本資料去掉飽和度。

下一個主題:

Grok SerDe

上一個主題:

路徑擷取器範例

在本頁面

隱私權網站條款Cookie 偏好設定
© 2025, Amazon Web Services, Inc.或其附屬公司。保留所有權利。