ApplyMapping Class - AWS Glue

ApplyMapping Class

Applies a mapping in a DynamicFrame.


__call__(frame, mappings, transformation_ctx = "", info = "", stageThreshold = 0, totalThreshold = 0)

Applies a declarative mapping to a specified DynamicFrame.

  • frame – The DynamicFrame in which to apply the mapping (required).

  • mappings – A list of mapping tuples, each consisting of: (source column, source type, target column, target type). Required.

    If the source column has dots ".", square brackets "[]" or parentheses "()" in the name, the mapping will not work unless you place back-ticks "``" around it. For example, to map (string) to thisNewName (string) and [id] (long) to id (long), you would use the following tuples:

    ("``", "string", "thisNewName", "string"), ("`[id]`", "long", "id", "long")
  • transformation_ctx – A unique string that is used to identify state information (optional).

  • info – A string associated with errors in the transformation (optional).

  • stageThreshold – The maximum number of errors that can occur in the transformation before it errors out (optional; the default is zero).

  • totalThreshold – The maximum number of errors that can occur overall before processing errors out (optional; the default is zero).

Returns only the fields of the DynamicFrame specified in the "mapping" tuples.

apply(cls, *args, **kwargs)

Inherited from GlueTransform apply.


Inherited from GlueTransform name.


Inherited from GlueTransform describeArgs.


Inherited from GlueTransform describeReturn.


Inherited from GlueTransform describeTransform.


Inherited from GlueTransform describeErrors.


Inherited from GlueTransform describe.

Example for ApplyMapping

This example calls ApplyMapping for a DynamicFrame that uses the following schema:

order_schema = StructType([ StructField("order_id", StringType()), StructField("customer_id", StringType()), StructField("essential_item", StringType()), StructField("timestamp", StringType()), StructField("zipcode", StringType()) ])

This example changes some of the String columns to Long format to save storage space. It also shortens the name of the column zipcode to zip.

dyf_applyMapping = ApplyMapping.apply( frame = dyf_orders, mappings = [ ("order_id","String","order_id","Long"), ("customer_id","String","customer_id","Long"), ("essential_item","String","essential_item","String"), ("timestamp","String", "timestamp","Long"), ("zipcode","String","zip","Long") ])