From e0596f63336ea1309e2f5ce59475eee518fd117a Mon Sep 17 00:00:00 2001 From: Gaurav Tarlok Kakkar Date: Tue, 17 Oct 2023 11:09:49 -0400 Subject: [PATCH] feat: function_metadata supports boolean and float (#1296) Fixes #1288 --- .../catalog/models/function_metadata_catalog.py | 4 ++-- evadb/parser/evadb.lark | 2 +- evadb/parser/lark_visitor/_expressions.py | 6 ++++++ .../long/test_function_executor.py | 17 +++++++++++++---- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/evadb/catalog/models/function_metadata_catalog.py b/evadb/catalog/models/function_metadata_catalog.py index 40bb00553..4b398a8c6 100644 --- a/evadb/catalog/models/function_metadata_catalog.py +++ b/evadb/catalog/models/function_metadata_catalog.py @@ -17,7 +17,7 @@ from sqlalchemy.orm import relationship from evadb.catalog.models.base_model import BaseModel -from evadb.catalog.models.utils import FunctionMetadataCatalogEntry +from evadb.catalog.models.utils import FunctionMetadataCatalogEntry, TextPickleType class FunctionMetadataCatalog(BaseModel): @@ -34,7 +34,7 @@ class FunctionMetadataCatalog(BaseModel): __tablename__ = "function_metadata_catalog" _key = Column("key", String(100)) - _value = Column("value", String(100)) + _value = Column("value", TextPickleType()) _function_id = Column( "function_id", Integer, ForeignKey("function_catalog._row_id") ) diff --git a/evadb/parser/evadb.lark b/evadb/parser/evadb.lark index 1014393a4..ab4d3a96d 100644 --- a/evadb/parser/evadb.lark +++ b/evadb/parser/evadb.lark @@ -70,7 +70,7 @@ function_metadata: function_metadata_key function_metadata_value function_metadata_key: uid -function_metadata_value: string_literal | decimal_literal +function_metadata_value: constant vector_store_type: USING (FAISS | QDRANT | PINECONE | PGVECTOR | CHROMADB) diff --git a/evadb/parser/lark_visitor/_expressions.py b/evadb/parser/lark_visitor/_expressions.py index c5cf5a0bf..91b5be77c 100644 --- a/evadb/parser/lark_visitor/_expressions.py +++ b/evadb/parser/lark_visitor/_expressions.py @@ -41,6 +41,12 @@ def array_literal(self, tree): res = ConstantValueExpression(np.array(array_elements), ColumnType.NDARRAY) return res + def boolean_literal(self, tree): + text = tree.children[0] + if text == "TRUE": + return ConstantValueExpression(True, ColumnType.BOOLEAN) + return ConstantValueExpression(False, ColumnType.BOOLEAN) + def constant(self, tree): for child in tree.children: if isinstance(child, Tree): diff --git a/test/integration_tests/long/test_function_executor.py b/test/integration_tests/long/test_function_executor.py index da8ec8289..9cbb93e1b 100644 --- a/test/integration_tests/long/test_function_executor.py +++ b/test/integration_tests/long/test_function_executor.py @@ -214,8 +214,11 @@ def test_should_create_function_with_metadata(self): OUTPUT (label NDARRAY STR(10)) TYPE Classification IMPL 'test/util.py' - CACHE 'TRUE' - BATCH 'FALSE'; + CACHE TRUE + BATCH FALSE + INT_VAL 1 + FLOAT_VAL 1.5 + STR_VAL "gg"; """ execute_query_fetch_all(self.evadb, create_function_query.format(function_name)) @@ -223,11 +226,17 @@ def test_should_create_function_with_metadata(self): entries = self.evadb.catalog().get_function_metadata_entries_by_function_name( function_name ) - self.assertEqual(len(entries), 2) + self.assertEqual(len(entries), 5) metadata = [(entry.key, entry.value) for entry in entries] # metadata ultimately stored as lowercase string literals in metadata - expected_metadata = [("cache", "TRUE"), ("batch", "FALSE")] + expected_metadata = [ + ("cache", True), + ("batch", False), + ("int_val", 1), + ("float_val", 1.5), + ("str_val", "gg"), + ] self.assertEqual(set(metadata), set(expected_metadata)) def test_should_return_empty_metadata_list_for_missing_function(self):