Skip to content
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

feat: implement udf server in databend #12729

Merged
merged 31 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
20da297
feat: implement create and alter udf server (#12168)
gitccl Jul 25, 2023
56d1840
feat: implement the excution of UDF Server call (#12417)
gitccl Aug 11, 2023
4eff381
feat: support more data types for UDF Server (#12463)
gitccl Aug 15, 2023
06fd9fb
ci: add udfserver sqllogictest (#12577)
gitccl Aug 25, 2023
7d1768e
Merge remote-tracking branch 'upstream/main' into udf
gitccl Sep 5, 2023
967d8b0
refactor: update create function syntax
gitccl Sep 6, 2023
be9b411
Merge remote-tracking branch 'upstream/main' into udf
gitccl Sep 6, 2023
13060d2
fix compiler error
gitccl Sep 6, 2023
635a495
fix: fix udf server sqllogictests and set columns defaults to nullable
gitccl Sep 7, 2023
0972058
Merge remote-tracking branch 'upstream/main' into udf
gitccl Sep 7, 2023
85b8a5f
revert arrow-ord to 46.0.0
gitccl Sep 7, 2023
80abd57
add query config: enable_udf_server
gitccl Sep 11, 2023
d918f5f
Merge remote-tracking branch 'upstream/main' into udf
gitccl Sep 11, 2023
4ffc3ee
Merge branch 'main' into udf
xudong963 Sep 11, 2023
04f2fd6
Merge branch 'main' into udf
xudong963 Sep 12, 2023
663bef9
add enable_udf_server and udf_server_allow_list config
gitccl Sep 13, 2023
6c76b76
Merge remote-tracking branch 'upstream/main' into udf
gitccl Sep 13, 2023
7828592
update udf ci
gitccl Sep 13, 2023
9114672
fix udf server ci
gitccl Sep 13, 2023
3e31d3b
chore: update util.sh
sundy-li Sep 15, 2023
63c7da2
Merge branch 'main' into udf
sundy-li Sep 15, 2023
b52ae71
chore: update util.sh
sundy-li Sep 15, 2023
20e38fa
chore: update util.sh
sundy-li Sep 15, 2023
e8e0b85
chore: update util.sh
sundy-li Sep 15, 2023
e985d87
chore: update util.sh
sundy-li Sep 15, 2023
2220165
chore: update util.sh
sundy-li Sep 15, 2023
16588fc
chore: update util.sh
sundy-li Sep 15, 2023
3dac20a
Merge branch 'main' into udf
sundy-li Sep 15, 2023
168fac7
Merge branch 'main' into udf
sundy-li Sep 16, 2023
4ac7da0
Update util.sh
sundy-li Sep 16, 2023
806fb9d
Merge branch 'main' into udf
sundy-li Sep 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/reuse.linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,33 @@ jobs:
with:
name: test-sqllogic-standalone-${{ matrix.dirs }}

sqllogic_standalone_udf_server:
gitccl marked this conversation as resolved.
Show resolved Hide resolved
name: sqllogic_standalone_${{ matrix.dirs }}
runs-on: [self-hosted, X64, Linux, 4c8g, "${{ inputs.runner_provider }}"]
needs: [build, check]
strategy:
matrix:
dirs:
- "udf_server"
steps:
- uses: actions/checkout@v3
- name: Start UDF Server
run: |
pip install pyarrow
python3 tests/udf-server/udf_test.py &
sleep 2
- uses: ./.github/actions/test_sqllogic_standalone_linux
timeout-minutes: 15
with:
dirs: ${{ matrix.dirs }}
handlers: mysql,http,clickhouse
storage-format: all
- name: Upload failure
if: failure() || cancelled()
uses: ./.github/actions/artifact_failure
with:
name: test-sqllogic-standalone-${{ matrix.dirs }}

sqllogic_standalone_with_native:
name: sqllogic_standalone_${{ matrix.dirs }}_${{ matrix.format }}
runs-on: [self-hosted, X64, Linux, 4c8g, "${{ inputs.runner_provider }}"]
Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions scripts/ci/deploy/config/databend-query-node-1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ table_engine_memory_enabled = true
default_storage_format = 'parquet'
default_compression = 'zstd'

enable_udf_server = true
udf_server_allow_list = ['http://0.0.0.0:8815']

[[query.users]]
name = "root"
auth_type = "no_password"
Expand Down
3 changes: 3 additions & 0 deletions scripts/ci/deploy/config/databend-query-node-native.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ cluster_id = "test_cluster"

table_engine_memory_enabled = true

enable_udf_server = true
udf_server_allow_list = ['http://0.0.0.0:8815']

[[query.users]]
name = "root"
auth_type = "no_password"
Expand Down
4 changes: 4 additions & 0 deletions src/common/exception/src/exception_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ build_exceptions! {
IllegalUDFFormat(2601),
UnknownUDF(2602),
UdfAlreadyExists(2603),
UDFServerConnectError(2604),
UDFSchemaMismatch(2605),
UnsupportedDataType(2606),
UDFDataError(2607),

// Database error codes.
UnknownDatabaseEngine(2701),
Expand Down
3 changes: 3 additions & 0 deletions src/meta/app/src/principal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ pub use user_auth::AuthInfo;
pub use user_auth::AuthType;
pub use user_auth::PasswordHashMethod;
pub use user_defined_file_format::UserDefinedFileFormat;
pub use user_defined_function::LambdaUDF;
pub use user_defined_function::UDFDefinition;
pub use user_defined_function::UDFServer;
pub use user_defined_function::UserDefinedFunction;
pub use user_grant::GrantEntry;
pub use user_grant::GrantObject;
Expand Down
116 changes: 93 additions & 23 deletions src/meta/app/src/principal/user_defined_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,114 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::convert::TryFrom;
use std::fmt::Display;
use std::fmt::Formatter;

use common_exception::ErrorCode;
use common_exception::Result;
use serde::Deserialize;
use serde::Serialize;
use common_expression::types::DataType;

#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Default)]
#[serde(default)]
pub struct UserDefinedFunction {
pub name: String,
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct LambdaUDF {
pub parameters: Vec<String>,
pub definition: String,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UDFServer {
pub address: String,
pub handler: String,
pub language: String,
pub arg_types: Vec<DataType>,
pub return_type: DataType,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum UDFDefinition {
LambdaUDF(LambdaUDF),
UDFServer(UDFServer),
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UserDefinedFunction {
pub name: String,
pub description: String,
pub definition: String,
pub definition: UDFDefinition,
}

impl UserDefinedFunction {
pub fn new(name: &str, parameters: Vec<String>, definition: &str, description: &str) -> Self {
pub fn create_lambda_udf(
name: &str,
parameters: Vec<String>,
definition: &str,
description: &str,
) -> Self {
Self {
name: name.to_string(),
parameters,
definition: definition.to_string(),
description: description.to_string(),
definition: UDFDefinition::LambdaUDF(LambdaUDF {
parameters,
definition: definition.to_string(),
}),
}
}
}

impl TryFrom<Vec<u8>> for UserDefinedFunction {
type Error = ErrorCode;
pub fn create_udf_server(
name: &str,
address: &str,
handler: &str,
language: &str,
arg_types: Vec<DataType>,
return_type: DataType,
description: &str,
) -> Self {
Self {
name: name.to_string(),
description: description.to_string(),
definition: UDFDefinition::UDFServer(UDFServer {
address: address.to_string(),
handler: handler.to_string(),
language: language.to_string(),
arg_types,
return_type,
}),
}
}
}

fn try_from(value: Vec<u8>) -> Result<Self> {
match serde_json::from_slice(&value) {
Ok(udf) => Ok(udf),
Err(serialize_error) => Err(ErrorCode::IllegalUDFFormat(format!(
"Cannot deserialize user defined function from bytes. cause {}",
serialize_error
))),
impl Display for UDFDefinition {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, " (")?;
match self {
UDFDefinition::LambdaUDF(LambdaUDF {
parameters,
definition,
}) => {
for (i, item) in parameters.iter().enumerate() {
if i > 0 {
write!(f, ", ")?;
}
write!(f, "{item}")?;
}
write!(f, ") -> {definition}")?;
}
UDFDefinition::UDFServer(UDFServer {
address,
arg_types,
return_type,
handler,
language,
}) => {
for (i, item) in arg_types.iter().enumerate() {
if i > 0 {
write!(f, ", ")?;
}
write!(f, "{item}")?;
}
write!(
f,
") RETURNS {return_type} LANGUAGE {language} HANDLER = {handler} ADDRESS = {address}"
)?;
}
}
Ok(())
}
}
1 change: 0 additions & 1 deletion src/meta/app/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

mod file_format;
mod user_defined_function;
mod user_grant;
mod user_info;
mod user_privilege;
Expand Down
32 changes: 0 additions & 32 deletions src/meta/app/tests/it/user_defined_function.rs

This file was deleted.

1 change: 1 addition & 0 deletions src/meta/proto-conv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ mod schema_from_to_protobuf_impl;
mod share_from_to_protobuf_impl;
mod stage_from_to_protobuf_impl;
mod table_from_to_protobuf_impl;
mod udf_from_to_protobuf_impl;
mod user_from_to_protobuf_impl;
mod util;
mod virtual_column_from_to_protobuf_impl;
Expand Down
Loading