IntToIp class - AWS Glue

IntToIp class

The IntToIp transform converts the integer value of source column or other value to the corresponding IPv4 value in then target column, and returns the result in a new column.

Example

from pyspark.context import SparkContext from pyspark.sql import SparkSession from awsgluedi.transforms import * sc = SparkContext() spark = SparkSession(sc) input_df = spark.createDataFrame( [ (3221225473,), (0,), (1,), (100,), (168430090,), (4294967295,), (4294967294,), (4294967296,), (-1,), (None,), ], ["source_column_int"], ) try: df_output = web_functions.IntToIp.apply( data_frame=input_df, spark_context=sc, source_column="source_column_int", target_column="target_column", value=None ) df_output.show() except: print("Unexpected Error happened ") raise

Output

The output will be:

``` +---------------+---------------+ |source_column_int|target_column| +---------------+---------------+ | 3221225473| 192.0.0.1 | | 0| 0.0.0.0 | | 1| 0.0.0.1 | | 100| 0.0.0.100| | 168430090 | 10.0.0.10 | | 4294967295| 255.255.255.255| | 4294967294| 255.255.255.254| | 4294967296| null | | -1| null | | null| null | +---------------+---------------+ ```

The IntToIp.apply transformation takes the `source_column` as `"source_column_int"` and the `target_column` as `"target_column"` and converts the integer values in the `source_column_int` column to their corresponding IPv4 address representation and stores the result in the `target_column` column.

For valid integer values within the range of IPv4 addresses (0 to 4294967295), the transformation successfully converts them to their IPv4 address representation (e.g., 192.0.0.1, 0.0.0.0, 10.0.0.10, 255.255.255.255).

For integer values outside the valid range (e.g., 4294967296, -1), the `target_column` value is set to `null`. For `null` values in the `source_column_int` column, the `target_column` value is also set to `null`.

Methods

__call__(spark_context, data_frame, target_column, source_column=None, value=None)

The IntToIp transform converts the integer value of source column or other value to the corresponding IPv4 value in then target column, and returns the result in a new column.

  • sourceColumn – The name of an existing column.

  • value – A character string to evaluate.

  • targetColumn – The name of the new column to be created.

apply(cls, *args, **kwargs)

Inherited from GlueTransform apply.

name(cls)

Inherited from GlueTransform name.

describeArgs(cls)

Inherited from GlueTransform describeArgs.

describeReturn(cls)

Inherited from GlueTransform describeReturn.

describeTransform(cls)

Inherited from GlueTransform describeTransform.

describeErrors(cls)

Inherited from GlueTransform describeErrors.

describe(cls)

Inherited from GlueTransform describe.