title: How to check the schema of DataFrame?
body: <p>I have the DataFrame <code>df</code> with some data that is the result of the calculation process. Then I store this DataFrame in the database for further usage.</p>
  
  <p>For example:</p>
  
  <pre><code>val rowsRDD: RDD[Row] = sc.parallelize(
    Seq(
      Row("first", 2.0, 7.0),
      Row("second", 3.5, 2.5),
      Row("third", 7.0, 5.9)
    )
  )
  
  val schema = new StructType()
    .add(StructField("id", StringType, true))
    .add(StructField("val1", DoubleType, true))
    .add(StructField("val2", DoubleType, true))
  
  val df = spark.createDataFrame(rowsRDD, schema)
  </code></pre>
  
  <p>I would need to check that all columns in the final DataFrame correspond to specific data types. Of course, one way is to create a DataFrame using schema (as an above example). However, in some cases the changes can be occasionally introduced to the data types during the calculation process - after the initial DataFrame was created (for example, when some formula applied to DataFrame was changed).</p>
  
  <p>Therefore, I want to double-check that the <strong>final</strong> DataFrame corresponds to the initial schema. If it does not correspond, then I would like to apply the corresponding casting. Is there any way to do it? </p>