Skip to content

Conversation

@lexluo09
Copy link
Contributor

@lexluo09 lexluo09 commented Mar 9, 2023

Proposed changes

Issue Number: close #16973

Support create/drop global function.
When you create a custom function, it can only be used within in one database. It cannot be used in other database/catalog. When there are many databases/catalog, it needs to create function one by one.

Problem summary

Describe your changes.
1、 When a function is created or deleted, add the global keyword.

CREATE [GLOBAL] [AGGREGATE] [ALIAS] FUNCTION function_name (arg_type [, ...]) [RETURNS ret_type] [INTERMEDIATE inter_type] [WITH PARAMETER(param [,...]) AS origin_function] [PROPERTIES ("key" = "value" [, ...]) ]

DROP [GLOBAL] FUNCTION function_name (arg_type [, ...])

2、A completely global global function is set, and the global function metadata is stored in the image. The function lookup strategy is to look in the database first, and if it can't be found, it looks in the global function.

Checklist(Required)

  • [ no] Does it affect the original behavior
  • [ yes] Has unit tests been added
  • [ no] Has document been added or modified
  • [ no] Does it need to update dependencies
  • [yes] Is this PR support rollback (If NO, please explain WHY)

Further comments

@github-actions github-actions bot added the area/planner Issues or PRs related to the query planner label Mar 9, 2023
@lexluo09 lexluo09 changed the title [enhancement] Function(create/drop) support the global operation [enhancement]The user defined functions support the global operation Mar 9, 2023
@lexluo09 lexluo09 force-pushed the add_global_function branch 2 times, most recently from 5d3840a to 808be93 Compare March 9, 2023 09:17
@lexluo09
Copy link
Contributor Author

lexluo09 commented Mar 9, 2023

run buildall

@lexluo09 lexluo09 force-pushed the add_global_function branch from 3ba2195 to 6f06578 Compare March 9, 2023 10:04
@lexluo09
Copy link
Contributor Author

run buildall


public ShowFunctionsStmt(String dbName, boolean isBuiltin, boolean isVerbose, String wild,
Expr expr) {
this.type = type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing type param?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show functions not fully implemented. I plan to fully implement next PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove the relevant code in this PR.

**/
public long loadGlobalFunction(DataInputStream in, long checksum) throws IOException {
GlobalFunctionMgr mgr = GlobalFunctionMgr.read(in);
if (mgr != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under what circumstances, mgr is null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is no case where mgr is null.

}

public long saveGlobalFunction(CountingDataOutputStream out, long checksum) throws IOException {
Env.getCurrentEnv().getGlobalFunctionMgr().write(out);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Env.getCurrentEnv().getGlobalFunctionMgr().write(out);
this.globalFunctionMgr.write(out);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thank you for your advice.

FunctionName name = stmt.getFunctionName();
Database db = getInternalCatalog().getDbOrDdlException(name.getDb());
db.addFunction(stmt.getFunction(), stmt.isIfNotExists());
InternalCatalog internalCatalog = getInternalCatalog();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this line to else block

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thank you for your advice

@lexluo09 lexluo09 force-pushed the add_global_function branch 2 times, most recently from fe7686e to 1395308 Compare March 13, 2023 02:41
@morrySnow morrySnow changed the title [enhancement]The user defined functions support the global operation [enhancement](UDF)The user defined functions support the global operation Mar 13, 2023
@morningman
Copy link
Contributor

run buildall

@lexluo09
Copy link
Contributor Author

run compile feut

1 similar comment
@lexluo09
Copy link
Contributor Author

run compile feut

@lexluo09 lexluo09 force-pushed the add_global_function branch 2 times, most recently from 0a60a69 to a1df463 Compare March 18, 2023 03:51
@github-actions github-actions bot added the kind/docs Categorizes issue or PR as related to documentation. label Mar 18, 2023
@lexluo09
Copy link
Contributor Author

run buildall

@lexluo09 lexluo09 force-pushed the add_global_function branch from a1df463 to 5261fc8 Compare March 18, 2023 03:58
@lexluo09
Copy link
Contributor Author

run buildall

@hello-stephen
Copy link
Contributor

hello-stephen commented Mar 18, 2023

TeamCity pipeline, clickbench performance test result:
the sum of best hot time: 34.85 seconds
stream load tsv: 470 seconds loaded 74807831229 Bytes, about 151 MB/s
stream load json: 22 seconds loaded 2358488459 Bytes, about 102 MB/s
stream load orc: 75 seconds loaded 1101869774 Bytes, about 14 MB/s
stream load parquet: 32 seconds loaded 861443392 Bytes, about 25 MB/s
https://doris-community-test-1308700295.cos.ap-hongkong.myqcloud.com/tmp/20230318080951_clickbench_pr_116385.html

@lexluo09
Copy link
Contributor Author

run buildall

Copy link
Contributor

@morningman morningman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@morningman morningman merged commit c95eb8a into apache:master Mar 18, 2023
gnehil pushed a commit to gnehil/doris that referenced this pull request Apr 21, 2023
…che#16973) (apache#17608)

Support create/drop global function. 
     When you create a custom function, it can only be used within in one database. It cannot be used in other database/catalog. When there are many databases/catalog, it needs to create function one by one.

## Problem summary

Describe your changes.
1、 When a function is created or deleted, add the global keyword.

CREATE [GLOBAL] [AGGREGATE] [ALIAS] FUNCTION function_name (arg_type [, ...]) [RETURNS ret_type] [INTERMEDIATE inter_type] [WITH PARAMETER(param [,...]) AS origin_function] [PROPERTIES ("key" = "value" [, ...]) ]

DROP [GLOBAL] FUNCTION function_name (arg_type [, ...])

2、A completely global global function is set, and the global function metadata is stored in the image. The function lookup strategy is to look in the database first, and if it can't be found, it looks in the global function.
Co-authored-by: lexluo <lexluo@tencent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/planner Issues or PRs related to the query planner kind/docs Categorizes issue or PR as related to documentation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Function support the global operation

3 participants