Skip to content

Latest commit

 

History

History
23 lines (16 loc) · 709 Bytes

spark-sql-dataframe-schema.adoc

File metadata and controls

23 lines (16 loc) · 709 Bytes

Schema

Caution
FIXME Add sections about explicit and implicit schemas.

Implicit Schema

val df = Seq((0, s"""hello\tworld"""), (1, "two  spaces inside")).toDF("label", "sentence")

scala> df.printSchema
root
 |-- label: integer (nullable = false)
 |-- sentence: string (nullable = true)

scala> df.schema
res0: org.apache.spark.sql.types.StructType = StructType(StructField(label,IntegerType,false), StructField(sentence,StringType,true))

scala> df.schema("label").dataType
res1: org.apache.spark.sql.types.DataType = IntegerType