Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add test for checking ambiguous field
  • Loading branch information
xuanyuanking committed Sep 17, 2019
commit 03305bea4e8663f7bcd12963b489b1e8755c382f
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class DataFrameNaFunctionsSuite extends QueryTest with SharedSparkSession {
}
}

test("fill for join operation") {
def createDFsWithSameFieldsName(): (DataFrame, DataFrame) = {
val df1 = Seq(
("f1-1", "f2", null),
("f1-2", null, null),
Expand All @@ -243,6 +243,11 @@ class DataFrameNaFunctionsSuite extends QueryTest with SharedSparkSession {
("f1-2", "f2", null),
("f1-3", "f2", "f4-1")
).toDF("f1", "f2", "f4")
(df1, df2)
}

test("fill unambiguous field for join operation") {
val (df1, df2) = createDFsWithSameFieldsName()
val joined_df = df1.join(df2, Seq("f1"), joinType = "left_outer")
checkAnswer(joined_df.na.fill("", cols = Seq("f4")),
Row("f1-1", "f2", null, null, "") ::
Expand All @@ -251,6 +256,16 @@ class DataFrameNaFunctionsSuite extends QueryTest with SharedSparkSession {
Row("f1-4", "f2", "f3-1", null, "") :: Nil)
}

test("fill ambiguous field for join operation") {
val (df1, df2) = createDFsWithSameFieldsName()
val joined_df = df1.join(df2, Seq("f1"), joinType = "left_outer")

val message = intercept[AnalysisException] {
joined_df.na.fill("", cols = Seq("f2"))
}.getMessage
assert(message.contains("Reference 'f2' is ambiguous"))
}

test("replace") {
val input = createDF()

Expand Down