Skip to content

Commit

Permalink
[KYUUBI-156][KYUUBI-185] Implementing all meta operations support by …
Browse files Browse the repository at this point in the history
…spark (#191)

* [KYUUBI-156][KYUUBI-185] Implementing all meta operations support by spark

* rm used metastore client fix #156 fix #185

* add more uts

* add more uts

* fix bugs and add show functions

* meta operation method abstraction

* readme
  • Loading branch information
yaooqinn committed Jun 4, 2019
1 parent 71eea2b commit cf4ee6a
Show file tree
Hide file tree
Showing 36 changed files with 1,939 additions and 747 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Kyuubi [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) [![](https://tokei.rs/b1/github/yaooqinn/kyuubi)](https://github.com/yaooqinn/kyuubi) [![GitHub release](https://img.shields.io/github/release/yaooqinn/kyuubi.svg)](https://github.com/yaooqinn/kyuubi/releases) [![codecov](https://codecov.io/gh/yaooqinn/kyuubi/branch/master/graph/badge.svg)](https://codecov.io/gh/yaooqinn/kyuubi) [![Build Status](https://travis-ci.org/yaooqinn/kyuubi.svg?branch=master)](https://travis-ci.org/yaooqinn/kyuubi)[![HitCount](http://hits.dwyl.io/yaooqinn/kyuubi.svg)](http://hits.dwyl.io/yaooqinn/kyuubi)
# Kyuubi [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) [![](https://tokei.rs/b1/github/yaooqinn/kyuubi)](https://github.com/yaooqinn/kyuubi) [![GitHub release](https://img.shields.io/github/release/yaooqinn/kyuubi.svg)](https://github.com/yaooqinn/kyuubi/releases) [![codecov](https://codecov.io/gh/yaooqinn/kyuubi/branch/master/graph/badge.svg)](https://codecov.io/gh/yaooqinn/kyuubi) [![Build Status](https://travis-ci.org/yaooqinn/kyuubi.svg?branch=master)](https://travis-ci.org/yaooqinn/kyuubi) [![HitCount](http://hits.dwyl.io/yaooqinn/kyuubi.svg)](http://hits.dwyl.io/yaooqinn/kyuubi)

<img style="zoom: 0.3141592653589" src="docs/imgs/kyuubi.png" />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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.spark.sql.execution.command

import org.apache.spark.sql.{Row, SparkSession}

import yaooqinn.kyuubi.schema.SchemaMapper

case class KyuubiShowColumnsCommand(
databasePattern: String,
tableIdentifierPattern: String,
columnPattern: String) extends RunnableCommand {

override def run(sparkSession: SparkSession): Seq[Row] = {
val catalog = sparkSession.sessionState.catalog
val pattern = columnPattern.r.pattern
val databases = catalog.listDatabases(databasePattern)
val tableIdentifiers = databases.flatMap { db =>
catalog.listTables(db, tableIdentifierPattern)
}
val tables = tableIdentifiers.map(catalog.getTempViewOrPermanentTableMetadata)
val result = tables.flatMap { table =>
table.schema
.filter(f => pattern.matcher(f.name).matches())
.zipWithIndex.map { case (f, i) =>
Row(
"", // TABLE_CAT
table.database, // TABLE_SCHEM
table.identifier.table, // TABLE_NAME
f.name, // COLUMN_NAME
SchemaMapper.toJavaSQLType(f.dataType), // DATA_TYPE
f.dataType.typeName, // TYPE_NAME
SchemaMapper.getColumnSize(f.dataType).orNull, // COLUMN_SIZE
null, // BUFFER_LENGTH, unused
SchemaMapper.getDecimalDigits(f.dataType).orNull, // DECIMAL_DIGITS
SchemaMapper.getNumPrecRadix(f.dataType).orNull, // NUM_PREC_RADIX
if (f.nullable) 1 else 0, // NULLABLE
f.getComment().getOrElse(""), //
null, // COLUMN_DEF
null, // SQL_DATA_TYPE
null, // SQL_DATETIME_SUB
null, // CHAR_OCTET_LENGTH
i, // ORDINAL_POSITION
if (f.nullable) "YES" else "NO", // IS_NULLABLE
null, // SCOPE_CATALOG
null, // SCOPE_SCHEMA
null, // SCOPE_TABLE
null, // SOURCE_DATA_TYPE
"NO" // IS_AUTO_INCREMENT
)
}
}
result
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.spark.sql.execution.command

import org.apache.spark.sql.{Row, SparkSession}

case class KyuubiShowFunctionsCommand(
databasePattern: String,
functionName: String) extends RunnableCommand {
override def run(sparkSession: SparkSession): Seq[Row] = {
val catalog = sparkSession.sessionState.catalog
val databases = catalog.listDatabases(databasePattern)
databases.flatMap { db =>
catalog.listFunctions(db, functionName).map { case (f, typ) =>
val info = catalog.lookupFunctionInfo(f)
Row(
typ,
f.database.orNull,
f.funcName,
info.getUsage + info.getExtended,
null,
info.getClassName
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.spark.sql.execution.command

import org.apache.spark.sql.{Row, SparkSession}

case class KyuubiShowTablesCommand(
databaseName: String,
tableIdentifierPattern: String,
tableTypes: Seq[String]) extends RunnableCommand {

override def run(sparkSession: SparkSession): Seq[Row] = {
val catalog = sparkSession.sessionState.catalog
val databases = catalog.listDatabases(databaseName)
val tableIdentifiers = databases.flatMap { db => catalog.listTables(db, tableIdentifierPattern)}
val types = tableTypes.map(_.toUpperCase)

val tables = tableIdentifiers.map(catalog.getTempViewOrPermanentTableMetadata)
tables.flatMap { table =>
val tableType = table.tableType.name
if (types.contains(tableType)) {
Some(
Row("", table.database, table.identifier.table, tableType, table.comment.getOrElse(""))
)
} else {
None
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ private[kyuubi] abstract class HighAvailableService(name: String, server: Kyuubi
protected var zkClient: CuratorFramework = _
protected var serviceRootNamespace: String = _

private[this] var serviceNode: PersistentEphemeralNode = _
private[this] var servicePath: String = _
private var serviceNode: PersistentEphemeralNode = _
private var servicePath: String = _

/**
* reset current service
Expand Down

This file was deleted.

0 comments on commit cf4ee6a

Please sign in to comment.