0

I'm trying to create a dataframe with the following schema:

|-- data: struct (nullable = true) | |-- id: long (nullable = true) | |-- keyNote: struct (nullable = true) | | |-- key: string (nullable = true) | | |-- note: string (nullable = true) | |-- details: map (nullable = true) | | |-- key: string | | |-- value: string (valueContainsNull = true) 

This is the best I managed to do:

schema = StructType([ StructField("id",LongType(), True), StructField("keyNote",StructType([ StructField("key",StringType(),True), StructField("note",StringType(),True) ])), StructField("details",MapType(StringType, StringType, True)) ]) df = spark\ .createDataFrame([("idd",("keyy","notee"),("keyy","valuee")),schema]) 

But I'm getting an exception:

AssertionError: keyType should be DataType

2
  • 1
    missing () after StringType in details? Commented Jan 27, 2020 at 1:36
  • 1
    Always share the entire error message. Commented Jan 27, 2020 at 2:26

1 Answer 1

1

Seems you should write the correct syntax for the MapType:

MapType(StringType(), StringType(), True) 

Instead of StringType(), you wrote StringType without parentheses.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.