From 821ba3e57662ebce65e2cc71885f29d136d0b507 Mon Sep 17 00:00:00 2001 From: xzdandy Date: Thu, 21 Sep 2023 03:24:31 -0400 Subject: [PATCH 1/2] Fix `FUNC()` without input arguments --- evadb/parser/evadb.lark | 2 +- evadb/parser/lark_visitor/_functions.py | 2 +- test/util.py | 29 ++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/evadb/parser/evadb.lark b/evadb/parser/evadb.lark index 2ccc08d221..8c6a0fe9dc 100644 --- a/evadb/parser/evadb.lark +++ b/evadb/parser/evadb.lark @@ -272,7 +272,7 @@ or_replace: OR REPLACE function_call: function ->function_call | aggregate_windowed_function ->aggregate_function_call -function: simple_id "(" (STAR | function_args) ")" dotted_id? +function: simple_id "(" (STAR | function_args)? ")" dotted_id? aggregate_windowed_function: aggregate_function_name "(" function_arg ")" | COUNT "(" (STAR | function_arg) ")" diff --git a/evadb/parser/lark_visitor/_functions.py b/evadb/parser/lark_visitor/_functions.py index 7baa4e66bb..a3b5a868af 100644 --- a/evadb/parser/lark_visitor/_functions.py +++ b/evadb/parser/lark_visitor/_functions.py @@ -30,7 +30,7 @@ class Functions: def function(self, tree): function_name = None function_output = None - function_args = None + function_args = [] for child in tree.children: if isinstance(child, Token): diff --git a/test/util.py b/test/util.py index 732aabc15a..d793d14317 100644 --- a/test/util.py +++ b/test/util.py @@ -33,7 +33,10 @@ from evadb.configuration.constants import EvaDB_DATABASE_DIR, EvaDB_INSTALLATION_DIR from evadb.database import init_evadb_instance from evadb.expression.function_expression import FunctionExpression -from evadb.functions.abstract.abstract_function import AbstractClassifierFunction +from evadb.functions.abstract.abstract_function import ( + AbstractClassifierFunction, + AbstractFunction, +) from evadb.functions.decorators import decorators from evadb.functions.decorators.io_descriptors.data_types import ( NumpyArray, @@ -636,3 +639,27 @@ def classify_one(self, frames: np.ndarray): i = int(frames[0][0][0][0]) - 1 label = self.labels[i % 2 + 1] return np.array([label]) + + +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 From 56561964e204ef269168f91b9f1999d9e9edd9ec Mon Sep 17 00:00:00 2001 From: xzdandy Date: Thu, 21 Sep 2023 03:34:41 -0400 Subject: [PATCH 2/2] Add short integration test for `SELECT FUNC();` --- evadb/functions/function_bootstrap_queries.py | 10 +++++++++- test/integration_tests/short/test_select_executor.py | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/evadb/functions/function_bootstrap_queries.py b/evadb/functions/function_bootstrap_queries.py index cd75e9a655..e51e75638a 100644 --- a/evadb/functions/function_bootstrap_queries.py +++ b/evadb/functions/function_bootstrap_queries.py @@ -49,6 +49,13 @@ EvaDB_INSTALLATION_DIR ) +DummyNoInputFunction_function_query = """CREATE FUNCTION + IF NOT EXISTS DummyNoInputFunction + IMPL '{}/../test/util.py'; + """.format( + EvaDB_INSTALLATION_DIR +) + fuzzy_function_query = """CREATE FUNCTION IF NOT EXISTS FuzzDistance INPUT (Input_Array1 NDARRAY ANYTYPE, Input_Array2 NDARRAY ANYTYPE) OUTPUT (distance FLOAT(32, 7)) @@ -197,7 +204,7 @@ def init_builtin_functions(db: EvaDBDatabase, mode: str = "debug") -> None: In 'release' mode, only release functions are loaded. In addition, in 'debug' mode, the function loads a smaller model to accelerate the test suite time. - Args: + Args:G mode (str, optional): The mode for loading functions, either 'debug' or 'release'. Defaults to 'debug'. @@ -242,6 +249,7 @@ def init_builtin_functions(db: EvaDBDatabase, mode: str = "debug") -> None: DummyObjectDetector_function_query, DummyMultiObjectDetector_function_query, DummyFeatureExtractor_function_query, + DummyNoInputFunction_function_query, ] ) diff --git a/test/integration_tests/short/test_select_executor.py b/test/integration_tests/short/test_select_executor.py index 7dc1f757c8..2e0f24fd8d 100644 --- a/test/integration_tests/short/test_select_executor.py +++ b/test/integration_tests/short/test_select_executor.py @@ -434,3 +434,11 @@ def test_expression_tree_signature(self): signature, f"DummyMultiObjectDetector[{function_id}](MyVideo.data[{col_id}])", ) + + def test_function_with_no_input_arguments(self): + select_query = "SELECT DummyNoInputFunction();" + actual_batch = execute_query_fetch_all(self.evadb, select_query) + expected = Batch( + pd.DataFrame([{"dummynoinputfunction.label": "DummyNoInputFunction"}]) + ) + self.assertEqual(actual_batch, expected)