Runner
Module for Running BQuest Tests
BQConfigFileRunner
Class for Running BQConfigs
Source code in bquest/runner.py
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 |
|
run_config(start_date, end_date, source_table_definitions, path_to_config, result_table_definition=None, allow_partial_table_substitutions=False, templating_vars=None)
Runs a BQ configuration file
Source code in bquest/runner.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
BQConfigRunner
Bases: BaseRunner
Runs BQ configurations on custom data for testing
Source code in bquest/runner.py
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 |
|
run_config(start_date, end_date, source_table_definitions, substitutor, result_table_definition=None, templating_vars=None)
Runs a BQ configuration with custom table definitions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_date |
str
|
the start date (e.g. 20190301) |
required |
end_date |
str
|
the end date (e.g. 20190308) |
required |
source_table_definitions |
List[BQTableDefinition]
|
custom table definitions that replace the source tables of the BQ configuration |
required |
substitutor |
BQConfigSubstitutor
|
a substitutor for BQ configurations |
required |
result_table_definition |
Optional[BQTableDefinition]
|
optional result table definition used for creating an empty result table |
None
|
templating_vars |
Optional[Dict[str, str]]
|
variables that are inserted into the given bq configuration |
None
|
Returns: the contents of the results table
Source code in bquest/runner.py
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 |
|
BQConfigSubstitutor
Substitutes parameters inside a BQ configuration
Source code in bquest/runner.py
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 |
|
substitute(start_date, end_date, feature_table_name, test_tables)
Substitutes a wide array of parameters inside a BQ configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_date |
str
|
the start date |
required |
end_date |
str
|
the end date |
required |
feature_table_name |
BQTable
|
the test table where the results will be stored |
required |
test_tables |
List[BQTable]
|
test tables that replace the original source tables |
required |
Returns:
Name | Type | Description |
---|---|---|
Dict |
Dict[str, Any]
|
a new BQ configuration where parameters have been substituted. |
Source code in bquest/runner.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
BaseRunner
Base class for runners
Source code in bquest/runner.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
SQLFileRunner
Class for running SQLFiles.
Source code in bquest/runner.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
__init__(sql_runner, base_path)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sql_runner |
SQLRunner
|
SQLRunner used to execute SQL config |
required |
base_path |
str
|
base path where SQL config is looked for |
required |
Source code in bquest/runner.py
240 241 242 243 244 245 246 247 248 |
|
run(path_to_sql, source_table_definitions, substitutions=None, string_replacements=None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_to_sql |
str
|
relative path to SQL config file based on base path |
required |
source_table_definitions |
List[BQTableDefinition]
|
source table definitions |
required |
substitutions |
Optional[Dict[str, str]]
|
substitutions for SQL query |
None
|
string_replacements |
Optional[Dict[str, str]]
|
entire string replacements for the query, substitutions are placed before |
None
|
Returns:
Source code in bquest/runner.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
SQLRunner
Bases: BaseRunner
Runs SQL queries on custom data for testing
Source code in bquest/runner.py
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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
__init__(bq_client, dataset='bquest', clean_up=True)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bq_client |
Client
|
BigQuery client used for interaction with BigQuery |
required |
dataset |
str
|
dataset which will be used for testing |
'bquest'
|
clean_up |
Optional[bool]
|
boolean if tables should be cleaned up |
True
|
Source code in bquest/runner.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
run(sql, source_table_definitions, substitutions=None, string_replacements=None, result_table_definition=None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sql |
str
|
SQL query that is being executed in BigQuery |
required |
source_table_definitions |
List[BQTableDefinition]
|
source table definitions, list of BQTableDefinition |
required |
substitutions |
Optional[Dict[str, str]]
|
substitutions for the given query |
None
|
string_replacements |
Optional[Dict[str, str]]
|
entire string replacements for the query, substitutions are placed before |
None
|
result_table_definition |
Optional[BQTableDefinition]
|
result table definition |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
pandas DataFrame of result table |
Source code in bquest/runner.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|