Skip to content

Commit 44afb5c

Browse files
committed
Restore createNamespace call and behavior.
1 parent 347c999 commit 44afb5c

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

sql/catalyst/src/main/java/org/apache/spark/sql/catalog/v2/SupportsNamespaces.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ default boolean namespaceExists(String[] namespace) {
112112
* @throws NamespaceAlreadyExistsException If the namespace already exists
113113
* @throws UnsupportedOperationException If create is not a supported operation
114114
*/
115-
void createNamespaceMetadata(
115+
void createNamespace(
116116
String[] namespace,
117117
Map<String, String> metadata) throws NamespaceAlreadyExistsException;
118118

sql/catalyst/src/test/scala/org/apache/spark/sql/catalog/v2/TableCatalogSuite.scala

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ class TableCatalogSuite extends SparkFunSuite {
658658

659659
test("listNamespaces: list namespaces from metadata") {
660660
val catalog = newCatalog()
661-
catalog.createNamespaceMetadata(Array("ns1"), Map("property" -> "value").asJava)
661+
catalog.createNamespace(Array("ns1"), Map("property" -> "value").asJava)
662662

663663
assert(catalog.listNamespaces === Array(Array("ns1")))
664664
assert(catalog.listNamespaces(Array()) === Array(Array("ns1")))
@@ -684,7 +684,7 @@ class TableCatalogSuite extends SparkFunSuite {
684684
val ident1 = Identifier.of(Array("ns1", "ns2"), "test_table_1")
685685
val ident2 = Identifier.of(Array("ns1", "ns2"), "test_table_2")
686686

687-
catalog.createNamespaceMetadata(Array("ns1"), Map("property" -> "value").asJava)
687+
catalog.createNamespace(Array("ns1"), Map("property" -> "value").asJava)
688688
catalog.createTable(ident1, schema, Array.empty, emptyProps)
689689
catalog.createTable(ident2, schema, Array.empty, emptyProps)
690690

@@ -717,7 +717,7 @@ class TableCatalogSuite extends SparkFunSuite {
717717
test("loadNamespaceMetadata: metadata exists, no tables") {
718718
val catalog = newCatalog()
719719

720-
catalog.createNamespaceMetadata(testNs, Map("property" -> "value").asJava)
720+
catalog.createNamespace(testNs, Map("property" -> "value").asJava)
721721

722722
val metadata = catalog.loadNamespaceMetadata(testNs)
723723

@@ -727,49 +727,52 @@ class TableCatalogSuite extends SparkFunSuite {
727727
test("loadNamespaceMetadata: metadata and table exist") {
728728
val catalog = newCatalog()
729729

730+
catalog.createNamespace(testNs, Map("property" -> "value").asJava)
730731
catalog.createTable(testIdent, schema, Array.empty, emptyProps)
731-
catalog.createNamespaceMetadata(testNs, Map("property" -> "value").asJava)
732732

733733
val metadata = catalog.loadNamespaceMetadata(testNs)
734734

735735
assert(metadata.asScala === Map("property" -> "value"))
736736
}
737737

738-
test("createNamespaceMetadata: basic behavior") {
738+
test("createNamespace: basic behavior") {
739739
val catalog = newCatalog()
740740

741-
catalog.createNamespaceMetadata(testNs, Map("property" -> "value").asJava)
741+
catalog.createNamespace(testNs, Map("property" -> "value").asJava)
742742

743743
assert(catalog.namespaceExists(testNs) === true)
744744
assert(catalog.loadNamespaceMetadata(testNs).asScala === Map("property" -> "value"))
745745
}
746746

747-
test("createNamespaceMetadata: fail if metadata already exists") {
747+
test("createNamespace: fail if metadata already exists") {
748748
val catalog = newCatalog()
749749

750-
catalog.createNamespaceMetadata(testNs, Map("property" -> "value").asJava)
750+
catalog.createNamespace(testNs, Map("property" -> "value").asJava)
751751

752752
val exc = intercept[NamespaceAlreadyExistsException] {
753-
catalog.createNamespaceMetadata(testNs, Map("property" -> "value").asJava)
753+
catalog.createNamespace(testNs, Map("property" -> "value").asJava)
754754
}
755755

756756
assert(exc.getMessage.contains(testNs.quoted))
757757
assert(catalog.namespaceExists(testNs) === true)
758758
assert(catalog.loadNamespaceMetadata(testNs).asScala === Map("property" -> "value"))
759759
}
760760

761-
test("createNamespaceMetadata: table exists") {
761+
test("createNamespace: fail if namespace already exists from table") {
762762
val catalog = newCatalog()
763763

764764
catalog.createTable(testIdent, schema, Array.empty, emptyProps)
765765

766766
assert(catalog.namespaceExists(testNs) === true)
767767
assert(catalog.loadNamespaceMetadata(testNs).asScala === Map.empty)
768768

769-
catalog.createNamespaceMetadata(testNs, Map("property" -> "value").asJava)
769+
val exc = intercept[NamespaceAlreadyExistsException] {
770+
catalog.createNamespace(testNs, Map("property" -> "value").asJava)
771+
}
770772

773+
assert(exc.getMessage.contains(testNs.quoted))
771774
assert(catalog.namespaceExists(testNs) === true)
772-
assert(catalog.loadNamespaceMetadata(testNs).asScala === Map("property" -> "value"))
775+
assert(catalog.loadNamespaceMetadata(testNs).asScala === Map.empty)
773776
}
774777

775778
test("dropNamespace: drop missing namespace") {
@@ -785,7 +788,7 @@ class TableCatalogSuite extends SparkFunSuite {
785788
test("dropNamespace: drop empty namespace") {
786789
val catalog = newCatalog()
787790

788-
catalog.createNamespaceMetadata(testNs, Map("property" -> "value").asJava)
791+
catalog.createNamespace(testNs, Map("property" -> "value").asJava)
789792

790793
assert(catalog.namespaceExists(testNs) === true)
791794
assert(catalog.loadNamespaceMetadata(testNs).asScala === Map("property" -> "value"))
@@ -799,8 +802,8 @@ class TableCatalogSuite extends SparkFunSuite {
799802
test("dropNamespace: fail if not empty") {
800803
val catalog = newCatalog()
801804

805+
catalog.createNamespace(testNs, Map("property" -> "value").asJava)
802806
catalog.createTable(testIdent, schema, Array.empty, emptyProps)
803-
catalog.createNamespaceMetadata(testNs, Map("property" -> "value").asJava)
804807

805808
val exc = intercept[IllegalStateException] {
806809
catalog.dropNamespace(testNs)
@@ -814,7 +817,7 @@ class TableCatalogSuite extends SparkFunSuite {
814817
test("alterNamespace: basic behavior") {
815818
val catalog = newCatalog()
816819

817-
catalog.createNamespaceMetadata(testNs, Map("property" -> "value").asJava)
820+
catalog.createNamespace(testNs, Map("property" -> "value").asJava)
818821

819822
catalog.alterNamespace(testNs, NamespaceChange.setProperty("property2", "value2"))
820823
assert(catalog.loadNamespaceMetadata(testNs).asScala === Map(

sql/catalyst/src/test/scala/org/apache/spark/sql/catalog/v2/TestTableCatalog.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ class TestTableCatalog extends TableCatalog with SupportsNamespaces {
105105
allNamespaces.map(_.head).distinct.map(Array(_)).toArray
106106
}
107107

108-
override def listNamespaces(
109-
namespace: Array[String]): Array[Array[String]] = {
108+
override def listNamespaces(namespace: Array[String]): Array[Array[String]] = {
110109
allNamespaces
111110
.filter(_.size > namespace.length)
112111
.filter(_.startsWith(namespace))
@@ -127,14 +126,18 @@ class TestTableCatalog extends TableCatalog with SupportsNamespaces {
127126
}
128127
}
129128

130-
override def createNamespaceMetadata(
129+
override def createNamespace(
131130
namespace: Array[String],
132131
metadata: util.Map[String, String]): Unit = {
132+
if (namespaceExists(namespace)) {
133+
throw new NamespaceAlreadyExistsException(namespace)
134+
}
135+
133136
Option(namespaces.putIfAbsent(namespace.toList, metadata.asScala.toMap)) match {
134137
case Some(_) =>
135138
throw new NamespaceAlreadyExistsException(namespace)
136139
case _ =>
137-
// created successfully
140+
// created successfully
138141
}
139142
}
140143

0 commit comments

Comments
 (0)