Skip to content

Commit

Permalink
SHOW CONFIGS now gets all configs (georgia-tech-db#1345)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hershd23 authored Nov 22, 2023
1 parent 3d0b647 commit 334c8b1
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,5 @@ eva_db/*
eva/*

blog.md

tests/integration_tests/short/*.db
8 changes: 6 additions & 2 deletions docs/source/reference/evaql/set_config.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SET CONFIG
SET CONFIGS
==============

.. _set_config:
Expand All @@ -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";
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.
10 changes: 9 additions & 1 deletion docs/source/reference/evaql/show_config.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SHOW CONFIG
SHOW CONFIGS
==============

.. _show_config:
Expand All @@ -9,3 +9,11 @@ Returns the value of a specified configuration parameter.
SHOW <parameter_name>;
SHOW OPENAI_KEY;
.. _show_configs:

In order to see all the configuration parameters, use the following command:

.. code:: sql
SHOW CONFIGS;
3 changes: 3 additions & 0 deletions evadb/catalog/catalog_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 6 additions & 0 deletions evadb/evadb_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions evadb/executor/set_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
Expand Down
25 changes: 16 additions & 9 deletions evadb/executor/show_info_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))
2 changes: 1 addition & 1 deletion evadb/parser/lark_visitor/_show_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 1 addition & 1 deletion evadb/parser/show_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion evadb/parser/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion evadb/plan_nodes/show_info_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion test/integration_tests/short/test_show_info_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand All @@ -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;")
Expand Down
2 changes: 1 addition & 1 deletion test/unit_tests/parser/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 334c8b1

Please sign in to comment.