Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/src/main/resources/error/error-classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
"FAILED_SET_ORIGINAL_PERMISSION_BACK" : {
"message" : [ "Failed to set original permission %s back to the created path: %s. Exception: %s" ]
},
"FORBIDDEN_OPERATION" : {
"message" : [ "The operation %s is not allowed on %s: %s" ]
},
"GRAPHITE_SINK_INVALID_PROTOCOL" : {
"message" : [ "Invalid Graphite protocol: %s" ]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1931,11 +1931,17 @@ object QueryCompilationErrors extends QueryErrorsBase {
}

def descPartitionNotAllowedOnTempView(table: String): Throwable = {
new AnalysisException(s"DESC PARTITION is not allowed on a temporary view: $table")
new AnalysisException(
errorClass = "FORBIDDEN_OPERATION",
messageParameters =
Array(toSQLStmt("DESC PARTITION"), "the temporary view", toSQLId(table)))
}

def descPartitionNotAllowedOnView(table: String): Throwable = {
new AnalysisException(s"DESC PARTITION is not allowed on a view: $table")
new AnalysisException(
errorClass = "FORBIDDEN_OPERATION",
messageParameters = Array(
toSQLStmt("DESC PARTITION"), "the view", toSQLId(table)))
}

def showPartitionNotAllowedOnTableNotPartitionedError(tableIdentWithDB: String): Throwable = {
Expand Down Expand Up @@ -1971,10 +1977,6 @@ object QueryCompilationErrors extends QueryErrorsBase {
)
}

def descPartitionNotAllowedOnViewError(table: String): Throwable = {
new AnalysisException(s"DESC PARTITION is not allowed on a view: $table")
}

def showCreateTableAsSerdeNotAllowedOnSparkDataSourceTableError(
table: TableIdentifier): Throwable = {
new AnalysisException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ trait QueryErrorsBase {
litToErrorValue(Literal.create(v, t))
}

// Quote sql statements in error messages.
def toSQLStmt(text: String): String = {
s"'$text'"
}

def toSQLId(parts: Seq[String]): String = {
parts.map(quoteIdentifier).mkString(".")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ DESC temp_v PARTITION (c='Us', d=1)
struct<>
-- !query output
org.apache.spark.sql.AnalysisException
DESC PARTITION is not allowed on a temporary view: temp_v
The operation 'DESC PARTITION' is not allowed on the temporary view: `temp_v`


-- !query
Expand Down Expand Up @@ -539,7 +539,7 @@ DESC v PARTITION (c='Us', d=1)
struct<>
-- !query output
org.apache.spark.sql.AnalysisException
DESC PARTITION is not allowed on a view: v
The operation 'DESC PARTITION' is not allowed on the view: `v`


-- !query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,56 @@ class QueryCompilationErrorsSuite extends QueryTest with SharedSparkSession {
}
}
}

test("FORBIDDEN_OPERATION: desc partition on a temporary view") {
val tableName: String = "t"
val tempViewName: String = "tempView"

withTable(tableName) {
sql(
s"""
|CREATE TABLE $tableName (a STRING, b INT, c STRING, d STRING)
|USING parquet
|PARTITIONED BY (c, d)
|""".stripMargin)

withTempView(tempViewName) {
sql(s"CREATE TEMPORARY VIEW $tempViewName as SELECT * FROM $tableName")

val e = intercept[AnalysisException](
sql(s"DESC TABLE $tempViewName PARTITION (c='Us', d=1)")
)
assert(e.getErrorClass === "FORBIDDEN_OPERATION")
assert(e.message ===
s"The operation 'DESC PARTITION' is not allowed on the temporary view: `$tempViewName`")
}
}
}

test("FORBIDDEN_OPERATION: desc partition on a view") {
val tableName: String = "t"
val viewName: String = "view"

withTable(tableName) {
sql(
s"""
|CREATE TABLE $tableName (a STRING, b INT, c STRING, d STRING)
|USING parquet
|PARTITIONED BY (c, d)
|""".stripMargin)

withView(viewName) {
sql(s"CREATE VIEW $viewName as SELECT * FROM $tableName")

val e = intercept[AnalysisException](
sql(s"DESC TABLE $viewName PARTITION (c='Us', d=1)")
)
assert(e.getErrorClass === "FORBIDDEN_OPERATION")
assert(e.message ===
s"The operation 'DESC PARTITION' is not allowed on the view: `$viewName`")
}
}
}
}

class MyCastToString extends SparkUserDefinedFunction(
Expand Down