标签:url 顺序 核心 源码 项目 www public ace har
dremio 自定义函数的开发与drill 模式是一样的,以下是一个简单demo
dremio 一些核心的功能都是在 dremio-sabot-kernel 中的,可以看看源码还是比较有用的
项目主要是创建一个uuid 的函数
├── pom.xml
├── src
│ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ └── dalong
│ │ │ └── udf
│ │ │ └── MyFunc.java
│ │ └── resources
│ │ └── sabot-module.conf
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>com.dalong</groupId>
<artifactId>dremio-func</artifactId>
<version>1.2-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<version.dremio>13.0.0-202101272034330307-20fb9275</version.dremio>
</properties>
<dependencies>
<dependency>
<groupId>com.dremio.sabot</groupId>
<artifactId>dremio-sabot-kernel</artifactId>
<version>${version.dremio}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>dremio-free</id>
<url>http://maven.dremio.com/free/</url>
</repository>
<repository>
<id>dremio-public</id>
<url>http://maven.dremio.com/public/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
dremio.classpath.scanning.packages += com.dalong.udf
package com.dalong.udf;
import com.dremio.exec.expr.SimpleFunction;
import com.dremio.exec.expr.annotations.FunctionTemplate;
import com.dremio.exec.expr.annotations.Output;
import com.dremio.exec.expr.annotations.Param;
import com.dremio.exec.expr.fn.FunctionErrorContext;
import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.vector.holders.IntHolder;
import org.apache.arrow.vector.holders.VarCharHolder;
import javax.inject.Inject;
@FunctionTemplate(names = {"mychar_len"},desc = "char length",scope = FunctionTemplate.FunctionScope.SIMPLE,nulls = FunctionTemplate.NullHandling.NULL_IF_NULL )
public class MyFunc implements SimpleFunction {
@Param
VarCharHolder input;
@Output
IntHolder out;
@Inject
FunctionErrorContext errCtx;
@Override
public void setup() {
}
@Override
public void eval() {
// 需要使用完整的包名,同时使用了dremio内部包装的函数
out.value = com.dremio.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharLength(io.netty.buffer.NettyArrowBuf.unwrapBuffer(input.buffer),
input.start, input.end, errCtx);
}
}
基于docker 运行的,注意需要放jars 目录,同时需要包含带有源码的jar
FROM dremio/dremio-oss:13.0
COPY demodremio-driver-1.2-SNAPSHOT.jar /opt/dremio/jars/
COPY dremio-func-1.2-SNAPSHOT.jar /opt/dremio/jars/
COPY dremio-func-1.2-SNAPSHOT-sources.jar /opt/dremio/jars/
注意顺序以及位置,同时maven-source-plugin 也是很重要的,这点demio 与drill 是一样的需要包含源码文件
https://github.com/dremio-hub/dremio-internal-function-example
https://drill.apache.org/docs/custom-function-interfaces/
标签:url 顺序 核心 源码 项目 www public ace har
原文地址:https://www.cnblogs.com/rongfengliang/p/14398306.html