Skip to content

Commit 9bbe3b5

Browse files
committed
Make MergeIntoTestUtils agnostic to path/name-based access
1 parent 51f60ca commit 9bbe3b5

File tree

6 files changed

+16
-7
lines changed

6 files changed

+16
-7
lines changed

spark/src/test/scala/org/apache/spark/sql/delta/DeltaTestUtils.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,14 @@ trait DeltaDMLTestUtils
624624
}
625625
}
626626

627+
/**
628+
* Reads a delta table by its identifier. The identifier can either be the table name or table
629+
* path that is in the form of delta.`tablePath`.
630+
*/
631+
protected def readDeltaTableByIdentifier(tableIdentifier: String): DataFrame = {
632+
spark.read.format("delta").table(tableIdentifier)
633+
}
634+
627635
/**
628636
* Finds the latest operation of the given type that ran on the test table and returns the
629637
* dataframe with the changes of the corresponding table version.

spark/src/test/scala/org/apache/spark/sql/delta/MergeIntoSchemaEvolutionSuite.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,19 @@ trait MergeIntoSchemaEvolutionMixin {
7272

7373
if (error != null) {
7474
val ex = intercept[AnalysisException] {
75-
executeMerge(s"delta.`$tempPath` t", "source s", cond, clauses: _*)
75+
executeMerge(s"$tableSQLIdentifier t", "source s", cond, clauses: _*)
7676
}
7777
errorContains(Utils.exceptionString(ex), error)
7878
} else {
79-
executeMerge(s"delta.`$tempPath` t", "source s", cond, clauses: _*)
80-
checkAnswer(spark.read.format("delta").load(tempPath), df.collect())
79+
executeMerge(s"$tableSQLIdentifier t", "source s", cond, clauses: _*)
80+
checkAnswer(readDeltaTableByIdentifier(tableSQLIdentifier), df.collect())
8181
if (schema != null) {
82-
assert(spark.read.format("delta").load(tempPath).schema === schema)
82+
assert(readDeltaTableByIdentifier(tableSQLIdentifier).schema === schema)
8383
} else {
8484
// Check against the schema of the expected result df if no explicit schema was
8585
// provided. Nullability of fields will vary depending on the actual data in the df so
8686
// we ignore it.
87-
assert(spark.read.format("delta").load(tempPath).schema.asNullable ===
87+
assert(readDeltaTableByIdentifier(tableSQLIdentifier).schema.asNullable ===
8888
df.schema.asNullable)
8989
}
9090
}

spark/src/test/scala/org/apache/spark/sql/delta/MergeIntoSuiteBase.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ abstract class MergeIntoSuiteBase
4545
extends QueryTest
4646
with SharedSparkSession
4747
with DeltaSQLTestUtils
48+
with DeltaDMLByPathTestUtils
4849
with ScanReportHelper
4950
with DeltaTestUtilsForTempViews
5051
with MergeIntoTestUtils

spark/src/test/scala/org/apache/spark/sql/delta/MergeIntoTestUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import org.apache.spark.sql.test.SharedSparkSession
2828
* either [[MergeIntoSQLTestUtils]] or [[MergeIntoScalaTestUtils]] to run merge tests using the SQL
2929
* or Scala API resp.
3030
*/
31-
trait MergeIntoTestUtils extends DeltaDMLByPathTestUtils with MergeHelpers {
31+
trait MergeIntoTestUtils extends DeltaDMLTestUtils with MergeHelpers {
3232
self: SharedSparkSession =>
3333

3434
protected def executeMerge(

spark/src/test/scala/org/apache/spark/sql/delta/cdc/MergeCDCSuite.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class MergeCDCSuite extends MergeIntoSQLSuite with MergeCDCTests
4444
*/
4545
trait MergeCDCTests extends QueryTest
4646
with MergeIntoSQLTestUtils
47+
with DeltaDMLByPathTestUtils
4748
with DeltaColumnMappingTestUtils
4849
with DeltaSQLCommandTest {
4950
import testImplicits._

spark/src/test/scala/org/apache/spark/sql/delta/typewidening/TypeWideningInsertSchemaEvolutionBasicSuite.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import org.apache.spark.sql.util.CaseInsensitiveStringMap
3838
*/
3939
class TypeWideningInsertSchemaEvolutionBasicSuite
4040
extends QueryTest
41-
with DeltaDMLTestUtils
4241
with TypeWideningTestMixin
4342
with TypeWideningInsertSchemaEvolutionBasicTests {
4443

0 commit comments

Comments
 (0)