Skip to content

Commit

Permalink
[KYUUBI #5797] Support to describe engine with command in current ses…
Browse files Browse the repository at this point in the history
…sion

# 🔍 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 <[email protected]>
Signed-off-by: Cheng Pan <[email protected]>
  • Loading branch information
wangjunbo authored and pan3793 committed Jan 4, 2024
1 parent c6bba91 commit 4cceb1d
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ KYUUBIADMIN: 'KYUUBIADMIN';

SESSION: 'SESSION';

ENGINE: 'ENGINE';

BACKQUOTED_IDENTIFIER
: '`' ( ~'`' | '``' )* '`'
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ statement

runnableCommand
: (DESC | DESCRIBE) SESSION #describeSession
| (DESC | DESCRIBE) ENGINE #describeEngine
;
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package org.apache.kyuubi.sql.parser.server
import org.apache.kyuubi.sql.{KyuubiSqlBaseParser, KyuubiSqlBaseParserBaseVisitor}
import org.apache.kyuubi.sql.KyuubiSqlBaseParser.SingleStatementContext
import org.apache.kyuubi.sql.plan.{KyuubiTreeNode, PassThroughNode}
import org.apache.kyuubi.sql.plan.command.{DescribeSession, RunnableCommand}
import org.apache.kyuubi.sql.plan.command.{DescribeEngine, DescribeSession, RunnableCommand}

class KyuubiAstBuilder extends KyuubiSqlBaseParserBaseVisitor[AnyRef] {

Expand All @@ -44,4 +44,9 @@ class KyuubiAstBuilder extends KyuubiSqlBaseParserBaseVisitor[AnyRef] {
: RunnableCommand = {
DescribeSession()
}

override def visitDescribeEngine(ctx: KyuubiSqlBaseParser.DescribeEngineContext)
: RunnableCommand = {
DescribeEngine()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.kyuubi.sql.plan.command

import scala.collection.mutable.ListBuffer

import org.apache.kyuubi.operation.IterableFetchIterator
import org.apache.kyuubi.session.{KyuubiSession, KyuubiSessionImpl}
import org.apache.kyuubi.shaded.hive.service.rpc.thrift.TTypeId
import org.apache.kyuubi.sql.schema.{Column, Row, Schema}

/**
* A runnable node for description the current session engine.
*
* The syntax of using this command in SQL is:
* {{{
* [DESC|DESCRIBE] ENGINE;
* }}}
*/
case class DescribeEngine() extends RunnableCommand {

override def run(kyuubiSession: KyuubiSession): Unit = {
val rows = Seq(kyuubiSession).map { session =>
lazy val client = session.asInstanceOf[KyuubiSessionImpl].client
val values = new ListBuffer[String]()
values += client.engineId.getOrElse("")
values += client.engineName.getOrElse("")
values += client.engineUrl.getOrElse("")
Row(values.toList)
}
iter = new IterableFetchIterator(rows)
}

override def resultSchema: Schema = {
Schema(DescribeEngine.outputCols().toList)
}

override def name(): String = "Describe Engine Node"
}

object DescribeEngine {

def outputCols(): Seq[Column] = {
Seq(
Column("ENGINE_ID", TTypeId.STRING_TYPE, Some("Kyuubi engine identify")),
Column("ENGINE_NAME", TTypeId.STRING_TYPE, Some("Kyuubi engine name")),
Column("ENGINE_URL", TTypeId.STRING_TYPE, Some("Kyuubi engine url")))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ object DescribeSession {

def outputCols(): Seq[Column] = {
Seq(
Column("id", TTypeId.STRING_TYPE, Some("Kyuubi session identify")),
Column("user", TTypeId.STRING_TYPE, Some("Kyuubi session user")),
Column("type", TTypeId.STRING_TYPE, Some("Kyuubi session type")))
Column("SESSION_ID", TTypeId.STRING_TYPE, Some("Kyuubi session identify")),
Column("SESSION_USER", TTypeId.STRING_TYPE, Some("Kyuubi session user")),
Column("SESSION_TYPE", TTypeId.STRING_TYPE, Some("Kyuubi session type")))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.kyuubi.operation.parser

class DescribeEngineSuite extends ExecutedCommandExecSuite {

test("desc/describe kyuubi engine") {
Seq("DESC", "DESCRIBE").foreach { desc =>
withJdbcStatement() { statement =>
val resultSet = statement.executeQuery(s"KYUUBI $desc ENGINE")
assert(resultSet.next())

assert(resultSet.getMetaData.getColumnCount == 3)
assert(resultSet.getMetaData.getColumnName(1) == "ENGINE_ID")
assert(resultSet.getMetaData.getColumnName(2) == "ENGINE_NAME")
assert(resultSet.getMetaData.getColumnName(3) == "ENGINE_URL")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ package org.apache.kyuubi.operation.parser

class DescribeSessionSuite extends ExecutedCommandExecSuite {

test("desc kyuubi session") {
withJdbcStatement() { statement =>
val resultSet = statement.executeQuery("KYUUBI DESC SESSION")
assert(resultSet.next())
test("desc/describe kyuubi session") {
Seq("DESC", "DESCRIBE").foreach { desc =>
withJdbcStatement() { statement =>
val resultSet = statement.executeQuery(s"KYUUBI $desc SESSION")
assert(resultSet.next())

assert(resultSet.getMetaData.getColumnCount == 3)
assert(resultSet.getMetaData.getColumnName(1) == "id")
assert(resultSet.getMetaData.getColumnName(2) == "user")
assert(resultSet.getMetaData.getColumnName(3) == "type")
assert(resultSet.getMetaData.getColumnCount == 3)
assert(resultSet.getMetaData.getColumnName(1) == "SESSION_ID")
assert(resultSet.getMetaData.getColumnName(2) == "SESSION_USER")
assert(resultSet.getMetaData.getColumnName(3) == "SESSION_TYPE")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package org.apache.kyuubi.parser
import org.apache.kyuubi.KyuubiFunSuite
import org.apache.kyuubi.sql.parser.server.KyuubiParser
import org.apache.kyuubi.sql.plan.PassThroughNode
import org.apache.kyuubi.sql.plan.command.DescribeSession
import org.apache.kyuubi.sql.plan.command.{DescribeEngine, DescribeSession}

class KyuubiParserSuite extends KyuubiFunSuite {

Expand Down Expand Up @@ -51,4 +51,11 @@ class KyuubiParserSuite extends KyuubiFunSuite {
assert(node.isInstanceOf[DescribeSession])
assert(node.name() == "Describe Session Node")
}

test("Describe session engine") {
val node = parser.parsePlan("KYUUBI DESC ENGINE")

assert(node.isInstanceOf[DescribeEngine])
assert(node.name() == "Describe Engine Node")
}
}

0 comments on commit 4cceb1d

Please sign in to comment.