Skip to main content

ip_network_last

Applies to: check marked yes 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 last address of an IPv4 or IPv6 CIDR block in its canonical form.

For the corresponding SQL function, see ip_network_last function.

Syntax

Python
from pyspark.databricks.sql import functions as dbf

dbf.ip_network_last(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 last address 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_network_last('cidr').alias('result')).collect()
Output
[Row(result='192.168.1.255')]

Example 2: Get last address from an IPv6 CIDR block.

Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('2001:db8::/32',)], ['cidr'])
df.select(dbf.ip_network_last('cidr').alias('result')).collect()
Output
[Row(result='2001:db8:ffff:ffff:ffff:ffff:ffff:ffff')]

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_network_last('cidr').alias('result')).collect()
Output
[Row(result=None)]