-
-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial Redshift support (#1641)
* Add initial Redshift support * Linting
- Loading branch information
1 parent
ed23bf6
commit 8619f79
Showing
9 changed files
with
1,029 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"""The Amazon Redshift dialect. | ||
This is based on postgres dialect, since it was initially based off of Postgres 8. | ||
We should monitor in future and see if it should be rebased off of ANSI | ||
""" | ||
|
||
from sqlfluff.core.parser import ( | ||
OneOf, | ||
BaseSegment, | ||
) | ||
|
||
from sqlfluff.core.dialects import load_raw_dialect | ||
|
||
from sqlfluff.dialects.dialect_redshift_keywords import ( | ||
redshift_reserved_keywords, | ||
redshift_unreserved_keywords, | ||
) | ||
|
||
|
||
postgres_dialect = load_raw_dialect("postgres") | ||
ansi_dialect = load_raw_dialect("ansi") | ||
|
||
redshift_dialect = postgres_dialect.copy_as("redshift") | ||
|
||
# Set Keywords | ||
redshift_dialect.sets("unreserved_keywords").clear() | ||
redshift_dialect.sets("unreserved_keywords").update( | ||
[n.strip().upper() for n in redshift_unreserved_keywords.split("\n")] | ||
) | ||
|
||
redshift_dialect.sets("reserved_keywords").clear() | ||
redshift_dialect.sets("reserved_keywords").update( | ||
[n.strip().upper() for n in redshift_reserved_keywords.split("\n")] | ||
) | ||
|
||
|
||
@redshift_dialect.segment(replace=True) | ||
class DateAddFunctionNameSegment(BaseSegment): | ||
"""DATEADD function name segment. | ||
Override to support DATEDIFF as well | ||
""" | ||
|
||
type = "function_name" | ||
match_grammar = OneOf("DATEADD", "DATEDIFF") | ||
|
||
|
||
@redshift_dialect.segment(replace=True) | ||
class FunctionSegment(BaseSegment): | ||
"""A scalar or aggregate function. | ||
Revert back to the ANSI definition to support ignore nulls | ||
""" | ||
|
||
type = "function" | ||
match_grammar = ansi_dialect.get_segment("FunctionSegment").match_grammar.copy() |
Oops, something went wrong.