Skip to content

Commit

Permalink
[SPARK-28705][SQL][TEST] Drop tables after being used in AnalysisExte…
Browse files Browse the repository at this point in the history
…rnalCatalogSuite

## What changes were proposed in this pull request?

drop the table after the test `query builtin functions don't call the external catalog`  executed

This is required for [SPARK-25464](#22466)

## How was this patch tested?

existing UT

Closes #25427 from sandeep-katta/cleanuptable.

Authored-by: sandeep katta <sandeep.katta2007@gmail.com>
Signed-off-by: HyukjinKwon <gurwls223@apache.org>
  • Loading branch information
sandeep-katta authored and HyukjinKwon committed Sep 2, 2019
1 parent bd3915e commit e1946a5
Showing 1 changed file with 27 additions and 21 deletions.
Expand Up @@ -17,6 +17,7 @@

package org.apache.spark.sql.catalyst.analysis

import java.io.File
import java.net.URI

import org.mockito.Mockito._
Expand All @@ -28,13 +29,14 @@ import org.apache.spark.sql.catalyst.expressions.{Alias, AttributeReference}
import org.apache.spark.sql.catalyst.plans.logical.{LocalRelation, Project}
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types._
import org.apache.spark.util.Utils

class AnalysisExternalCatalogSuite extends AnalysisTest with Matchers {
private def getAnalyzer(externCatalog: ExternalCatalog): Analyzer = {
private def getAnalyzer(externCatalog: ExternalCatalog, databasePath: File): Analyzer = {
val conf = new SQLConf()
val catalog = new SessionCatalog(externCatalog, FunctionRegistry.builtin, conf)
catalog.createDatabase(
CatalogDatabase("default", "", new URI("loc"), Map.empty),
CatalogDatabase("default", "", databasePath.toURI, Map.empty),
ignoreIfExists = false)
catalog.createTable(
CatalogTable(
Expand All @@ -47,28 +49,32 @@ class AnalysisExternalCatalogSuite extends AnalysisTest with Matchers {
}

test("query builtin functions don't call the external catalog") {
val inMemoryCatalog = new InMemoryCatalog
val catalog = spy(inMemoryCatalog)
val analyzer = getAnalyzer(catalog)
reset(catalog)
val testRelation = LocalRelation(AttributeReference("a", IntegerType, nullable = true)())
val func =
Alias(UnresolvedFunction("sum", Seq(UnresolvedAttribute("a")), isDistinct = false), "s")()
val plan = Project(Seq(func), testRelation)
analyzer.execute(plan)
verifyZeroInteractions(catalog)
withTempDir { tempDir =>
val inMemoryCatalog = new InMemoryCatalog
val catalog = spy(inMemoryCatalog)
val analyzer = getAnalyzer(catalog, tempDir)
reset(catalog)
val testRelation = LocalRelation(AttributeReference("a", IntegerType, nullable = true)())
val func =
Alias(UnresolvedFunction("sum", Seq(UnresolvedAttribute("a")), isDistinct = false), "s")()
val plan = Project(Seq(func), testRelation)
analyzer.execute(plan)
verifyZeroInteractions(catalog)
}
}

test("check the existence of builtin functions don't call the external catalog") {
val inMemoryCatalog = new InMemoryCatalog
val externCatalog = spy(inMemoryCatalog)
val catalog = new SessionCatalog(externCatalog, FunctionRegistry.builtin, conf)
catalog.createDatabase(
CatalogDatabase("default", "", new URI("loc"), Map.empty),
ignoreIfExists = false)
reset(externCatalog)
catalog.functionExists(FunctionIdentifier("sum"))
verifyZeroInteractions(externCatalog)
withTempDir { tempDir =>
val inMemoryCatalog = new InMemoryCatalog
val externCatalog = spy(inMemoryCatalog)
val catalog = new SessionCatalog(externCatalog, FunctionRegistry.builtin, conf)
catalog.createDatabase(
CatalogDatabase("default", "", new URI(tempDir.toString), Map.empty),
ignoreIfExists = false)
reset(externCatalog)
catalog.functionExists(FunctionIdentifier("sum"))
verifyZeroInteractions(externCatalog)
}
}

}

0 comments on commit e1946a5

Please sign in to comment.