Refresh Model
refresh.py
is the main file to handle all the components of refreshing your model.
You have may ways to interact with refreshing.
Example
import pytabular as p
model = p.Tabular(CONNECTION_STR)
model.refresh('Table Name')
- Refresh all tables with 'fact' in the name.
RefreshCheck
Bases: ABC
RefreshCheck
is an test you run after your refreshes.
It will run the given function
before and after refreshes,
then run the assertion of before and after.
The default given in a refresh is to check row count.
It will check row count before, and row count after.
Then fail if row count after is zero.
Source code in pytabular/refresh.py
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 |
|
name
deletable
property
writable
Get your custom name of refresh check.
function
deletable
property
writable
Get the function that is used to run a pre and post check.
pre
deletable
property
writable
Get the pre value that is the result from the pre refresh check.
post
deletable
property
writable
Get the post value that is the result from the post refresh check.
assertion
deletable
property
writable
Get the assertion that is the result from the post refresh check.
__init__(name, function, assertion=None)
Sets the necessary components to perform a refresh check.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of refresh check. |
required |
function |
Callable
|
Function to run on pre and post checks. For example, a dax query. readme has examples of this. |
required |
assertion |
Callable
|
A function that can be run.
Supply the assertion function with 2 arguments. The first one
for your 'pre' results from the |
None
|
Source code in pytabular/refresh.py
__repr__()
pre_check()
post_check()
assertion_run()
Runs the given self.assertion function with self.pre
and self.post
.
So, self.assertion_run(self.pre, self.post)
.
Source code in pytabular/refresh.py
RefreshCheckCollection
Groups together your RefreshChecks
.
Used to handle multiple types of checks in a single refresh.
Source code in pytabular/refresh.py
__init__(refresh_checks=[])
Init to supply RefreshChecks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
refresh_checks |
RefreshCheck
|
Defaults to []. |
[]
|
__iter__()
add_refresh_check(refresh_check)
Add a RefreshCheck.
Supply the RefreshCheck
to add.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
refresh_check |
RefreshCheck
|
|
required |
remove_refresh_check(refresh_check)
Remove a RefreshCheck.
Supply the RefreshCheck
to remove.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
refresh_check |
RefreshCheck
|
|
required |
PyRefresh
PyRefresh Class to handle refreshes of model.
Source code in pytabular/refresh.py
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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
|
__init__(model, object, trace=RefreshTrace, refresh_checks=RefreshCheckCollection(), default_row_count_check=True, refresh_type=RefreshType.Full)
Init when a refresh is requested.
Runs through requested tables and partitions to make sure they are in model. Then will run pre checks on the requested objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Tabular
|
Tabular model. |
required |
object |
Union[str, PyTable, PyPartition, Dict[str, Any]]
|
The objects
that you are wanting to refresh. Can be a |
required |
trace |
BaseTrace
|
Defaults to RefreshTrace. |
RefreshTrace
|
refresh_checks |
RefreshCheckCollection
|
Defaults to RefreshCheckCollection(). |
RefreshCheckCollection()
|
default_row_count_check |
bool
|
Defaults to True. |
True
|
refresh_type |
RefreshType
|
Defaults to RefreshType.Full. |
Full
|
Source code in pytabular/refresh.py
run()
When ready, execute to start the refresh process.
First checks if connected and reconnects if needed.
Then starts the trace if needed.
Next will execute save_changes()
and run the post checks after that.
Last will return a pd.DataFrame
of refresh results.