當我嘗試在 Amazon Redshift Spectrum 中使用外部結構描述、物件或檔案格式時收到錯誤訊息。
解決方法
注意: 如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤訊息,請參閱 Troubleshooting errors for the AWS CLI (對 AWS CLI 錯誤進行疑難排解)。此外,請務必使用最新版 AWS CLI。
資料格式不相容錯誤
若要解決 Redshift Spectrum 中 資料格式不相容的錯誤,請完成下列步驟:
-
若要從 SVL_S3LOG 系統檢視取得完整的錯誤訊息,請執行下列查詢:
select * from SVL_S3LOG where query = 'Spectrum_query_ID';
注意: 將 Spectrum_query_ID 替換為 Redshift Spectrum ID。
如果您的 Parquet 結構描述不相容,則可能會收到下列錯誤訊息:
"File 'https://s3bucket/location/file has an incompatible Parquet schema for column 's3://s3bucket/location.col1'.Column type: VARCHAR, Par..."
-
檢查 Message 欄以查看錯誤描述。錯誤描述說明了 Redshift Spectrum 與外部檔案之間的資料不相容性。
-
若要檢查外部檔案的結構描述,請執行下列命令:
show external table schema-name.table-name
注意: 請將 schema-name 替換為您的結構描述名稱,並將 table-name 替換為您的資料表名稱。
-
比較結構描述與 CREATE EXTERNAL TABLE 定義中的欄定義。
-
(選用) 如果 Apache Parquet 檔案中的欄定義與外部資料表不同,請修改外部資料表中的欄定義。欄定義必須符合 Apache Parquet 檔案的欄式檔案格式。
-
若要檢查 CREATE EXTERNAL TABLE 定義中欄的資料類型,請執行下列 SVV_EXTERNAL_COLUMNS 查詢:
select * from SVV_EXTERNAL_COLUMNS where schemaname = 'ext_schema_name' and tablename = 'ext_table_name';
注意: 請將 ext_schema_name 替換為您的外部欄結構描述名稱,並將 ext_table_name 替換為您的外部欄資料表名稱。
對於 Apache Parquet 等欄式檔案格式,欄類型是嵌入在資料中的。CREATE EXTERNAL TABLE 定義中的欄類型必須符合資料檔案的欄類型。不相符的欄定義會導致資料不相容錯誤。
無效的類型長度錯誤
如果您選取具有 DECIMAL 資料欄的 Redshift Spectrum 資料表,則可能會收到下列錯誤訊息:
"S3 Query Exception (Fetch).Task failed due to an internal error.File 'https://s3.amazonaws.com/…/' has an incompatible Parquet schema for column ''column '' has an invalid type length"
若要解決此錯誤,請使用外部資料表定義。資料表定義值必須符合您在外部檔案中定義的 精確度和小數位數值。
範例:
create external table ext_schema.tablename (c1 int, c2 decimal (6,2)) stored as PARQUET location 's3://.../.../';
注意: 請將 6,2 替換為您的精確度與小數位數值。
內部錯誤
如果您從 Amazon Athena 目錄選取外部結構描述,則可能會收到下列錯誤訊息:
"Task failed due to an internal error.File 'https://s3...snappy.parquet has an incompatible Parquet schema for column 's3://.../tbl.a'.Column type: BOOLEAN, Parquet schema:\noptional int32 b [i:26 d:1 r:0]"
在 Redshift Spectrum 中,CREATE EXTERNAL TABLE 中的欄順序必須符合 Parquet 檔案欄位順序。對於 Apache Parquet 檔案,檔案欄位順序必須與外部資料表定義中的順序相同。如果您跳過此順序或重新排列資料類型欄,則會收到錯誤訊息。
注意: Redshift Spectrum 會將欄名稱與 Apache Parquet 檔案欄位進行比對。Amazon Athena 會使用欄名稱將其對應至 Apache Parquet 檔案中的欄位。
若要解決此錯誤,請在 SELECT 陳述式中指定下列欄名稱:
select col_1, col_2, col_3, .... col_n from athena_schema.tablename;
請確保 AWS Identity and Access Management (IAM) 角色允許存取 Amazon Athena。如需更多資訊,請參閱 IAM policies for Amazon Redshift Spectrum (Amazon Redshift Spectrum 的 IAM 政策)。
欄類型無效錯誤
如果您使用 Redshift Spectrum 從 AWS Glue Data Catalog 資料表查詢 VARCHAR 資料類型欄,則可能會收到下列錯誤訊息:
"<column_name> - Invalid column type for column <column_name>.Type: varchar"
AWS Glue 與 Redshift Spectrum 皆支援 VARCHAR 資料類型。然而,AWS Glue Catalog 定義的 VARCHAR 資料類型並不包含大小參數,例如 VARCHAR (256)。當 Redshift Spectrum 查詢未定義大小參數的 VARCHAR 欄時,您可能會收到欄類型無效的錯誤訊息。
若要解決此錯誤,請完成下列步驟:
- 若要檢索 AWS Glue 資料表資料並將其儲存於本機檔案中,請執行下列 get-table AWS CLI 命令:
aws glue get-table --region your-region --database gluedb --name click_data_json > click-data-table.json
注意: 請將 your-region 替換為您的 AWS 區域。
- 使用文字編輯器開啟 click-data-table.json 檔案,然後移除外層的 {"Table": ...} 包裹結構。
- 移除 UpdateTable 動作中不允許的欄位。
- 將 STRING 欄類型修改為帶有更新後大小參數的 varchar。例如:
"Type": "varchar(1000)"
注意: 請將 1000 替換為您的大小參數。
- 若要更新您的 AWS Glue 資料表,請執行下列 update-table AWS CLI 命令:
aws glue update-table --region your-region --database gluedb --table-input "$(cat click-data-table.json)"
注意: 請將 your-region 替換為您的區域。
- 檢查您在 AWS Glue 中的資料表定義,並確認您已更新資料類型。
- 在 Amazon Redshift 中針對外部結構描述查詢 AWS Glue 資料表。例如:
create external schema glue_schema from data catalog database 'gluedb' iam_role 'arn:aws:iam::111111111111:role/myRedshiftRole' region 'your-region';
注意: 請將 your-region 替換為您的區域。
- 若要查詢 click_data_json,請執行下列命令:
select * from glue_schema.click_data_json;
無效範圍錯誤
如果 Redshift Spectrum 查詢嘗試從已修改、覆寫或刪除的 Amazon Simple Storage Service (Amazon S3) 檔案中讀取資料,則您可能會收到下列錯誤訊息:
"Error: Spectrum Scan Error.Error: HTTP response error code: 416 Message: InvalidRange The requested range is not satisfiable"
若要解決此錯誤,請確保在使用 Redshift Spectrum 查詢時不會覆寫 Amazon S3 檔案。
Parquet 版本號碼無效
Redshift Spectrum 會驗證其存取的每個 Apache Parquet 檔案的中繼資料。如果驗證失敗,則您可能會收到類似下列的錯誤訊息:
"File 'https://s3.region.amazonaws.com/s3bucket/location/file has an invalid version number"
如果在查詢期間覆寫了 Parquet 檔案,或是 Parquet 檔案已損壞,則驗證可能會失敗。
當您更新現有檔案時,就會發生驗證失敗的情況。建立新的 Parquet 檔案以進行版本控制是一種最佳實務。
相關資訊
Troubleshooting queries in Amazon Redshift Spectrum (在 Amazon Redshift Spectrum 中對查詢進行疑難排解)