Mysql source
MySQLDBSource
Bases: DataSource
Source code in blue/data/sources/mysql_source.py
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 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 235 236 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 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 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | |
execute_query(query, database=None, collection=None, optional_properties={})
Execute a SQL query on a MySQL database and return the result as JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
SQL query to execute. |
required |
database
|
str
|
Name of the database to execute against. |
None
|
collection
|
str
|
Placeholder argument for consistency. |
None
|
optional_properties
|
dict
|
Optional flags such as commit. |
{}
|
Returns:
| Type | Description |
|---|---|
|
list[dict]: Query results as a list of JSON-compatible dictionaries. |
Source code in blue/data/sources/mysql_source.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
fetch_collection_stats(database, collection_name, entities, relations)
Collect basic statistics for a database collection (schema grouping).
Computes counts of entities (tables) and relations within the given collection for reporting or registry enrichment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
str
|
Name of the database the collection belongs to. |
required |
collection_name
|
str
|
Name of the collection. |
required |
entities
|
list
|
List of entity definitions (e.g., tables). |
required |
relations
|
list
|
List of relationships between entities. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dictionary containing counts of entities and relations. |
Source code in blue/data/sources/mysql_source.py
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 | |
fetch_database_collection_entities(database, collection)
Extract entity (table) and property (column) metadata from a MySQL database.
Queries information_schema.columns to gather table and column structure,
including enumeration values for ENUM data types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
str
|
Name of the database. |
required |
collection
|
str
|
Collection name (always 'public' for MySQL). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Mapping of entities (tables) to their properties and types. |
Source code in blue/data/sources/mysql_source.py
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 | |
fetch_database_collection_metadata(database, collection)
Placeholder for future collection-level metadata extraction in MySQL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
str
|
Name of the database. |
required |
collection
|
str
|
The placeholder collection name ("public"). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Currently empty. |
Source code in blue/data/sources/mysql_source.py
147 148 149 150 151 152 153 154 155 156 157 158 | |
fetch_database_collection_relations(database, collection)
Placeholder for relationship extraction between MySQL tables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
str
|
Database name. |
required |
collection
|
str
|
Collection name (always 'public'). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Currently empty. |
Source code in blue/data/sources/mysql_source.py
202 203 204 205 206 207 208 209 210 211 212 213 | |
fetch_database_collections(database)
Return a default 'public' collection for MySQL databases.
Since MySQL does not use named schemas (collections) like PostgreSQL, this method returns a single collection called 'public' for registry consistency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
str
|
Name of the database. |
required |
Returns:
| Type | Description |
|---|---|
|
list[str]: Always returns ['public']. |
Source code in blue/data/sources/mysql_source.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
fetch_database_metadata(database)
Fetch high-level metadata for a specific MySQL database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
str
|
Name of the database. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
currently empty. |
Source code in blue/data/sources/mysql_source.py
89 90 91 92 93 94 95 96 97 98 99 | |
fetch_database_schema(database)
Retrieve schema definition for a MySQL database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
str
|
Name of the database. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Schema definition, currently empty. |
Source code in blue/data/sources/mysql_source.py
101 102 103 104 105 106 107 108 109 110 111 | |
fetch_database_stats(database)
Collect size-related statistics for a given MySQL database.
Computes the total size (data + index) of all tables in the specified schema
using the information_schema.tables system view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
str
|
Name of the database (schema) to inspect. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
A JSON-safe dictionary containing database-level statistics such |
|
|
as total size in bytes. |
Source code in blue/data/sources/mysql_source.py
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 | |
fetch_databases()
Retrieve a list of available MySQL databases, excluding system schemas.
Executes SHOW DATABASES and filters out MySQL system databases like
information_schema, performance_schema, sys, and mysql.
Returns:
| Type | Description |
|---|---|
|
list[str]: List of user-defined databases. |
Source code in blue/data/sources/mysql_source.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
fetch_entity_stats(database, collection, entity)
Collect basic statistics for a single entity (table) in a MySQL database.
Executes a COUNT(*) query to determine the total number of rows.
The collection argument is ignored for MySQL sources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
str
|
Name of the database (schema) containing the entity. |
required |
collection
|
str
|
Unused for MySQL but included for interface consistency. |
required |
entity
|
str
|
Name of the table to analyze. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
A JSON-safe dictionary containing entity-level stats, such as |
|
|
row count. |
Source code in blue/data/sources/mysql_source.py
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 | |
fetch_metadata()
Fetch high-level metadata for the MySQL source connection.
Currently a placeholder method. Returns: dict: Currently returns an empty dictionary.
Source code in blue/data/sources/mysql_source.py
47 48 49 50 51 52 53 54 55 | |
fetch_property_stats(database, collection, table, property_name, sample_limit=10)
Fetch basic statistics for a specific column (property) in a MySQL table.
This method queries INFORMATION_SCHEMA.COLUMNS and the target table to
compute statistics such as counts, distinct values, nulls, sample values,
min/max (for numeric/date types), and most common values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
str
|
Name of the database to connect to. |
required |
collection
|
str
|
Schema name in MySQL (equivalent to database namespace). |
required |
table
|
str
|
The table name containing the property. |
required |
property_name
|
str
|
The column (property) name to analyze. |
required |
sample_limit
|
int
|
Maximum number of sample non-null values to retrieve. Defaults to 10. |
10
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
A dictionary containing the following statistics:
- count (int): Number of non-null values in the column.
- distinct_count (int): Number of distinct non-null values.
- null_count (int): Number of null values.
- sample_values (list): Up to |
Notes
- Min/max are computed only for numeric, date, timestamp, boolean, and enum types.
- "Most common values" are computed by grouping and counting occurrences,
since MySQL does not expose statistics like PostgreSQL's
pg_stats. - Returns an empty dict if the query fails.
Source code in blue/data/sources/mysql_source.py
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 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | |
fetch_schema()
Retrieve global schema metadata for the MySQL source.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Currently returns an empty dictionary. |
Source code in blue/data/sources/mysql_source.py
57 58 59 60 61 62 63 64 | |
fetch_source_stats()
Collect high-level metadata about the MySQL source connection.
Executes a simple query (e.g., SELECT version()) to verify connectivity
and retrieve basic version information.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
A dictionary containing source-level statistics such as version |
|
|
or error details if collection fails. |
Source code in blue/data/sources/mysql_source.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |