-
Notifications
You must be signed in to change notification settings - Fork 28.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-27813][SQL] DataSourceV2: Add DropTable logical operation
- Loading branch information
Showing
17 changed files
with
441 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
sql/catalyst/src/main/java/org/apache/spark/sql/catalog/v2/CatalogManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.catalog.v2; | ||
|
||
import org.apache.spark.SparkException; | ||
import org.apache.spark.annotation.Private; | ||
import org.apache.spark.sql.internal.SQLConf; | ||
import org.apache.spark.sql.util.CaseInsensitiveStringMap; | ||
|
||
import static org.apache.spark.sql.catalog.v2.Catalogs.classKey; | ||
import static org.apache.spark.sql.catalog.v2.Catalogs.isOptionKey; | ||
import static org.apache.spark.sql.catalog.v2.Catalogs.optionKeyPrefix; | ||
import static scala.collection.JavaConverters.mapAsJavaMapConverter; | ||
|
||
@Private | ||
public class CatalogManager { | ||
|
||
private final SQLConf conf; | ||
|
||
public CatalogManager(SQLConf conf) { | ||
this.conf = conf; | ||
} | ||
|
||
/** | ||
* Load a catalog. | ||
* | ||
* @param name a catalog name | ||
* @return a catalog plugin | ||
*/ | ||
public CatalogPlugin load(String name) throws SparkException { | ||
return Catalogs.load(name, conf); | ||
} | ||
|
||
/** | ||
* Add a catalog. | ||
* | ||
* @param name a catalog name | ||
* @param pluginClassName a catalog plugin class name | ||
* @param options catalog options | ||
*/ | ||
public void add( | ||
String name, | ||
String pluginClassName, | ||
CaseInsensitiveStringMap options) { | ||
options.entrySet().stream() | ||
.forEach(e -> conf.setConfString(optionKeyPrefix(name) + e.getKey(), e.getValue())); | ||
conf.setConfString(classKey(name), pluginClassName); | ||
} | ||
|
||
/** | ||
* Add a catalog without option. | ||
* | ||
* @param name a catalog name | ||
* @param pluginClassName a catalog plugin class name | ||
*/ | ||
public void add( | ||
String name, | ||
String pluginClassName) { | ||
add(name, pluginClassName, CaseInsensitiveStringMap.empty()); | ||
} | ||
|
||
/** | ||
* Remove a catalog. | ||
* | ||
* @param name a catalog name | ||
*/ | ||
public void remove(String name) { | ||
conf.unsetConf(classKey(name)); | ||
mapAsJavaMapConverter(conf.getAllConfs()).asJava().keySet().stream() | ||
.filter(key -> isOptionKey(name, key)) | ||
.forEach(conf::unsetConf); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...t/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/sql/DropTableStatement.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.catalyst.plans.logical.sql | ||
|
||
import org.apache.spark.sql.catalyst.expressions.Attribute | ||
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
|
||
/** | ||
* A DROP TABLE statement, as parsed from SQL. | ||
*/ | ||
case class DropTableStatement( | ||
tableName: Seq[String], | ||
ifExists: Boolean, | ||
isView: Boolean, | ||
purge: Boolean) extends ParsedStatement { | ||
|
||
override def output: Seq[Attribute] = Seq.empty | ||
|
||
override def children: Seq[LogicalPlan] = Seq.empty | ||
} |
71 changes: 71 additions & 0 deletions
71
sql/catalyst/src/test/java/org/apache/spark/sql/catalog/v2/CatalogManagerSuite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.catalog.v2; | ||
|
||
import org.apache.spark.SparkException; | ||
import org.apache.spark.sql.internal.SQLConf; | ||
import org.apache.spark.sql.util.CaseInsensitiveStringMap; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import java.util.HashMap; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
import static org.hamcrest.core.IsInstanceOf.instanceOf; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class CatalogManagerSuite { | ||
|
||
@Rule | ||
public final ExpectedException exception = ExpectedException.none(); | ||
|
||
CatalogManager catalogManager = new CatalogManager(new SQLConf()); | ||
|
||
@Test | ||
public void testAdd() throws SparkException { | ||
CaseInsensitiveStringMap options = new CaseInsensitiveStringMap( | ||
new HashMap<String, String>() {{ | ||
put("option1", "value1"); | ||
put("option2", "value2"); | ||
}}); | ||
catalogManager.add("testcat", TestCatalogPlugin.class.getCanonicalName(), options); | ||
CatalogPlugin catalogPlugin = catalogManager.load("testcat"); | ||
assertThat(catalogPlugin.name(), is("testcat")); | ||
assertThat(catalogPlugin, instanceOf(TestCatalogPlugin.class)); | ||
assertThat(((TestCatalogPlugin) catalogPlugin).options, is(options)); | ||
} | ||
|
||
@Test | ||
public void testAddWithOption() throws SparkException { | ||
catalogManager.add("testcat", TestCatalogPlugin.class.getCanonicalName()); | ||
CatalogPlugin catalogPlugin = catalogManager.load("testcat"); | ||
assertThat(catalogPlugin.name(), is("testcat")); | ||
assertThat(catalogPlugin, instanceOf(TestCatalogPlugin.class)); | ||
assertThat(((TestCatalogPlugin) catalogPlugin).options, is(CaseInsensitiveStringMap.empty())); | ||
} | ||
|
||
@Test | ||
public void testRemove() throws SparkException { | ||
catalogManager.add("testcat", TestCatalogPlugin.class.getCanonicalName()); | ||
catalogManager.load("testcat"); | ||
catalogManager.remove("testcat"); | ||
exception.expect(CatalogNotFoundException.class); | ||
catalogManager.load("testcat"); | ||
} | ||
} |
Oops, something went wrong.