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

Add support for function calls without input arguments: FUNC() #1185

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion evadb/functions/function_bootstrap_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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'.

Expand Down Expand Up @@ -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,
]
)

Expand Down
2 changes: 1 addition & 1 deletion evadb/parser/evadb.lark
Original file line number Diff line number Diff line change
Expand Up @@ -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) ")"
Expand Down
2 changes: 1 addition & 1 deletion evadb/parser/lark_visitor/_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions test/integration_tests/short/test_select_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
29 changes: 28 additions & 1 deletion test/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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