Skip to content

Commit

Permalink
update checkInputColumn to print more info if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
rekhajoshm committed Jul 1, 2015
1 parent 8993c0e commit acf3e17
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
15 changes: 1 addition & 14 deletions mllib/src/main/scala/org/apache/spark/ml/param/params.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import scala.annotation.varargs
import scala.collection.mutable

import org.apache.spark.annotation.AlphaComponent
import org.apache.spark.ml.util.{SchemaUtils, Identifiable}
import org.apache.spark.sql.types.{DataType, StructType}
import org.apache.spark.ml.util.Identifiable

/**
* :: AlphaComponent ::
Expand Down Expand Up @@ -381,18 +380,6 @@ trait Params extends Identifiable with Serializable {
this
}

/**
* Check whether the given schema contains an input column.
* @param colName Input column name
* @param dataType Input column DataType
*/
protected def checkInputColumn(schema: StructType, colName: String, dataType: DataType): Unit = {
val actualDataType = schema(colName).dataType
SchemaUtils.checkColumnType(schema, colName, dataType)
require(actualDataType.equals(dataType), s"Input column Name: $colName Description: ${getParam(colName)}")
}


/**
* Gets the default value of a parameter.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ 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
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.$msg")
}

/**
Expand Down

0 comments on commit acf3e17

Please sign in to comment.