Utils
Utils for big expectations
execute_query(query, duckdb_client, database_provider)
Execute a query, using bigquery_query() if the accessor is a BigQuery database.
This handles the limitation where BigQuery's Storage Read API cannot read views. When a BigQuery accessor is detected, the query is wrapped in bigquery_query() which uses the Jobs API instead.
Note: bigquery_query() only works for SELECT queries. Write operations (INSERT, CREATE, UPDATE, DELETE) use standard DuckDB execution with the accessor prefix.
Source code in src/koality/utils.py
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 | |
parse_date(date, offset_days=0)
Parses a date string which can be a relative terms like "today", "yesterday", or "tomorrow", actual dates, or relative dates like "today-2".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
str
|
The date string to be parsed. |
required |
offset_days
|
int
|
The number of days to be added/substracted. |
0
|
Source code in src/koality/utils.py
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 | |
to_set(value)
Converts the input string to a set. The special case of one single string is also covered. Duplicates are also removed and for deterministic behavior, the values are sorted.
It will, convert input as follows: - 1 -> {1} - True -> {True} - "toys" / '"toys"' -> {"toys"} - ("toys") / '("toys")' -> {"toys"} - ("toys", "shirt") / '("toys", "shirt")' -> {"shirt", "toys"} - ["toys"] -> {"toys"} - {"toys"} -> {"toys"}
Source code in src/koality/utils.py
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 | |