[ https://issues.apache.org/jira/browse/SPARK-18054?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15597816#comment-15597816 ]
Barry Becker commented on SPARK-18054: -------------------------------------- Ah. That is quite likely the problem. I will verify next week. A simple fix for this then, would be to include the package name of the 2 classes in the error message. > Unexpected error from UDF that gets an element of a vector: argument 1 > requires vector type, however, '`_column_`' is of vector type > ------------------------------------------------------------------------------------------------------------------------------------ > > Key: SPARK-18054 > URL: https://issues.apache.org/jira/browse/SPARK-18054 > Project: Spark > Issue Type: Bug > Components: ML > Affects Versions: 2.0.1 > Reporter: Barry Becker > > Not sure if this is a bug in ML or a more core part of spark. > It used to work in spark 1.6.2, but now gives me an error. > I have a pipeline that contains a NaiveBayesModel which I created like this > {code} > val nbModel = new NaiveBayes() > .setLabelCol(target) > .setFeaturesCol(FEATURES_COL) > .setPredictionCol(PREDICTION_COLUMN) > .setProbabilityCol("_probability_column_") > .setModelType("multinomial") > {code} > When I apply that pipeline to some data there will be a > "_probability_column_" of type vector. I want to extract a probability for a > specific class label using the following, but it no longer works. > {code} > var newDf = pipeline.transform(df) > val extractProbability = udf((vector: DenseVector) => vector(1)) > val dfWithProbability = newDf.withColumn("foo", > extractProbability(col("_probability_column_"))) > {code} > The error I get now that I have upgraded to 2.0.1 from 1.6.2 is shnown below. > I consider this a strange error because its basically saying "argument 1 > requires a vector, but we got a vector instead". That does not make any sense > to me. It wants a vector, and a vector was given. Why does it fail? > {code} > org.apache.spark.sql.AnalysisException: cannot resolve > 'UDF(_class_probability_column__)' due to data type mismatch: argument 1 > requires vector type, however, '`_class_probability_column__`' is of vector > type.; > at > org.apache.spark.sql.catalyst.analysis.package$AnalysisErrorAt.failAnalysis(package.scala:42) > at > org.apache.spark.sql.catalyst.analysis.CheckAnalysis$$anonfun$checkAnalysis$1$$anonfun$apply$2.applyOrElse(CheckAnalysis.scala:82) > at > org.apache.spark.sql.catalyst.analysis.CheckAnalysis$$anonfun$checkAnalysis$1$$anonfun$apply$2.applyOrElse(CheckAnalysis.scala:74) > at > org.apache.spark.sql.catalyst.trees.TreeNode$$anonfun$transformUp$1.apply(TreeNode.scala:301) > at > org.apache.spark.sql.catalyst.trees.TreeNode$$anonfun$transformUp$1.apply(TreeNode.scala:301) > at > org.apache.spark.sql.catalyst.trees.CurrentOrigin$.withOrigin(TreeNode.scala:69) > at > org.apache.spark.sql.catalyst.trees.TreeNode.transformUp(TreeNode.scala:300) > at > org.apache.spark.sql.catalyst.trees.TreeNode$$anonfun$4.apply(TreeNode.scala:298) > at > org.apache.spark.sql.catalyst.trees.TreeNode$$anonfun$4.apply(TreeNode.scala:298) > at > org.apache.spark.sql.catalyst.trees.TreeNode$$anonfun$5.apply(TreeNode.scala:321) > at > org.apache.spark.sql.catalyst.trees.TreeNode.mapProductIterator(TreeNode.scala:179) > at > org.apache.spark.sql.catalyst.trees.TreeNode.transformChildren(TreeNode.scala:319) > at > org.apache.spark.sql.catalyst.trees.TreeNode.transformUp(TreeNode.scala:298) > at > org.apache.spark.sql.catalyst.plans.QueryPlan.transformExpressionUp$1(QueryPlan.scala:191) > at > org.apache.spark.sql.catalyst.plans.QueryPlan.org$apache$spark$sql$catalyst$plans$QueryPlan$$recursiveTransform$2(QueryPlan.scala:201) > at > org.apache.spark.sql.catalyst.plans.QueryPlan$$anonfun$org$apache$spark$sql$catalyst$plans$QueryPlan$$recursiveTransform$2$1.apply(QueryPlan.scala:205) > at > scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) > at > scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) > at > scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59) > at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48) > at scala.collection.TraversableLike$class.map(TraversableLike.scala:234) > at scala.collection.AbstractTraversable.map(Traversable.scala:104) > at > org.apache.spark.sql.catalyst.plans.QueryPlan.org$apache$spark$sql$catalyst$plans$QueryPlan$$recursiveTransform$2(QueryPlan.scala:205) > at > org.apache.spark.sql.catalyst.plans.QueryPlan$$anonfun$5.apply(QueryPlan.scala:210) > at > org.apache.spark.sql.catalyst.trees.TreeNode.mapProductIterator(TreeNode.scala:179) > at > org.apache.spark.sql.catalyst.plans.QueryPlan.transformExpressionsUp(QueryPlan.scala:210) > at > org.apache.spark.sql.catalyst.analysis.CheckAnalysis$$anonfun$checkAnalysis$1.apply(CheckAnalysis.scala:74) > at > org.apache.spark.sql.catalyst.analysis.CheckAnalysis$$anonfun$checkAnalysis$1.apply(CheckAnalysis.scala:67) > at > org.apache.spark.sql.catalyst.trees.TreeNode.foreachUp(TreeNode.scala:126) > at > org.apache.spark.sql.catalyst.analysis.CheckAnalysis$class.checkAnalysis(CheckAnalysis.scala:67) > at > org.apache.spark.sql.catalyst.analysis.Analyzer.checkAnalysis(Analyzer.scala:58) > at > org.apache.spark.sql.execution.QueryExecution.assertAnalyzed(QueryExecution.scala:49) > at org.apache.spark.sql.Dataset$.ofRows(Dataset.scala:64) > at > org.apache.spark.sql.Dataset.org$apache$spark$sql$Dataset$$withPlan(Dataset.scala:2603) > at org.apache.spark.sql.Dataset.select(Dataset.scala:969) > at org.apache.spark.sql.Dataset.withColumn(Dataset.scala:1697) > at > com.mineset.spark.transformations.ApplyModel.addProbabilityColumn(ApplyModel.scala:120) > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org