Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -1578,13 +1578,29 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually {
val arguments = Seq(Literal(1), Literal(2), Literal(3))
assert(catalog.lookupFunction(FunctionIdentifier("func1"), arguments) === Literal(1))
catalog.dropTempFunction("func1", ignoreIfNotExists = false)
intercept[NoSuchFunctionException] {
catalog.lookupFunction(FunctionIdentifier("func1"), arguments)
}
intercept[NoSuchTempFunctionException] {
catalog.dropTempFunction("func1", ignoreIfNotExists = false)
}
checkError(
exception = intercept[NoSuchFunctionException] {
catalog.lookupFunction(FunctionIdentifier("func1"), arguments)
},
errorClass = "ROUTINE_NOT_FOUND",
parameters = Map("routineName" -> "`default`.`func1`")
)
checkError(
exception = intercept[NoSuchTempFunctionException] {
catalog.dropTempFunction("func1", ignoreIfNotExists = false)
},
errorClass = "ROUTINE_NOT_FOUND",
parameters = Map("routineName" -> "`func1`")
)
catalog.dropTempFunction("func1", ignoreIfNotExists = true)

checkError(
exception = intercept[NoSuchTempFunctionException] {
catalog.dropTempFunction("func2", ignoreIfNotExists = false)
},
errorClass = "ROUTINE_NOT_FOUND",
parameters = Map("routineName" -> "`func2`")
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import java.net.URL
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory

import org.apache.spark.SparkConf
import org.apache.spark.{SparkConf, SparkException}
import org.apache.spark.sql.catalyst.catalog.SessionCatalog
import org.apache.spark.sql.test.SharedSparkSession


/**
* Tests for [[org.apache.spark.sql.internal.SharedState]].
*/
Expand All @@ -52,4 +52,20 @@ class SharedStateSuite extends SharedSparkSession {
assert(conf.isInstanceOf[Configuration])
assert(conf.asInstanceOf[Configuration].get("fs.defaultFS") == "file:///")
}

test("Default database does not exist") {
SQLConf.get.setConfString("spark.sql.catalog.spark_catalog.defaultDatabase",
"default_database_not_exists")

checkError(
exception = intercept[SparkException] {
spark.sharedState.externalCatalog
},
errorClass = "DEFAULT_DATABASE_NOT_EXISTS",
parameters = Map("defaultDatabase" -> "default_database_not_exists")
)

SQLConf.get.setConfString("spark.sql.catalog.spark_catalog.defaultDatabase",
SessionCatalog.DEFAULT_DATABASE)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import scala.util.control.NonFatal
import org.apache.spark.{SparkConf, SparkException}
import org.apache.spark.sql.{AnalysisException, DataFrame, ExplainSuiteHelper, QueryTest, Row}
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.analysis.CannotReplaceMissingTableException
import org.apache.spark.sql.catalyst.analysis.{CannotReplaceMissingTableException, IndexAlreadyExistsException, NoSuchIndexException}
import org.apache.spark.sql.catalyst.plans.logical.{Aggregate, Filter, GlobalLimit, LocalLimit, Offset, Sort}
import org.apache.spark.sql.connector.{IntegralAverage, StrLen}
import org.apache.spark.sql.connector.catalog.{Catalogs, Identifier, TableCatalog}
Expand Down Expand Up @@ -2628,6 +2628,15 @@ class JDBCV2Suite extends QueryTest with SharedSparkSession with ExplainSuiteHel
assert(indexes1.isEmpty)

sql(s"CREATE INDEX people_index ON TABLE h2.test.people (id)")
checkError(
exception = intercept[IndexAlreadyExistsException] {
sql(s"CREATE INDEX people_index ON TABLE h2.test.people (id)")
},
errorClass = "INDEX_ALREADY_EXISTS",
parameters = Map(
"message" -> "Failed to create index people_index in test.people"
)
)
assert(jdbcTable.indexExists("people_index"))
val indexes2 = jdbcTable.listIndexes()
assert(!indexes2.isEmpty)
Expand All @@ -2636,6 +2645,15 @@ class JDBCV2Suite extends QueryTest with SharedSparkSession with ExplainSuiteHel
assert(tableIndex.indexName() == "people_index")

sql(s"DROP INDEX people_index ON TABLE h2.test.people")
checkError(
exception = intercept[NoSuchIndexException] {
sql(s"DROP INDEX people_index ON TABLE h2.test.people")
},
errorClass = "INDEX_NOT_FOUND",
parameters = Map(
"message" -> "Failed to drop index people_index in test.people"
)
)
assert(jdbcTable.indexExists("people_index") == false)
val indexes3 = jdbcTable.listIndexes()
assert(indexes3.isEmpty)
Expand Down