From 334c8b157259a7eeb8d30ea9e2499f8cca3f63d2 Mon Sep 17 00:00:00 2001 From: Hersh Dhillon Date: Wed, 22 Nov 2023 02:47:22 -0500 Subject: [PATCH] `SHOW CONFIGS` now gets all configs (#1345) Added method to get all configs modified: evadb/catalog/catalog_manager.py Added case to get all configs modified: evadb/executor/show_info_executor.py Test for get all configs modified: test/integration_tests/short/test_show_info_executor.py --- .gitignore | 2 ++ docs/source/reference/evaql/set_config.rst | 8 ++++-- docs/source/reference/evaql/show_config.rst | 10 +++++++- evadb/catalog/catalog_manager.py | 3 +++ evadb/evadb_config.py | 6 +++++ evadb/executor/set_executor.py | 9 +++++++ evadb/executor/show_info_executor.py | 25 ++++++++++++------- evadb/parser/lark_visitor/_show_statements.py | 2 +- evadb/parser/show_statement.py | 2 +- evadb/parser/types.py | 2 +- evadb/plan_nodes/show_info_plan.py | 2 +- .../short/test_show_info_executor.py | 10 +++++++- test/unit_tests/parser/test_parser.py | 2 +- 13 files changed, 65 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 697a42a819..dc7ddbf5ed 100644 --- a/.gitignore +++ b/.gitignore @@ -226,3 +226,5 @@ eva_db/* eva/* blog.md + +tests/integration_tests/short/*.db diff --git a/docs/source/reference/evaql/set_config.rst b/docs/source/reference/evaql/set_config.rst index 599fe0fc04..c45041b5a0 100644 --- a/docs/source/reference/evaql/set_config.rst +++ b/docs/source/reference/evaql/set_config.rst @@ -1,4 +1,4 @@ -SET CONFIG +SET CONFIGS ============== .. _set_config: @@ -8,4 +8,8 @@ Sets the value of a configuration parameter to the passed value. Both `TO` and ` .. code:: sql SET OPENAI_KEY TO "abc"; - SET OPENAI_KEY = "abc"; \ No newline at end of file + SET OPENAI_KEY = "abc"; + +.. note:: + + The `SET` command does not support `CONFIG` or `CONFIGS` as keys names. This is because `CONFIG` and `CONFIGS` are reserved keywords. diff --git a/docs/source/reference/evaql/show_config.rst b/docs/source/reference/evaql/show_config.rst index 2991f4c28e..0e7dba9960 100644 --- a/docs/source/reference/evaql/show_config.rst +++ b/docs/source/reference/evaql/show_config.rst @@ -1,4 +1,4 @@ -SHOW CONFIG +SHOW CONFIGS ============== .. _show_config: @@ -9,3 +9,11 @@ Returns the value of a specified configuration parameter. SHOW ; SHOW OPENAI_KEY; + +.. _show_configs: + +In order to see all the configuration parameters, use the following command: + +.. code:: sql + + SHOW CONFIGS; diff --git a/evadb/catalog/catalog_manager.py b/evadb/catalog/catalog_manager.py index 8482bf1bd6..70d3e0acff 100644 --- a/evadb/catalog/catalog_manager.py +++ b/evadb/catalog/catalog_manager.py @@ -786,3 +786,6 @@ def get_configuration_catalog_value(self, key: str, default: Any = None) -> Any: if table_entry: return table_entry.value return default + + def get_all_configuration_catalog_entries(self) -> List: + return self._config_catalog_service.get_all_entries() diff --git a/evadb/evadb_config.py b/evadb/evadb_config.py index 6117514b25..ec357fbd91 100644 --- a/evadb/evadb_config.py +++ b/evadb/evadb_config.py @@ -24,6 +24,12 @@ "evadb_installation_dir": "", "datasets_dir": "", "catalog_database_uri": "", + "index_dir": "", + "cache_dir": "", + "s3_download_dir": "", + "tmp_dir": "", + "function_dir": "", + "model_dir": "", "application": "evadb", "mode": "release", "batch_mem_size": 30000000, diff --git a/evadb/executor/set_executor.py b/evadb/executor/set_executor.py index 309fe2747c..1acb9b3098 100644 --- a/evadb/executor/set_executor.py +++ b/evadb/executor/set_executor.py @@ -16,6 +16,8 @@ from evadb.executor.abstract_executor import AbstractExecutor from evadb.parser.set_statement import SetStatement +RESERVED_CONFIG_KEYWORDS = ["CONFIG", "CONFIGS"] + class SetExecutor(AbstractExecutor): def __init__(self, db: EvaDBDatabase, node: SetStatement): @@ -37,6 +39,13 @@ def exec(self, *args, **kwargs): will be replaced """ + if self.node.config_name in RESERVED_CONFIG_KEYWORDS: + raise Exception( + "{} is a reserved keyword for configurations. Please use a word other than the following list: {}".format( + self.node.config_name, RESERVED_CONFIG_KEYWORDS + ) + ) + self.catalog().upsert_configuration_catalog_entry( key=self.node.config_name, value=self.node.config_value.value, diff --git a/evadb/executor/show_info_executor.py b/evadb/executor/show_info_executor.py index 16871b8435..87c4ef7063 100644 --- a/evadb/executor/show_info_executor.py +++ b/evadb/executor/show_info_executor.py @@ -33,7 +33,7 @@ def exec(self, *args, **kwargs): self.node.show_type is ShowType.FUNCTIONS or ShowType.TABLES or ShowType.DATABASES - or ShowType.CONFIG + or ShowType.CONFIGS ), f"Show command does not support type {self.node.show_type}" if self.node.show_type is ShowType.FUNCTIONS: @@ -50,16 +50,23 @@ def exec(self, *args, **kwargs): databases = self.catalog().get_all_database_catalog_entries() for db in databases: show_entries.append(db.display_format()) - elif self.node.show_type is ShowType.CONFIG: - value = self.catalog().get_configuration_catalog_value( - key=self.node.show_val.upper(), - ) + elif self.node.show_type is ShowType.CONFIGS: show_entries = {} - if value is not None: - show_entries = {self.node.show_val: [value]} + # CONFIGS is a special word, which is used to display all the configurations + if self.node.show_val.upper() == ShowType.CONFIGS.name: + configs = self.catalog().get_all_configuration_catalog_entries() + for config in configs: + show_entries[config.key] = config.value else: - raise Exception( - "No configuration found with key {}".format(self.node.show_val) + value = self.catalog().get_configuration_catalog_value( + key=self.node.show_val.upper(), ) + show_entries = {} + if value is not None: + show_entries = {self.node.show_val: [value]} + else: + raise Exception( + "No configuration found with key {}".format(self.node.show_val) + ) yield Batch(pd.DataFrame(show_entries)) diff --git a/evadb/parser/lark_visitor/_show_statements.py b/evadb/parser/lark_visitor/_show_statements.py index ca9581aca7..9340b1d9b8 100644 --- a/evadb/parser/lark_visitor/_show_statements.py +++ b/evadb/parser/lark_visitor/_show_statements.py @@ -30,4 +30,4 @@ def show_statement(self, tree): elif isinstance(token, str) and str.upper(token) == "DATABASES": return ShowStatement(show_type=ShowType.DATABASES) elif token is not None: - return ShowStatement(show_type=ShowType.CONFIG, show_val=self.visit(token)) + return ShowStatement(show_type=ShowType.CONFIGS, show_val=self.visit(token)) diff --git a/evadb/parser/show_statement.py b/evadb/parser/show_statement.py index d7eca052f2..857a35d1b1 100644 --- a/evadb/parser/show_statement.py +++ b/evadb/parser/show_statement.py @@ -40,7 +40,7 @@ def __str__(self): show_str = "FUNCTIONS" elif self.show_type == ShowType.TABLES: show_str = "TABLES" - elif self.show_type == ShowType.CONFIG: + elif self.show_type == ShowType.CONFIGS: show_str = self.show_val elif self.show_type == ShowType.DATABASES: show_str = "DATABASES" diff --git a/evadb/parser/types.py b/evadb/parser/types.py index 227a768c7b..0ea68a5f56 100644 --- a/evadb/parser/types.py +++ b/evadb/parser/types.py @@ -71,7 +71,7 @@ class FileFormatType(EvaDBEnum): class ShowType(EvaDBEnum): FUNCTIONS # noqa: F821 TABLES # noqa: F821 - CONFIG # noqa: F821 + CONFIGS # noqa: F821 DATABASES # noqa: F821 diff --git a/evadb/plan_nodes/show_info_plan.py b/evadb/plan_nodes/show_info_plan.py index 733cc0401d..b47afd56e5 100644 --- a/evadb/plan_nodes/show_info_plan.py +++ b/evadb/plan_nodes/show_info_plan.py @@ -40,7 +40,7 @@ def __str__(self): return "ShowDatabasePlan" elif self._show_type == ShowType.TABLES: return "ShowTablePlan" - elif self._show_type == ShowType.CONFIG: + elif self._show_type == ShowType.CONFIGS: return "ShowConfigPlan" def __hash__(self) -> int: diff --git a/test/integration_tests/short/test_show_info_executor.py b/test/integration_tests/short/test_show_info_executor.py index f875d266e0..cba59227e6 100644 --- a/test/integration_tests/short/test_show_info_executor.py +++ b/test/integration_tests/short/test_show_info_executor.py @@ -21,6 +21,7 @@ import pytest from evadb.configuration.constants import EvaDB_ROOT_DIR +from evadb.evadb_config import BASE_EVADB_CONFIG from evadb.functions.function_bootstrap_queries import ( ArrayCount_function_query, Fastrcnn_function_query, @@ -118,7 +119,6 @@ def test_show_tables(self): def test_show_config_execution(self): execute_query_fetch_all(self.evadb, "SET OPENAIKEY = 'ABCD';") - # expected_output = Batch(pd.DataFrame({"OPENAIKEY": ["ABCD"]})) show_config_value = execute_query_fetch_all(self.evadb, "SHOW OPENAIKEY") @@ -128,6 +128,14 @@ def test_show_config_execution(self): with self.assertRaises(Exception): execute_query_fetch_all(self.evadb, "SHOW BADCONFIG") + def test_show_all_configs(self): + show_all_config_value = execute_query_fetch_all(self.evadb, "SHOW CONFIGS") + + # NOTE :- Since the values of configs like the paths are not user/machine/installation agnostic, + # It doesn't make sense to test for the values. Hence, we are only testing for the keys + columns = show_all_config_value.columns + self.assertEqual(columns == list(BASE_EVADB_CONFIG.keys()), True) + # integration test def test_show_databases(self): result = execute_query_fetch_all(self.evadb, "SHOW DATABASES;") diff --git a/test/unit_tests/parser/test_parser.py b/test/unit_tests/parser/test_parser.py index 6086db088e..3091e8f3d0 100644 --- a/test/unit_tests/parser/test_parser.py +++ b/test/unit_tests/parser/test_parser.py @@ -905,7 +905,7 @@ def test_show_config_statement(self): show_config_stmt = evadb_statement_list[0] - expected_stmt = ShowStatement(show_type=ShowType.CONFIG, show_val="OPENAIKEY") + expected_stmt = ShowStatement(show_type=ShowType.CONFIGS, show_val="OPENAIKEY") self.assertEqual(show_config_stmt, expected_stmt)