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

Support for calling functions without any arguments #1121

Closed
1 of 2 tasks
americast opened this issue Sep 14, 2023 · 4 comments · Fixed by #1185
Closed
1 of 2 tasks

Support for calling functions without any arguments #1121

americast opened this issue Sep 14, 2023 · 4 comments · Fixed by #1185
Assignees
Labels
Milestone

Comments

@americast
Copy link
Member

Search before asking

  • I have searched the EvaDB issues and found no similar feature requests.

Description

There might be a need to call a function without any arguments. Currently, calling SELECT <function>() FROM <table>; gives this error:

    raise UnexpectedToken(token, e.allowed, state=parser_state, token_history=[last_token], terminals_by_name=self.root_lexer.terminals_by_name)
lark.exceptions.UnexpectedToken: Unexpected token Token('RR_BRACKET', ')') at line 1, column 17.
Expected one of: 
        * MAX
        * AVG
        * DECIMAL_LITERAL
        * SUM
        * ONE_DECIMAL
        * MINUS
        * LR_SQ_BRACKET
        * LR_BRACKET
        * COUNT
        * BIT_NOT_OP
        * TRUE
        * FALSE
        * LOCAL_ID
        * STRING_LITERAL
        * TWO_DECIMAL
        * SEGMENT
        * STAR
        * REVERSE_QUOTE_ID
        * PLUS
        * ID
        * MIN
        * FIRST
        * REAL_LITERAL
        * ANYDIM
        * NOT
        * LAST
        * EXCLAMATION_SYMBOL
        * ZERO_DECIMAL
Previous tokens: [Token('LR_BRACKET', '(')]

while calling SELECT <function>(); results in

    raise UnexpectedToken(token, e.allowed, state=parser_state, token_history=[last_token], terminals_by_name=self.root_lexer.terminals_by_name)
lark.exceptions.UnexpectedToken: Unexpected token Token('RR_BRACKET', ')') at line 1, column 17.
Expected one of: 
        * ONE_DECIMAL
        * LR_SQ_BRACKET
        * COUNT
        * SEGMENT
        * STRING_LITERAL
        * MIN
        * STAR
        * TRUE
        * LR_BRACKET
        * NOT
        * FIRST
        * REAL_LITERAL
        * BIT_NOT_OP
        * LAST
        * ZERO_DECIMAL
        * PLUS
        * REVERSE_QUOTE_ID
        * FALSE
        * MINUS
        * AVG
        * ANYDIM
        * LOCAL_ID
        * SUM
        * DECIMAL_LITERAL
        * ID
        * MAX
        * TWO_DECIMAL
        * EXCLAMATION_SYMBOL
Previous tokens: [Token('LR_BRACKET', '(')]

Use case

We expect to call SELECT <function>(); without any error. It will help call functions that are specific to data when they are created.

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@gaurav274
Copy link
Member

@xzdandy This is fixed, right?

@gaurav274
Copy link
Member

@americast @xzdandy Are we going to go with SELECT <function>(); or SELECT <function>() from table;?

@xzdandy
Copy link
Collaborator

xzdandy commented Sep 16, 2023

This is not fixed. For now SELECT <function>(); is recommended. We need optimize SELECT <function>() from table; so if does not actually read the table (when the table is large it can take time). To systemically support it, it can be non trivial.

@xzdandy
Copy link
Collaborator

xzdandy commented Sep 21, 2023

The problem can be reproduced using the following dummy function and queries:

Function defined in test/util.py:

class DummyNoInputFunction(AbstractFunction):
    @decorators.setup(cacheable=False, function_type="test", batchable=False)
    def setup(self, *args, **kwargs):
        pass

    @property
    def name(self) -> str:
        return "DummyNoInputFunction"

    @decorators.forward(
        input_signatures = [],
        output_signatures = [
            PandasDataframe(
                columns = ["label"],
                column_types = [NdArrayType.STR],
                column_shapes = [(None,)],
            )
        ],
    )
    def forward(self, df: pd.DataFrame) -> pd.DataFrame:
        ret = pd.DataFrame([{"label": "DummyNoInputFunction"}])
        return ret

Queries:

import evadb
cursor = evadb.connect().cursor()

df = cursor.query("""
    CREATE OR REPLACE FUNCTION DummyNoInputFunction
    IMPL 'test/util.py'
""").df()
print(df)

df = cursor.query("SELECT DummyNoInputFunction();").df()
print(df)

Looking into the fix now.

@xzdandy xzdandy added the Feature Request ✨ New feature or request label Sep 21, 2023
@xzdandy xzdandy added this to the v0.3.7 milestone Sep 21, 2023
@xzdandy xzdandy linked a pull request Sep 21, 2023 that will close this issue
2 tasks
americast added a commit that referenced this issue Sep 30, 2023
Adding support for `neuralforecast`. Fixes #1112.

```sql
DROP TABLE IF EXISTS AirData;

CREATE TABLE AirData (
    unique_id TEXT(30),
    ds TEXT(30),
    y INTEGER);

LOAD CSV 'data/forecasting/air-passengers.csv' INTO AirData;

DROP FUNCTION IF EXISTS Forecast;

CREATE FUNCTION Forecast FROM
(SELECT unique_id, ds, y FROM AirData)
TYPE Forecasting
PREDICT 'y'
HORIZON 12
LIBRARY 'neuralforecast';

SELECT Forecast(12);
```
One quick issue here is that `neuralforecast` needs `horizon` as a
parameter while training, unlike `statsforecast`. Thus, a better way to
call the UDF would be simply `SELECT Forecast();`, which is currently
unsupported. @xzdandy Please let me know your thoughts.

List of stuff yet to be done:

- [x] Incorporate `neuralforecast`
- [x] Fix `HORIZON` redundancy (UPDATE: Being fixed in #1121)
- [x] Reuse model with lower horizon no
- [x] Add support for ~multivariate forecasting~ exogenous variables
- [x] Add tests
- [x] Add docs

---------

Co-authored-by: xzdandy <[email protected]>
a0x8o pushed a commit to alexxx-db/eva that referenced this issue Oct 30, 2023
Adding support for `neuralforecast`. Fixes georgia-tech-db#1112.

```sql
DROP TABLE IF EXISTS AirData;

CREATE TABLE AirData (
    unique_id TEXT(30),
    ds TEXT(30),
    y INTEGER);

LOAD CSV 'data/forecasting/air-passengers.csv' INTO AirData;

DROP FUNCTION IF EXISTS Forecast;

CREATE FUNCTION Forecast FROM
(SELECT unique_id, ds, y FROM AirData)
TYPE Forecasting
PREDICT 'y'
HORIZON 12
LIBRARY 'neuralforecast';

SELECT Forecast(12);
```
One quick issue here is that `neuralforecast` needs `horizon` as a
parameter while training, unlike `statsforecast`. Thus, a better way to
call the UDF would be simply `SELECT Forecast();`, which is currently
unsupported. @xzdandy Please let me know your thoughts.

List of stuff yet to be done:

- [x] Incorporate `neuralforecast`
- [x] Fix `HORIZON` redundancy (UPDATE: Being fixed in georgia-tech-db#1121)
- [x] Reuse model with lower horizon no
- [x] Add support for ~multivariate forecasting~ exogenous variables
- [x] Add tests
- [x] Add docs

---------

Co-authored-by: xzdandy <[email protected]>
a0x8o pushed a commit to alexxx-db/eva that referenced this issue Oct 30, 2023
Adding support for `neuralforecast`. Fixes georgia-tech-db#1112.

```sql
DROP TABLE IF EXISTS AirData;

CREATE TABLE AirData (
    unique_id TEXT(30),
    ds TEXT(30),
    y INTEGER);

LOAD CSV 'data/forecasting/air-passengers.csv' INTO AirData;

DROP FUNCTION IF EXISTS Forecast;

CREATE FUNCTION Forecast FROM
(SELECT unique_id, ds, y FROM AirData)
TYPE Forecasting
PREDICT 'y'
HORIZON 12
LIBRARY 'neuralforecast';

SELECT Forecast(12);
```
One quick issue here is that `neuralforecast` needs `horizon` as a
parameter while training, unlike `statsforecast`. Thus, a better way to
call the UDF would be simply `SELECT Forecast();`, which is currently
unsupported. @xzdandy Please let me know your thoughts.

List of stuff yet to be done:

- [x] Incorporate `neuralforecast`
- [x] Fix `HORIZON` redundancy (UPDATE: Being fixed in georgia-tech-db#1121)
- [x] Reuse model with lower horizon no
- [x] Add support for ~multivariate forecasting~ exogenous variables
- [x] Add tests
- [x] Add docs

---------

Co-authored-by: xzdandy <[email protected]>
a0x8o pushed a commit to alexxx-db/eva that referenced this issue Nov 22, 2023
Adding support for `neuralforecast`. Fixes georgia-tech-db#1112.

```sql
DROP TABLE IF EXISTS AirData;

CREATE TABLE AirData (
    unique_id TEXT(30),
    ds TEXT(30),
    y INTEGER);

LOAD CSV 'data/forecasting/air-passengers.csv' INTO AirData;

DROP FUNCTION IF EXISTS Forecast;

CREATE FUNCTION Forecast FROM
(SELECT unique_id, ds, y FROM AirData)
TYPE Forecasting
PREDICT 'y'
HORIZON 12
LIBRARY 'neuralforecast';

SELECT Forecast(12);
```
One quick issue here is that `neuralforecast` needs `horizon` as a
parameter while training, unlike `statsforecast`. Thus, a better way to
call the UDF would be simply `SELECT Forecast();`, which is currently
unsupported. @xzdandy Please let me know your thoughts.

List of stuff yet to be done:

- [x] Incorporate `neuralforecast`
- [x] Fix `HORIZON` redundancy (UPDATE: Being fixed in georgia-tech-db#1121)
- [x] Reuse model with lower horizon no
- [x] Add support for ~multivariate forecasting~ exogenous variables
- [x] Add tests
- [x] Add docs

---------

Co-authored-by: xzdandy <[email protected]>
a0x8o pushed a commit to alexxx-db/eva that referenced this issue Nov 22, 2023
Adding support for `neuralforecast`. Fixes georgia-tech-db#1112.

```sql
DROP TABLE IF EXISTS AirData;

CREATE TABLE AirData (
    unique_id TEXT(30),
    ds TEXT(30),
    y INTEGER);

LOAD CSV 'data/forecasting/air-passengers.csv' INTO AirData;

DROP FUNCTION IF EXISTS Forecast;

CREATE FUNCTION Forecast FROM
(SELECT unique_id, ds, y FROM AirData)
TYPE Forecasting
PREDICT 'y'
HORIZON 12
LIBRARY 'neuralforecast';

SELECT Forecast(12);
```
One quick issue here is that `neuralforecast` needs `horizon` as a
parameter while training, unlike `statsforecast`. Thus, a better way to
call the UDF would be simply `SELECT Forecast();`, which is currently
unsupported. @xzdandy Please let me know your thoughts.

List of stuff yet to be done:

- [x] Incorporate `neuralforecast`
- [x] Fix `HORIZON` redundancy (UPDATE: Being fixed in georgia-tech-db#1121)
- [x] Reuse model with lower horizon no
- [x] Add support for ~multivariate forecasting~ exogenous variables
- [x] Add tests
- [x] Add docs

---------

Co-authored-by: xzdandy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants