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

    https://github.com/apache/spark/pull/3632#discussion_r22420650
  
    --- Diff: core/src/main/scala/org/apache/spark/util/Ordering.scala ---
    @@ -0,0 +1,42 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.util
    +
    +private[spark] class HashOrdering[A] extends Ordering[A] {
    +  override def compare(x: A, y: A): Int = {
    +    val h1 = if (x == null) 0 else x.hashCode()
    +    val h2 = if (y == null) 0 else y.hashCode()
    +    if (h1 < h2) -1 else if (h1 == h2) 0 else 1
    +  }
    +}
    +
    +private[spark] class NoOrdering[A] extends Ordering[A] {
    +  override def compare(x: A, y: A): Int = 0
    +}
    +
    +private[spark] class KeyValueOrdering[A, B](
    +  ordering1: Option[Ordering[A]], ordering2: Option[Ordering[B]]
    +) extends Ordering[Product2[A, B]] {
    +  private val ord1 = ordering1.getOrElse(new HashOrdering[A])
    +  private val ord2 = ordering2.getOrElse(new NoOrdering[B])
    --- End diff --
    
    What is the expected scenario in which a `KeyValueOrdering` is called for 
with `B` unordered? You're setting up `KeyValueOrdering` to be more general 
than your needs for its only current usage in `OrderedValueRDDFunctions`, but 
I'm not quite grasping how and where else you are expecting `KeyValueOrdering` 
to be used.
    
    It's seeming to me that `KeyValueOrdering` should have two ctors: 
    ```scala
    KeyValueOrdering[A, B](keyOrdering: Ordering[A], valueOrdering: Ordering[B])
    
    ...
    
    this(valueOrdering: Ordering[B]) = this(new HashOrdering[A], valueOrdering)
    ``` 


---
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