morningman commented on a change in pull request #3760: URL: https://github.com/apache/incubator-doris/pull/3760#discussion_r438636930
########## File path: docs/zh-CN/extending-doris/user-defined-function.md ########## @@ -74,23 +93,150 @@ under the License. |Varchar|StringVal| |Decimal|DecimalVal| -## 编译UDF函数 + +## 编译 UDF 函数 + + 由于用户自己实现的 function 中依赖了 Doris 的 udf , 所以在编译 UDF 函数的时候首先对 Doris 进行编译。然后再编译用户自己实现的 UDF 即可。 ### 编译Doris -在Doris根目录下执行`sh build.sh`就会在`output/udf/`生成对应`headers|libs` +在Doris根目录下执行 `sh build.sh` 就会在 `output/udf/` 生成对应 `headers|libs` + +``` +├── output +│ └── udf +│ ├── include +│ │ ├── uda_test_harness.h +│ │ └── udf.h +│ └── lib +│ └── libDorisUdf.a + +``` + +### 编写 UDF 编译文件 + +1. 准备 third_party + + third_party 文件夹主要用于存放用户 UDF 函数依赖的第三方库,包括头文件及静态库。其中必须包含的是 `udf.h` 和 `libDorisUdf.a` 这两个文件。 + + 这里以 udf_sample 为例, 在 用户自己 `udf_samples` 目录用于存放 source code。在同级目录下再创建一个 `third_party` 文件夹用于存放上一步生成的依赖静态库。目录结构如下: + + ``` + ├── third_party + │ │── include + │ │ └── udf.h + │ └── lib + │ └── libDorisUdf.a + └── udf_samples + + ``` + + `udf.h` 是 UDF 函数必须依赖的头文件。原始存放路径为 `doris/be/src/udf/udf.h`。 用户需要将 Doris 工程中的这个头文件拷贝到自己的 `third_party` 的 include 文件夹下。 Review comment: ```suggestion `udf.h` 是 UDF 函数必须依赖的头文件。原始存放路径为 `output/udf/include/udf.h`。 用户需要将 Doris 工程中的这个头文件拷贝到自己的 `third_party` 的 include 文件夹下。 ``` ########## File path: custom_udf/build_custom_udf.sh ########## @@ -0,0 +1,142 @@ +#!/usr/bin/env bash +# 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. + +############################################################## +# This script is used to compile UDF +# Usage: +# sh build-custom-udf.sh build udf without clean. +# sh build-custom-udf.sh -clean clean previous output and build. +# +############################################################## + +set -eo pipefail + +ROOT=`dirname "$0"` +ROOT=`cd "$ROOT"; pwd` + +export DORIS_HOME=$(dirname "$PWD") +echo ${DORIS_HOME} +export CUSTOM_UDF_HOME=${ROOT} + +. ${DORIS_HOME}/env.sh + +# build thirdparty libraries if necessary Review comment: no need to build thirdparty in this script. This should be done `build.sh`. Just make this script simple. ########## File path: docs/zh-CN/extending-doris/user-defined-function.md ########## @@ -74,23 +93,150 @@ under the License. |Varchar|StringVal| |Decimal|DecimalVal| -## 编译UDF函数 + +## 编译 UDF 函数 + + 由于用户自己实现的 function 中依赖了 Doris 的 udf , 所以在编译 UDF 函数的时候首先对 Doris 进行编译。然后再编译用户自己实现的 UDF 即可。 ### 编译Doris -在Doris根目录下执行`sh build.sh`就会在`output/udf/`生成对应`headers|libs` +在Doris根目录下执行 `sh build.sh` 就会在 `output/udf/` 生成对应 `headers|libs` + +``` +├── output +│ └── udf +│ ├── include +│ │ ├── uda_test_harness.h +│ │ └── udf.h +│ └── lib +│ └── libDorisUdf.a + +``` + +### 编写 UDF 编译文件 + +1. 准备 third_party Review comment: ```suggestion 1. 准备 thirdparty ``` ########## File path: custom_udf/CMakeLists.txt ########## @@ -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. + +cmake_minimum_required(VERSION 2.8.10) + +# set CMAKE_C_COMPILER, this must set before project command +if (DEFINED ENV{DORIS_GCC_HOME}) + set(CMAKE_C_COMPILER "$ENV{DORIS_GCC_HOME}/bin/gcc") + set(CMAKE_CXX_COMPILER "$ENV{DORIS_GCC_HOME}/bin/g++") + set(GCC_HOME $ENV{DORIS_GCC_HOME}) +else() + message(FATAL_ERROR "DORIS_GCC_HOME environment variable is not set") +endif() + +project(doris) Review comment: ```suggestion project(doris_custom_udf) ``` ########## File path: docs/.vuepress/sidebar/en.js ########## @@ -124,6 +124,12 @@ module.exports = [ "plugin-development-manual", "user-defined-function", "spark-doris-connector", + "contribute_udf", Review comment: ```suggestion "contribute-udf", ``` ########## File path: docs/.vuepress/sidebar/en.js ########## @@ -124,6 +124,12 @@ module.exports = [ "plugin-development-manual", "user-defined-function", "spark-doris-connector", + "contribute_udf", + { + title: "Third-party UDF", Review comment: ```suggestion title: "Custom UDF", ``` Make it unify with `build_custom_udf.sh` ########## File path: docs/.vuepress/sidebar/en.js ########## @@ -124,6 +124,12 @@ module.exports = [ "plugin-development-manual", "user-defined-function", "spark-doris-connector", + "contribute_udf", + { + title: "Third-party UDF", + directoryPath: "third-party-udf/", Review comment: ```suggestion directoryPath: "custom-udf/", ``` ########## File path: custom_udf/build_custom_udf.sh ########## @@ -0,0 +1,142 @@ +#!/usr/bin/env bash +# 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. + +############################################################## +# This script is used to compile UDF +# Usage: +# sh build-custom-udf.sh build udf without clean. +# sh build-custom-udf.sh -clean clean previous output and build. Review comment: ```suggestion # sh build-custom-udf.sh --clean clean previous output and build. ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org