forked from apache/linkis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e13e1f3
commit 5378a18
Showing
8 changed files
with
104 additions
and
94 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,8 @@ public enum SqlCommand { | |
|
||
CREATE_DATABASE, | ||
|
||
CREATE_FUNCTION, | ||
|
||
ALTER_DATABASE, | ||
|
||
DROP_DATABASE, | ||
|
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
68 changes: 68 additions & 0 deletions
68
.../src/main/scala/org/apache/linkis/engineconnplugin/flink/hook/FlinkJarUdfEngineHook.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,68 @@ | ||
/* | ||
* 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.linkis.engineconnplugin.flink.hook | ||
|
||
import org.apache.linkis.engineconn.computation.executor.hook.UDFLoadEngineConnHook | ||
import org.apache.linkis.engineconnplugin.flink.client.utils.FlinkUdfUtils | ||
import org.apache.linkis.manager.label.entity.engine.RunType | ||
import org.apache.linkis.udf.utils.ConstantVar | ||
import org.apache.linkis.udf.vo.UDFInfoVo | ||
|
||
import org.apache.commons.lang3.StringUtils | ||
|
||
class FlinkJarUdfEngineHook extends UDFLoadEngineConnHook { | ||
override val udfType: BigInt = ConstantVar.UDF_JAR | ||
override val category: String = ConstantVar.UDF | ||
override val runType = RunType.SQL | ||
|
||
override protected def constructCode(udfInfo: UDFInfoVo): String = { | ||
val path: String = udfInfo.getPath | ||
val registerFormat: String = udfInfo.getRegisterFormat | ||
|
||
if (StringUtils.isBlank(path) && StringUtils.isBlank(registerFormat)) { | ||
logger.warn("Flink udfInfo path or registerFormat cannot is empty") | ||
return "" | ||
} | ||
|
||
val udfClassName: String = FlinkUdfUtils.extractUdfClass(registerFormat) | ||
if (StringUtils.isBlank(udfClassName)) { | ||
logger.warn("Flink extract udf class name cannot is empty") | ||
return "" | ||
} | ||
|
||
FlinkUdfUtils.loadJar(path) | ||
|
||
if (!FlinkUdfUtils.isFlinkUdf(ClassLoader.getSystemClassLoader(), udfClassName)) { | ||
logger.warn( | ||
"There is no extends Flink UserDefinedFunction, skip loading flink udf: {} ", | ||
path | ||
) | ||
return "" | ||
} | ||
|
||
val flinkUdfSql: String = | ||
FlinkUdfUtils.generateFlinkUdfSql(udfInfo.getUdfName, udfClassName) | ||
|
||
logger.info( | ||
s"Flink start load udf, udfName:${udfInfo.getUdfName}, udfJar:${path}, udfClass:${udfClassName}\n" | ||
) | ||
|
||
"%sql\n" + flinkUdfSql | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
.../flink-core/src/test/java/org/apache/linkis/engineplugin/flink/LinkisFlinkUdfExample.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.linkis.engineplugin.flink; | ||
|
||
import org.apache.flink.table.functions.ScalarFunction; | ||
|
||
public class LinkisFlinkUdfExample extends ScalarFunction { | ||
public String eval(String str) { | ||
return String.format("linkis flink udf test: %s", str); | ||
} | ||
} |