Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,13 @@ trait WatermarkSupport extends UnaryExecNode {
}

/** Predicate based on keys that matches data older than the watermark */
lazy val watermarkPredicateForKeys: Option[Predicate] =
watermarkExpression.map(newPredicate(_, keyExpressions))
lazy val watermarkPredicateForKeys: Option[Predicate] = watermarkExpression.flatMap { e =>
if (keyExpressions.exists(_.metadata.contains(EventTimeWatermark.delayKey))) {
Some(newPredicate(e, keyExpressions))
} else {
None
}
}

/** Predicate based on the child output that matches data older than the watermark. */
lazy val watermarkPredicateForData: Option[Predicate] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,17 @@ class DeduplicateSuite extends StateStoreMetricsTest with BeforeAndAfterAll {
CheckLastBatch(7)
)
}

test("SPARK-21546: dropDuplicates should ignore watermark when it's not a key") {
val input = MemoryStream[(Int, Int)]
val df = input.toDS.toDF("id", "time")
.withColumn("time", $"time".cast("timestamp"))
.withWatermark("time", "1 second")
.dropDuplicates("id")
.select($"id", $"time".cast("long"))
testStream(df)(
AddData(input, 1 -> 1, 1 -> 2, 2 -> 2),
CheckLastBatch(1 -> 1, 2 -> 2)
)
}
}