Skip to content

Commit a526470

Browse files
committed
Add negative tests
1 parent d124fa7 commit a526470

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

external/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/OracleIntegrationSuite.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import java.sql.Connection
2222
import org.scalatest.time.SpanSugar._
2323

2424
import org.apache.spark.SparkConf
25+
import org.apache.spark.sql.AnalysisException
2526
import org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCTableCatalog
2627
import org.apache.spark.sql.jdbc.{DatabaseOnDocker, DockerJDBCIntegrationSuite}
2728
import org.apache.spark.sql.test.SharedSparkSession
@@ -85,6 +86,14 @@ class OracleIntegrationSuite extends DockerJDBCIntegrationSuite with SharedSpark
8586
t = spark.table("oracle.alt_table")
8687
expectedSchema = expectedSchema.add("C3", StringType)
8788
assert(t.schema === expectedSchema)
89+
// Add already existing column
90+
intercept[AnalysisException] {
91+
sql(s"ALTER TABLE oracle.alt_table ADD COLUMNS (C3 DOUBLE)")
92+
}
93+
}
94+
// Add a column to not existing table
95+
intercept[AnalysisException] {
96+
sql(s"ALTER TABLE oracle.not_existing_table ADD COLUMNS (C4 STRING)")
8897
}
8998
}
9099

@@ -95,6 +104,18 @@ class OracleIntegrationSuite extends DockerJDBCIntegrationSuite with SharedSpark
95104
val t = spark.table("oracle.alt_table")
96105
val expectedSchema = new StructType().add("ID", StringType)
97106
assert(t.schema === expectedSchema)
107+
// Update not existing column
108+
intercept[AnalysisException] {
109+
sql("ALTER TABLE oracle.alt_table ALTER COLUMN bad_column TYPE DOUBLE")
110+
}
111+
// Update column to wrong type
112+
intercept[AnalysisException] {
113+
sql("ALTER TABLE oracle.alt_table ALTER COLUMN id TYPE bad_type")
114+
}
115+
}
116+
// Update column type in not existing table
117+
intercept[AnalysisException] {
118+
sql(s"ALTER TABLE oracle.not_existing_table ALTER COLUMN id TYPE DOUBLE")
98119
}
99120
}
100121

@@ -105,6 +126,14 @@ class OracleIntegrationSuite extends DockerJDBCIntegrationSuite with SharedSpark
105126
val t = spark.table("oracle.alt_table")
106127
val expectedSchema = new StructType().add("ID", StringType, nullable = true)
107128
assert(t.schema === expectedSchema)
129+
// Update nullability of not existing column
130+
intercept[AnalysisException] {
131+
sql("ALTER TABLE oracle.alt_table ALTER COLUMN bad_column DROP NOT NULL")
132+
}
133+
}
134+
// Update column nullability in not existing table
135+
intercept[AnalysisException] {
136+
sql(s"ALTER TABLE oracle.not_existing_table ALTER COLUMN ID DROP NOT NULL")
108137
}
109138
}
110139
}

0 commit comments

Comments
 (0)