LuciferYang commented on code in PR #44998:
URL: https://github.com/apache/spark/pull/44998#discussion_r1477177975
##########
core/src/main/scala/org/apache/spark/util/collection/OpenHashSet.scala:
##########
@@ -62,28 +62,12 @@ class OpenHashSet[@specialized(Long, Int, Double, Float) T:
ClassTag](
// specialization to work (specialized class extends the non-specialized one
and needs access
// to the "private" variables).
- protected val hasher: Hasher[T] = {
- // It would've been more natural to write the following using pattern
matching. But Scala 2.9.x
- // compiler has a bug when specialization is used together with this
pattern matching, and
- // throws:
- // scala.tools.nsc.symtab.Types$TypeError: type mismatch;
- // found : scala.reflect.AnyValManifest[Long]
- // required: scala.reflect.ClassTag[Int]
- // at
scala.tools.nsc.typechecker.Contexts$Context.error(Contexts.scala:298)
- // at
scala.tools.nsc.typechecker.Infer$Inferencer.error(Infer.scala:207)
- // ...
- val mt = classTag[T]
- if (mt == ClassTag.Long) {
- (new LongHasher).asInstanceOf[Hasher[T]]
- } else if (mt == ClassTag.Int) {
- (new IntHasher).asInstanceOf[Hasher[T]]
- } else if (mt == ClassTag.Double) {
- (new DoubleHasher).asInstanceOf[Hasher[T]]
- } else if (mt == ClassTag.Float) {
- (new FloatHasher).asInstanceOf[Hasher[T]]
- } else {
- new Hasher[T]
- }
+ protected val hasher: Hasher[T] = classTag[T] match {
+ case ClassTag.Long => new LongHasher().asInstanceOf[Hasher[T]]
+ case ClassTag.Int => new IntHasher().asInstanceOf[Hasher[T]]
+ case ClassTag.Double => new DoubleHasher().asInstanceOf[Hasher[T]]
+ case ClassTag.Float => new FloatHasher().asInstanceOf[Hasher[T]]
+ case _ => new Hasher[T]
Review Comment:
cc @cloud-fan @dongjoon-hyun @srowen
All test passed. Can we make this change? Or should we just delete the
previous comments? The bug mentioned in the comments should no longer exist.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]