

# IpToInt 类
<a name="aws-glue-api-pyspark-transforms-IpToInt"></a>

`IpToInt` 转换会将源列的 Internet 协议版本 4（IPv4）值或其他值转换为目标列中相应的整数值，然后在新列中返回结果。

## 示例
<a name="pyspark-IpToInt-examples"></a>

 对于 AWS Glue 4.0 及更高版本，使用 `key: --enable-glue-di-transforms, value: true` 创建或更新任务参数 

```
from pyspark.context import SparkContext
from awsgluedi.transforms import *

sc = SparkContext()

input_df = spark.createDataFrame(
    [
        ("192.0.0.1",),
        ("10.10.10.10",),
        ("1.2.3.4",),
        ("1.2.3.6",),
        ("http://12.13.14.15",),
        ("https://16.17.18.19",),
        ("1.2.3.4",),
        (None,),
        ("abc",),
        ("abc.abc.abc.abc",),
        ("321.123.123.123",),
        ("244.4.4.4",),
        ("255.255.255.255",),
    ],
    ["source_column_ip"],
)

    df_output = web_functions.IpToInt.apply(
        data_frame=input_df,
        spark_context=sc,
        source_column="source_column_ip",
        target_column="target_column",
        value=None
    )
    df_output.show()
```

## Output
<a name="pyspark-IpToInt-output"></a>

 输出是：

```
```
+----------------+---------------+
|source_column_ip| target_column|
+----------------+---------------+
| 192.0.0.1| 3221225473|
| 10.10.10.10| 168427722|
| 1.2.3.4| 16909060|
| 1.2.3.6| 16909062|
|http://12.13.14.15| null|
|https://16.17.18.19| null|
| 1.2.3.4| 16909060|
| null| null|
| abc| null|
|abc.abc.abc.abc| null|
| 321.123.123.123| null|
| 244.4.4.4| 4102444804|
| 255.255.255.255| 4294967295|
+----------------+---------------+
```
```

 `IpToInt` 转换会将“source\$1column”设为“source\$1column\$1ip”，将“target\$1column”设为“target\$1column”，并将“source\$1column\$1ip”列中的有效 IPv4 地址字符串转换为相应的 32 位整数表示形式，并将结果存储在“target\$1column”列中。

 对于有效的 IPv4 地址字符串（例如“192.0.0.1”、“10.10.10.10”、“1.2.3.4”），该转换可成功地将其转换为整数表示形式（例如 3221225473、168427722、16909060）。对于非有效 IPv4 地址的字符串 [例如 URL、非 IP 字符串（如“abc”）、无效 IP 格式（如“abc.abc.abc.abc”）]，“target\$1column”值会设置为“null”。对于“source\$1column\$1ip”列中的“null”值，“target\$1column”值也会设置为“null”。

## 方法
<a name="aws-glue-api-pyspark-transforms-IpToInt-_methods"></a>
+ [\$1\$1call\$1\$1](#aws-glue-api-pyspark-transforms-IpToInt-__call__)
+ [apply](#aws-glue-api-crawler-pyspark-transforms-IpToInt-apply)
+ [name](#aws-glue-api-crawler-pyspark-transforms-IpToInt-name)
+ [describeArgs](#aws-glue-api-crawler-pyspark-transforms-IpToInt-describeArgs)
+ [describeReturn](#aws-glue-api-crawler-pyspark-transforms-IpToInt-describeReturn)
+ [describeTransform](#aws-glue-api-crawler-pyspark-transforms-IpToInt-describeTransform)
+ [describeErrors](#aws-glue-api-crawler-pyspark-transforms-IpToInt-describeErrors)
+ [describe](#aws-glue-api-crawler-pyspark-transforms-IpToInt-describe)

## \$1\$1call\$1\$1(spark\$1context, data\$1frame, target\$1column, source\$1column=None, value=None)
<a name="aws-glue-api-pyspark-transforms-IpToInt-__call__"></a>

 `IpToInt` 转换会将源列的 Internet 协议版本 4（IPv4）值或其他值转换为目标列中相应的整数值，然后在新列中返回结果。
+ `sourceColumn`：现有列的名称。
+ `value`：要计算的字符串。
+ `targetColumn` – 要创建的新列的名称。

## apply(cls, \$1args, \$1\$1kwargs)
<a name="aws-glue-api-crawler-pyspark-transforms-IpToInt-apply"></a>

继承自 `GlueTransform` [apply](aws-glue-api-crawler-pyspark-transforms-GlueTransform.md#aws-glue-api-crawler-pyspark-transforms-GlueTransform-apply)。

## name(cls)
<a name="aws-glue-api-crawler-pyspark-transforms-IpToInt-name"></a>

继承自 `GlueTransform` [名称](aws-glue-api-crawler-pyspark-transforms-GlueTransform.md#aws-glue-api-crawler-pyspark-transforms-GlueTransform-name)。

## describeArgs(cls)
<a name="aws-glue-api-crawler-pyspark-transforms-IpToInt-describeArgs"></a>

继承自 `GlueTransform` [describeArgs](aws-glue-api-crawler-pyspark-transforms-GlueTransform.md#aws-glue-api-crawler-pyspark-transforms-GlueTransform-describeArgs)。

## describeReturn(cls)
<a name="aws-glue-api-crawler-pyspark-transforms-IpToInt-describeReturn"></a>

继承自 `GlueTransform` [describeReturn](aws-glue-api-crawler-pyspark-transforms-GlueTransform.md#aws-glue-api-crawler-pyspark-transforms-GlueTransform-describeReturn)。

## describeTransform(cls)
<a name="aws-glue-api-crawler-pyspark-transforms-IpToInt-describeTransform"></a>

继承自 `GlueTransform` [describeTransform](aws-glue-api-crawler-pyspark-transforms-GlueTransform.md#aws-glue-api-crawler-pyspark-transforms-GlueTransform-describeTransform)。

## describeErrors(cls)
<a name="aws-glue-api-crawler-pyspark-transforms-IpToInt-describeErrors"></a>

继承自 `GlueTransform` [describeErrors](aws-glue-api-crawler-pyspark-transforms-GlueTransform.md#aws-glue-api-crawler-pyspark-transforms-GlueTransform-describeErrors)。

## describe(cls)
<a name="aws-glue-api-crawler-pyspark-transforms-IpToInt-describe"></a>

继承自 `GlueTransform` [describe](aws-glue-api-crawler-pyspark-transforms-GlueTransform.md#aws-glue-api-crawler-pyspark-transforms-GlueTransform-describe)。