Ultimate access to all questions.
Upgrade Now 🚀
Sign in to unlock AI tutor
Suppose you have a DataFrame df with a column url containing URLs. How would you extract the domain name from these URLs and create a new column domain using Spark? Provide the code snippet.
df
url
domain
A
df.withColumn('domain', regexp_extract(col('url'), 'https?://([^/]+)', 1))
B
df.select(regexp_extract(col('url'), 'https?://([^/]+)', 1).alias('domain'))
C
df.withColumn('domain', split(col('url'), '/')[2])
D
df.select(split(col('url'), '/')[2].alias('domain'))