Skip to content

Commit

Permalink
fix(query): add udf name(in meta) into UdfServerCall
Browse files Browse the repository at this point in the history
  • Loading branch information
TCeason committed Dec 22, 2023
1 parent 9a58e79 commit 5458e6e
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .github/actions/test_stateless_cluster_linux/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ runs:
run: |
bash ./scripts/setup/dev_setup.sh -yd
- name: Start UDF Server
shell: bash
run: |
pip install databend-udf
python3 tests/udf/udf_server.py &
sleep 2
- name: Run Stateless Tests with Cluster mode
shell: bash
run: |
Expand Down
8 changes: 7 additions & 1 deletion .github/actions/test_stateless_cluster_macos/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ runs:
with:
sha: ${{ github.sha }}
target: ${{ inputs.target }}

- name: Test setup
shell: bash
run: |
bash ./scripts/setup/dev_setup.sh -yd
- name: Start UDF Server
shell: bash
run: |
pip install databend-udf
python3 tests/udf/udf_server.py &
sleep 2
- name: Run Stateless Tests with Cluster mode
shell: bash
run: |
Expand Down
7 changes: 7 additions & 0 deletions .github/actions/test_stateless_standalone_linux/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ runs:
run: |
bash ./scripts/setup/dev_setup.sh -yd
- name: Start UDF Server
shell: bash
run: |
pip install databend-udf
python3 tests/udf/udf_server.py &
sleep 2
- name: Run Stateless Tests with Standalone mode
shell: bash
run: |
Expand Down
7 changes: 7 additions & 0 deletions .github/actions/test_stateless_standalone_macos/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ runs:
run: |
bash ./scripts/setup/dev_setup.sh -yd
- name: Start UDF Server
shell: bash
run: |
pip install databend-udf
python3 tests/udf/udf_server.py &
sleep 2
- name: Run Stateless Tests with Standalone mode
shell: bash
run: |
Expand Down
9 changes: 5 additions & 4 deletions src/query/sql/src/planner/binder/ddl/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,23 +992,24 @@ impl Binder {
} = stmt;

let tenant = self.ctx.get_tenant();
let (catalog, database, table) =
let (catalog, db_name, table) =
self.normalize_object_identifier_triple(catalog, database, table);

let (new_catalog, new_database, new_table) =
self.normalize_object_identifier_triple(new_catalog, new_database, new_table);

if new_catalog != catalog || new_database != database {
if new_catalog != catalog || new_database != db_name {
return Err(ErrorCode::BadArguments(
"Rename table not allow modify catalog or database",
));
)
.set_span(database.as_ref().and_then(|ident| ident.span)));
}

Ok(Plan::RenameTable(Box::new(RenameTablePlan {
tenant,
if_exists: *if_exists,
catalog,
database,
database: db_name,
table,
new_database,
new_table,
Expand Down
1 change: 1 addition & 0 deletions src/query/sql/src/planner/binder/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ impl Binder {
.collect::<Result<Vec<_>>>()?;
Ok(UDFServerCall {
span: udf.span,
name: udf.name.clone(),
func_name: udf.func_name.clone(),
display_name: udf.display_name.clone(),
server_addr: udf.server_addr.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl SubqueryRewriter {
.collect::<Result<Vec<_>>>()?;
Ok(ScalarExpr::UDFServerCall(UDFServerCall {
span: udf.span,
name: udf.name.clone(),
func_name: udf.func_name.clone(),
display_name: udf.display_name.clone(),
server_addr: udf.server_addr.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ impl SubqueryRewriter {

let expr: ScalarExpr = UDFServerCall {
span: udf.span,
name: udf.name.clone(),
func_name: udf.func_name.clone(),
display_name: udf.display_name.clone(),
server_addr: udf.server_addr.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ fn rewrite_query_item(
Some(
UDFServerCall {
span: udf.span,
name: udf.name.clone(),
func_name: udf.func_name.clone(),
display_name: udf.display_name.clone(),
server_addr: udf.server_addr.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ impl RulePushDownFilterEvalScalar {

Ok(ScalarExpr::UDFServerCall(UDFServerCall {
span: udf.span,
name: udf.name.clone(),
func_name: udf.func_name.clone(),
display_name: udf.display_name.clone(),
server_addr: udf.server_addr.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ impl RulePushDownFilterScan {

Ok(ScalarExpr::UDFServerCall(UDFServerCall {
span: udf.span,
name: udf.name.clone(),
func_name: udf.func_name.clone(),
display_name: udf.display_name.clone(),
server_addr: udf.server_addr.clone(),
Expand Down
2 changes: 1 addition & 1 deletion src/query/sql/src/planner/optimizer/s_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ pub fn get_udf_names(scalar: &ScalarExpr) -> Result<HashSet<&String>> {
self.visit(expr)?;
}

self.udfs.insert(&udf.func_name);
self.udfs.insert(&udf.name);
Ok(())
}

Expand Down
3 changes: 3 additions & 0 deletions src/query/sql/src/planner/plans/scalar_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ fn hash_column_set<H: Hasher>(columns: &ColumnSet, state: &mut H) {
pub struct UDFServerCall {
#[educe(Hash(ignore), PartialEq(ignore), Eq(ignore))]
pub span: Span,
// name in meta
pub name: String,
// name in handler
pub func_name: String,
pub display_name: String,
pub server_addr: String,
Expand Down
5 changes: 4 additions & 1 deletion src/query/sql/src/planner/semantic/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2796,7 +2796,8 @@ impl<'a> TypeChecker<'a> {
.await?,
)),
UDFDefinition::UDFServer(udf_def) => Ok(Some(
self.resolve_udf_server(span, arguments, udf_def).await?,
self.resolve_udf_server(span, name, arguments, udf_def)
.await?,
)),
}
}
Expand All @@ -2806,6 +2807,7 @@ impl<'a> TypeChecker<'a> {
async fn resolve_udf_server(
&mut self,
span: Span,
name: String,
arguments: &[Expr],
udf_definition: UDFServer,
) -> Result<Box<(ScalarExpr, DataType)>> {
Expand Down Expand Up @@ -2852,6 +2854,7 @@ impl<'a> TypeChecker<'a> {
Ok(Box::new((
UDFServerCall {
span,
name,
func_name: udf_definition.handler,
display_name,
server_addr: udf_definition.address,
Expand Down
2 changes: 2 additions & 0 deletions tests/suites/0_stateless/18_rbac/18_0001_udf_priv.result
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ Error: APIError: ResponseError with 1063: Permission denied, privilege [Usage] i
200
100
200
4
Error: APIError: ResponseError with 1063: Permission denied, privilege [Usage] is required on UDF b for user 'test-user'@'%' with roles [public]
13 changes: 13 additions & 0 deletions tests/suites/0_stateless/18_rbac/18_0001_udf_priv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,22 @@ echo "select case when i > 100 then 200 else f2(f1(100)) end as c1 from t;" | $T
echo "select case when i > 100 then f2(f1(200)) else 100 end as c1 from t;" | $TEST_USER_CONNECT
echo "delete from t;" | $TEST_USER_CONNECT

#udf server test
echo "drop function if exists a;" | $BENDSQL_CLIENT_CONNECT
echo "drop function if exists b;" | $BENDSQL_CLIENT_CONNECT
echo "CREATE FUNCTION a (TINYINT, SMALLINT, INT, BIGINT) RETURNS BIGINT LANGUAGE python HANDLER = 'add_signed' ADDRESS = 'http://0.0.0.0:8815';" | $BENDSQL_CLIENT_CONNECT
echo "CREATE FUNCTION b (TINYINT, SMALLINT, INT, BIGINT) RETURNS BIGINT LANGUAGE python HANDLER = 'add_signed' ADDRESS = 'http://0.0.0.0:8815';" | $BENDSQL_CLIENT_CONNECT

echo "grant usage on udf a to 'test-user'" | $BENDSQL_CLIENT_CONNECT
echo "select a(1,1,1,1)" | $TEST_USER_CONNECT
echo "select b(1,1,1,1)" | $TEST_USER_CONNECT


echo "drop user if exists 'test-user'" | $BENDSQL_CLIENT_CONNECT
echo "DROP FUNCTION IF EXISTS f1;" | $BENDSQL_CLIENT_CONNECT
echo "DROP FUNCTION IF EXISTS f2;" | $BENDSQL_CLIENT_CONNECT
echo "drop function if exists a;" | $BENDSQL_CLIENT_CONNECT
echo "drop function if exists b;" | $BENDSQL_CLIENT_CONNECT
echo "drop table if exists default.t;" | $BENDSQL_CLIENT_CONNECT
echo "drop table if exists default.t2;" | $BENDSQL_CLIENT_CONNECT
echo "unset enable_experimental_rbac_check" | $BENDSQL_CLIENT_CONNECT

0 comments on commit 5458e6e

Please sign in to comment.