Skip to content

Commit

Permalink
Merge branch 'staging' into configuration_redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
xzdandy committed Oct 11, 2023
2 parents 9289dfc + a64d24b commit dd24a87
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 16 deletions.
1 change: 1 addition & 0 deletions evadb/executor/set_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def exec(self, *args, **kwargs):
as a separate PR for the issue #1140, where all instances of config use
will be replaced
"""

self.catalog().upsert_configuration_catalog_entry(
key=self.node.config_name,
value=self.node.config_value.value,
Expand Down
16 changes: 15 additions & 1 deletion evadb/executor/show_info_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def exec(self, *args, **kwargs):
show_entries = []

assert (
self.node.show_type is ShowType.FUNCTIONS or ShowType.TABLES
self.node.show_type is ShowType.FUNCTIONS
or ShowType.TABLES
or ShowType.CONFIG
), f"Show command does not support type {self.node.show_type}"

if self.node.show_type is ShowType.FUNCTIONS:
Expand All @@ -43,5 +45,17 @@ def exec(self, *args, **kwargs):
if table.table_type != TableType.SYSTEM_STRUCTURED_DATA:
show_entries.append(table.name)
show_entries = {"name": show_entries}
elif self.node.show_type is ShowType.CONFIG:
value = self._config.get_value(
category="default",
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))
19 changes: 15 additions & 4 deletions evadb/optimizer/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from collections import deque
from enum import IntEnum, auto
from pathlib import Path
from typing import Any, List
from typing import Any, List, Optional

from evadb.catalog.catalog_type import VectorStoreType
from evadb.catalog.models.column_catalog import ColumnCatalogEntry
Expand Down Expand Up @@ -1027,22 +1027,33 @@ def __hash__(self) -> int:


class LogicalShow(Operator):
def __init__(self, show_type: ShowType, children: List = None):
def __init__(
self, show_type: ShowType, show_val: Optional[str] = "", children: List = None
):
super().__init__(OperatorType.LOGICAL_SHOW, children)
self._show_type = show_type
self._show_val = show_val

@property
def show_type(self):
return self._show_type

@property
def show_val(self):
return self._show_val

def __eq__(self, other):
is_subtree_equal = super().__eq__(other)
if not isinstance(other, LogicalShow):
return False
return is_subtree_equal and self.show_type == other.show_type
return (
is_subtree_equal
and self.show_type == other.show_type
and self.show_val == other.show_val
)

def __hash__(self) -> int:
return hash((super().__hash__(), self.show_type))
return hash((super().__hash__(), self.show_type, self.show_val))


class LogicalExchange(Operator):
Expand Down
2 changes: 1 addition & 1 deletion evadb/optimizer/rules/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ def check(self, grp_id: int, context: OptimizerContext):
return True

def apply(self, before: LogicalShow, context: OptimizerContext):
after = ShowInfoPlan(before.show_type)
after = ShowInfoPlan(before.show_type, before.show_val)
yield after


Expand Down
2 changes: 1 addition & 1 deletion evadb/optimizer/statement_to_opr_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def visit_load_data(self, statement: LoadDataStatement):
self._plan = load_data_opr

def visit_show(self, statement: ShowStatement):
show_opr = LogicalShow(statement.show_type)
show_opr = LogicalShow(statement.show_type, statement.show_val)
self._plan = show_opr

def visit_explain(self, statement: ExplainStatement):
Expand Down
2 changes: 1 addition & 1 deletion evadb/parser/evadb.lark
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describe_statement: DESCRIBE table_name

help_statement: HELP STRING_LITERAL

show_statement: SHOW (FUNCTIONS | TABLES)
show_statement: SHOW (FUNCTIONS | TABLES | uid)

explain_statement: EXPLAIN explainable_statement

Expand Down
6 changes: 4 additions & 2 deletions evadb/parser/lark_visitor/_show_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class Show:
def show_statement(self, tree):
token = tree.children[1]

if str.upper(token) == "FUNCTIONS":
if isinstance(token, str) and str.upper(token) == "FUNCTIONS":
return ShowStatement(show_type=ShowType.FUNCTIONS)
elif str.upper(token) == "TABLES":
elif isinstance(token, str) and str.upper(token) == "TABLES":
return ShowStatement(show_type=ShowType.TABLES)
elif token is not None:
return ShowStatement(show_type=ShowType.CONFIG, show_val=self.visit(token))
15 changes: 12 additions & 3 deletions evadb/parser/show_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,41 @@
# limitations under the License.
from __future__ import annotations

from typing import Optional

from evadb.parser.statement import AbstractStatement
from evadb.parser.types import ShowType, StatementType


class ShowStatement(AbstractStatement):
def __init__(self, show_type: ShowType):
def __init__(self, show_type: ShowType, show_val: Optional[str] = ""):
super().__init__(StatementType.SHOW)
self._show_type = show_type
self._show_val = show_val.upper()

@property
def show_type(self):
return self._show_type

@property
def show_val(self):
return self._show_val

def __str__(self):
show_str = ""
if self.show_type == ShowType.FUNCTIONS:
show_str = "FUNCTIONS"
elif self.show_type == ShowType.TABLES:
show_str = "TABLES"
elif self.show_type == ShowType.CONFIG:
show_str = self.show_val

return f"SHOW {show_str}"

def __eq__(self, other: object) -> bool:
if not isinstance(other, ShowStatement):
return False
return self.show_type == other.show_type
return self.show_type == other.show_type and self.show_val == other.show_val

def __hash__(self) -> int:
return hash((super().__hash__(), self.show_type))
return hash((super().__hash__(), self.show_type, self.show_val))
1 change: 1 addition & 0 deletions evadb/parser/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class FileFormatType(EvaDBEnum):
class ShowType(EvaDBEnum):
FUNCTIONS # noqa: F821
TABLES # noqa: F821
CONFIG # noqa: F821


class FunctionType(EvaDBEnum):
Expand Down
15 changes: 12 additions & 3 deletions evadb/plan_nodes/show_info_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,34 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Optional

from evadb.parser.types import ShowType
from evadb.plan_nodes.abstract_plan import AbstractPlan
from evadb.plan_nodes.types import PlanOprType


class ShowInfoPlan(AbstractPlan):
def __init__(self, show_type: ShowType):
def __init__(self, show_type: ShowType, show_val: Optional[str] = ""):
self._show_type = show_type
self._show_val = show_val
super().__init__(PlanOprType.SHOW_INFO)

@property
def show_type(self):
return self._show_type

@property
def show_val(self):
return self._show_val

def __str__(self):
if self._show_type == ShowType.FUNCTIONS:
return "ShowFunctionPlan"
else:
elif self._show_type == ShowType.TABLES:
return "ShowTablePlan"
elif self._show_type == ShowType.CONFIG:
return "ShowConfigPlan"

def __hash__(self) -> int:
return hash((super().__hash__(), self.show_type))
return hash((super().__hash__(), self.show_type, self.show_val))
12 changes: 12 additions & 0 deletions test/integration_tests/short/test_show_info_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,15 @@ def test_show_tables(self):

# stop the server
os.system("nohup evadb_server --stop")

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")
self.assertEqual(show_config_value, expected_output)

# Ensure an Exception is raised if config is not present
with self.assertRaises(Exception):
execute_query_fetch_all(self.evadb, "SHOW BADCONFIG")
17 changes: 17 additions & 0 deletions test/unit_tests/parser/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@
from evadb.parser.rename_statement import RenameTableStatement
from evadb.parser.select_statement import SelectStatement
from evadb.parser.set_statement import SetStatement
from evadb.parser.show_statement import ShowStatement
from evadb.parser.statement import AbstractStatement, StatementType
from evadb.parser.table_ref import JoinNode, TableInfo, TableRef, TableValuedExpression
from evadb.parser.types import (
FileFormatType,
JoinType,
ObjectType,
ParserOrderBySortType,
ShowType,
)
from evadb.parser.use_statement import UseStatement

Expand Down Expand Up @@ -786,6 +788,21 @@ def test_set_statement(self):

self.assertEqual(set_stmt, expected_stmt)

def test_show_config_statement(self):
parser = Parser()
show_config_statement = """SHOW OPENAIKEY"""
evadb_statement_list = parser.parse(show_config_statement)

self.assertIsInstance(evadb_statement_list, list)
self.assertEqual(len(evadb_statement_list), 1)
self.assertEqual(evadb_statement_list[0].stmt_type, StatementType.SHOW)

show_config_stmt = evadb_statement_list[0]

expected_stmt = ShowStatement(show_type=ShowType.CONFIG, show_val="OPENAIKEY")

self.assertEqual(show_config_stmt, expected_stmt)

def test_create_predict_function_statement(self):
parser = Parser()
create_func_query = """
Expand Down

0 comments on commit dd24a87

Please sign in to comment.