Skip to content

Commit 780f7ff

Browse files
committed
Review comments
1 parent 7e11ca6 commit 780f7ff

File tree

18 files changed

+176
-346
lines changed

18 files changed

+176
-346
lines changed

sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ statement
140140
| ALTER TABLE tableIdentifier partitionSpec? SET locationSpec #setTableLocation
141141
| ALTER TABLE tableIdentifier RECOVER PARTITIONS #recoverPartitions
142142
| DROP TABLE (IF EXISTS)? multipartIdentifier PURGE? #dropTable
143-
| DROP VIEW (IF EXISTS)? multipartIdentifier #dropTable
143+
| DROP VIEW (IF EXISTS)? multipartIdentifier #dropView
144144
| CREATE (OR REPLACE)? (GLOBAL? TEMPORARY)?
145145
VIEW (IF NOT EXISTS)? tableIdentifier
146146
identifierCommentList?

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

Lines changed: 0 additions & 88 deletions
This file was deleted.

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

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
import org.apache.spark.sql.util.CaseInsensitiveStringMap;
2424
import org.apache.spark.util.Utils;
2525

26+
import java.util.HashMap;
2627
import java.util.Map;
27-
import java.util.stream.Collectors;
28+
import java.util.regex.Matcher;
29+
import java.util.regex.Pattern;
2830

2931
import static scala.collection.JavaConverters.mapAsJavaMapConverter;
3032

@@ -33,23 +35,6 @@ public class Catalogs {
3335
private Catalogs() {
3436
}
3537

36-
public static String classKey(String name) {
37-
return "spark.sql.catalog." + name;
38-
}
39-
40-
public static String optionKeyPrefix(String name) {
41-
return "spark.sql.catalog." + name + ".";
42-
}
43-
44-
public static boolean isOptionKey(String name, String keyName) {
45-
return keyName.startsWith(optionKeyPrefix(name));
46-
}
47-
48-
public static String optionName(String name, String keyName) {
49-
assert(isOptionKey(name, keyName));
50-
return keyName.substring(optionKeyPrefix(name).length());
51-
}
52-
5338
/**
5439
* Load and configure a catalog by name.
5540
* <p>
@@ -64,10 +49,10 @@ public static String optionName(String name, String keyName) {
6449
*/
6550
public static CatalogPlugin load(String name, SQLConf conf)
6651
throws CatalogNotFoundException, SparkException {
67-
String pluginClassName = conf.getConfString(classKey(name), null);
52+
String pluginClassName = conf.getConfString("spark.sql.catalog." + name, null);
6853
if (pluginClassName == null) {
6954
throw new CatalogNotFoundException(String.format(
70-
"Catalog '%s' plugin class not found: %s is not defined", name, classKey(name)));
55+
"Catalog '%s' plugin class not found: spark.sql.catalog.%s is not defined", name, name));
7156
}
7257

7358
ClassLoader loader = Utils.getContextOrSparkClassLoader();
@@ -111,12 +96,17 @@ public static CatalogPlugin load(String name, SQLConf conf)
11196
* @return a case insensitive string map of options starting with spark.sql.catalog.(name).
11297
*/
11398
private static CaseInsensitiveStringMap catalogOptions(String name, SQLConf conf) {
114-
Map<String, String> options =
115-
mapAsJavaMapConverter(conf.getAllConfs()).asJava().entrySet().stream()
116-
.filter(e -> isOptionKey(name, e.getKey()))
117-
.collect(Collectors.toMap(
118-
e -> optionName(name, e.getKey()),
119-
e -> e.getValue()));
99+
Map<String, String> allConfs = mapAsJavaMapConverter(conf.getAllConfs()).asJava();
100+
Pattern prefix = Pattern.compile("^spark\\.sql\\.catalog\\." + name + "\\.(.+)");
101+
102+
HashMap<String, String> options = new HashMap<>();
103+
for (Map.Entry<String, String> entry : allConfs.entrySet()) {
104+
Matcher matcher = prefix.matcher(entry.getKey());
105+
if (matcher.matches() && matcher.groupCount() > 0) {
106+
options.put(matcher.group(1), entry.getValue());
107+
}
108+
}
109+
120110
return new CaseInsensitiveStringMap(options);
121111
}
122112
}

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
import java.util.Arrays;
2424
import java.util.Objects;
25-
import java.util.stream.Collectors;
26-
import java.util.stream.Stream;
2725

2826
/**
2927
* An {@link Identifier} implementation.
@@ -51,21 +49,6 @@ public String name() {
5149
return name;
5250
}
5351

54-
private String quote(String part) {
55-
if (part.contains("`")) {
56-
return part.replace("`", "``");
57-
} else {
58-
return part;
59-
}
60-
}
61-
62-
@Override
63-
public String toString() {
64-
return Stream.concat(Stream.of(namespace), Stream.of(name))
65-
.map(part -> '`' + quote(part) + '`')
66-
.collect(Collectors.joining("."));
67-
}
68-
6952
@Override
7053
public boolean equals(Object o) {
7154
if (this == o) {

sql/catalyst/src/main/java/org/apache/spark/sql/util/CaseInsensitiveStringMap.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.HashMap;
2727
import java.util.Locale;
2828
import java.util.Map;
29-
import java.util.Objects;
3029
import java.util.Set;
3130

3231
/**
@@ -179,17 +178,4 @@ public double getDouble(String key, double defaultValue) {
179178
public Map<String, String> asCaseSensitiveMap() {
180179
return Collections.unmodifiableMap(original);
181180
}
182-
183-
@Override
184-
public boolean equals(Object o) {
185-
if (this == o) return true;
186-
if (o == null || getClass() != o.getClass()) return false;
187-
CaseInsensitiveStringMap that = (CaseInsensitiveStringMap) o;
188-
return delegate.equals(that.delegate);
189-
}
190-
191-
@Override
192-
public int hashCode() {
193-
return Objects.hash(delegate);
194-
}
195181
}

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,4 +2195,22 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
21952195
}
21962196
}
21972197

2198+
/**
2199+
* Create a [[sql.DropTableStatement]] command.
2200+
*/
2201+
override def visitDropTable(ctx: DropTableContext): LogicalPlan = withOrigin(ctx) {
2202+
sql.DropTableStatement(
2203+
visitMultipartIdentifier(ctx.multipartIdentifier()),
2204+
ctx.EXISTS != null,
2205+
ctx.PURGE != null)
2206+
}
2207+
2208+
/**
2209+
* Create a [[sql.DropViewStatement]] command.
2210+
*/
2211+
override def visitDropView(ctx: DropViewContext): AnyRef = withOrigin(ctx) {
2212+
sql.DropViewStatement(
2213+
visitMultipartIdentifier(ctx.multipartIdentifier()),
2214+
ctx.EXISTS != null)
2215+
}
21982216
}

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/sql/DropTableStatement.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
2626
case class DropTableStatement(
2727
tableName: Seq[String],
2828
ifExists: Boolean,
29-
isView: Boolean,
3029
purge: Boolean) extends ParsedStatement {
3130

3231
override def output: Seq[Attribute] = Seq.empty
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.sql.catalyst.plans.logical.sql
19+
20+
import org.apache.spark.sql.catalyst.expressions.Attribute
21+
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
22+
23+
/**
24+
* A DROP VIEW statement, as parsed from SQL.
25+
*/
26+
case class DropViewStatement(
27+
tableName: Seq[String],
28+
ifExists: Boolean) extends ParsedStatement {
29+
30+
override def output: Seq[Attribute] = Seq.empty
31+
32+
override def children: Seq[LogicalPlan] = Seq.empty
33+
}

sql/catalyst/src/test/java/org/apache/spark/sql/catalog/v2/CatalogManagerSuite.java

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)