Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jzhuge committed May 30, 2019
1 parent dd5b799 commit d5b0d4a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* An {@link Identifier} implementation.
Expand Down Expand Up @@ -49,6 +51,21 @@ public String name() {
return name;
}

private String escapeQuote(String part) {
if (part.contains("`")) {
return part.replace("`", "``");
} else {
return part;
}
}

@Override
public String toString() {
return Stream.concat(Stream.of(namespace), Stream.of(name))
.map(part -> '`' + escapeQuote(part) + '`')
.collect(Collectors.joining("."));
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import org.apache.spark.sql.catalyst.expressions.aggregate.{First, Last}
import org.apache.spark.sql.catalyst.parser.SqlBaseParser._
import org.apache.spark.sql.catalyst.plans._
import org.apache.spark.sql.catalyst.plans.logical._
import org.apache.spark.sql.catalyst.plans.logical.sql.{CreateTableAsSelectStatement, CreateTableStatement}
import org.apache.spark.sql.catalyst.plans.logical.sql.{CreateTableAsSelectStatement, CreateTableStatement, DropTableStatement, DropViewStatement}
import org.apache.spark.sql.catalyst.util.DateTimeUtils.{getZoneId, stringToDate, stringToTimestamp}
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types._
Expand Down Expand Up @@ -2196,20 +2196,20 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
}

/**
* Create a [[sql.DropTableStatement]] command.
* Create a [[DropTableStatement]] command.
*/
override def visitDropTable(ctx: DropTableContext): LogicalPlan = withOrigin(ctx) {
sql.DropTableStatement(
DropTableStatement(
visitMultipartIdentifier(ctx.multipartIdentifier()),
ctx.EXISTS != null,
ctx.PURGE != null)
}

/**
* Create a [[sql.DropViewStatement]] command.
* Create a [[DropViewStatement]] command.
*/
override def visitDropView(ctx: DropViewContext): AnyRef = withOrigin(ctx) {
sql.DropViewStatement(
DropViewStatement(
visitMultipartIdentifier(ctx.multipartIdentifier()),
ctx.EXISTS != null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
* A DROP VIEW statement, as parsed from SQL.
*/
case class DropViewStatement(
tableName: Seq[String],
viewName: Seq[String],
ifExists: Boolean) extends ParsedStatement {

override def output: Seq[Attribute] = Seq.empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,15 @@ case class DataSourceResolution(
DropTable(catalog.asTableCatalog, ident, ifExists)

case DropTableStatement(AsTableIdentifier(tableName), ifExists, purge) =>
DropTableCommand(tableName, ifExists, false, purge)
DropTableCommand(tableName, ifExists, isView = false, purge)

case DropViewStatement(CatalogObjectIdentifier(Some(catalog), ident), _) =>
throw new AnalysisException(
s"Can not specify catalog `${catalog.name}` for view $ident " +
s"because view support in catalog has not been implemented yet")

case DropViewStatement(AsTableIdentifier(tableName), ifExists) =>
DropTableCommand(tableName, ifExists, true, false)
DropTableCommand(tableName, ifExists, isView = true, purge = false)
}

object V1WriteProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.spark.sql.execution.command

import java.net.URI
import java.util.Locale

import org.apache.spark.sql.{AnalysisException, SaveMode}
import org.apache.spark.sql.catalog.v2.{CatalogNotFoundException, CatalogPlugin, Identifier, TableCatalog, TestTableCatalog}
Expand Down Expand Up @@ -462,7 +463,7 @@ class PlanResolutionSuite extends AnalysisTest {
DropTableCommand(tableIdent2, ifExists = true, isView = false, purge = true))
}

test("drop table v2") {
test("drop table in v2 catalog") {
val tableName1 = "testcat.db.tab"
val tableIdent1 = Identifier.of(Array("db"), "tab")
val tableName2 = "testcat.tab"
Expand Down Expand Up @@ -494,10 +495,10 @@ class PlanResolutionSuite extends AnalysisTest {
DropTableCommand(viewIdent2, ifExists = true, isView = true, purge = false))
}

test("drop view v2") {
assertAnalysisError(
parseAndResolve("DROP VIEW testcat.db.view"),
Seq("unresolved operator 'DropViewStatement"),
caseSensitive = false)
test("drop view in v2 catalog") {
intercept[AnalysisException] {
parseAndResolve("DROP VIEW testcat.db.view")
}.getMessage.toLowerCase(Locale.ROOT).contains(
"view support in catalog has not been implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import org.apache.spark.sql.execution.datasources.v2.orc.OrcDataSourceV2
import org.apache.spark.sql.test.SharedSQLContext
import org.apache.spark.sql.types.{LongType, StringType, StructType}

class DataSourceV2SQLSuite
extends QueryTest with SharedSQLContext with BeforeAndAfter {
class DataSourceV2SQLSuite extends QueryTest with SharedSQLContext with BeforeAndAfter {

import org.apache.spark.sql.catalog.v2.CatalogV2Implicits._

Expand Down

0 comments on commit d5b0d4a

Please sign in to comment.