zhengruifeng commented on code in PR #54014:
URL: https://github.com/apache/spark/pull/54014#discussion_r2745325345
##########
sql/connect/client/jvm/src/test/scala/org/apache/spark/sql/connect/ClientE2ETestSuite.scala:
##########
@@ -772,6 +772,30 @@ class ClientE2ETestSuite
assert(spark.range(10).count() === 10)
}
+ test("Dataset zipWithIndex") {
+ val df = spark.range(5).repartition(3)
+ val result = df.zipWithIndex()
+ assert(result.columns === Array("id", "index"))
+ assert(result.schema.last.dataType === LongType)
+ val indices = result.collect().map(_.getLong(1)).sorted
+ assert(indices === (0L until 5L).toArray)
+ }
+
+ test("Dataset zipWithIndex with custom column name") {
+ val result = spark.range(3).zipWithIndex("row_num")
+ assert(result.columns === Array("id", "row_num"))
+ val indices = result.collect().map(_.getLong(1)).sorted
+ assert(indices === Array(0L, 1L, 2L))
+ }
+
+ test("Dataset zipWithIndex should throw if column name already exists") {
Review Comment:
I think we should clearly define the behavior in case `name` already exists
in `df`
```
df.zipWithIndex("name")
```
should it fail (as in the first commit) or silently replace the old column
or keep both columns (existing implementation)?
@cloud-fan @HyukjinKwon @ueshin
--
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]