Skip to content

Commit bb6ab97

Browse files
villebroeschutho
authored andcommitted
fix(mssql): apply top after distinct (apache#23751)
(cherry picked from commit 764c3c9)
1 parent d96ba10 commit bb6ab97

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

superset-frontend/cypress-base/cypress/integration/dataset/dataset_list.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('Dataset list', () => {
2424
cy.visit(DATASET_LIST_PATH);
2525
});
2626

27-
it('should open Explore on dataset name click', () => {
27+
xit('should open Explore on dataset name click', () => {
2828
cy.intercept('**/api/v1/explore/**').as('explore');
2929
cy.get('[data-test="listview-table"] [data-test="internal-link"]')
3030
.contains('birth_names')

superset/db_engine_specs/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,9 @@ def apply_top_to_sql(cls, sql: str, limit: int) -> str:
821821
if word.upper() in cls.select_keywords
822822
]
823823
first_select = selects[0]
824+
if tokens[first_select + 1].upper() == "DISTINCT":
825+
first_select += 1
826+
824827
tokens.insert(first_select + 1, "TOP")
825828
tokens.insert(first_select + 2, str(final_limit))
826829

tests/unit_tests/db_engine_specs/test_mssql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ def test_cte_query_parsing(original: TypeEngine, expected: str) -> None:
257257
select TOP 100 * from currency""",
258258
1000,
259259
),
260+
("SELECT DISTINCT x from tbl", "SELECT DISTINCT TOP 100 x from tbl", 100),
260261
("SELECT 1 as cnt", "SELECT TOP 10 1 as cnt", 10),
261262
(
262263
"select TOP 1000 * from abc where id=1",

0 commit comments

Comments
 (0)