ip_prefix_length
Applies to: Databricks Runtime 18.2 and above
Beta
This feature is in Beta. Workspace admins can control access to this feature from the Previews page. See Manage Databricks previews.
Returns the prefix length of an IPv4 or IPv6 CIDR block.
For the corresponding SQL function, see ip_prefix_length function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.ip_prefix_length(col=<col>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| A STRING or BINARY value representing a valid IPv4 or IPv6 CIDR block. |
Examples
Example 1: Get prefix length from an IPv4 CIDR block.
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('192.168.1.0/24',)], ['cidr'])
df.select(dbf.ip_prefix_length('cidr').alias('result')).collect()
Output
[Row(result=24)]
Example 2: Get prefix length from an IPv6 CIDR block.
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('2001:db8::1/64',)], ['cidr'])
df.select(dbf.ip_prefix_length('cidr').alias('result')).collect()
Output
[Row(result=64)]
Example 3: None input returns None.
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([(None,)], 'cidr: string')
df.select(dbf.ip_prefix_length('cidr').alias('result')).collect()
Output
[Row(result=None)]