Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-bli committed Nov 20, 2023
1 parent f428a7c commit 1453f0b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/com/snowflake/snowpark/DataFrame.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1975,7 +1975,7 @@ class DataFrame private[snowpark] (
val resultSchema = originalResult.schema
val columnNames = resultSchema.map(_.name)
// duplicated names
val dup = columnNames.diff(columnNames.distinct).distinct
val dup = columnNames.diff(columnNames.distinct).distinct.map(quoteName)
// guarantee no duplicated names in the result
if (dup.nonEmpty) {
val dfPrefix = DataFrame.generatePrefix('o')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,22 @@ class TableFunctionSuite extends TestData {

test("table function join with duplicated column name") {
val df = Seq((1, "1,2"), (2, "3,4")).toDF("idx", "value")
df.show()
val result = df.join(tableFunctions.split_to_table(df("value"), lit(",")))
// only one VALUE in the result
checkAnswer(result.select("value"), Seq(Row("1"), Row("2"), Row("3"), Row("4")))
checkAnswer(result.select(result("value")), Seq(Row("1"), Row("2"), Row("3"), Row("4")))
checkAnswer(result.select(df("value")), Seq(Row("1,2"), Row("1,2"), Row("3,4"), Row("3,4")))
}

test("table function select with duplicated column name") {
val df = Seq((1, "1,2"), (2, "3,4")).toDF("idx", "value")
val result1 = df.select(tableFunctions.split_to_table(df("value"), lit(",")))
checkAnswer(result1, Seq(Row(1, 1, "1"), Row(1, 2, "2"), Row(2, 1, "3"), Row(2, 2, "4")))
val result = df.select(df("value"), tableFunctions.split_to_table(df("value"), lit(",")))
// only one VALUE in the result
checkAnswer(result.select("value"), Seq(Row("1"), Row("2"), Row("3"), Row("4")))
checkAnswer(result.select(result("value")), Seq(Row("1"), Row("2"), Row("3"), Row("4")))
checkAnswer(result.select(df("value")), Seq(Row("1,2"), Row("1,2"), Row("3,4"), Row("3,4")))
}

}

0 comments on commit 1453f0b

Please sign in to comment.