Skip to content

Commit

Permalink
[KYUUBI #1920] Skip the Plan parsing of UseStatement
Browse files Browse the repository at this point in the history
Close #1920

### _Why are the changes needed?_

### _How was this patch tested?_
- [x] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [ ] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #1921 from iodone/kyuubi-1902.

Closes #1920

79d7ba6 [odone] [KYUUBI #1920] Added CacheTableAsSelect to be skiped
571003d [odone] [KYUUBI #1920] Added CacheTableStatement to be skiped
889cb2b [odone] [KYUUBI #1920] Added CacheTableCommand and CreateView to be skiped
456dbf5 [odone] [KYUUBI #1920] Update test
9000169 [odone] [KYUUBI #1920] Update
80e0cef [odone] [KYUUBI #1920] Update

Authored-by: odone <odone.zhang@gmail.com>
Signed-off-by: Kent Yao <yao@apache.org>
  • Loading branch information
iodone authored and yaooqinn committed Feb 22, 2022
1 parent 44b6507 commit cec25d9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
Expand Up @@ -38,23 +38,32 @@ class PlanOnlyStatement(
private val operationLog: OperationLog = OperationLog.createOperationLog(session, getHandle)
override def getOperationLog: Option[OperationLog] = Option(operationLog)

override protected def resultSchema: StructType =
override protected def resultSchema: StructType = {
if (result == null) {
new StructType().add("plan", "string")
} else {
result.schema
}
} else if (result.isEmpty) {
new StructType().add("result", "string")
} else result.schema
}

private def isSetOrReset(plan: LogicalPlan): Boolean = {
private def shouldDirectRun(plan: LogicalPlan): Boolean = {
val className = plan.getClass.getSimpleName
className == "SetCommand" || className == "ResetCommand"
className == "SetCommand" ||
className == "ResetCommand" ||
className == "UseStatement" ||
className == "SetNamespaceCommand" ||
className == "CacheTableStatement" ||
className == "CacheTableCommand" ||
className == "CacheTableAsSelect" ||
className == "CreateViewStatement" ||
className == "CreateViewCommand"
}

override protected def runInternal(): Unit = {
try {
val parsed = spark.sessionState.sqlParser.parsePlan(statement)
parsed match {
case cmd if isSetOrReset(cmd) =>
case cmd if shouldDirectRun(cmd) =>
result = spark.sql(statement)
iter = new ArrayFetchIterator(result.collect())
case plan => mode match {
Expand Down
Expand Up @@ -79,6 +79,35 @@ class PlanOnlyOperationSuite extends WithKyuubiServer with HiveJDBCTestHelper {
}
}

test("KYUUBI #1920: Plan only operations with Usestatement or SetNamespaceCommand skiped") {
withSessionConf()(Map(KyuubiConf.OPERATION_PLAN_ONLY.key -> NONE.toString))(Map.empty) {
withDatabases("test_database") { statement =>
statement.execute("create database test_database")
statement.execute(s"set ${KyuubiConf.OPERATION_PLAN_ONLY.key}=optimize")
val result = statement.executeQuery("use test_database")
assert(!result.next(), "In contrast to PlanOnly mode, it will returns an empty result")
}
}
}

test("KYUUBI #1920: Plan only operations with CacheTable skiped") {
withSessionConf()(Map(KyuubiConf.OPERATION_PLAN_ONLY.key -> OPTIMIZE.toString))(Map.empty) {
withJdbcStatement() { statement =>
val result = statement.executeQuery("cache table cached_table as select 1")
assert(!result.next(), "In contrast to PlanOnly mode, it will returns an empty result")
}
}
}

test("KYUUBI #1920: Plan only operations with CreateViewStatement or CreateViewCommand skiped") {
withSessionConf()(Map(KyuubiConf.OPERATION_PLAN_ONLY.key -> OPTIMIZE.toString))(Map.empty) {
withJdbcStatement() { statement =>
val result = statement.executeQuery("create temp view temp_view as select 1")
assert(!result.next(), "In contrast to PlanOnly mode, it will returns an empty result")
}
}
}

private def getOperationPlanWithStatement(statement: Statement): String = {
val resultSet = statement.executeQuery("select 1 where true")
assert(resultSet.next())
Expand Down

0 comments on commit cec25d9

Please sign in to comment.