/var/opt/nydus/ops/mysql/ai/utils/__pycache__
Edit: /var/opt/nydus/ops/mysql/ai/utils/__pycache__/utils.cpython-312.pyc (19922B)
NjE
d Z ddlZddlZddlZddlZddlZddlmZ ddlm Z m
Z
mZmZm
Z
mZmZmZ ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ d Zd
Zddd
dddZd Z dee! de!fdZ"ededee#e$e%e%f fd Z& d1dede%deddfdZ'de%fdZ(d2de
e%ge)f de*de%fdZ+de dee%e
e f fdZ,dedejZ fd Z.ded!e%d"e%dejZ fd#Z/ded!e%d"e%de)fd$Z0ded!e%d"e%ddfd%Z1 d1ded!e%d"e%d&ejZ d'ee%e%f ddfd(Z2ded!e%d&ejZ dee%e%f fd)Z3d*e%de%fd+Z4dede%fd,Z5ded!e%d"e%de)fd-Z6 d3d.eeejZ ejn ejp f d/e%deejZ fd0Z9y)4a. General utilities for AI features in MySQL Connector/Python.
Includes helpers for:
- defensive dict copying
- temporary table lifecycle management
- SQL execution and result conversions
- DataFrame to/from SQL table utilities
- schema/table/column name validation
- array-like to DataFrame conversion
N)contextmanager)AnyCallableDictIteratorListOptionalTupleUnion)atomic_transaction)MySQLConnectionAbstract)MySQLCursorAbstract)ParamsSequenceOrDictTypemysql_ai BIGINTDOUBLELONGTEXTBOOLEANDATETIME)int64float64objectboolzdatetime64[ns]optionsreturnc 4 | i S t j | S )z
Make a defensive copy of a dictionary, or return an empty dict if None.
Args:
options: param dict or None
Returns:
dict
)copydeepcopy)r s E/opt/nydus/tmp/pip-target-a90h98xg/lib/python/mysql/ai/utils/utils.py copy_dictr! I s ==!!
db_connectionc # K g } | t | 5 }|D ] \ }}t ||| ddd y# 1 sw Y yxY w# t | 5 }|D ] \ }}t ||| ddd w # 1 sw Y w xY wxY ww)a
Context manager to track and automatically clean up temporary SQL tables.
Args:
db_connection: Database connection object used to create and delete tables.
Returns:
None
Raises:
DatabaseError:
If a database connection issue occurs.
If an operational error occurs during execution.
Yields:
temporary_tables: List of (schema_name, table_name) tuples created during the
context. All tables in this list are deleted on context exit.
N)r delete_sql_table)r# temporary_tablescursorschema_name
table_names r temporary_sql_tablesr* Y s{ , /1B
.&+;'Z jA ,< /
.
.
.&+;'Z jA ,< /
.
.sF B A B 7 B A B A=A1( A=1A:6A==B r' queryparamsc 0 | j ||xs d y)aB
Execute an SQL query with optional parameters using the given cursor.
Args:
cursor: MySQLCursorAbstract object to execute the query.
query: SQL query string to execute.
params: Optional sequence or dict providing parameters for the query.
Raises:
DatabaseError:
If the provided SQL query/params are invalid
If the query is valid but the sql raises as an exception
If a database connection issue occurs.
If an operational error occurs during execution.
Returns:
None
N)execute)r' r+ r, s r execute_sqlr0 x s * NN5&,B'r" c v t j } dj t j | t
S )z
Generate a random uppercase string of fixed length for table names.
Returns:
Random string of length RANDOM_TABLE_NAME_LENGTH.
)k)stringascii_uppercasejoinrandomchoicesRANDOM_TABLE_NAME_LENGTH)char_sets r _get_namer; s* %%H
776>>(.FGHHr" condition max_callsc d t | D ] } | t x} s|c S t d )a
Generate a random string name that satisfies a given condition.
Args:
condition: Callable that takes a generated name and returns True if it is valid.
max_calls: Maximum number of attempts before giving up (default 100).
Returns:
A random string that fulfills the provided condition.
Raises:
RuntimeError: If the maximum number of attempts is reached without success.
z