-
Notifications
You must be signed in to change notification settings - Fork 10
/
queries.py
209 lines (208 loc) · 3.72 KB
/
queries.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
GRAPHQL_QUERIES = {
"metrics": """
query GetMetrics($environmentId: BigInt!) {
metrics(environmentId: $environmentId) {
name
label
description
config {
meta
}
dimensions {
description
expr
isPartition
label
name
qualifiedName
queryableGranularities
type
}
entities {
description
expr
name
role
type
}
filter {
whereSqlTemplate
}
measures {
agg
aggTimeDimension
expr
name
}
queryableGranularities
requiresMetricTime
type
}
}
""",
"dimensions": """
query GetDimensions($environmentId: BigInt!, $metrics: [MetricInput!]!) {
dimensions(environmentId: $environmentId, metrics: $metrics) {
description
expr
isPartition
metadata {
fileSlice {
content
endLineNumber
filename
startLineNumber
}
repoFilePath
}
name
qualifiedName
type
typeParams {
timeGranularity
validityParams {
isEnd
isStart
}
}
}
}
""",
"dimension_values": """
mutation GetDimensionValues($environmentId: BigInt!, $groupBy: [GroupByInput!]!, $metrics: [MetricInput!]!) {
createDimensionValuesQuery(
environmentId: $environmentId
groupBy: $groupBy
metrics: $metrics
) {
queryId
}
}
""",
"metric_for_dimensions": """
query GetMetricsForDimensions($environmentId: BigInt!, $dimensions: [GroupByInput!]) {
metricsForDimensions(environmentId: $environmentId, dimensions: $dimensions) {
description
name
queryableGranularities
type
}
}
""",
"create_query": """
mutation CreateQuery({arguments}) {{
createQuery(
{kwargs}
) {{
queryId
}}
}}
""",
"get_results": """
query GetResults($environmentId: BigInt!, $queryId: String!) {
query(environmentId: $environmentId, queryId: $queryId) {
arrowResult
error
queryId
sql
status
}
}
""",
"queryable_granularities": """
query GetQueryableGranularities($environmentId: BigInt!, $metrics:[MetricInput!]!) {
queryableGranularities(environmentId: $environmentId, metrics: $metrics)
}
""",
"metrics_for_dimensions": """
query GetMetricsForDimensions($environmentId: BigInt!, $dimensions:[GroupByInput!]!) {
metricsForDimensions(environmentId: $environmentId, dimensions: $dimensions) {
description
name
queryableGranularities
type
filter {
whereSqlTemplate
}
}
}
""",
"saved_queries": """
query GetSavedQueries($environmentId: BigInt!) {
savedQueries(environmentId: $environmentId) {
description
label
name
queryParams {
groupBy {
grain
name
}
metrics {
name
}
where {
whereSqlTemplate
}
}
}
}
""",
"account": """
query Environment($environmentId: BigInt!, $first: Int!) {
environment(id: $environmentId) {
applied {
models(first: $first) {
edges {
node {
accountId
projectId
}
}
}
}
}
}
""",
}
JDBC_QUERIES = {
"metrics": """
select *
from {{
semantic_layer.metrics()
}}
""",
"dimensions": """
select *
from {{{{
semantic_layer.dimensions(
metrics={metrics}
)
}}}}
""",
"dimension_values": """
select *
from {{{{
semantic_layer.dimension_values(
metrics={metrics},
group_by='{dimension}'
)
}}}}
""",
"queryable_granularities": """
select *
from {{{{
semantic_layer.queryable_granularities(
metrics={metrics}
)
}}}}
""",
"metrics_for_dimensions": """
select *
from {{{{
semantic_layer.metrics_for_dimensions(
group_by={dimensions}
)
}}}}
""",
}