From c4a162e34ef607d6cfc5d93d9347ecdc1f7d3e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=8E=89=E9=91=AB?= Date: Mon, 17 Aug 2026 16:59:47 +0800 Subject: [PATCH 1/2] fix: add column identifier backticks and include test cases for include_me filter predicate --- dtable_events/tests/sql/test_reference.py | 22 ++++++++++++++++++++++ dtable_events/utils/sql_generator.py | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/dtable_events/tests/sql/test_reference.py b/dtable_events/tests/sql/test_reference.py index e74dc146..c4d28941 100644 --- a/dtable_events/tests/sql/test_reference.py +++ b/dtable_events/tests/sql/test_reference.py @@ -526,6 +526,28 @@ def get_expected_sql_for_modifier(filter_modifier, column_name): "expected_sql": "SELECT * FROM `Table1` WHERE (`Modify` not in ('87d485c2281a42adbddb137a1070f395@auth.local', 'xxx')) LIMIT 0, 100", "by_group": False, }, + { + "filter_conditions": { + "filters": [ + {'column_name': 'Creator', 'filter_predicate': 'include_me', 'filter_term': ["87d485c2281a42adbddb137a1070f395@auth.local"]} + ], + "filter_predicate": 'And', + "sorts":[], + }, + "expected_sql": "SELECT * FROM `Table1` WHERE (`Creator` = '87d485c2281a42adbddb137a1070f395@auth.local') LIMIT 0, 100", + "by_group": False, + }, + { + "filter_conditions": { + "filters": [ + {'column_name': 'Modify', 'filter_predicate': 'include_me', 'filter_term': ["87d485c2281a42adbddb137a1070f395@auth.local"]} + ], + "filter_predicate": 'And', + "sorts":[], + }, + "expected_sql": "SELECT * FROM `Table1` WHERE (`Modify` = '87d485c2281a42adbddb137a1070f395@auth.local') LIMIT 0, 100", + "by_group": False, + }, # ignore conditions ## filter-term incomplete diff --git a/dtable_events/utils/sql_generator.py b/dtable_events/utils/sql_generator.py index 862b84e1..f79ee8fa 100644 --- a/dtable_events/utils/sql_generator.py +++ b/dtable_events/utils/sql_generator.py @@ -1107,7 +1107,7 @@ def op_include_me(self): if not isinstance(select_collaborators, list): select_collaborators = [select_collaborators, ] creator = select_collaborators[0] if select_collaborators else '' - return "%s %s '%s'" % ( + return "`%s` %s '%s'" % ( self.column_name, '=', creator From e71d091341024c3972a1ce41ddcce37836911c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=8E=89=E9=91=AB?= Date: Fri, 21 Aug 2026 16:11:11 +0800 Subject: [PATCH 2/2] test: add test case for include_me filter with hyphenated column names --- dtable_events/tests/sql/sql_test.py | 22 ++++++++++++++++++++-- dtable_events/tests/sql/test_reference.py | 22 ---------------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/dtable_events/tests/sql/sql_test.py b/dtable_events/tests/sql/sql_test.py index 80df384f..afeca058 100644 --- a/dtable_events/tests/sql/sql_test.py +++ b/dtable_events/tests/sql/sql_test.py @@ -6,7 +6,8 @@ sys.path.append(sys.path.append(d(d(d(d(__file__)))))) from sql.column_reference import TEST_COLUMNS, TABLES, LINK_COLUMN from sql.test_reference import TEST_CONDITIONS, TEST_CONDITIONS_LINK -from dtable_events import filter2sql, linkRecords2sql +from dtable_events import filter2sql, linkRecords2sql, statistic2sql +from dtable_events.utils.constants import StatisticType from dtable_events.utils.sql_generator import pre_filter_to_filter_term class SqlTest(unittest.TestCase): @@ -49,8 +50,25 @@ def test_equal(self): record_ids = condition_l.get('row_ids') sql_link = linkRecords2sql(current_table, link_column, record_ids, tables) self.assertEqual(sql_link, expected_sql_link) - + def test_include_me_with_hyphenated_creator_column(self): + username = '87d485c2281a42adbddb137a1070f395@auth.local' + table = { + 'name': self.table_name, + 'columns': [{'key': '_creator', 'type': 'creator', 'name': 'Creator-Name'}], + } + statistic = { + 'summary_type': 'count', + 'filters': [{'column_key': '_creator', 'filter_predicate': 'include_me', 'filter_term': []}], + } + + sql, error = statistic2sql(table, StatisticType.BASIC_NUMBER_CARD, statistic, username=username) + + self.assertIsNone(error) + self.assertEqual( + sql, + "SELECT COUNT(*) FROM `Table1` WHERE (`Creator-Name` = '%s') LIMIT 0, 5000" % username, + ) def test_user_filter_normalization(self): diff --git a/dtable_events/tests/sql/test_reference.py b/dtable_events/tests/sql/test_reference.py index c4d28941..e74dc146 100644 --- a/dtable_events/tests/sql/test_reference.py +++ b/dtable_events/tests/sql/test_reference.py @@ -526,28 +526,6 @@ def get_expected_sql_for_modifier(filter_modifier, column_name): "expected_sql": "SELECT * FROM `Table1` WHERE (`Modify` not in ('87d485c2281a42adbddb137a1070f395@auth.local', 'xxx')) LIMIT 0, 100", "by_group": False, }, - { - "filter_conditions": { - "filters": [ - {'column_name': 'Creator', 'filter_predicate': 'include_me', 'filter_term': ["87d485c2281a42adbddb137a1070f395@auth.local"]} - ], - "filter_predicate": 'And', - "sorts":[], - }, - "expected_sql": "SELECT * FROM `Table1` WHERE (`Creator` = '87d485c2281a42adbddb137a1070f395@auth.local') LIMIT 0, 100", - "by_group": False, - }, - { - "filter_conditions": { - "filters": [ - {'column_name': 'Modify', 'filter_predicate': 'include_me', 'filter_term': ["87d485c2281a42adbddb137a1070f395@auth.local"]} - ], - "filter_predicate": 'And', - "sorts":[], - }, - "expected_sql": "SELECT * FROM `Table1` WHERE (`Modify` = '87d485c2281a42adbddb137a1070f395@auth.local') LIMIT 0, 100", - "by_group": False, - }, # ignore conditions ## filter-term incomplete