diff --git a/src/main/scala/org/apache/spark/sql/delta/sources/DeltaSQLConf.scala b/src/main/scala/org/apache/spark/sql/delta/sources/DeltaSQLConf.scala index 30164955e8b..71c3576cc4f 100644 --- a/src/main/scala/org/apache/spark/sql/delta/sources/DeltaSQLConf.scala +++ b/src/main/scala/org/apache/spark/sql/delta/sources/DeltaSQLConf.scala @@ -326,6 +326,18 @@ trait DeltaSQLConfBase { .booleanConf .createWithDefault(true) + val MERGE_SKIP_OSS_RESOLUTION_WITH_STAR = + buildConf("merge.skipOssResolutionWithStar") + .internal() + .doc( + """ + |If enabled, then any MERGE operation having UPDATE * / INSERT * will skip Apache + |Spark's resolution logic and use Delta's specific resolution logic. This is to avoid + |bug with star and temp views. See SC-72276 for details. + """.stripMargin) + .booleanConf + .createWithDefault(true) + val DELTA_LAST_COMMIT_VERSION_IN_SESSION = buildConf("lastCommitVersionInSession") .doc("The version of the last commit made in the SparkSession for any table.") diff --git a/src/test/scala/org/apache/spark/sql/delta/MergeIntoSQLSuite.scala b/src/test/scala/org/apache/spark/sql/delta/MergeIntoSQLSuite.scala index 31cbf28910f..37801ca1395 100644 --- a/src/test/scala/org/apache/spark/sql/delta/MergeIntoSQLSuite.scala +++ b/src/test/scala/org/apache/spark/sql/delta/MergeIntoSQLSuite.scala @@ -356,4 +356,27 @@ class MergeIntoSQLSuite extends MergeIntoSuiteBase with DeltaSQLCommandTest { } } } + + // This test is to capture the incorrect behavior caused by + // https://github.com/delta-io/delta/issues/618 . + // If this test fails then the issue has been fixed. Replace this test with a correct test + test("merge into a dataset temp views with star gives incorrect results") { + withTempView("v") { + withTempView("src") { + append(Seq((0, 0), (1, 1)).toDF("key", "value")) + readDeltaTable(tempPath).createOrReplaceTempView("v") + sql("CREATE TEMP VIEW src AS SELECT * FROM VALUES (10, 1) AS t(value, key)") + sql(s"""MERGE INTO v USING src + |ON src.key = v.key + |WHEN MATCHED THEN + | UPDATE SET * + |WHEN NOT MATCHED THEN + | INSERT * + |""".stripMargin) + val result = readDeltaTable(tempPath).as[(Long, Long)].collect().toSet + // This is expected to fail until the issue mentioned above is resolved. + assert(result != Set((0, 0), (1, 10))) + } + } + } }