From 564a815d218f06a6b55dd9da790bdbf87bd36a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=AE=B6=E5=90=8D?= <13774486042@163.com> Date: Sat, 27 Aug 2022 12:17:06 +0800 Subject: [PATCH] [fix][python] Sql pattern add truncate. (#11666) --- .../pydolphinscheduler/src/pydolphinscheduler/tasks/sql.py | 2 +- .../pydolphinscheduler/tests/tasks/test_sql.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/tasks/sql.py b/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/tasks/sql.py index a1259824f1..716a024daf 100644 --- a/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/tasks/sql.py +++ b/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/tasks/sql.py @@ -98,7 +98,7 @@ class Sql(Task): return self.param_sql_type pattern_select_str = ( "^(?!(.* |)insert |(.* |)delete |(.* |)drop " - "|(.* |)update |(.* |)alter |(.* |)create ).*" + "|(.* |)update |(.* |)truncate |(.* |)alter |(.* |)create ).*" ) pattern_select = re.compile(pattern_select_str, re.IGNORECASE) if pattern_select.match(self.sql) is None: diff --git a/dolphinscheduler-python/pydolphinscheduler/tests/tasks/test_sql.py b/dolphinscheduler-python/pydolphinscheduler/tests/tasks/test_sql.py index ee0acc442e..50ccd946a9 100644 --- a/dolphinscheduler-python/pydolphinscheduler/tests/tasks/test_sql.py +++ b/dolphinscheduler-python/pydolphinscheduler/tests/tasks/test_sql.py @@ -54,6 +54,7 @@ from pydolphinscheduler.tasks.sql import Sql, SqlType ("delete from table_name where id < 10", None, SqlType.NOT_SELECT), ("alter table table_name add column col1 int", None, SqlType.NOT_SELECT), ("create table table_name2 (col1 int)", None, SqlType.NOT_SELECT), + ("truncate table table_name", None, SqlType.NOT_SELECT), ("create table table_name2 (col1 int)", SqlType.SELECT, SqlType.SELECT), ("select 1", SqlType.NOT_SELECT, SqlType.NOT_SELECT), ("create table table_name2 (col1 int)", SqlType.NOT_SELECT, SqlType.NOT_SELECT),