Problems / Mask Phone Numbers / Editorial
substr(phone, 7)
'XXXXXX' || substr(phone, 7)
customer_id
In PySpark the same shape is F.concat(F.lit('XXXXXX'), F.substring('phone', 7, 4)).
F.concat(F.lit('XXXXXX'), F.substring('phone', 7, 4))
Phone numbers must be handled as strings, not integers — casting to a number silently drops leading zeros (0225554321 would shrink to 9 digits and the mask would slip by one character). Because the width is fixed at 10, no regex is needed: positional slicing is simpler and faster.
0225554321
Solve Mask Phone Numbers yourself →