¿Cómo puedo solucionar el error «FAILED: NullPointerException Name is null» cuando consulto una tabla en Amazon Athena?

4 minutos de lectura
0

Se muestra el mensaje de error «FAILED: NullPointerException Name is Null» cuando consulto mi tabla de Amazon Athena.

Breve descripción

Este error se muestra cuando no se ha definido el atributo TableType para la tabla consultada en el Catálogo de datos de AWS Glue. El atributo TableType define si la tabla es una vista o una tabla externa. Este atributo se puede definir con valores, por ejemplo, EXTERNAL_TABLE y VIRTUAL_VIEW. Si desea ejecutar consultas de DDL, como SHOW CREATE TABLE o MSCK REPAIR TABLE, debe definir el atributo TableType.

Si ha definido la tabla mediante una plantilla de AWS CloudFormation o la API de AWS Glue sin especificar TableType como una de las propiedades, es posible que se muestre este error.

Resolución

Para solucionar este error, realice una o más de las siguientes acciones según su caso de uso:

Adición del atributo durante la creación de la tabla

Añada el atributo TableType al crear la tabla.

Nota: Si la tabla se crea mediante una instrucción de DDL o un rastreador de AWS Glue, la propiedad TableType se define automáticamente.

Actualización de la plantilla de CloudFormation o la llamada a la API de AWS Glue

Si la tabla se ha definido mediante una plantilla de CloudFormation o la API de AWS Glue sin especificar TableType, actualice la plantilla de CloudFormation o la llamada a la API de AWS Glue para añadir el atributo TableType.

Actualización de la tabla mediante la Interfaz de la línea de comandos de AWS (AWS CLI)

Para actualizar el atributo TableType para su tabla, utilice el comando aws glue update-table de AWS CLI. Para ejecutar este comando, debe tener el objeto TableInput, que define la arquitectura de toda la tabla.

Para obtener el objeto TableInput para su tabla, ejecute el comando aws glue get-table. A continuación, actualice el resultado de este comando tal y como se define en los pasos siguientes.

Nota: Si se muestran errores mientras ejecuta comandos de AWS CLI, compruebe si está utilizando la versión más reciente de AWS CLI.

1.    Ejecute en la tabla un comando similar al siguiente.

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

2.    Obtendrá un resultado similar al siguiente:

{
    "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"
    }
}

3.    Elimine del resultado anterior parámetros como UpdateTime, IsRegisteredWithLakeFormation, CreatedBy, DatabaseName y CreateTime. AWS Glue no admite estos parámetros. Si incluye estos parámetros en el atributo TableInput al ejecutar el comando update-table, es posible que se muestren los siguientes errores:

Parameter validation failed:
Unknown parameter in TableInput: "UpdateTime", must be one of: 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
Unknown parameter in TableInput: "CreatedBy", must be one of: 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
Unknown parameter in TableInput: "CreateTime", must be one of: Name, Description, Owner, LastAccessTime, LastAnalyzedTime, Retention, StorageDescriptor, PartitionKeys, ViewOriginalText, ViewExpandedText, TableType, Parameters

4.    Añada el parámetro "TableType": "EXTERNAL_TABLE" al resultado.

5.    Utilice el resultado como parámetro TableInput para ejecutar el comando update-table.

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"
    }

No olvide reemplazar lo siguiente en los comandos anteriores:

  • doc_example_database por el nombre de su base de datos
  • doc_example_table por el nombre de su tabla
  • 1111222233334444 por el ID de su cuenta
  • s3://doc_example_bucket/doc_example_prefix/ por la ubicación de Amazon Simple Storage Service (Amazon S3) en la que desee guardar la tabla

Tras ejecutar el comando anterior, el parámetro TableType se actualiza y las consultas de DDL, por ejemplo, SHOW CREATE TABLE o MSCK REPAIR TABLE, se ejecutan correctamente.


Información relacionada

Troubleshooting in Athena

OFICIAL DE AWS
OFICIAL DE AWSActualizada hace 3 años