내용으로 건너뛰기

Athena에서 테이블을 쿼리할 때 "FAILED: NullPointerException Name is null" 오류를 해결하려면 어떻게 해야 하나요?

5분 분량
0

Amazon Athena 테이블을 쿼리할 때 "FAILED: NullPointerException Name is Null" 오류가 표시됩니다.

간략한 설명

FAILED: NullPointerException 유형의 오류 메시지를 받았습니다.

NullPointerException Name is null

AWS Glue 데이터 카탈로그에서 쿼리된 테이블에 대해 TableType 속성이 정의되지 않은 경우 이 오류가 발생합니다. TableType 속성은 테이블이 외부 테이블인지 뷰인지를 정의합니다. EXTERNAL_TABLE 및 VIRTUAL_VIEW와 같은 값으로 속성을 정의할 수 있습니다.

SHOW CREATE TABLE 또는 MSCK REPAIR TABLE 과 같은 DDL 쿼리를 실행하려면 TableType 속성을 정의해야 합니다.

AWS CloudFormation 템플릿 또는 AWS Glue API를 사용하고 TableType 속성을 지정하지 않은 경우에도 이 오류가 발생할 수 있습니다.

java.lang.NullPointerException: Cannot invoke "java.util.Map.entrySet()" because the return value of "org.apache.hadoop.hive.metastore.api.SerDeInfo.getParameters()" is null

데이터 카탈로그에서 쿼리된 테이블에 대해 SerDeInfo 파라미터가 정의되지 않은 경우, 이 오류가 발생합니다. SerDeInfo 파라미터는 SerDe의 초기화 파라미터를 정의하는 키-값 쌍입니다. 다음과 같은 값을 사용하여 속성을 정의할 수 있습니다. "serialization.format": "1". SHOW CREATE TABLE과 같은 DDL 쿼리를 실행하려면 SerDeInfo 속성 파라미터를 정의해야 합니다.

CloudFormation 템플릿 또는 AWS Glue API를 사용하고 SerDeInfo 속성을 지정하지 않은 경우에도 이 오류가 발생할 수 있습니다.

해결 방법

수신한 오류 메시지에 가장 적합한 문제 해결 단계를 따르십시오.

참고: AWS Command Line Interface(AWS CLI) 명령 실행 시 오류가 발생하는 경우, AWS CLI 오류 문제 해결을 참고하세요. 또한 최신 AWS CLI 버전을 사용하고 있는지 확인하세요.

NullPointerException Name is null

이 오류를 해결하려면 사용 사례에 따라 다음 작업 중 하나 이상을 완료하십시오.

테이블 생성 시 속성 추가

테이블을 생성할 때 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 파라미터를 포함해야 합니다. CreateTable 또는 UpdateTable 작업을 호출할 때 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. 출력에서 UpdateTime, IsRegisteredWithLakeFormation, CreatedBy, DatabaseName 및 CreateTime 파라미터를 제거합니다. AWS Glue는 이러한 파라미터를 지원하지 않습니다.
    update-table 명령을 실행할 때 이러한 파라미터를 TableInput 속성에 포함하면 다음과 같은 오류가 발생할 수 있습니다.

    "Parameter validation failed:Unknown parameter in TableInput: "UpdateTime"은 다음 중 하나여야 합니다. Name, Description, Owner, LastAccessTime, LastAnalyzedTime, Retention, StorageDescriptor, PartitionKeys, ViewOriginalText, ViewExpandedText, TableType, Parameters"
    "Unknown parameter in TableInput: "IsRegisteredWithLakeFormation"은 다음 중 하나여야 합니다. Name, Description, Owner, LastAccessTime, LastAnalyzedTime, Retention, StorageDescriptor, PartitionKeys, ViewOriginalText, ViewExpandedText, TableType, Parameters"
    "Unknown parameter in TableInput: "CreatedBy"는 다음 중 하나여야 합니다. Name, Description, Owner, LastAccessTime, LastAnalyzedTime, Retention, StorageDescriptor, PartitionKeys, ViewOriginalText, ViewExpandedText, TableType, Parameters"
    "Unknown parameter in TableInput: "DatabaseName"은 다음 중 하나여야 합니다. Name, Description, Owner, LastAccessTime, LastAnalyzedTime, Retention, StorageDescriptor, PartitionKeys, ViewOriginalText, ViewExpandedText, TableType, Parameters"
    "Unknown parameter in 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을 해당 테이블 이름으로 교체
    1111222233334444을 해당 AWS 계정 ID로 교체
    **s3://doc_example_bucket/doc_example_prefix/**을 테이블이 저장된 Amazon Simple Storage Service(Amazon S3) 위치로 교체
    위 명령을 실행하면 TableType 파라미터가 업데이트되고, DDL 쿼리가 성공합니다.

java.lang.NullPointerException: Cannot invoke "java.util.Map.entrySet()" because the return value of "org.apache.hadoop.hive.metastore.api.SerDeInfo.getParameters()" is null

이 오류를 해결하려면 사용 사례에 따라 다음 작업 중 하나 이상을 완료하십시오.

테이블 생성 중에 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 호출을 사용하여 테이블을 생성하거나 업데이트할 때는 TableInput의 StorageDescriptor에 SerDeInfo 파라미터를 포함합니다. SerDeInfo의 Parameters 필드를 {"serialization.format": "1"}로 설정합니다.

이 파라미터는 CreateTable 또는 UpdateTable 같은 작업을 호출할 때 사용됩니다. 자세한 내용은 StorageDescriptor 구조를 참조하십시오.

AWS Glue 콘솔을 사용하여 테이블 업데이트

데이터 카탈로그에서 테이블의 속성을 업데이트하려면 다음 단계를 완료하십시오.

  1. AWS Glue 콘솔을 엽니다.
  2. 탐색 창의 데이터 카탈로그에서 테이블을 선택합니다.
  3. 업데이트하려는 테이블을 선택합니다.
  4. 작업을 선택한 다음, 테이블 편집을 선택하세요.
  5. SerDe 파라미터 섹션에서 추가를 선택합니다.
  6. 키에 “serialization.format”을 입력하고 값에 “1”을 입력합니다.
  7. 저장을 선택합니다.

AWS CLI를 사용하여 테이블 업데이트

테이블의 SerDeInfo 파라미터를 업데이트하려면 update-table AWS CLI 명령을 실행합니다. 이 명령을 실행하려면 전체 테이블 아키텍처를 정의하는 TableInput 객체가 있어야 합니다.

테이블의 TableInput 객체를 가져오려면 get-table AWS CLI 명령을 실행합니다. 그런 다음 SerDeInfo 파라미터를 포함하도록 이 명령의 출력을 업데이트합니다.

관련 정보

Athena의 문제 해결

AWS 공식업데이트됨 2년 전