Search code examples
amazon-athena

mismatched input 'EXTERNAL'. Expecting: 'OR', 'SCHEMA', 'TABLE', 'VIEW'


I am trying to create a table in AWS Athena with the following command. However I get the error:mismatched input 'EXTERNAL'. Expecting: 'OR', 'SCHEMA', 'TABLE', 'VIEW'

Can you helpp with this?

    CREATE EXTERNAL TABLE IF NOT EXISTS 'transport_evaluator_prod' (
    `messageId` STRING,
    `type` STRING,
    `causationId` STRING,
    `correlationId` STRING,
    `traceparent` STRING,
    `data` STRUCT<
    `evaluationOccurred`:STRING,
`eta`:STRUCT<
    `distance`:INT,
`timeToDestination`:INT,
`eta`:STRING,
`destination`:STRUCT<
    `latitude`:DOUBLE,
`longitude`:DOUBLE,
`altitude`:DOUBLE>,
`destinationEventId`:STRING,
`origin`:STRUCT<
    `latitude`:DOUBLE,
`longitude`:DOUBLE,
`altitude`:DOUBLE>,
`originEventId`:STRING,
`plannedArrival`:STRING,
`locationActionReference`:STRING,
`resourceUrn`:STRING,
`eventProvider`:STRING,
`occured`:STRING,
`position`:STRUCT<
    `latitude`:DOUBLE,
`longitude`:DOUBLE,
`altitude`:DOUBLE>,
`equipmentNumber`:STRING,
`received`:STRING>>)
ROW FORMAT SERDE 
     'org.openx.data.jsonserde.JsonSerDe'
LOCATION
     'for-security-pointing-to-folder'

Solution

  • I am providing what I changed in order to get it to work for the sake of the next person that might run into similar issues

    1. I removed all quotation marks for the columns of the table as well as the inner attributes inside the 'data' struct.
    2. Also watch out that all attributes under 'struct' are followed by ':'
    3. Ensure that the type provided matches the one for the payload json