Skip to content

Commit 4ca4969

Browse files
committed
review comments
1 parent f7a6606 commit 4ca4969

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

‎mssql_python/cursor.py‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,23 +2451,17 @@ def nextset(self) -> Union[bool, None]:
24512451
)
24522452
return True
24532453

2454-
def _bulkcopy(
2455-
self,
2456-
table_name: str,
2457-
data,
2458-
batch_size: int = 1000,
2459-
timeout: int = 30,
2460-
column_mappings: list = None,
2461-
):
2454+
def _bulkcopy(self, table_name: str, data, **kwargs):
24622455
"""
24632456
Perform bulk copy operation using Rust-based implementation.
24642457
24652458
Args:
24662459
table_name: Target table name
24672460
data: Iterable of tuples/lists containing row data
2468-
batch_size: Number of rows per batch (default: 1000)
2469-
timeout: Timeout in seconds (default: 30)
2470-
column_mappings: List of tuples mapping source column index to target column name
2461+
**kwargs: Additional options passed to the Rust bulkcopy method
2462+
- batch_size: Number of rows per batch (default: 1000)
2463+
- timeout: Timeout in seconds (default: 30)
2464+
- column_mappings: List of tuples mapping source column index to target column name
24712465
24722466
Returns:
24732467
Dictionary with rows_copied, batch_count, and elapsed_time
@@ -2488,6 +2482,11 @@ def _bulkcopy(
24882482
# Validate inputs
24892483
if not table_name or not isinstance(table_name, str):
24902484
raise ValueError("table_name must be a non-empty string")
2485+
2486+
# Extract and validate kwargs with defaults
2487+
batch_size = kwargs.get("batch_size", 1000)
2488+
timeout = kwargs.get("timeout", 30)
2489+
24912490
if batch_size <= 0:
24922491
raise ValueError(f"batch_size must be positive, got {batch_size}")
24932492
if timeout <= 0:
@@ -2526,10 +2525,6 @@ def _bulkcopy(
25262525
rust_connection = mssql_py_core.PyCoreConnection(context)
25272526
rust_cursor = rust_connection.cursor()
25282527

2529-
kwargs = {"batch_size": batch_size, "timeout": timeout}
2530-
if column_mappings:
2531-
kwargs["column_mappings"] = column_mappings
2532-
25332528
logger.debug("Bulk copy to '%s' - batch_size=%d", table_name, batch_size)
25342529
result = rust_cursor.bulkcopy(table_name, iter(data), kwargs=kwargs)
25352530

0 commit comments

Comments
 (0)