-
Notifications
You must be signed in to change notification settings - Fork 919
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 #6577] Add spark sql engine plugin module and define a sql stringify plugin #6578
Open
wForget
wants to merge
10
commits into
apache:master
Choose a base branch
from
wForget:KYUUBI-6577
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c3ce8dd
[KYUUBI #6577] Define a PlanOnlyExecutor interface to extend plan onl…
wForget a4f9dd3
newline
wForget 24f1f79
license
wForget 5129317
fix style
wForget 8d65c7e
narrow interface definition
wForget 870a9b4
refactor
wForget 4aca8ea
address comments
wForget f8fdafe
add readme
wForget 567e185
fix
wForget 5f5494e
fix readme
wForget File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<!-- | ||
- 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. | ||
--> | ||
|
||
# Kyuubi Spark SQL Engine Plugin | ||
|
||
The `Kyuubi Spark SQL Engine Plugin` is a plugin that includes SPI definitions for extending some features of the Spark SQL Engine. | ||
|
||
## Plugins | ||
|
||
| Plugin | Description | | ||
|:-----------------------------------------------------------|:-------------------------------------------------------| | ||
| `org.apache.kyuubi.engine.spark.plugin.SQLStringifyPlugin` | The plugin to extend custom stringified sql statement. | | ||
|
||
## How to implement a custom plugin | ||
|
||
Usually to implement a custom plugin we need to do the following steps: | ||
|
||
+ Add `kyuubi-spark-sql-engine-plugin` dependency | ||
+ Implement plugin interface | ||
+ Create a service file | ||
+ Package and integration with Kyuubi Spark SQL Engine | ||
|
||
### Example of implementing a custom SQLStringifyPlugin | ||
|
||
Add `kyuubi-spark-sql-engine-plugin` dependency: | ||
|
||
```xml | ||
<dependency> | ||
<groupId>org.apache.kyuubi</groupId> | ||
<artifactId>kyuubi-spark-sql-engine-plugin</artifactId> | ||
<version>${kyuubi.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
``` | ||
|
||
Extend `SQLStringifyPlugin` interface and implement methods: | ||
|
||
```java | ||
package org.apache.kyuubi.custom; | ||
|
||
import java.util.Locale; | ||
import org.apache.spark.sql.SparkSession; | ||
import org.apache.kyuubi.engine.spark.plugin.SQLStringifyPlugin; | ||
|
||
|
||
public class CustomSQLStringifyPlugin implements SQLStringifyPlugin { | ||
@Override | ||
public String mode() { | ||
return "custom_to_upper"; | ||
} | ||
|
||
@Override | ||
public String toString(SparkSession spark, String statement) { | ||
return statement.toUpperCase(Locale.ROOT); | ||
} | ||
} | ||
``` | ||
|
||
Create a `org.apache.kyuubi.engine.spark.plugin.SQLStringifyPlugin` file in `src/main/resources/META-INF/services/` with content: | ||
|
||
``` | ||
org.apache.kyuubi.custom.CustomSQLStringifyPlugin | ||
``` | ||
|
||
Package the custom plugin jar, and set `spark.jars=/path/to/custom-plugin-jar`. | ||
|
||
Enjoy your custom plugin with Kyuubi Spark SQL Engine: | ||
|
||
```sql | ||
set kyuubi.operation.plan.only.mode=custom_to_upper; | ||
select * from table; | ||
``` | ||
|
||
output: | ||
|
||
```text | ||
SELECT * FROM TABLE; | ||
``` |
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,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.kyuubi</groupId> | ||
<artifactId>kyuubi-parent</artifactId> | ||
<version>1.10.0-SNAPSHOT</version> | ||
<relativePath>../../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>kyuubi-spark-sql-engine-plugin</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Kyuubi Project Spark SQL Engine Plugin</name> | ||
<url>https://kyuubi.apache.org/</url> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.spark</groupId> | ||
<artifactId>spark-sql_${scala.binary.version}</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>net.alchim31.maven</groupId> | ||
<artifactId>scala-maven-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
26 changes: 26 additions & 0 deletions
26
...engine-plugin/src/main/java/org/apache/kyuubi/engine/spark/plugin/SQLStringifyPlugin.java
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.plugin; | ||
|
||
import org.apache.spark.sql.SparkSession; | ||
|
||
public interface SQLStringifyPlugin { | ||
|
||
String mode(); | ||
|
||
String toString(SparkSession spark, String statement); | ||
} |
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
35 changes: 35 additions & 0 deletions
35
...rc/main/scala/org/apache/kyuubi/engine/spark/operation/planonly/SQLStringifyPlugins.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,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.engine.spark.operation.planonly | ||
|
||
import java.util.Locale | ||
|
||
import org.apache.kyuubi.engine.spark.plugin.SQLStringifyPlugin | ||
import org.apache.kyuubi.util.reflect.ReflectUtils | ||
|
||
object SQLStringifyPlugins { | ||
|
||
private lazy val plugins: Map[String, SQLStringifyPlugin] = { | ||
ReflectUtils.loadFromServiceLoader[SQLStringifyPlugin]() | ||
.map(e => e.mode().toLowerCase(Locale.ROOT) -> e).toMap | ||
} | ||
|
||
def unapply(mode: String): Option[SQLStringifyPlugin] = { | ||
plugins.get(mode.toLowerCase(Locale.ROOT)) | ||
} | ||
|
||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the plugin is actually a must for spark sql engine? why do we need to separate it from the engine module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I don't want to introduce kyuubi engine dependency in kyuubi spark extensions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have to bundle this when packaging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the kyuubi server plugin also works this way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This plugin will be lightweight enough to only retain some interface definitions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sense