row = Row('k', 'v')
df = sc.parallelize([row(1, 'foo1'), row(1, 'foo2'), row(2, 'bar1'), row(2,
    'bar2')]).toDF()

def groupConcat(col):
    """Group and concatenate values for a given column
    >>> df = sqlContext.createDataFrame([(1, "foo"), (2, "bar")], ("k", "v"))
    >>> df.select(groupConcat("v").alias("vs"))
    [Row(vs=u'foo,bar')]
    """
sc = SparkContext._active_spark_context
_groupConcat = sc._jvm.com.example.udaf.GroupConcat.apply
return Column(_groupConcat(_to_seq(sc, [col], _to_java_column)))
df.groupBy('k').agg(groupConcat('v').alias('vs')).show()
Spark: How to map Python with Scala or Java User Defined Functions?