40
votes

As per this AWS Forum Thread, does anyone know how to use AWS Glue to create an AWS Athena table whose partitions contain different schemas (in this case different subsets of columns from the table schema)?

At the moment, when I run the crawler over this data and then make a query in Athena, I get the error 'HIVE_PARTITION_SCHEMA_MISMATCH'

My use case is:

  • Partitions represent days
  • Files represent events
  • Each event is a json blob in a single s3 file
  • An event contains a subset of columns (dependent on the type of event)
  • The 'schema' of the entire table is the full set of columns for all the event types (this is correctly put together by Glue crawler)
  • The 'schema' of each partition is the subset of columns for the event types that occurred on that day (hence in Glue each partition potentially has a different subset of columns from the table schema)
  • This inconsistency causes the error in Athena I think

If I were to manually write a schema I could do this fine as there would just be one table schema, and keys which are missing in the JSON file would be treated as Nulls.

Thanks in advance!

4
I have the same issue where Partition schemas are different in column order. Its the same data but he is not smart enough to just apply the table schema correctly. Did you solve the issue?Dusan Vasiljevic
No, unfortunately, I didn't solve this one. In terms of column order, you could try writing as newline separated JSON. It's not ideal but I think if you gzip the files it won't make a huge size difference to size. Good luck and let me know if you learn anything!rjmurt
Defining several crawlers (one per partition) is not a solution?Cherry

4 Answers

61
votes

I had the same issue, solved it by configuring crawler to update table metadata for preexisting partitions:

enter image description here

4
votes

This helped me. Posting the image for others in case the link is lost enter image description here

3
votes

It also fixed my issue! If somebody need to provision This Configuration Crawler with Terraform so here is how I did it:

resource "aws_glue_crawler" "crawler-s3-rawdata" {
  database_name = "my_glue_database"
  name          = "my_crawler"
  role          = "my_iam_role.arn"

  configuration = <<EOF
{
   "Version": 1.0,
   "CrawlerOutput": {
      "Partitions": { "AddOrUpdateBehavior": "InheritFromTable" }
   }
}
EOF
  s3_target {
    path = "s3://mybucket"
  }
}
0
votes

Despite selecting Update all new and existing partitions with metadata from the table. in the crawler's configuration, it still occasionally failed to set the expected parameters for all partitions (specifically jsonPath wasn't inherited from the table's properties in my case).

As suggested in https://docs.aws.amazon.com/athena/latest/ug/updates-and-partitions.html, "to drop the partition that is causing the error and recreate it" helped

After dropping the problematic partitions, glue crawler re-created them correctly on the following run