Skip to content

Unable to use Glue table EDIT SCHEMA AS JSON option

0

Hi, I'm new to the aws glue tables , i'm trying to read nested json files from s3 location and store the data into tables using crawlers. Crawler is not identifying the schema of the json, So i did my research on how can i pass the json schema so that the data will be loaded in to the tables correctly and can easily queried by using aws athena. I tried classifiers, ETL jobs, Lambdas e.t.c those are working great but my intension was to use only crawlers then i found the option at the tables in the DB "EDIT SCHEMA AS JSON" I've given my schema in that but it's not moving forward or giving me errors after that ,

Could anyone please let me how can i add that schema and load the data in that format when ever i use crawler EDIT_SCHEMA_AS_JSON SAVE OPTION NOT WORKING

asked 2 years ago785 views

1 Answer
0

I understand you're facing challenges with AWS Glue crawlers not correctly identifying the schema of nested JSON files in S3, and you're looking for a way to manually specify the schema. While the "EDIT SCHEMA AS JSON" option in the AWS Glue console seems like a potential solution, it appears to be not working as expected in your case.

For nested JSON files, crawlers can sometimes struggle to infer the correct schema. Here are a few alternative approaches you can consider:

  1. Use a custom classifier: You can create a custom JSON classifier that defines the structure of your nested JSON. This classifier can then be associated with your crawler to help it correctly interpret the schema.

  2. Manually create the table: Instead of relying on the crawler, you can manually create the table in the AWS Glue Data Catalog with the correct schema. Here's how:

    • In the AWS Glue console, go to Tables and choose "Add table"
    • Set the table properties, including the database and S3 data location
    • For the data format, choose JSON
    • When defining the schema, you can add columns that represent your nested structure
    • You can use dot notation to represent nested fields (e.g., "parent.child.grandchild")
  3. Use AWS Glue ETL jobs: If you've had success with ETL jobs, you might want to consider using them in combination with crawlers. You could use an ETL job to flatten or transform your nested JSON into a format that's easier for the crawler to interpret.

  4. Optimize JSON reading: If you're using AWS Glue version 3.0 or later, you can try using the optimized JSON reader. This can be done by setting "optimizePerformance" to True in the format_options when creating a dynamic frame. However, note that this requires providing a schema and has some limitations with nested structures.

  5. Use the AWS Glue Schema Registry: You can create a schema for your JSON data using the AWS Glue Schema Registry. This allows you to define and evolve schemas over time, which can be particularly useful for complex, nested JSON structures.

Remember, when dealing with nested JSON, it's crucial to have a clear understanding of your data structure. You might need to experiment with different approaches to find the one that works best for your specific use case.
Sources
Using the JSON format in AWS Glue - AWS Glue
Creating a schema - AWS Glue
Getting started with the AWS Glue Data Catalog - AWS Glue

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.