[ 
https://issues.apache.org/jira/browse/SPARK-14023?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16727491#comment-16727491
 ] 

ASF GitHub Bot commented on SPARK-14023:
----------------------------------------

srowen closed pull request #20500: [SPARK-14023][MLlib] Make exceptions 
consistent regarding fields and columns
URL: https://github.com/apache/spark/pull/20500
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructType.scala 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructType.scala
index e3b0969283a84..c6c295487ecc6 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructType.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructType.scala
@@ -57,7 +57,7 @@ import org.apache.spark.util.Utils
  *
  * // If this struct does not have a field called "d", it throws an exception.
  * struct("d")
- * // java.lang.IllegalArgumentException: Field "d" does not exist.
+ * // java.lang.IllegalArgumentException: Column "d" does not exist.
  * //   ...
  *
  * // Extract multiple StructFields. Field names are provided in a set.
@@ -69,7 +69,7 @@ import org.apache.spark.util.Utils
  * // Any names without matching fields will throw an exception.
  * // For the case shown below, an exception is thrown due to "d".
  * struct(Set("b", "c", "d"))
- * // java.lang.IllegalArgumentException: Field "d" does not exist.
+ * // java.lang.IllegalArgumentException: Column "d" does not exist.
  * //    ...
  * }}}
  *
@@ -260,24 +260,24 @@ case class StructType(fields: Array[StructField]) extends 
DataType with Seq[Stru
   /**
    * Extracts the [[StructField]] with the given name.
    *
-   * @throws IllegalArgumentException if a field with the given name does not 
exist
+   * @throws IllegalArgumentException if a column with the given name does not 
exist
    */
   def apply(name: String): StructField = {
     nameToField.getOrElse(name,
-      throw new IllegalArgumentException(s"""Field "$name" does not exist."""))
+      throw new IllegalArgumentException(s"""Column "$name" does not 
exist."""))
   }
 
   /**
    * Returns a [[StructType]] containing [[StructField]]s of the given names, 
preserving the
    * original order of fields.
    *
-   * @throws IllegalArgumentException if a field cannot be found for any of 
the given names
+   * @throws IllegalArgumentException if a column cannot be found for any of 
the given names
    */
   def apply(names: Set[String]): StructType = {
     val nonExistFields = names -- fieldNamesSet
     if (nonExistFields.nonEmpty) {
       throw new IllegalArgumentException(
-        s"Field ${nonExistFields.mkString(",")} does not exist.")
+        s"Column ${nonExistFields.mkString(",")} does not exist.")
     }
     // Preserve the original order of fields.
     StructType(fields.filter(f => names.contains(f.name)))
@@ -286,11 +286,11 @@ case class StructType(fields: Array[StructField]) extends 
DataType with Seq[Stru
   /**
    * Returns the index of a given field.
    *
-   * @throws IllegalArgumentException if a field with the given name does not 
exist
+   * @throws IllegalArgumentException if a column with the given name does not 
exist
    */
   def fieldIndex(name: String): Int = {
     nameToIndex.getOrElse(name,
-      throw new IllegalArgumentException(s"""Field "$name" does not exist."""))
+      throw new IllegalArgumentException(s"""Column "$name" does not 
exist."""))
   }
 
   private[sql] def getFieldIndex(name: String): Option[Int] = {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Make exceptions consistent regarding fields and columns
> -------------------------------------------------------
>
>                 Key: SPARK-14023
>                 URL: https://issues.apache.org/jira/browse/SPARK-14023
>             Project: Spark
>          Issue Type: Improvement
>          Components: MLlib
>    Affects Versions: 2.0.0
>            Reporter: Jacek Laskowski
>            Priority: Trivial
>
> As you can see below, a column is called a field depending on where an 
> exception is thrown. I think it should be "column" everywhere (since that's 
> what has a type from a schema).
> {code}
> scala> lr
> res32: org.apache.spark.ml.regression.LinearRegression = linReg_d9bfe808e743
> scala> lr.fit(ds)
> java.lang.IllegalArgumentException: Field "features" does not exist.
>   at 
> org.apache.spark.sql.types.StructType$$anonfun$apply$1.apply(StructType.scala:214)
>   at 
> org.apache.spark.sql.types.StructType$$anonfun$apply$1.apply(StructType.scala:214)
>   at scala.collection.MapLike$class.getOrElse(MapLike.scala:128)
>   at scala.collection.AbstractMap.getOrElse(Map.scala:59)
>   at org.apache.spark.sql.types.StructType.apply(StructType.scala:213)
>   at 
> org.apache.spark.ml.util.SchemaUtils$.checkColumnType(SchemaUtils.scala:40)
>   at 
> org.apache.spark.ml.PredictorParams$class.validateAndTransformSchema(Predictor.scala:50)
>   at 
> org.apache.spark.ml.Predictor.validateAndTransformSchema(Predictor.scala:71)
>   at org.apache.spark.ml.Predictor.transformSchema(Predictor.scala:116)
>   at org.apache.spark.ml.PipelineStage.transformSchema(Pipeline.scala:67)
>   at org.apache.spark.ml.Predictor.fit(Predictor.scala:89)
>   ... 51 elided
> scala> lr.fit(ds)
> java.lang.IllegalArgumentException: requirement failed: Column label must be 
> of type DoubleType but was actually StringType.
>   at scala.Predef$.require(Predef.scala:219)
>   at 
> org.apache.spark.ml.util.SchemaUtils$.checkColumnType(SchemaUtils.scala:42)
>   at 
> org.apache.spark.ml.PredictorParams$class.validateAndTransformSchema(Predictor.scala:53)
>   at 
> org.apache.spark.ml.Predictor.validateAndTransformSchema(Predictor.scala:71)
>   at org.apache.spark.ml.Predictor.transformSchema(Predictor.scala:116)
>   at org.apache.spark.ml.PipelineStage.transformSchema(Pipeline.scala:67)
>   at org.apache.spark.ml.Predictor.fit(Predictor.scala:89)
>   ... 51 elided
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org
For additional commands, e-mail: issues-h...@spark.apache.org

Reply via email to