You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2022/11/27 13:31:56 UTC
[airflow] branch main updated: Improve filtering for invalid schemas in Hive hook (#27808)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 2d45f9d6c3 Improve filtering for invalid schemas in Hive hook (#27808)
2d45f9d6c3 is described below
commit 2d45f9d6c30aabebce3449eae9f152ba6d2306e2
Author: PApostol <50...@users.noreply.github.com>
AuthorDate: Sun Nov 27 15:31:49 2022 +0200
Improve filtering for invalid schemas in Hive hook (#27808)
* Improve filtering for invalid schemas in Hive hook
---
airflow/providers/apache/hive/hooks/hive.py | 8 ++++++--
tests/providers/apache/hive/hooks/test_hive.py | 4 +++-
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/airflow/providers/apache/hive/hooks/hive.py b/airflow/providers/apache/hive/hooks/hive.py
index edd8a4b372..430032d8f1 100644
--- a/airflow/providers/apache/hive/hooks/hive.py
+++ b/airflow/providers/apache/hive/hooks/hive.py
@@ -204,8 +204,12 @@ class HiveCliHook(BaseHook):
"""
conn = self.conn
schema = schema or conn.schema
- if "!" in schema or ";" in schema:
- raise RuntimeError(f"The schema `{schema}` contains invalid characters (!;)")
+
+ invalid_chars_list = re.findall(r"[^a-z0-9_]", schema)
+ if invalid_chars_list:
+ invalid_chars = "".join(char for char in invalid_chars_list)
+ raise RuntimeError(f"The schema `{schema}` contains invalid characters: {invalid_chars}")
+
if schema:
hql = f"USE {schema};\n{hql}"
diff --git a/tests/providers/apache/hive/hooks/test_hive.py b/tests/providers/apache/hive/hooks/test_hive.py
index 130554283b..ecb151a521 100644
--- a/tests/providers/apache/hive/hooks/test_hive.py
+++ b/tests/providers/apache/hive/hooks/test_hive.py
@@ -133,10 +133,12 @@ class TestHiveCliHook(unittest.TestCase):
)
def test_hive_cli_hook_invalid_schema(self):
- with pytest.raises(RuntimeError):
+ with pytest.raises(RuntimeError) as error:
hook = InvalidHiveCliHook()
hook.run_cli("SHOW DATABASES")
+ assert str(error.value) == "The schema `default;` contains invalid characters: ;"
+
@mock.patch("subprocess.Popen")
def test_run_cli_with_hive_conf(self, mock_popen):
hql = (