-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding SET statement for configuration management (#1180)
Added - Parser for SET statement - Class for SET statement - StatementType.SET to parser.types
- Loading branch information
Showing
11 changed files
with
223 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# coding=utf-8 | ||
# Copyright 2018-2023 EvaDB | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# 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 evadb.database import EvaDBDatabase | ||
from evadb.executor.abstract_executor import AbstractExecutor | ||
from evadb.parser.set_statement import SetStatement | ||
|
||
|
||
class SetExecutor(AbstractExecutor): | ||
def __init__(self, db: EvaDBDatabase, node: SetStatement): | ||
super().__init__(db, node) | ||
|
||
def exec(self, *args, **kwargs): | ||
# Get method implementation from the config.update_value | ||
""" | ||
NOTE :- Currently adding adding all configs in 'default' category. | ||
The idea is to deprecate category to maintain the same format for | ||
the query as DuckDB and Postgres | ||
Ref :- | ||
https://www.postgresql.org/docs/7.0/sql-set.htm | ||
https://duckdb.org/docs/sql/configuration.html | ||
This design change for configuation manager will be taken care of | ||
as a separate PR for the issue #1140, where all instances of config use | ||
will be replaced | ||
""" | ||
self._config.update_value( | ||
category="default", | ||
key=self.node.config_name, | ||
value=self.node.config_value.value, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# coding=utf-8 | ||
# Copyright 2018-2023 EvaDB | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# 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 lark.tree import Tree | ||
|
||
from evadb.parser.set_statement import SetStatement | ||
|
||
|
||
################################################################## | ||
# DELETE STATEMENTS | ||
################################################################## | ||
class Set: | ||
def set_statement(self, tree): | ||
config_name = None | ||
config_value = None | ||
for child in tree.children: | ||
if isinstance(child, Tree): | ||
if child.data == "config_name": | ||
config_name = self.visit(child) | ||
elif child.data == "config_value": | ||
config_value = self.visit(child) | ||
|
||
set_stmt = SetStatement(config_name, config_value) | ||
return set_stmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# coding=utf-8 | ||
# Copyright 2018-2023 EvaDB | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# 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 __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
from evadb.parser.statement import AbstractStatement | ||
from evadb.parser.types import StatementType | ||
|
||
|
||
class SetStatement(AbstractStatement): | ||
def __init__(self, config_name: str, config_value: Any): | ||
super().__init__(StatementType.SET) | ||
self._config_name = config_name | ||
self._config_value = config_value | ||
|
||
@property | ||
def config_name(self): | ||
return self._config_name | ||
|
||
@property | ||
def config_value(self): | ||
return self._config_value | ||
|
||
def __str__(self): | ||
return f"SET {str(self.config_name)} = {str(self.config_value)}" | ||
|
||
def __eq__(self, other: object) -> bool: | ||
if not isinstance(other, SetStatement): | ||
return False | ||
return ( | ||
self.config_name == other.config_name | ||
and self.config_value == other.config_value | ||
) | ||
|
||
def __hash__(self) -> int: | ||
return hash((super().__hash__(), self.config_name, self.config_value)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# coding=utf-8 | ||
# Copyright 2018-2023 EvaDB | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# 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. | ||
import unittest | ||
from test.util import get_evadb_for_testing | ||
|
||
import pytest | ||
|
||
from evadb.server.command_handler import execute_query_fetch_all | ||
|
||
NUM_FRAMES = 10 | ||
|
||
|
||
@pytest.mark.notparallel | ||
class SetExecutorTest(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
cls.evadb = get_evadb_for_testing() | ||
cls.evadb.catalog().reset() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
pass | ||
|
||
# integration test | ||
def test_set_execution(self): | ||
execute_query_fetch_all(self.evadb, "SET OPENAIKEY = 'ABCD';") | ||
current_config_value = self.evadb.config.get_value("default", "OPENAIKEY") | ||
|
||
self.assertEqual("ABCD", current_config_value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters