Problems / Clean Product Codes / Editorial
split_part(product_code, '-', n)
1
2
3
CAST(... AS INT)
'00317'
317
product_id
In PySpark, F.split produces an array column; .getItem(i) (0-indexed) picks each element, and .cast('int') converts the SKU.
F.split
.getItem(i)
.cast('int')
Composite codes are a classic denormalization: one string, three facts. split_part beats regex here because the structure is rigid (exactly two dashes). The subtle step is the cast — leaving sku as text would keep zero-padded artifacts like '00317' that break numeric comparisons and joins downstream.
split_part
sku
Solve Clean Product Codes yourself →