Q:

Spark dropDuplicates source code

I am looking into Spark source code to see how dropDuplicates method work. In the method definition there is a method Deduplicate call. But I am unable to find it's definition or reference. It would be great if someone can point me in the right direction. The link is here.

A:

It's in spark-catalyst, see here.
Since the implementation is a bit confusing, I'll add some explanation.
Current implementation of Deduplicate is:
/** A logical plan for `dropDuplicates`. */
case class Deduplicate(
    keys: Seq[Attribute],
    child: LogicalPlan) extends UnaryNode {

  override def output: Seq[Attribute] = child.output
}

It's not clear what happens here, but if you'll take a look into Optimizer class, you'll see ReplaceDeduplicateWithAggregate object, and then it becomes much clearer.
/**
 * Replaces logical [[Deduplicate]] operator with an [[Aggregate]] operator.
 */
object ReplaceDeduplicateWithAggregate extends Rule[LogicalPlan] {
  def apply(plan: LogicalPlan): LogicalPlan = plan transform {
    case Deduplicate(keys, child) if !child.isStreaming =>
      val keyExprIds = keys.map(_.exprId)
      val aggCols = child.output.map { attr =>
        if (keyExprIds.contains(attr.exprId)) {
          attr
        } else {
          Alias(new First(attr).toAggregateExpression(), attr.name)(attr.exprId)
        }
      }
      // SPARK-22951: Physical aggregate operators distinguishes global aggregation and grouping
      // aggregations by checking the number of grouping keys. The key difference here is that a
      // global aggregation always returns at least one row even if there are no input rows. Here
      // we append a literal when the grouping key list is empty so that the result aggregate
      // operator is properly treated as a grouping aggregation.
      val nonemptyKeys = if (keys.isEmpty) Literal(1) :: Nil else keys
      Aggregate(nonemptyKeys, aggCols, child)
  }
}

Bottom line, for df with columns col1, col2, col3, col4
df.dropDuplicates("col1", "col2") 

is more or less 
df.groupBy("col1", "col2").agg(first("col3"), first("col4"))

