Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8830#discussion_r40046360
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/feature/RFormulaParser.scala ---
    @@ -31,20 +32,28 @@ private[ml] case class ParsedRFormula(label: ColumnRef, 
terms: Seq[Term]) {
        * of the special '.' term. Duplicate terms will be removed during 
resolution.
        */
       def resolve(schema: StructType): ResolvedRFormula = {
    -    var includedTerms = Seq[String]()
    +    val dotTerms = expandDot(schema)
    +    var includedTerms = Seq[Seq[String]]()
         terms.foreach {
    +      case term: ColumnRef =>
    +        includedTerms :+= Seq(term.value)
    +      case ColumnInteraction(terms) =>
    +        includedTerms ++= expandInteraction(schema, terms)
           case Dot =>
    -        includedTerms ++= simpleTypes(schema).filter(_ != label.value)
    -      case ColumnRef(value) =>
    -        includedTerms :+= value
    +        includedTerms ++= dotTerms.map(Seq(_))
           case Deletion(term: Term) =>
             term match {
    -          case ColumnRef(value) =>
    -            includedTerms = includedTerms.filter(_ != value)
    +          case inner: ColumnRef =>
    +            includedTerms = includedTerms.filter(_ != Seq(inner.value))
    +          case ColumnInteraction(terms) =>
    +            val fromInteraction = expandInteraction(schema, 
terms).map(_.toSet)
    +            includedTerms = includedTerms.filter(t => 
!fromInteraction.contains(t.toSet))
               case Dot =>
                 // e.g. "- .", which removes all first-order terms
    -            val fromSchema = simpleTypes(schema)
    -            includedTerms = includedTerms.filter(fromSchema.contains(_))
    +            includedTerms = includedTerms.filter {
    +              case Seq(t) => !dotTerms.contains(t)
    +              case _ => true
    +            }
               case _: Deletion =>
                 assert(false, "Deletion terms cannot be nested")
    --- End diff --
    
    * not part of this PR: `throw new RuntimeException(...)`
    * also not part of this PR: Shall we move `hasIntercept` to 
`ResolvedRFormula`? It is a little strange to have two places to store the 
fully parsed formula.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to