Utils Reference
sqldeps.utils
Utility functions for SQLDeps.
This module provides helper functions for finding SQL files, merging SQL profiles, and performing schema validation and comparison.
find_sql_files(folder_path, recursive=False, valid_extensions=None)
Find SQL files in a folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder_path
|
str | Path
|
Path to the folder |
required |
recursive
|
bool
|
Whether to search recursively |
False
|
valid_extensions
|
set[str] | None
|
Set of valid file extensions (default: {'sql'}) |
None
|
Returns:
| Type | Description |
|---|---|
list[Path]
|
List of file paths |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If folder doesn't exist |
NotADirectoryError
|
If path is not a directory |
ValueError
|
If no SQL files are found |
Source code in sqldeps/utils.py
merge_profiles(analyses)
Merges multiple SQLProfile objects into a single one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
analyses
|
list[SQLProfile]
|
List of SQLProfile objects to merge |
required |
Returns:
| Type | Description |
|---|---|
SQLProfile
|
A new SQLProfile with merged dependencies and outputs |
Source code in sqldeps/utils.py
merge_schemas(df_extracted_schema, df_db_schema)
Matches extracted SQL dependencies with the actual database schema.
Handles both exact schema matches and schema-agnostic matches. Expands wildcards ('*') to match all columns from the relevant table(s). Handles tables with no columns (None).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_extracted_schema
|
DataFrame
|
Extracted table-column dependencies |
required |
df_db_schema
|
DataFrame
|
Actual database schema information |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Merged schema with an |
DataFrame
|
the schema name matched exactly |
Source code in sqldeps/utils.py
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 | |
schema_diff(df_extracted_schema, df_db_schema, copy=True)
Checks if extracted schema entries exist in the database schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_extracted_schema
|
DataFrame
|
Extracted table-column dependencies |
required |
df_db_schema
|
DataFrame
|
Actual database schema information |
required |
copy
|
bool
|
Whether to create a copy of the input DataFrame |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The extracted schema with an added |