Git Product home page Git Product logo

Comments (1)

mohitsax avatar mohitsax commented on July 22, 2024

Thanks for trying AWS Glue. Here is a solution for your problem.

First, you can refer the following blog post on how to partition a dynamic frame into Hive-style s3 partitions based on key values:

https://aws.amazon.com/blogs/big-data/work-with-partitioned-data-in-aws-glue/

glueContext.write_dynamic_frame.from_options(
frame = datasource0,
connection_type = "s3",
connection_options = {"path": "s3://my-result-bucket/sub-bucket", "partitionKeys" : ["key1"]},
format = "json",
transformation_ctx = "datasink2")

Now if you would like to coalesce all files in each of these written Hive-style partition into a single file, you can create another dynamic frame using the Grouping feature in Glue that could read a large number of files from these Hive-style partitions into a group:

https://docs.aws.amazon.com/glue/latest/dg/grouping-input-files.html

datasource1 = glueContext.create_dynamic_frame_from_options("s3", {'paths': ["s3://my-result-bucket/sub-bucket/"], "recurse": True, 'groupFiles': 'inPartition', 'groupSize': 1024 * 1024}, format="json")

Finally, you can write out this dynamic frame datasource1 out to individual s3 files, where each output file would be roughly the same as groupSize. Make sure that your groupSize is larger than the size of each Hive-style partition, so that you have exactly 1 file per Hive-style partition or key value.

from aws-glue-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.