Athena - parole riservate e tabella che non possono essere interrogate

Oct 22 2020

Sto inserendo file di dati JSON in S3 e utilizzo AWS-Glue per creare la definizione della tabella. Ho circa 120 campi per ogni "riga" json. Uno dei campi si chiama "timestamp" in minuscolo. Ho migliaia di file di grandi dimensioni e mi dispiacerebbe cambiarli tutti.

Qui (https://docs.aws.amazon.com/athena/latest/ug/reserved-words.html), Vedo che TIMESTAMP in DDL è una parola riservata. Significa che non sarò in grado di leggere quei file JSON da Athena.

Ricevo questo errore, che mi ha portato a considerare quanto sopra una potenziale ragione.

Ho fatto clic sui 3 punti a destra del tablename e ho fatto clic su "Preview Table", che ha creato ed eseguito questa istruzione select:

SELECT * FROM "relatixcurrdayjson"."table_currday" limit 10;

Ciò porta a un errore che sembra sbagliato o fuorviante:

Your query has the following error(s):

SYNTAX_ERROR: line 1:8: SELECT * not allowed in queries without FROM clause

This query ran against the "relatixcurrdayjson" database, unless qualified by the query. Please post the error message on our forum or contact customer support with Query Id: c448f0ea-5086-4436-9107-2b60dab0f04f.

Se faccio clic sull'opzione che dice "Genera Crea DDL tabella", costruisce questa riga per eseguire:

SHOW CREATE TABLE table_currday;

e si traduce in questo errore:

Your query has the following error(s):

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. java.lang.NullPointerException

This query ran against the "relatixcurrdayjson" database, unless qualified by the query. Please post the error message on our forum or contact customer support with Query Id: 6ac5d90f-8d52-4e3e-8f16-cd42e1edcfa3.

Questo è il registro di AWS Glue:

AGGIORNAMENTO # 1:

Ho usato Athena un paio di settimane fa con CSV e ha funzionato benissimo. Questa volta sto usando JSON.

Ho creato una nuova cartella con un file contenente quanto segue, ho eseguito il Glue Crawler:

[
    {"firstName": "Neal",
     "lastName": "Walters",
     "city": "Irving",
     "state", "TX"
     }
     
    {"firstName": "Fred",
     "lastName": "Flintstone",
     "city": "Bedrock",
     "state", "TX"
     }
     
    {"firstName": "Barney",
     "lastName": "Rubble",
     "city": "Stillwater",
     "state", "OK"
     }
     
]

e questo SQL dà lo stesso errore di cui sopra:

SELECT * FROM "relatixcurrdayjson"."tbeasyeasytest" limit 10;

Risposte

1 Theo Oct 23 2020 at 07:43

È molto facile fare in modo che i crawler di Glue creino tabelle che non funzionano in Athena, il che è sorprendente dato che è l'obiettivo principale per cui è stato progettato.

Se il JSON che hai pubblicato è esattamente quello su cui hai eseguito il crawler, il problema è che Athena non supporta i documenti JSON multilinea. I tuoi file devono avere esattamente un documento JSON per riga. Vedere Gestione di JSON multilinea? (E, punti bonus, CRLF) , query di file JSON su più righe in hive e Crea tabella in Athena da JSON annidato