Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KYUUBI #5797] Support to describe engine with command in current session #5931

Closed
wants to merge 2 commits into from
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
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")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you raise a follow up pr to showthee engine registered attributes?

FYI: Refer the kyuubi-admin get engine command.

}
}
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")
}
}
Loading