跳至內容

如何解決「FAILED: NullPointerException 名稱為空」錯誤?

4 分的閱讀內容
0

當我查詢我的 Amazon Athena 資料表時,我會得到「FAILED: NullPointerException Name is Null」(失敗:NullPointerException 名稱為空) 錯誤

簡短描述

下列錯誤訊息是您可能收到的失敗: NullPointerException 錯誤類型。

NullPointerException 名稱為空

在 AWS Glue Data Catalog 中未為查詢的資料表定義 TableType 屬性時,您會收到此錯誤。TableType 屬性用於定義資料表是否為外部資料表或視圖。您可以使用 EXTERNAL_TABLEVIRTUAL_VIEW 等值定義屬性。

若要執行 DDL 查詢,例如 SHOW CREATE TABLEMSCK REPAIR TABLE,必須定義 TableType 屬性。

當您使用 AWS CloudFormation 範本或 AWS Glue API 且未指定 TableType 屬性時,也可能會遇到此錯誤。

java.lang.NullPointerException: 無法調用「java.util.Map.entrySet()」因為「org.apache.hadoop.hive.metastore.api.SerDeInfo.getParameters()」的回傳值為空

當未為 Data Catalog 中查詢表格定義 SerDeInfo 參數時,您會收到此錯誤。SerDeInfo 參數是定義 SerDe 的初始化參數金鑰組。您可以用下列值定義屬性:"serialization.format": “1”。若要執行 DDL 查詢,例如 SHOW CREATE TABLE,您必須定義 SerDeInfo 屬性參數。

使用 CloudFormation 範本或 AWS Glue API 且未指定 SerDeInfo 屬性時,也可能會遇到此錯誤。

解決方法

完成最符合您收到的錯誤訊息疑難排解步驟。

**注意:**如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤,請參閱AWS CLI 錯誤疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本

NullPointerException 名稱為空

若要解決此錯誤,請根據您的使用案例完成下列一或多項動作。

在資料表建立期間新增屬性

在建立資料表時,新增 TableType 屬性。

注意: 如果使用 DDL 陳述式或 AWS Glue 編目程式建立資料表,則會自動定義 TableType 屬性。

更新 CloudFormation 範本

當您使用 CloudFormation 範本來建立 AWS Glue 資料表時,請在 AWS Glue 資料表資源的 TableInput 屬性中,指定 TableType 屬性。將 TableType 設定為「EXTERNAL_TABLE」。如需詳細資訊,請參閱 AWS::Glue::Table TableInput

更新 AWS Glue API 呼叫

當您使用 AWS Glue API 呼叫來建立或更新資料表時,請確保在 TableInput 屬性中包含 TableType 參數。當您呼叫 CreateTableUpdateTable 操作時,請將 TableType 參數設定為「EXTERNAL_TABLE」。

使用 AWS CLI 更新資料表

若要更新資料表的 TableType 屬性,請執行 update-table AWS CLI 命令。若要執行此命令,您必須擁有定義整個資料表架構的 TableInput 物件。

為取得資料表的 TableInput 物件,請執行 get-table AWS CLI 命令。然後,完成下列步驟以更新此命令的輸出:

  1. 在資料表上,執行類似下列範例的命令:

    aws glue get-table --catalog-id 1111222233334444 --database doc_example_database --name doc_example_table

    輸出範例:

    {    "Table": {            "StorageDescriptor": {
                "OutputFormat": "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat",
                "SortColumns": [],
                "InputFormat": "org.apache.hadoop.mapred.TextInputFormat",
                "SerdeInfo": {
                        "SerializationLibrary": "org.apache.hadoop.hive.serde2.OpenCSVSerde",
                        "Parameters": {
                        "serialization.format": "1"
                            }
                },
                "Parameters": {
                    "separatorChar": ","
                },
                "Location": "s3://doc_example_bucket/doc_example_prefix/",
                "NumberOfBuckets": 0,
                "StoredAsSubDirectories": false,
                "Columns": [
                    {
                        "Type": "int",
                        "Name": "id"
                    },
                    {
                        "Type": "string",
                        "Name": "name"
                    }
                ],
                "Compressed": false
            },
            "UpdateTime": 1620508098.0,
            "IsRegisteredWithLakeFormation": false,
            "Name": "doc_example_table",
            "CreatedBy": "arn:aws:iam::1111222233334444:user/Administrator",
            "DatabaseName": "doc_example_database",
            "Owner": "1111222233334444",
            "Retention": 0,
            "CreateTime": 1619909955.0,
            "Description": "tb description"
        }
    }
  2. 在輸出中,移除 UpdateTimeIsRegisteredWithLakeFormationCreatedByDatabaseNameCreateTime 參數。AWS Glue 不支援這些參數。
    如果您在執行 update-table 命令時,在 TableInput 屬性中包含這些參數,則可能會看到下列錯誤:

    「Parameter validation failed:Unknown parameter in TableInput: "UpdateTime", must be one of: Name, Description, Owner, LastAccessTime, LastAnalyzedTime, Retention, StorageDescriptor, PartitionKeys, ViewOriginalText, ViewExpandedText, TableType, Parameters」 (參數驗證失敗:TableInput 中的未知參數:「UpdateTime」,必須是以下其中一個:Name、Description、Owner、LastAccessTime、LastAnalyzedTime、Retention、StorageDescriptor、PartitionKeys、ViewOriginalText、ViewExpandedText、TableType、Parameters) 「Unknown parameter in TableInput: "IsRegisteredWithLakeFormation", must be one of: Name, Description, Owner, LastAccessTime, LastAnalyzedTime, Retention, StorageDescriptor, PartitionKeys, ViewOriginalText, ViewExpandedText, TableType, Parameters」 (參數驗證失敗:TableInput 中的未知參數:「UpdateTime」,必須是以下其中一個:Name、Description、Owner、LastAccessTime、LastAnalyzedTime、Retention、StorageDescriptor、PartitionKeys、ViewOriginalText、ViewExpandedText、TableType、Parameters) 「Unknown parameter in TableInput: "CreatedBy", must be one of: Name, Description, Owner, LastAccessTime, LastAnalyzedTime, Retention, StorageDescriptor, PartitionKeys, ViewOriginalText, ViewExpandedText, TableType, Parameters」 (參數驗證失敗:TableInput 中的未知參數:「UpdateTime」,必須是以下其中一個:Name、Description、Owner、LastAccessTime、LastAnalyzedTime、Retention、StorageDescriptor、PartitionKeys、ViewOriginalText、ViewExpandedText、TableType、Parameters) 「Unknown parameter in TableInput: "DatabaseName", must be one of: Name, Description, Owner, LastAccessTime, LastAnalyzedTime, Retention, StorageDescriptor, PartitionKeys, ViewOriginalText, ViewExpandedText, TableType, Parameters」 (參數驗證失敗:TableInput 中的未知參數:「UpdateTime」,必須是以下其中一個:Name、Description、Owner、LastAccessTime、LastAnalyzedTime、Retention、StorageDescriptor、PartitionKeys、ViewOriginalText、ViewExpandedText、TableType、Parameters) 「Unknown parameter in TableInput: "CreateTime", must be one of: Name, Description, Owner, LastAccessTime, LastAnalyzedTime, Retention, StorageDescriptor, PartitionKeys, ViewOriginalText, ViewExpandedText, TableType, Parameters」(TableInput 中的未知參數:「CreateTime」,必須是以下其中一個:Name、Description、Owner、LastAccessTime、LastAnalyzedTime、Retention、StorageDescriptor、PartitionKeys、ViewOriginalText、ViewExpandedText、TableType、Parameters)

  3. 新增 "TableType": "EXTERNAL_TABLE" 參數至輸出。

  4. 使用輸出作為 TableInput 參數以執行下列命令:

    aws glue update-table --catalog-id 1111222233334444 --database-name doc_example_database --table-input '{        "StorageDescriptor": {            "OutputFormat": "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat",
                "SortColumns": [],
                "InputFormat": "org.apache.hadoop.mapred.TextInputFormat",
                "SerdeInfo": {
                    "SerializationLibrary": "org.apache.hadoop.hive.serde2.OpenCSVSerde",
                    "Parameters": {
                        "serialization.format":"1"
                    }
                },
                "Parameters": {
                    "separatorChar":","
                },
                "Location": "s3://doc_example_bucket/doc_example_prefix/",
                "NumberOfBuckets": 0,
                "StoredAsSubDirectories": false,
                "Columns": [
                    {
                        "Type": "int",
                        "Name": "id"
                    },
                    {
                        "Type": "string",
                        "Name": "name"
                    }
                ],
                "Compressed": false
            },
            "Name": "doc_example_table",
            "TableType": "EXTERNAL_TABLE",
            "Owner": "1111222233334444",
            "Retention": 0,
            "Description": "tb description"
        }'

    注意: 依下列方式取代以下變數:
    使用您的資料庫名稱取代 doc_example_database
    使用您的資料表名稱取代 doc_example_table
    使用您的 AWS 帳戶 ID 取代 1111222233334444
    使用儲存資料表的 Amazon Simple Storage Service (Amazon S3) 位置取代 s3://doc_example_bucket/doc_example_prefix/
    執行上述命令後,TableType 參數會更新,並且 DDL 查詢成功。

java.lang.NullPointerException: 無法調用「java.util.Map.entrySet()」因為「org.apache.hadoop.hive.metastore.api.SerDeInfo.getParameters()」的回傳值為空

若要解決此錯誤,請根據您的使用案例完成下列一或多項動作。

在資料表建立期間新增 SerDeInfo 參數

建立資料表時,新增 SerDeInfo 參數,例如 "serialization.format": "1", "field.delim":","

更新 CloudFormation 範本

當您使用 CloudFormation 範本建立 AWS Glue 資料表時,請指定 SerDeInfo 參數。在您的 Glue 資料表資源中的 TableInput 區段,導覽至 StorageDescriptor。選擇SerDeInfo,然後選擇 Parameters (參數)。新增 {"serialization.format": "1"} 作為參數。

如需詳細資訊,請參閱 AWS::Glue::Table SerdeInfo

更新 AWS Glue API 呼叫

當您使用 AWS Glue API 呼叫來建立或更新資料表時,請在 TableInputStorageDescriptor 中包含 SerDeInfo 參數。將 SerDeInfoParameters (參數) 欄位設定為 {"serialization.format": "1"}.

當您呼叫 CreateTableUpdateTable 等操作時,會使用此參數。如需詳細資訊,請參閱 StorageDescriptor 結構

使用 AWS Glue 主控台更新資料表

若要更新 Data Catalog 中資料表的屬性,請完成下列步驟:

  1. 開啟 AWS Glue 主控台
  2. 在導覽窗格的 Data Catalog下,選擇 Tables (資料表)。
  3. 選取您要更新的資料表。
  4. 選擇 Action (動作),然後選擇 Edit table (編輯資料表)。
  5. SerDe parameters (SerDe 參數) 區段中,選擇 Add (新增)。
  6. Key (金鑰) 輸入「serialization.format」,並為 Value (值) 輸入「1」。
  7. 選擇儲存

使用 AWS CLI 更新資料表

若要更新資料表的 SerDeInfo 參數,請執行 update-table AWS CLI 命令。若要執行此命令,您必須擁有定義整個資料表架構的 TableInput 物件。

為取得資料表的 TableInput 物件,請執行 get-table AWS CLI 命令。然後,更新此命令的輸出以包括 SerDeInfo 參數。

相關資訊

在 Athena 中疑難排解問題

AWS 官方已更新 1 年前