QuestionQ282Verified/Developing Apache Spark™ DataFrame/DataSet API ApplicationsCopy linkReport a problemAsk AstroTutorSave questionWhich UDF implementation computes the length of strings in a Spark DataFrame?Adf.withcolumn("length", spark.udf("len", StringType()))Bdf.select(length (col("stringColumn")) -alias("Length"))Cspark.udf.register("stringLength", lambda s: len(s))Ddf.withcolumn("length", udf(lambda s: len(s), StringType()))Show AnswerAnswerExplanationRegistering a Python function such as lambda s: len(s) with spark.udf.register creates a Spark SQL UDF that returns the length of each string passed to it.Show comments0Show commentsCommunity DiscussionNo comments yet. Be the first to start the discussion!
Community Discussion