

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

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

`IpToInt` 轉換會將來源資料欄的網際網路協定第 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\_column` 作為 `"source\_column\_ip"`，將 `target\_column` 作為 `"target\_column"`，將 `source\_column\_ip` 資料欄中的有效 IPv4 地址字串轉換為對應的 32 位元整數表示法，並將結果儲存在 `target\_column` 資料欄中。

 對於有效的 IPv4 地址字串 (例如 "192.0.0.1"、"10.10.10.10"、"1.2.3.4")，轉換會成功將其轉換為整數表示法 (例如 3221225473、168427722、16909060)。對於不是有效 IPv4 地址的字串 (例如 URL、"abc" 等非 IP 字串、"abc.abc.abc.abc" 等無效的 IP 格式)，`target\_column` 值設定為 `null`。對於 `source\_column\_ip` 資料欄中的 `null` 值，`target\_column` 值也會設定為 `null`。

## 方法
<a name="aws-glue-api-pyspark-transforms-IpToInt-_methods"></a>
+ [\_\_call\_\_](#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)

## \_\_call\_\_(spark\_context, data\_frame, target\_column, source\_column=None, value=None)
<a name="aws-glue-api-pyspark-transforms-IpToInt-__call__"></a>

 `IpToInt` 轉換會將來源資料欄的網際網路協定第 4 版 (IPv4) 值或其他值轉換為目標資料欄中對應的整數值，並在新的資料欄中傳回結果。
+ `sourceColumn` – 現有資料欄的名稱。
+ `value` – 要評估的字元字串。
+ `targetColumn` – 要建立的新資料欄的名稱。

## apply(cls, \*args, \*\*kwargs)
<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` [name](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)。