Skip to content

FEAT: Bulk Copy #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

FEAT: Bulk Copy #73

wants to merge 3 commits into from

Conversation

jahnvi480
Copy link
Contributor

This pull request introduces significant enhancements to the Bulk Copy Program (BCP) functionality in the mssql_python library, including the addition of new classes, methods, and configuration options to support bulk data operations. It also includes updates to data files and format files to facilitate testing and integration.

Enhancements to BCP functionality:

  • New BCPClient class for bulk copy operations:

    • Added BCPClient in mssql_python/bcp_main.py to manage bulk copy operations using the BCP utility. This includes initialization, validation, and execution of BCP operations with detailed logging.
    • Integrated support for format files and column definitions for flexible data handling.
  • Updates to BCPOptions and ColumnFormat classes:

    • Enhanced ColumnFormat with new attributes such as user_data_type and col_name, along with default values for prefix_len and data_len.
    • Added constants for allowed directions (in, out, format, query) and file modes (native, char, unicode) in BCPOptions.

Integration and usage:

  • New main_bcp.py script:

    • Introduced a standalone script to demonstrate BCP functionality, including database connection, data import, and logging for operational insights.
  • Initialization of BCP components:

    • Updated mssql_python/__init__.py to include imports for BCPClient, BCPOptions, and ColumnFormat.

Data and format file updates:

  • Employee data file (EmployeeFullNames.bcp):

    • Added sample employee data for testing BCP operations.
  • Format files:

    • Added EmployeeFullNames.fmt and TestBCP.fmt to define data structure and encoding for bulk operations. [1] [2]
  • Unicode data file (data_unicode.csv):

    • Added sample Unicode data for testing character encoding during BCP operations.

@Copilot Copilot AI review requested due to automatic review settings June 11, 2025 04:36
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces new Bulk Copy functionality in the mssql_python library by implementing a new BCPClient class and enhancing BCPOptions and ColumnFormat to support flexible bulk copy operations. Key changes include:

  • Addition of the BCPClient class and associated pybind11 bindings in C++ for managing BCP operations.
  • Updates to BCPOptions and ColumnFormat with extra validations and support for new configuration parameters.
  • New integration scripts and sample data/format files to facilitate testing of bulk copy operations.

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_007_bcpOptions.py Unit tests to validate the new BCPOptions and ColumnFormat behavior.
mssql_python/pybind/ddbc_bindings.{h,cpp} Updated function pointer loading and inclusion of new BCP API pointers.
mssql_python/pybind/connection/connection.cpp BCP-specific connection attribute handling added.
mssql_python/pybind/bcp/{bcp_wrapper.h,cpp} New BCPWrapper implementation with methods for initializing and executing BCP.
mssql_python/CMakeLists.txt Updated to include BCPWrapper sources and header directories.
mssql_python/constants.py Added new enum for BCP control options.
mssql_python/bcp_options.py Enhanced validation and options for bulk copy configurations.
mssql_python/bcp_main.py New BCPClient class implementation that wraps BCPWrapper operations.
main_bcp.py Standalone example script demonstrating the BCP functionality.
Data and format files Added sample BCP data (.bcp), Unicode data file, and format files (.fmt).
Comments suppressed due to low confidence (1)

mssql_python/pybind/bcp/bcp_wrapper.cpp:197

  • The two overloads of bcp_control show inconsistent error handling—one throws an exception when in an invalid state while the other returns SQL_ERROR. Consider adopting a consistent error handling strategy across both overloads.
if (!_bcp_initialized || _bcp_finished) {

#include <stdexcept>
#include <unordered_map>
#include <string> // For std::to_string, std::string
#include <iostream> // Added for std::cout
Copy link
Preview

Copilot AI Jun 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider replacing raw std::cout debug prints with a dedicated logging framework to ensure consistent logging behavior in production code.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant