Repository navigation
Expand file tree
/
Copy pathredshift.py
More file actions
60 lines (49 loc) · 1.95 KB
/
Copy pathredshift.py
File metadata and controls
60 lines (49 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from __future__ import annotations
from sqlglot.typing.redshift import EXPRESSION_METADATA
from sqlglot.dialects.dialect import NormalizationStrategy
from sqlglot.dialects.postgres import Postgres
from sqlglot.generators.redshift import RedshiftGenerator
from sqlglot.parsers.redshift import RedshiftParser
from sqlglot.tokens import TokenType
class Redshift(Postgres):
# https://docs.aws.amazon.com/redshift/latest/dg/r_names.html
NORMALIZATION_STRATEGY = NormalizationStrategy.CASE_INSENSITIVE
EXPRESSION_METADATA = EXPRESSION_METADATA.copy()
SUPPORTS_USER_DEFINED_TYPES = False
INDEX_OFFSET = 0
COPY_PARAMS_ARE_CSV = False
HEX_LOWERCASE = True
HAS_DISTINCT_ARRAY_CONSTRUCTORS = True
COALESCE_COMPARISON_NON_STANDARD = True
REGEXP_EXTRACT_POSITION_OVERFLOW_RETURNS_NULL = False
ARRAY_FUNCS_PROPAGATES_NULLS = True
# ref: https://docs.aws.amazon.com/redshift/latest/dg/r_FORMAT_strings.html
TIME_FORMAT = "'YYYY-MM-DD HH24:MI:SS'"
TIME_MAPPING = {
**Postgres.TIME_MAPPING,
"MON": "%b",
"MONTH": "%B",
}
Parser = RedshiftParser
class Tokenizer(Postgres.Tokenizer):
BIT_STRINGS = []
HEX_STRINGS = []
STRING_ESCAPES = ["\\", "'"]
KEYWORDS = {
**Postgres.Tokenizer.KEYWORDS,
"(+)": TokenType.JOIN_MARKER,
"BINARY VARYING": TokenType.VARBINARY,
"CURRENT_USER_ID": TokenType.CURRENT_USER_ID,
"HLLSKETCH": TokenType.HLLSKETCH,
"MINUS": TokenType.EXCEPT,
"SUPER": TokenType.SUPER,
"TOP": TokenType.TOP,
"UNLOAD": TokenType.COMMAND,
"USER": TokenType.CURRENT_USER,
"VARBYTE": TokenType.VARBINARY,
}
KEYWORDS.pop("VALUES")
# Redshift allows # to appear as a table identifier prefix
SINGLE_TOKENS = Postgres.Tokenizer.SINGLE_TOKENS.copy()
SINGLE_TOKENS.pop("#")
Generator = RedshiftGenerator