-
Notifications
You must be signed in to change notification settings - Fork 328
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
fix: dynamically get python udf from scripts table #3774
Conversation
Signed-off-by: xxxuuu <xxuuu0@outlook.com>
ea881ab
to
9a06553
Compare
Thanks for your contribution! You may take a look at #3777. I suppose we may implement PyUDF in a more structural and proven way, said PL/Python, instead of hacky interpreting decorators and making new tribal rules. For example, instead of making version names, we should use statement like: CREATE FUNCTION pymax (a integer, b integer)
RETURNS integer
AS $$
if (a is None) or (b is None):
return None
if a > b:
return a
return b
$$ LANGUAGE plpython3u; And then a function named |
If you have other proposal, we can discuss in #3777. Generally it's good to discuss before implementing code, to avoid going in the wrong direction in the first place. I found #2434 has a lazy consensus now. Perhaps we can revisit this direction with #3777 in count. For example, in the PL/Python way, we can have This should be more reliable than patching |
Yes, this is a better approach, and I've also seen some other DBMSs doing it similar way. I will consider close this PR and then reevaluate/discuss this feature. |
cc @xxxuuu @waynexia @discord9 After another round of this issue, compared with the CREATE/DROP FUNCTION, I found that we can easily solve the original issue by banning "update scripts" but instead add a delete script API. Thus the script cache can be invalidated on deleted and otherwise it's always the corrected compiled cached ones. Even if we'd later reimplement the scripting in CREATE/DROP FUNCTION, such handling of a system scripts table should leave the same. |
Scripts created on one frontend are not registered on another frontend, and there is a similar issue with deletion. We still need to solve this issue. |
This is quite surprising. IIUC the script table should not be different with other normal tables, and thus it should be visible to every frontend instances. |
scripts table is visible, but it is not accessed when executed through SQL. Therefore, the script remains unregistered. This PR includes the modifications for this issue. |
I hereby agree to the terms of the GreptimeDB CLA.
Refer to a related PR or issue link (optional)
#2434
#2532
What's changed and what's your intention?
Add a
version
column to the scripts table and retrieve the latest script from the database before each script execution. If it is newer than the one in the local cache, recompile it.This solves the problem where a script updated on one frontend in a cluster with multiple frontends does not take effect on the other frontends(because the script compilation cache cannot be updated, or the script is not registered).
BREAKING CHANGE:
Since the scripts are now obtained through scripts table, when executing via UDF in SQL, the script name must be used instead of the function name. This fixes the issue mentioned in #2532. However, in cases where the script name and function name are different, if the program is using the function name, it will no longer work.
Checklist