-
Notifications
You must be signed in to change notification settings - Fork 938
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KYUUBI #307]GetCatalogs supports DSv2 and keeps its backward compati…
…bility (#307)  [](https://github.com/yaooqinn/kyuubi/pull/307)  [❨?❩](https://pullrequestbadge.com/?utm_medium=github&utm_source=yaooqinn&utm_campaign=badge_info)<!-- PR-BADGE: PLEASE DO NOT REMOVE THIS COMMENT --> <!-- Thanks for sending a pull request! Here are some tips for you: 1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/contributions.html --> ### Please add issue ID here? <!-- replace ${issue ID} with the actual issue id --> Fixes #307 ### Why are the changes needed? <!-- Please clarify why the changes are needed. For instance, 1. If you add a feature, you can talk about the user case of it. 2. If you fix a bug, you can clarify why it is a bug. --> GetCatalogs supports DSv2 and keeps its backward compatibility ### Test Plan: - [x] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [x] Add screenshots for manual tests if appropriate  - [x] [Run test](https://kyuubi.readthedocs.io/en/latest/tools/testing.html#running-tests) locally before make a pull request * GetCatalogs supports DSv2 * pr template * nit * nit * shim * add iceberg tests * nit
- Loading branch information
Showing
15 changed files
with
282 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,31 @@ | ||
<!-- | ||
Thanks for sending a pull request! Here are some tips for you: | ||
1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/contributions.html | ||
Thanks for sending a pull request! | ||
|
||
Here are some tips for you: | ||
1. If this is your first time, please read our contributor guidelines: | ||
https://kyuubi.readthedocs.io/en/latest/community/contributions.html | ||
--> | ||
|
||
### _Which issue are you going to fix?_ | ||
<!-- | ||
Replace ${ID} below with the actual issue id from | ||
https://github.com/yaooqinn/kyuubi/issues, | ||
so that the issue will be linked and automatically closed after merging | ||
--> | ||
|
||
### Please add issue ID here? | ||
<!-- replace ${issue ID} with the actual issue id --> | ||
Fixes #${issue ID} | ||
Fixes #${ID} | ||
|
||
### Why are the changes needed? | ||
### _Why are the changes needed?_ | ||
<!-- | ||
Please clarify why the changes are needed. For instance, | ||
1. If you add a feature, you can talk about the user case of it. | ||
2. If you fix a bug, you can clarify why it is a bug. | ||
--> | ||
|
||
### Test Plan: | ||
- 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.readthedocs.io/en/latest/tools/testing.html#running-tests) locally before make a pull request | ||
|
||
### _How was this patch tested?_ | ||
- [ ] 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.readthedocs.io/en/latest/tools/testing.html#running-tests) locally before make a pull request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...yuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/shim/Shim_v2_4.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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.engine.spark.shim | ||
|
||
import org.apache.spark.sql.{Row, SparkSession} | ||
|
||
class Shim_v2_4 extends SparkShim { | ||
override def getCatalogs(ss: SparkSession): Seq[Row] = { | ||
Seq(Row("spark_catalog")) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...yuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/shim/Shim_v3_0.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.engine.spark.shim | ||
|
||
import org.apache.spark.sql.{Row, SparkSession} | ||
|
||
class Shim_v3_0 extends Shim_v2_4 { | ||
|
||
override def getCatalogs(ss: SparkSession): Seq[Row] = { | ||
val sessionState = getSessionState(ss) | ||
|
||
// A [[CatalogManager]] is session unique | ||
val catalogMgr = invoke(sessionState, "catalogManager") | ||
// get the custom v2 session catalog or default spark_catalog | ||
val sessionCatalog = invoke(catalogMgr, "v2SessionCatalog") | ||
val defaultCatalog = invoke(catalogMgr, "currentCatalog") | ||
|
||
val defaults = Seq(sessionCatalog, defaultCatalog).distinct | ||
.map(invoke(_, "name").asInstanceOf[String]) | ||
val catalogs = getField(catalogMgr, "catalogs") | ||
.asInstanceOf[scala.collection.Map[String, _]] | ||
(catalogs.keys ++: defaults).distinct.map(Row(_)) | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...yuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/shim/SparkShim.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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.engine.spark.shim | ||
|
||
import org.apache.spark.sql.{Row, SparkSession} | ||
|
||
import org.apache.kyuubi.{Logging, Utils} | ||
|
||
/** | ||
* A shim that defines the interface interact with Spark's catalogs | ||
*/ | ||
trait SparkShim extends Logging { | ||
|
||
/** | ||
* Get all register catalogs in Spark's `CatalogManager` | ||
*/ | ||
def getCatalogs(ss: SparkSession): Seq[Row] | ||
|
||
protected def getSessionState(ss: SparkSession): Any = { | ||
invoke(classOf[SparkSession], ss, "sessionState") | ||
} | ||
|
||
protected def invoke( | ||
obj: Any, | ||
methodName: String, | ||
args: (Class[_], AnyRef)*): Any = { | ||
val (types, values) = args.unzip | ||
val method = obj.getClass.getDeclaredMethod(methodName, types: _*) | ||
method.setAccessible(true) | ||
method.invoke(obj, values.toSeq: _*) | ||
} | ||
|
||
protected def invoke( | ||
clazz: Class[_], | ||
obj: AnyRef, | ||
methodName: String, | ||
args: (Class[_], AnyRef)*): AnyRef = { | ||
val (types, values) = args.unzip | ||
val method = clazz.getDeclaredMethod(methodName, types: _*) | ||
method.setAccessible(true) | ||
method.invoke(obj, values.toSeq: _*) | ||
} | ||
|
||
protected def getField(o: Any, fieldName: String): Any = { | ||
val field = o.getClass.getDeclaredField(fieldName) | ||
field.setAccessible(true) | ||
field.get(o) | ||
} | ||
} | ||
|
||
object SparkShim { | ||
def apply(): SparkShim = { | ||
val runtimeSparkVer = org.apache.spark.SPARK_VERSION | ||
val (major, minor) = Utils.majorMinorVersion(runtimeSparkVer) | ||
(major, minor) match { | ||
case (3, _) => new Shim_v3_0 | ||
case (2, _) => new Shim_v2_4 | ||
case _ => throw new IllegalArgumentException(s"Not Support spark version $runtimeSparkVer") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.