val newDf = df.withColumn("D", when($"B".isNull or $"B" === "", 0).otherwise(1))
Unfortunately text8 has had periods stripped out so you can't just split on them, but you can find the raw version here as well as the perl script used to process it, and it isn't hard to edit the script to not remove periods.
import org.apache.spark.sql.functions.{udf, explode}
val zip = udf((xs: Seq Long » , ys: Seq Long » ) => xs.zip(ys))
df.withColumn("vars", explode(zip_udf($"varA", $"varB"))).select(
$"userId", $"someString",
$"vars._1".alias("varA"), $"vars._2".alias("varB")).show