[SPARK-7137] [ML] Update SchemaUtils checkInputColumn to print more info if needed

Author: Joshi <rekhajoshm@gmail.com>
Author: Rekha Joshi <rekhajoshm@gmail.com>

Closes #5992 from rekhajoshm/fix/SPARK-7137 and squashes the following commits:

8c42b57 [Joshi] update checkInputColumn to print more info if needed
33ddd2e [Joshi] update checkInputColumn to print more info if needed
acf3e17 [Joshi] update checkInputColumn to print more info if needed
8993c0e [Joshi] SPARK-7137: Add checkInputColumn back to Params and print more info
e3677c9 [Rekha Joshi] Merge pull request #1 from apache/master
This commit is contained in:
Joshi 2015-07-05 12:58:03 -07:00 committed by Joseph K. Bradley
parent 2b820f2a4b
commit f9c448dce8

View file

@ -32,10 +32,15 @@ private[spark] object SchemaUtils {
* @param colName column name
* @param dataType required column data type
*/
def checkColumnType(schema: StructType, colName: String, dataType: DataType): Unit = {
def checkColumnType(
schema: StructType,
colName: String,
dataType: DataType,
msg: String = ""): Unit = {
val actualDataType = schema(colName).dataType
val message = if (msg != null && msg.trim.length > 0) " " + msg else ""
require(actualDataType.equals(dataType),
s"Column $colName must be of type $dataType but was actually $actualDataType.")
s"Column $colName must be of type $dataType but was actually $actualDataType.$message")
}
/**