Skip to content

Commit 33ddd2e

Browse files
committed
update checkInputColumn to print more info if needed
1 parent acf3e17 commit 33ddd2e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

mllib/src/main/scala/org/apache/spark/ml/util/SchemaUtils.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ object SchemaUtils {
3434
* @param colName column name
3535
* @param dataType required column data type
3636
*/
37-
def checkColumnType(schema: StructType, colName: String, dataType: DataType,
37+
def checkColumnType(schema: StructType,
38+
colName: String,
39+
dataType: DataType,
3840
msg: String = ""): Unit = {
3941
val actualDataType = schema(colName).dataType
42+
val message = if (msg != null && msg.trim.length > 0) " " + msg else ""
4043
require(actualDataType.equals(dataType),
41-
s"Column $colName must be of type $dataType but was actually $actualDataType.$msg")
44+
s"Column $colName must be of type $dataType but was actually $actualDataType.$message")
4245
}
4346

4447
/**

0 commit comments

Comments
 (0)