2016-10-04 3 views
0

私は、型キャストを行っている関数に対してIntelliJで単体テストを作成しました。だから私のユニットテストでは、私は次のようassertステートメントを使用して検証する:spark DataFrame列のデータ型をプログラムで検証するにはどうすればよいですか?

assert(testDF.select(col1).dataType == Integer) 

上記のassert文を満たすのであれば、ユニットテストは成功となります。

誰でもこれについてお手伝いできますか?あなたは、たとえばパターンマッチングに使用することができます

答えて

1

:あなたは別の特性を一致させたい場合は

import org.apache.spark.sql.types.IntegerType 

assert(testDF.schema(col1).dataType match { 
    case IntegerType => true 
    case _ => false 
}) 

import org.apache.spark.sql.types.StructField 

assert(testDF.schema(col1) match { 
    case StructField(_, IntegerType, nullable, _) => true 
    case _ => false 
}) 
関連する問題