Skip to content

Commit cec25d9

Browse files
iodoneyaooqinn
authored andcommitted
[KYUUBI #1920] Skip the Plan parsing of UseStatement
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>
1 parent 44b6507 commit cec25d9

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/PlanOnlyStatement.scala

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,32 @@ class PlanOnlyStatement(
3838
private val operationLog: OperationLog = OperationLog.createOperationLog(session, getHandle)
3939
override def getOperationLog: Option[OperationLog] = Option(operationLog)
4040

41-
override protected def resultSchema: StructType =
41+
override protected def resultSchema: StructType = {
4242
if (result == null) {
4343
new StructType().add("plan", "string")
44-
} else {
45-
result.schema
46-
}
44+
} else if (result.isEmpty) {
45+
new StructType().add("result", "string")
46+
} else result.schema
47+
}
4748

48-
private def isSetOrReset(plan: LogicalPlan): Boolean = {
49+
private def shouldDirectRun(plan: LogicalPlan): Boolean = {
4950
val className = plan.getClass.getSimpleName
50-
className == "SetCommand" || className == "ResetCommand"
51+
className == "SetCommand" ||
52+
className == "ResetCommand" ||
53+
className == "UseStatement" ||
54+
className == "SetNamespaceCommand" ||
55+
className == "CacheTableStatement" ||
56+
className == "CacheTableCommand" ||
57+
className == "CacheTableAsSelect" ||
58+
className == "CreateViewStatement" ||
59+
className == "CreateViewCommand"
5160
}
5261

5362
override protected def runInternal(): Unit = {
5463
try {
5564
val parsed = spark.sessionState.sqlParser.parsePlan(statement)
5665
parsed match {
57-
case cmd if isSetOrReset(cmd) =>
66+
case cmd if shouldDirectRun(cmd) =>
5867
result = spark.sql(statement)
5968
iter = new ArrayFetchIterator(result.collect())
6069
case plan => mode match {

kyuubi-server/src/test/scala/org/apache/kyuubi/operation/PlanOnlyOperationSuite.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,35 @@ class PlanOnlyOperationSuite extends WithKyuubiServer with HiveJDBCTestHelper {
7979
}
8080
}
8181

82+
test("KYUUBI #1920: Plan only operations with Usestatement or SetNamespaceCommand skiped") {
83+
withSessionConf()(Map(KyuubiConf.OPERATION_PLAN_ONLY.key -> NONE.toString))(Map.empty) {
84+
withDatabases("test_database") { statement =>
85+
statement.execute("create database test_database")
86+
statement.execute(s"set ${KyuubiConf.OPERATION_PLAN_ONLY.key}=optimize")
87+
val result = statement.executeQuery("use test_database")
88+
assert(!result.next(), "In contrast to PlanOnly mode, it will returns an empty result")
89+
}
90+
}
91+
}
92+
93+
test("KYUUBI #1920: Plan only operations with CacheTable skiped") {
94+
withSessionConf()(Map(KyuubiConf.OPERATION_PLAN_ONLY.key -> OPTIMIZE.toString))(Map.empty) {
95+
withJdbcStatement() { statement =>
96+
val result = statement.executeQuery("cache table cached_table as select 1")
97+
assert(!result.next(), "In contrast to PlanOnly mode, it will returns an empty result")
98+
}
99+
}
100+
}
101+
102+
test("KYUUBI #1920: Plan only operations with CreateViewStatement or CreateViewCommand skiped") {
103+
withSessionConf()(Map(KyuubiConf.OPERATION_PLAN_ONLY.key -> OPTIMIZE.toString))(Map.empty) {
104+
withJdbcStatement() { statement =>
105+
val result = statement.executeQuery("create temp view temp_view as select 1")
106+
assert(!result.next(), "In contrast to PlanOnly mode, it will returns an empty result")
107+
}
108+
}
109+
}
110+
82111
private def getOperationPlanWithStatement(statement: Statement): String = {
83112
val resultSet = statement.executeQuery("select 1 where true")
84113
assert(resultSet.next())

0 commit comments

Comments
 (0)