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

The script must have the same name as the function #2532

Open
WenyXu opened this issue Oct 7, 2023 · 4 comments
Open

The script must have the same name as the function #2532

WenyXu opened this issue Oct 7, 2023 · 4 comments
Labels
C-bug Category Bugs

Comments

@WenyXu
Copy link
Member

WenyXu commented Oct 7, 2023

What type of bug is this?

Unexpected error

What subsystems are affected?

Datanode

What happened?

Mentioned in https://docs.greptime.com/user-guide/python-scripts/data-types

Notes: the function name is query_numbers

// file query_numbers.py

from greptime import PyDataFrame, col
@copr(returns = ["value"])
def query_numbers() -> vector[f64]:
    df = PyDataFrame.from_sql("select number from numbers")
    return df.filter(col('number') <= 5).collect()[0]

curl --data-binary "@query_numbers.py" -XPOST "http://localhost:4000/v1/scripts?name=query_number&db=public"

Execute sql select query_number();

Output:

ERROR 1815 (HY000): Error during planning: Invalid function 'query_number'.
Did you mean 'encode'?

However, it works via http.

curl  -XPOST \
 "http://localhost:4000/v1/run-script?name=query_number&db=public"
{"code":0,"output":[{"records":{"schema":{"column_schemas":[{"name":"value","data_type":"Float64"}]},"rows":[[0.0],[1.0],[2.0],[3.0],[4.0],[5.0]]}}],"execution_time_ms":16}%   

If you change ?name=query_number to ?name=query_numbers , everything works.

What operating system did you use?

Ubuntu 23.04

Relevant log output and stack trace

No response

How can we reproduce the bug?

Mentioned in https://docs.greptime.com/user-guide/python-scripts/data-types

Notes: the function name is query_numbers

// file query_numbers.py

from greptime import PyDataFrame, col
@copr(returns = ["value"])
def query_numbers() -> vector[f64]:
    df = PyDataFrame.from_sql("select number from numbers")
    return df.filter(col('number') <= 5).collect()[0]

curl --data-binary "@query_numbers.py" -XPOST "http://localhost:4000/v1/scripts?name=query_number&db=public"

Execute sql select query_number();

@WenyXu WenyXu added the C-bug Category Bugs label Oct 7, 2023
@killme2008
Copy link
Contributor

It's not a bug too.

If you want to call script by HTTP API, the name is the script name you pass when saving the scripts.
If you want to call the function in SQL, you must use the function name in script.
Sorry for the misunderstood, I will clarify it in the documentation.

@killme2008 killme2008 self-assigned this Jan 2, 2024
@tisonkun
Copy link
Collaborator

tisonkun commented Mar 22, 2024

Some more subtle manner:

  1. If the database is closed and restart, you should execute via HTTP or register a new script to trigger the scripts function load for SQL.

If we don't support multiple @coprocessor in one file, what if we always infer the name from script?

@tisonkun
Copy link
Collaborator

If the database is closed and restart, you should execute via HTTP or register a new script to trigger the scripts function load for SQL.

recompile_register_udf seems indicate that we don't auto reload scripts on restart.

@tisonkun
Copy link
Collaborator

cc @discord9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category Bugs
Projects
None yet
Development

No branches or pull requests

3 participants