Skip to content

Commit 4cceb1d

Browse files
wangjunbopan3793
authored andcommitted
[KYUUBI #5797] Support to describe engine with command in current session
# 🔍 Description ## Issue References 🔗 This pull request fixes #5797 ,impl `describe engine` first, `restart engine` will impl soon. ## Describe Your Solution 🔧 Support to describe engine with command in current session. ## Types of changes 🔖 - [ ] Bugfix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Test Plan 🧪 #### Behavior Without This Pull Request ⚰️ #### Behavior With This Pull Request 🎉 user can use sql `KYUUBI DESCRIBE[DESC] ENGINE` to show engine info. #### Related Unit Tests --- # Checklist 📝 - [ ] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html) **Be nice. Be informative.** Closes #5931 from Kwafoor/kyuubi_5797_desc_engine. Closes #5797 f768fb5 [wangjunbo] [KYUUBI #5797] fix 4746fa6 [wangjunbo] [KYUUBI #5797] Support to describe engine with command in current session Authored-by: wangjunbo <wangjunbo@qiyi.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
1 parent c6bba91 commit 4cceb1d

File tree

8 files changed

+129
-13
lines changed

8 files changed

+129
-13
lines changed

kyuubi-server/src/main/antlr4/org/apache/kyuubi/sql/KyuubiSqlBaseLexer.g4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ KYUUBIADMIN: 'KYUUBIADMIN';
5151

5252
SESSION: 'SESSION';
5353

54+
ENGINE: 'ENGINE';
55+
5456
BACKQUOTED_IDENTIFIER
5557
: '`' ( ~'`' | '``' )* '`'
5658
;

kyuubi-server/src/main/antlr4/org/apache/kyuubi/sql/KyuubiSqlBaseParser.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ statement
3030

3131
runnableCommand
3232
: (DESC | DESCRIBE) SESSION #describeSession
33+
| (DESC | DESCRIBE) ENGINE #describeEngine
3334
;

kyuubi-server/src/main/scala/org/apache/kyuubi/sql/parser/server/KyuubiAstBuilder.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package org.apache.kyuubi.sql.parser.server
2020
import org.apache.kyuubi.sql.{KyuubiSqlBaseParser, KyuubiSqlBaseParserBaseVisitor}
2121
import org.apache.kyuubi.sql.KyuubiSqlBaseParser.SingleStatementContext
2222
import org.apache.kyuubi.sql.plan.{KyuubiTreeNode, PassThroughNode}
23-
import org.apache.kyuubi.sql.plan.command.{DescribeSession, RunnableCommand}
23+
import org.apache.kyuubi.sql.plan.command.{DescribeEngine, DescribeSession, RunnableCommand}
2424

2525
class KyuubiAstBuilder extends KyuubiSqlBaseParserBaseVisitor[AnyRef] {
2626

@@ -44,4 +44,9 @@ class KyuubiAstBuilder extends KyuubiSqlBaseParserBaseVisitor[AnyRef] {
4444
: RunnableCommand = {
4545
DescribeSession()
4646
}
47+
48+
override def visitDescribeEngine(ctx: KyuubiSqlBaseParser.DescribeEngineContext)
49+
: RunnableCommand = {
50+
DescribeEngine()
51+
}
4752
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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.kyuubi.sql.plan.command
19+
20+
import scala.collection.mutable.ListBuffer
21+
22+
import org.apache.kyuubi.operation.IterableFetchIterator
23+
import org.apache.kyuubi.session.{KyuubiSession, KyuubiSessionImpl}
24+
import org.apache.kyuubi.shaded.hive.service.rpc.thrift.TTypeId
25+
import org.apache.kyuubi.sql.schema.{Column, Row, Schema}
26+
27+
/**
28+
* A runnable node for description the current session engine.
29+
*
30+
* The syntax of using this command in SQL is:
31+
* {{{
32+
* [DESC|DESCRIBE] ENGINE;
33+
* }}}
34+
*/
35+
case class DescribeEngine() extends RunnableCommand {
36+
37+
override def run(kyuubiSession: KyuubiSession): Unit = {
38+
val rows = Seq(kyuubiSession).map { session =>
39+
lazy val client = session.asInstanceOf[KyuubiSessionImpl].client
40+
val values = new ListBuffer[String]()
41+
values += client.engineId.getOrElse("")
42+
values += client.engineName.getOrElse("")
43+
values += client.engineUrl.getOrElse("")
44+
Row(values.toList)
45+
}
46+
iter = new IterableFetchIterator(rows)
47+
}
48+
49+
override def resultSchema: Schema = {
50+
Schema(DescribeEngine.outputCols().toList)
51+
}
52+
53+
override def name(): String = "Describe Engine Node"
54+
}
55+
56+
object DescribeEngine {
57+
58+
def outputCols(): Seq[Column] = {
59+
Seq(
60+
Column("ENGINE_ID", TTypeId.STRING_TYPE, Some("Kyuubi engine identify")),
61+
Column("ENGINE_NAME", TTypeId.STRING_TYPE, Some("Kyuubi engine name")),
62+
Column("ENGINE_URL", TTypeId.STRING_TYPE, Some("Kyuubi engine url")))
63+
}
64+
}

kyuubi-server/src/main/scala/org/apache/kyuubi/sql/plan/command/DescribeSession.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ object DescribeSession {
5656

5757
def outputCols(): Seq[Column] = {
5858
Seq(
59-
Column("id", TTypeId.STRING_TYPE, Some("Kyuubi session identify")),
60-
Column("user", TTypeId.STRING_TYPE, Some("Kyuubi session user")),
61-
Column("type", TTypeId.STRING_TYPE, Some("Kyuubi session type")))
59+
Column("SESSION_ID", TTypeId.STRING_TYPE, Some("Kyuubi session identify")),
60+
Column("SESSION_USER", TTypeId.STRING_TYPE, Some("Kyuubi session user")),
61+
Column("SESSION_TYPE", TTypeId.STRING_TYPE, Some("Kyuubi session type")))
6262
}
6363
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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.kyuubi.operation.parser
19+
20+
class DescribeEngineSuite extends ExecutedCommandExecSuite {
21+
22+
test("desc/describe kyuubi engine") {
23+
Seq("DESC", "DESCRIBE").foreach { desc =>
24+
withJdbcStatement() { statement =>
25+
val resultSet = statement.executeQuery(s"KYUUBI $desc ENGINE")
26+
assert(resultSet.next())
27+
28+
assert(resultSet.getMetaData.getColumnCount == 3)
29+
assert(resultSet.getMetaData.getColumnName(1) == "ENGINE_ID")
30+
assert(resultSet.getMetaData.getColumnName(2) == "ENGINE_NAME")
31+
assert(resultSet.getMetaData.getColumnName(3) == "ENGINE_URL")
32+
}
33+
}
34+
}
35+
}

kyuubi-server/src/test/scala/org/apache/kyuubi/operation/parser/DescribeSessionSuite.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ package org.apache.kyuubi.operation.parser
1919

2020
class DescribeSessionSuite extends ExecutedCommandExecSuite {
2121

22-
test("desc kyuubi session") {
23-
withJdbcStatement() { statement =>
24-
val resultSet = statement.executeQuery("KYUUBI DESC SESSION")
25-
assert(resultSet.next())
22+
test("desc/describe kyuubi session") {
23+
Seq("DESC", "DESCRIBE").foreach { desc =>
24+
withJdbcStatement() { statement =>
25+
val resultSet = statement.executeQuery(s"KYUUBI $desc SESSION")
26+
assert(resultSet.next())
2627

27-
assert(resultSet.getMetaData.getColumnCount == 3)
28-
assert(resultSet.getMetaData.getColumnName(1) == "id")
29-
assert(resultSet.getMetaData.getColumnName(2) == "user")
30-
assert(resultSet.getMetaData.getColumnName(3) == "type")
28+
assert(resultSet.getMetaData.getColumnCount == 3)
29+
assert(resultSet.getMetaData.getColumnName(1) == "SESSION_ID")
30+
assert(resultSet.getMetaData.getColumnName(2) == "SESSION_USER")
31+
assert(resultSet.getMetaData.getColumnName(3) == "SESSION_TYPE")
32+
}
3133
}
3234
}
3335
}

kyuubi-server/src/test/scala/org/apache/kyuubi/parser/KyuubiParserSuite.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package org.apache.kyuubi.parser
2020
import org.apache.kyuubi.KyuubiFunSuite
2121
import org.apache.kyuubi.sql.parser.server.KyuubiParser
2222
import org.apache.kyuubi.sql.plan.PassThroughNode
23-
import org.apache.kyuubi.sql.plan.command.DescribeSession
23+
import org.apache.kyuubi.sql.plan.command.{DescribeEngine, DescribeSession}
2424

2525
class KyuubiParserSuite extends KyuubiFunSuite {
2626

@@ -51,4 +51,11 @@ class KyuubiParserSuite extends KyuubiFunSuite {
5151
assert(node.isInstanceOf[DescribeSession])
5252
assert(node.name() == "Describe Session Node")
5353
}
54+
55+
test("Describe session engine") {
56+
val node = parser.parsePlan("KYUUBI DESC ENGINE")
57+
58+
assert(node.isInstanceOf[DescribeEngine])
59+
assert(node.name() == "Describe Engine Node")
60+
}
5461
}

0 commit comments

Comments
 (0)