It is the below line which is setting the data types for both the fields as StringType:
val schema =
StructType(
schemaString.split(" ").map(fieldName => StructField(fieldName, StringType, true)))You can define your custom schema as follows :
val customSchema = StructType(Array(
StructField("name", StringType, true),
StructField("age", IntegerType, true)))You can add additional fields as well in the above schema definition.
And then you can use this customSchema while creating the dataframe as follows:
val peopleDataFrame = sqlContext.createDataFrame(rowRDD, customSchema)
Also for details, please see this page.