@@ -24,7 +24,7 @@ import org.apache.spark.sql.catalyst.dsl.plans._
2424import org .apache .spark .sql .catalyst .expressions .{And , ArrayExists , ArrayFilter , ArrayTransform , CaseWhen , Expression , GreaterThan , If , LambdaFunction , Literal , MapFilter , NamedExpression , Or , UnresolvedNamedLambdaVariable }
2525import org .apache .spark .sql .catalyst .expressions .Literal .{FalseLiteral , TrueLiteral }
2626import org .apache .spark .sql .catalyst .plans .{Inner , PlanTest }
27- import org .apache .spark .sql .catalyst .plans .logical .{DeleteFromTable , LocalRelation , LogicalPlan , UpdateTable }
27+ import org .apache .spark .sql .catalyst .plans .logical .{Assignment , DeleteAction , DeleteFromTable , InsertAction , LocalRelation , LogicalPlan , MergeIntoTable , UpdateAction , UpdateTable }
2828import org .apache .spark .sql .catalyst .rules .RuleExecutor
2929import org .apache .spark .sql .internal .SQLConf
3030import org .apache .spark .sql .types .{BooleanType , IntegerType }
@@ -50,6 +50,7 @@ class ReplaceNullWithFalseInPredicateSuite extends PlanTest {
5050 testJoin(originalCond = Literal (null , BooleanType ), expectedCond = FalseLiteral )
5151 testDelete(originalCond = Literal (null , BooleanType ), expectedCond = FalseLiteral )
5252 testUpdate(originalCond = Literal (null , BooleanType ), expectedCond = FalseLiteral )
53+ testMerge(originalCond = Literal (null , BooleanType ), expectedCond = FalseLiteral )
5354 }
5455
5556 test(" Not expected type - replaceNullWithFalse" ) {
@@ -68,6 +69,7 @@ class ReplaceNullWithFalseInPredicateSuite extends PlanTest {
6869 testJoin(originalCond, expectedCond = FalseLiteral )
6970 testDelete(originalCond, expectedCond = FalseLiteral )
7071 testUpdate(originalCond, expectedCond = FalseLiteral )
72+ testMerge(originalCond, expectedCond = FalseLiteral )
7173 }
7274
7375 test(" replace nulls in nested expressions in branches of If" ) {
@@ -79,6 +81,7 @@ class ReplaceNullWithFalseInPredicateSuite extends PlanTest {
7981 testJoin(originalCond, expectedCond = FalseLiteral )
8082 testDelete(originalCond, expectedCond = FalseLiteral )
8183 testUpdate(originalCond, expectedCond = FalseLiteral )
84+ testMerge(originalCond, expectedCond = FalseLiteral )
8285 }
8386
8487 test(" replace null in elseValue of CaseWhen" ) {
@@ -91,6 +94,7 @@ class ReplaceNullWithFalseInPredicateSuite extends PlanTest {
9194 testJoin(originalCond, expectedCond)
9295 testDelete(originalCond, expectedCond)
9396 testUpdate(originalCond, expectedCond)
97+ testMerge(originalCond, expectedCond)
9498 }
9599
96100 test(" replace null in branch values of CaseWhen" ) {
@@ -102,6 +106,7 @@ class ReplaceNullWithFalseInPredicateSuite extends PlanTest {
102106 testJoin(originalCond, expectedCond = FalseLiteral )
103107 testDelete(originalCond, expectedCond = FalseLiteral )
104108 testUpdate(originalCond, expectedCond = FalseLiteral )
109+ testMerge(originalCond, expectedCond = FalseLiteral )
105110 }
106111
107112 test(" replace null in branches of If inside CaseWhen" ) {
@@ -120,6 +125,7 @@ class ReplaceNullWithFalseInPredicateSuite extends PlanTest {
120125 testJoin(originalCond, expectedCond)
121126 testDelete(originalCond, expectedCond)
122127 testUpdate(originalCond, expectedCond)
128+ testMerge(originalCond, expectedCond)
123129 }
124130
125131 test(" replace null in complex CaseWhen expressions" ) {
@@ -141,6 +147,7 @@ class ReplaceNullWithFalseInPredicateSuite extends PlanTest {
141147 testJoin(originalCond, expectedCond)
142148 testDelete(originalCond, expectedCond)
143149 testUpdate(originalCond, expectedCond)
150+ testMerge(originalCond, expectedCond)
144151 }
145152
146153 test(" replace null in Or" ) {
@@ -150,6 +157,7 @@ class ReplaceNullWithFalseInPredicateSuite extends PlanTest {
150157 testJoin(originalCond, expectedCond)
151158 testDelete(originalCond, expectedCond)
152159 testUpdate(originalCond, expectedCond)
160+ testMerge(originalCond, expectedCond)
153161 }
154162
155163 test(" replace null in And" ) {
@@ -158,6 +166,7 @@ class ReplaceNullWithFalseInPredicateSuite extends PlanTest {
158166 testJoin(originalCond, expectedCond = FalseLiteral )
159167 testDelete(originalCond, expectedCond = FalseLiteral )
160168 testUpdate(originalCond, expectedCond = FalseLiteral )
169+ testMerge(originalCond, expectedCond = FalseLiteral )
161170 }
162171
163172 test(" replace nulls in nested And/Or expressions" ) {
@@ -168,6 +177,7 @@ class ReplaceNullWithFalseInPredicateSuite extends PlanTest {
168177 testJoin(originalCond, expectedCond = FalseLiteral )
169178 testDelete(originalCond, expectedCond = FalseLiteral )
170179 testUpdate(originalCond, expectedCond = FalseLiteral )
180+ testMerge(originalCond, expectedCond = FalseLiteral )
171181 }
172182
173183 test(" replace null in And inside branches of If" ) {
@@ -179,6 +189,7 @@ class ReplaceNullWithFalseInPredicateSuite extends PlanTest {
179189 testJoin(originalCond, expectedCond = FalseLiteral )
180190 testDelete(originalCond, expectedCond = FalseLiteral )
181191 testUpdate(originalCond, expectedCond = FalseLiteral )
192+ testMerge(originalCond, expectedCond = FalseLiteral )
182193 }
183194
184195 test(" replace null in branches of If inside And" ) {
@@ -192,6 +203,7 @@ class ReplaceNullWithFalseInPredicateSuite extends PlanTest {
192203 testJoin(originalCond, expectedCond = FalseLiteral )
193204 testDelete(originalCond, expectedCond = FalseLiteral )
194205 testUpdate(originalCond, expectedCond = FalseLiteral )
206+ testMerge(originalCond, expectedCond = FalseLiteral )
195207 }
196208
197209 test(" replace null in branches of If inside another If" ) {
@@ -203,6 +215,7 @@ class ReplaceNullWithFalseInPredicateSuite extends PlanTest {
203215 testJoin(originalCond, expectedCond = FalseLiteral )
204216 testDelete(originalCond, expectedCond = FalseLiteral )
205217 testUpdate(originalCond, expectedCond = FalseLiteral )
218+ testMerge(originalCond, expectedCond = FalseLiteral )
206219 }
207220
208221 test(" replace null in CaseWhen inside another CaseWhen" ) {
@@ -212,6 +225,7 @@ class ReplaceNullWithFalseInPredicateSuite extends PlanTest {
212225 testJoin(originalCond, expectedCond = FalseLiteral )
213226 testDelete(originalCond, expectedCond = FalseLiteral )
214227 testUpdate(originalCond, expectedCond = FalseLiteral )
228+ testMerge(originalCond, expectedCond = FalseLiteral )
215229 }
216230
217231 test(" inability to replace null in non-boolean branches of If" ) {
@@ -226,6 +240,7 @@ class ReplaceNullWithFalseInPredicateSuite extends PlanTest {
226240 testJoin(originalCond = condition, expectedCond = condition)
227241 testDelete(originalCond = condition, expectedCond = condition)
228242 testUpdate(originalCond = condition, expectedCond = condition)
243+ testMerge(originalCond = condition, expectedCond = condition)
229244 }
230245
231246 test(" inability to replace null in non-boolean values of CaseWhen" ) {
@@ -395,6 +410,21 @@ class ReplaceNullWithFalseInPredicateSuite extends PlanTest {
395410 test((rel, expr) => UpdateTable (rel, Seq .empty, Some (expr)), originalCond, expectedCond)
396411 }
397412
413+ private def testMerge (originalCond : Expression , expectedCond : Expression ): Unit = {
414+ val func = (rel : LogicalPlan , expr : Expression ) => {
415+ val assignments = Seq (
416+ Assignment (' i , ' i ),
417+ Assignment (' b , ' b ),
418+ Assignment (' a , ' a ),
419+ Assignment (' m , ' m )
420+ )
421+ val matchedActions = UpdateAction (Some (expr), assignments) :: DeleteAction (Some (expr)) :: Nil
422+ val notMatchedActions = InsertAction (Some (expr), assignments) :: Nil
423+ MergeIntoTable (rel, rel, mergeCondition = expr, matchedActions, notMatchedActions)
424+ }
425+ test(func, originalCond, expectedCond)
426+ }
427+
398428 private def testHigherOrderFunc (
399429 argument : Expression ,
400430 createExpr : (Expression , Expression ) => Expression ,
0 commit comments