Skip to content

Commit

Permalink
feat: add built-in udfs in config (databendlabs#15938)
Browse files Browse the repository at this point in the history
* chore: spill out built-in users and udfs

* fix the unit test

* add unit test

* add udf parser to UserDefinedFunction

* add sqllogic test

* fix sqllogic test

* idm -> builtin

* ignore the invalid built-in user&udf

* add built-in to toml config
  • Loading branch information
BohuTANG authored Jul 2, 2024
1 parent d21e1b9 commit 38c157b
Show file tree
Hide file tree
Showing 34 changed files with 946 additions and 408 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions scripts/ci/deploy/config/databend-query-node-1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ auth_type = "no_password"
# # echo -n "datafuselabs" | sha256sum
# auth_string = "6db1a2f5da402b43c066fcadcbf78f04260b3236d9035e44dd463f21e29e6f3b"

# This for test
[[query.udfs]]
name = "ping"
definition = "CREATE FUNCTION ping(STRING) RETURNS STRING LANGUAGE python HANDLER = 'ping' ADDRESS = 'http://0.0.0.0:8815'"

[query.settings]
aggregate_spilling_memory_ratio = 60
join_spilling_memory_ratio = 60
Expand Down
5 changes: 5 additions & 0 deletions scripts/ci/deploy/config/databend-query-node-2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ auth_type = "no_password"
name = "default"
auth_type = "no_password"

# This for test
[[query.udfs]]
name = "ping"
definition = "CREATE FUNCTION ping(STRING) RETURNS STRING LANGUAGE python HANDLER = 'ping' ADDRESS = 'http://0.0.0.0:8815'"

[log]

[log.file]
Expand Down
5 changes: 5 additions & 0 deletions scripts/ci/deploy/config/databend-query-node-3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ auth_type = "no_password"
name = "default"
auth_type = "no_password"

# This for test
[[query.udfs]]
name = "ping"
definition = "CREATE FUNCTION ping(STRING) RETURNS STRING LANGUAGE python HANDLER = 'ping' ADDRESS = 'http://0.0.0.0:8815'"

[log]

[log.file]
Expand Down
5 changes: 5 additions & 0 deletions scripts/ci/deploy/config/databend-query-node-hive.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ auth_type = "no_password"
name = "default"
auth_type = "no_password"

# This for test
[[query.udfs]]
name = "ping"
definition = "CREATE FUNCTION ping(STRING) RETURNS STRING LANGUAGE python HANDLER = 'ping' ADDRESS = 'http://0.0.0.0:8815'"

[log]

[log.file]
Expand Down
5 changes: 5 additions & 0 deletions scripts/ci/deploy/config/databend-query-node-native.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ auth_type = "no_password"
# # echo -n "datafuselabs" | sha256sum
# auth_string = "6db1a2f5da402b43c066fcadcbf78f04260b3236d9035e44dd463f21e29e6f3b"

# This for test
[[query.udfs]]
name = "ping"
definition = "CREATE FUNCTION ping(STRING) RETURNS STRING LANGUAGE python HANDLER = 'ping' ADDRESS = 'http://0.0.0.0:8815'"


[log]

Expand Down
5 changes: 5 additions & 0 deletions scripts/ci/deploy/config/databend-query-node-otlp-logs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ auth_type = "no_password"
name = "default"
auth_type = "no_password"

# This for test
[[query.udfs]]
name = "ping"
definition = "CREATE FUNCTION ping(STRING) RETURNS STRING LANGUAGE python HANDLER = 'ping' ADDRESS = 'http://0.0.0.0:8815'"

[log]

[log.file]
Expand Down
4 changes: 4 additions & 0 deletions scripts/ci/deploy/config/databend-query-node-share-1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ auth_type = "no_password"
# # echo -n "datafuselabs" | sha256sum
# auth_string = "6db1a2f5da402b43c066fcadcbf78f04260b3236d9035e44dd463f21e29e6f3b"

# This for test
[[query.udfs]]
name = "ping"
definition = "CREATE FUNCTION ping(STRING) RETURNS STRING LANGUAGE python HANDLER = 'ping' ADDRESS = 'http://0.0.0.0:8815'"

[log]

Expand Down
5 changes: 5 additions & 0 deletions scripts/ci/deploy/config/databend-query-node-share-2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ auth_type = "no_password"
# # echo -n "datafuselabs" | sha256sum
# auth_string = "6db1a2f5da402b43c066fcadcbf78f04260b3236d9035e44dd463f21e29e6f3b"

# This for test
[[query.udfs]]
name = "ping"
definition = "CREATE FUNCTION ping(STRING) RETURNS STRING LANGUAGE python HANDLER = 'ping' ADDRESS = 'http://0.0.0.0:8815'"

[log]

[log.file]
Expand Down
5 changes: 5 additions & 0 deletions scripts/ci/deploy/config/databend-query-node-share-3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ auth_type = "no_password"
# # echo -n "datafuselabs" | sha256sum
# auth_string = "6db1a2f5da402b43c066fcadcbf78f04260b3236d9035e44dd463f21e29e6f3b"

# This for test
[[query.udfs]]
name = "ping"
definition = "CREATE FUNCTION ping(STRING) RETURNS STRING LANGUAGE python HANDLER = 'ping' ADDRESS = 'http://0.0.0.0:8815'"

[log]

[log.file]
Expand Down
17 changes: 14 additions & 3 deletions src/binaries/query/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,21 @@ pub async fn start_services(conf: &InnerConfig) -> Result<()> {
println!(
"Builtin users: {}",
conf.query
.idm
.builtin
.users
.keys()
.map(|name| name.to_string())
.iter()
.map(|config| config.name.clone())
.collect::<Vec<_>>()
.join(", ")
);
println!();
println!(
"Builtin UDFs: {}",
conf.query
.builtin
.udfs
.iter()
.map(|config| config.name.clone())
.collect::<Vec<_>>()
.join(", ")
);
Expand Down
2 changes: 0 additions & 2 deletions src/query/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ databend-common-grpc = { workspace = true }
databend-common-meta-app = { workspace = true }
databend-common-storage = { workspace = true }
databend-common-tracing = { workspace = true }
databend-common-users = { workspace = true }
hex = "0.4.3"
log = { workspace = true }
semver = { workspace = true }
serde = { workspace = true }
Expand Down
41 changes: 41 additions & 0 deletions src/query/config/src/builtin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2021 Datafuse Labs
//
// Licensed 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.

use serde::Deserialize;
use serde::Serialize;

#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct BuiltInConfig {
pub users: Vec<UserConfig>,
pub udfs: Vec<UDFConfig>,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct UserConfig {
pub name: String,
#[serde(flatten)]
pub auth: UserAuthConfig,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct UserAuthConfig {
pub auth_type: String,
pub auth_string: Option<String>,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct UDFConfig {
pub name: String,
pub definition: String,
}
Loading

0 comments on commit 38c157b

Please sign in to comment.