-
Notifications
You must be signed in to change notification settings - Fork 30
/
keys.py
127 lines (116 loc) · 2.79 KB
/
keys.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""Defines constant sequences of LookML keys."""
from typing import Dict, Tuple, Type
from lkml import tokens
# These are repeatable keys in LookML that the parser should collapse into a single
# Python dictionary key. For example, LookML can have multiple dimensions, so the parser
# will combine those dimensions into a list of dictionaries with a top-level key,
# `dimensions`.
PLURAL_KEYS: Tuple[str, ...] = (
"view",
"measure",
"dimension",
"dimension_group",
"filter",
"access_filter",
"bind_filters",
"map_layer",
"parameter",
"set",
"column",
"derived_column",
"include",
"explore",
"link",
"when",
"allowed_value",
"named_value_format",
"join",
"datagroup",
"access_grant",
"sql_step",
"action",
"param",
"form_param",
"option",
"user_attribute_param",
"assert",
"test",
)
# These are keys in LookML that should be recognized as expression blocks (end with ;;).
EXPR_BLOCK_KEYS: Tuple[str, ...] = (
"expression_custom_filter",
"expression",
"html",
"sql_trigger_value",
"sql_table_name",
"sql_distinct_key",
"sql_start",
"sql_always_having",
"sql_always_where",
"sql_trigger",
"sql_foreign_key",
"sql_where",
"sql_end",
"sql_create",
"sql_latitude",
"sql_longitude",
"sql_step",
"sql_on",
"sql",
)
# These are keys that the serializer should quote the value of (e.g. `label: "Label"`).
# An example of an unquoted literal would be `hidden: no`.
QUOTED_LITERAL_KEYS: Tuple[str, ...] = (
"label",
"view_label",
"group_label",
"group_item_label",
"suggest_persist_for",
"default_value",
"direction",
"value_format",
"name",
"url",
"icon_url",
"form_url",
"default",
"tags",
"value",
"description",
"sortkeys",
"indexes",
"partition_keys",
"connection",
"include",
"max_cache_age",
"allowed_values",
"timezone",
"persist_for",
"cluster_keys",
"distribution",
"extents_json_url",
"feature_key",
"file",
"property_key",
"property_label_key",
"else",
)
# These are keys for fields in Looker that have a "name" attribute. Since lkml uses the
# key `name` to represent the name of the field (e.g. for `dimension: dimension_name {`,
# the `name` key would hold the value `dimension_name`.)
KEYS_WITH_NAME_FIELDS: Tuple[str, ...] = (
"user_attribute_param",
"param",
"form_param",
"option",
)
CHARACTER_TO_TOKEN: Dict[str, Type[tokens.Token]] = {
"\0": tokens.StreamEndToken,
"{": tokens.BlockStartToken,
"}": tokens.BlockEndToken,
"[": tokens.ListStartToken,
"]": tokens.ListEndToken,
",": tokens.CommaToken,
":": tokens.ValueToken,
";": tokens.ExpressionBlockEndToken,
}