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

    https://github.com/apache/spark/pull/12762#discussion_r64868978
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/recommendation/ALS.scala 
---
    @@ -242,16 +263,19 @@ class ALSModel private[ml] (
           }
         }
         dataset
    -      .join(userFactors, dataset($(userCol)) === userFactors("id"), "left")
    -      .join(itemFactors, dataset($(itemCol)) === itemFactors("id"), "left")
    +      .join(userFactors,
    +        checkedCast(dataset($(userCol)).cast(DoubleType)) === 
userFactors("id"), "left")
    --- End diff --
    
    @jkbradley the existing code did the cast to `Int` - that means passing in 
`Long` or `Double` (say) would silently cast and potentially lose precison and 
give weird results, with no exception or warning. That's why here we cast to 
`DoubleType` and use the `checkedCast` `udf` to do a safe cast _if_ the value 
is within `Integer` range. If not we throw an exception with a helpful message.
    
    This is so we allow can any numeric type for the user/item columns 
(providing some form of "backward compatability" with the old version that 
didn't check types at all), but we can still only support actual _values_ that 
are `Int`s. 


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to