Skip to content

Commit

Permalink
Merge pull request #1294 from tunetheweb/empty-over-window-specification
Browse files Browse the repository at this point in the history
Support empty OVER() clause in Window Specification
  • Loading branch information
barrywhart committed Aug 17, 2021
2 parents 00fca3a + 59f0f86 commit 3005983
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Added
- Added support for empty WINDOWS specificiations [#1293](https://github.com/sqlfluff/sqlfluff/pull/1293)
### Changed
- Fix typo in the in the wild page [#1285](https://github.com/sqlfluff/sqlfluff/pull/1285)

Expand Down
4 changes: 2 additions & 2 deletions src/sqlfluff/dialects/dialect_ansi.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,15 +845,15 @@ class OverClauseSegment(BaseSegment):
OneOf(
Ref("SingleIdentifierGrammar"), # Window name
Bracketed(
Ref("WindowSpecificationSegment"),
Ref("WindowSpecificationSegment", optional=True),
),
),
)


@ansi_dialect.segment()
class WindowSpecificationSegment(BaseSegment):
"""Window specification, e.g. OVER() or named window."""
"""Window specification within OVER(...)."""

type = "window_specification"
match_grammar = Sequence(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
SELECT
NTH_VALUE(bar, 1) OVER(w1) AS baz
NTH_VALUE(bar, 1) OVER(w1) AS baz,
NTH_VALUE(bar, 1) OVER() AS foo
FROM t
WINDOW w1 AS (
PARTITION BY
Expand Down
26 changes: 24 additions & 2 deletions test/fixtures/parser/ansi/select_named_window_with_parentheses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ file:
statement:
select_statement:
select_clause:
keyword: SELECT
select_clause_element:
- keyword: SELECT
- select_clause_element:
function:
function_name:
function_name_identifier: NTH_VALUE
Expand All @@ -26,6 +26,28 @@ file:
alias_expression:
keyword: AS
identifier: baz
- comma: ','
- select_clause_element:
function:
function_name:
function_name_identifier: NTH_VALUE
bracketed:
- start_bracket: (
- expression:
column_reference:
identifier: bar
- comma: ','
- expression:
literal: '1'
- end_bracket: )
over_clause:
keyword: OVER
bracketed:
start_bracket: (
end_bracket: )
alias_expression:
keyword: AS
identifier: foo
from_clause:
keyword: FROM
from_expression:
Expand Down

0 comments on commit 3005983

Please sign in to comment.