You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/07/16 11:48:20 UTC

[GitHub] [spark] ozancicek commented on a change in pull request #24939: [SPARK-18569][ML][R] Support RFormula arithmetic, I() and spark functions

ozancicek commented on a change in pull request #24939: [SPARK-18569][ML][R] Support RFormula arithmetic, I() and spark functions
URL: https://github.com/apache/spark/pull/24939#discussion_r303864360
 
 

 ##########
 File path: mllib/src/main/scala/org/apache/spark/ml/feature/RFormula.scala
 ##########
 @@ -362,6 +381,16 @@ class RFormulaModel private[feature](
         case _ => true
       }
       StructType(withFeatures.fields :+ StructField($(labelCol), DoubleType, nullable))
+    } else if (resolvedFormula.evalExprs.contains(resolvedFormula.label)) {
+      val spark = SparkSession.builder().getOrCreate()
+      val dummyRDD = spark.sparkContext.parallelize(Seq(Row.empty))
+      val dummyDF = spark.createDataFrame(dummyRDD, schema)
+        .withColumn(resolvedFormula.label, expr(resolvedFormula.label))
+      val nullable = dummyDF.schema(resolvedFormula.label).dataType match {
 
 Review comment:
   In order to create a schema with arbitrary types, I actually borrowed this pattern from here: https://github.com/apache/spark/blob/master/mllib/src/main/scala/org/apache/spark/ml/feature/SQLTransformer.scala#L79
   
   However, the datatype check to determine whether the field should be nullable seems unnecessary here, because only `NumericType` and `BooleanType` seems to be supported, so I modified here to return schema without checking datatype. https://github.com/apache/spark/blob/master/mllib/src/main/scala/org/apache/spark/ml/feature/RFormula.scala#L390  
   
   

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org