Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'StructType' object has no attribute 'toDDL'

I'm running this script with spark 2.4.3 & python 3.6.10

columns = ["language","users_count"]
data = [("Java", "20000"), ("Python", "100000"), ("Scala", "3000")]
spark = SparkSession.builder.appName('SparkByExamples.com').getOrCreate()
rdd = spark.sparkContext.parallelize(data)
df = rdd.toDF()
print(df.schema.toDDL)

AttributeError: 'StructType' object has no attribute 'toDDL'

The java documentation mentions that toDDL function is available from spark 2.4.0, which is not in the python documentation.

Is there any other way to use this java function from python?

like image 281
Jérémy Avatar asked Sep 01 '25 04:09

Jérémy


1 Answers

You can call the toDDL method on the Java dataframe object:

df._jdf.schema().toDDL()
like image 123
mck Avatar answered Sep 02 '25 22:09

mck