-
Notifications
You must be signed in to change notification settings - Fork 2
Fix export excel bugs #906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
538ecc2
export normal view query rows step by step 10000 -> 1000
AlexCXC 0424ec6
convert view query rows by SQL query instead of dtable-db list-rows API
AlexCXC 19b15bb
Recursive normalization filter
AlexCXC fa9c00c
fix grouped duration display format
AlexCXC f0d87af
Add more nested filters that depend on user information to unit tests.
AlexCXC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| 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.utils.sql_generator import pre_filter_to_filter_term | ||
|
|
||
| class SqlTest(unittest.TestCase): | ||
|
|
||
|
|
@@ -52,5 +53,122 @@ def test_equal(self): | |
|
|
||
|
|
||
|
|
||
| def test_user_filter_normalization(self): | ||
|
|
||
| def to_sql(filters): | ||
| normalized = pre_filter_to_filter_term(filters, 'me@x.com', 'admin-1', [1, 2], [1, 2, 3]) | ||
| return self._toSql({'filters': normalized, 'filter_conjunction': 'And'}) | ||
|
|
||
| # collaborator include_me appends current user email | ||
| self.assertEqual( | ||
| to_sql([{'column_name': 'Colla', 'filter_predicate': 'include_me', 'filter_term': ['a@x.com']}]), | ||
| "SELECT * FROM `Table1` WHERE (`Colla` in ('a@x.com', 'me@x.com')) LIMIT 0, 100", | ||
| ) | ||
| # text is_current_user_ID replaced with id_in_org | ||
| self.assertEqual( | ||
| to_sql([{'column_name': '名称', 'filter_predicate': 'is_current_user_ID', 'filter_term': ''}]), | ||
| "SELECT * FROM `Table1` WHERE (`名称` = 'admin-1') LIMIT 0, 100", | ||
| ) | ||
| # department current_user_department / current_user_department_and_sub | ||
| self.assertEqual( | ||
| to_sql([{'column_name': 'Dept', 'filter_predicate': 'is', 'filter_term': 'current_user_department'}]), | ||
| "SELECT * FROM `Table1` WHERE (`Dept` IN (1, 2)) LIMIT 0, 100", | ||
| ) | ||
| self.assertEqual( | ||
| to_sql([{'column_name': 'Dept', 'filter_predicate': 'is_not', 'filter_term': 'current_user_department_and_sub'}]), | ||
| "SELECT * FROM `Table1` WHERE (`Dept` NOT IN (1, 2, 3)) LIMIT 0, 100", | ||
| ) | ||
| # nested filter group include_me | ||
| self.assertEqual( | ||
| to_sql([{'filters': [{'column_name': 'Colla', 'filter_predicate': 'include_me', 'filter_term': ['b@x.com']}], 'filter_conjunction': 'And'}]), | ||
| "SELECT * FROM `Table1` WHERE ((`Colla` in ('b@x.com', 'me@x.com'))) LIMIT 0, 100", | ||
| ) | ||
| # deeply nested filter group (3 levels) include_me must still be normalized | ||
| self.assertEqual( | ||
| to_sql([ | ||
| { | ||
| 'filters': [ | ||
| { | ||
| 'filters': [ | ||
| {'column_name': 'Colla', 'filter_predicate': 'include_me', 'filter_term': ['c@x.com']}, | ||
| ], | ||
| 'filter_conjunction': 'And', | ||
| }, | ||
| ], | ||
| 'filter_conjunction': 'And', | ||
| }, | ||
| ]), | ||
| "SELECT * FROM `Table1` WHERE (((`Colla` in ('c@x.com', 'me@x.com')))) LIMIT 0, 100", | ||
| ) | ||
| # deeply nested filter group (3 levels) current_user_department must still be normalized | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Warning] 深层用户条件测试覆盖不足 为什么重要:递归修复后的三层嵌套断言只覆盖了“包含我”和“当前用户所在部门”。“是当前用户 ID”及“当前用户所在部门 / 含子部门”仍只在顶层验证,未来这两条分支在递归路径回归时无法被测试拦截。 建议修复:在这里补充三层嵌套的 |
||
| self.assertEqual( | ||
| to_sql([ | ||
| { | ||
| 'filters': [ | ||
| { | ||
| 'filters': [ | ||
| {'column_name': 'Dept', 'filter_predicate': 'is', 'filter_term': 'current_user_department'}, | ||
| ], | ||
| 'filter_conjunction': 'And', | ||
| }, | ||
| ], | ||
| 'filter_conjunction': 'And', | ||
| }, | ||
| ]), | ||
| "SELECT * FROM `Table1` WHERE (((`Dept` IN (1, 2)))) LIMIT 0, 100", | ||
| ) | ||
| # deeply nested filter group (3 levels) is_current_user_ID must still be normalized | ||
| self.assertEqual( | ||
| to_sql([ | ||
| { | ||
| 'filters': [ | ||
| { | ||
| 'filters': [ | ||
| {'column_name': '名称', 'filter_predicate': 'is_current_user_ID', 'filter_term': ''}, | ||
| ], | ||
| 'filter_conjunction': 'And', | ||
| }, | ||
| ], | ||
| 'filter_conjunction': 'And', | ||
| }, | ||
| ]), | ||
| "SELECT * FROM `Table1` WHERE (((`名称` = 'admin-1'))) LIMIT 0, 100", | ||
| ) | ||
| # deeply nested filter group (3 levels) current_user_department_and_sub must still be normalized | ||
| self.assertEqual( | ||
| to_sql([ | ||
| { | ||
| 'filters': [ | ||
| { | ||
| 'filters': [ | ||
| {'column_name': 'Dept', 'filter_predicate': 'is', 'filter_term': 'current_user_department_and_sub'}, | ||
| ], | ||
| 'filter_conjunction': 'And', | ||
| }, | ||
| ], | ||
| 'filter_conjunction': 'And', | ||
| }, | ||
| ]), | ||
| "SELECT * FROM `Table1` WHERE (((`Dept` IN (1, 2, 3)))) LIMIT 0, 100", | ||
| ) | ||
| # deeply nested filter group (3 levels) list-valued department filter must still be normalized | ||
| self.assertEqual( | ||
| to_sql([ | ||
| { | ||
| 'filters': [ | ||
| { | ||
| 'filters': [ | ||
| {'column_name': 'Dept', 'filter_predicate': 'is_any_of', 'filter_term': ['current_user_department_and_sub', 999]}, | ||
| ], | ||
| 'filter_conjunction': 'And', | ||
| }, | ||
| ], | ||
| 'filter_conjunction': 'And', | ||
| }, | ||
| ]), | ||
| "SELECT * FROM `Table1` WHERE (((`Dept` IN (1, 2, 3, 999)))) LIMIT 0, 100", | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Critical] SQL 未排除归档行
为什么重要:
设计要求普通视图只读取非归档存储,但这里生成的 SQL 仅包含视图过滤、排序和 LIMIT。归档行只要满足视图过滤就会被导出,导致普通视图导出包含不应出现的数据。
建议修复:在生成导出 SQL 时无条件追加非归档谓词(并正确合并已有 WHERE),或给
filter2sql增加明确的 normal-view/archived 开关,并补充归档行回归用例。