Nóta
Teastaíonn údarú chun rochtain a fháil ar an leathanach seo. Is féidir leat triail a bhaint as shíniú isteach nó eolairí a athrú.
Teastaíonn údarú chun rochtain a fháil ar an leathanach seo. Is féidir leat triail a bhaint as eolairí a athrú.
Applies to:
Databricks Runtime 18.2 and above
Important
This feature is in Beta. Workspace admins can control access to this feature from the Previews page. See Manage Azure Databricks previews.
Returns the prefix length of an IPv4 or IPv6 CIDR block.
For the corresponding SQL function, see ip_prefix_length function.
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.ip_prefix_length(col=<col>)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column or str |
A STRING or BINARY value representing a valid IPv4 or IPv6 CIDR block. |
Examples
Example 1: Get prefix length from an IPv4 CIDR block.
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()
[Row(result=24)]
Example 2: Get prefix length from an IPv6 CIDR block.
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()
[Row(result=64)]
Example 3: None input returns None.
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([(None,)], 'cidr: string')
df.select(dbf.ip_prefix_length('cidr').alias('result')).collect()
[Row(result=None)]