From 5d3abbb3485601fffab06ed3faa23a20579b5c7c Mon Sep 17 00:00:00 2001 From: Jiashen Cao Date: Wed, 30 Aug 2023 12:17:26 -0400 Subject: [PATCH] fix: improve error msg (#997) --- evadb/executor/use_executor.py | 5 +++ .../short/test_use_executor.py | 43 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 test/integration_tests/short/test_use_executor.py diff --git a/evadb/executor/use_executor.py b/evadb/executor/use_executor.py index f8f66df7a..dd1a94448 100644 --- a/evadb/executor/use_executor.py +++ b/evadb/executor/use_executor.py @@ -33,6 +33,11 @@ def exec(self, *args, **kwargs) -> Iterator[Batch]: self._database_name ) + if db_catalog_entry is None: + raise ExecutorError( + f"{self._database_name} data source does not exist. Use CREATE DATABASE to add a new data source." + ) + handler = get_database_handler( db_catalog_entry.engine, **db_catalog_entry.params, diff --git a/test/integration_tests/short/test_use_executor.py b/test/integration_tests/short/test_use_executor.py new file mode 100644 index 000000000..6f941e248 --- /dev/null +++ b/test/integration_tests/short/test_use_executor.py @@ -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. +import unittest +from test.util import get_evadb_for_testing, shutdown_ray + +from evadb.executor.executor_utils import ExecutorError +from evadb.server.command_handler import execute_query_fetch_all + + +class CreateDatabaseTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.evadb = get_evadb_for_testing() + # reset the catalog manager before running each test + cls.evadb.catalog().reset() + + @classmethod + def tearDownClass(cls): + shutdown_ray() + + def test_use_should_raise_executor_error(self): + query = """USE not_available_ds { + SELECT * FROM table + }""" + + with self.assertRaises(ExecutorError): + execute_query_fetch_all(self.evadb, query) + + +if __name__ == "__main__": + unittest.main()