Skip to content

FEAT: BCP Python APIs #60

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 5 commits into
base: main
Choose a base branch
from
Open

FEAT: BCP Python APIs #60

wants to merge 5 commits into from

Conversation

jahnvi480
Copy link
Contributor

This pull request introduces significant enhancements to the bulk copy functionality in the mssql_python package, including the addition of a new BCPClient class, improved validation logic in BCPOptions, and the introduction of BCPControlOptions for managing BCP control settings. These changes aim to provide better error handling, flexibility, and usability for bulk copy operations.

New Features and Enhancements:

Bulk Copy Client:

  • Added BCPClient class in mssql_python/bcp_main.py to encapsulate bulk copy operations. It includes robust logging, validation, and integration with BCPWrapper for executing BCP operations.

Validation Improvements:

  • Enhanced validation logic in BCPOptions to ensure correctness of parameters, including stricter checks for direction, data_file, error_file, and other attributes. Added support for new options such as bulk_mode, hints, and code_page.

Constants for BCP Control:

  • Introduced BCPControlOptions in mssql_python/constants.py, providing a centralized enum for BCP control settings like batch size, max errors, and row terminators. This improves clarity and reduces hardcoding of control options.

Code Refinements:

Default Values:

  • Updated ColumnFormat attributes (prefix_len and data_len) to have default values of 0, and added a new optional col_name attribute for column definitions.

Type Adjustments:

  • Replaced Literal types with str and Union in BCPOptions to improve flexibility and compatibility with dynamically validated values.

@Copilot Copilot AI review requested due to automatic review settings May 28, 2025 10:06
Copy link
Contributor

@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 enhancements to the bulk copy functionality in the mssql_python package by adding a new BCPClient, improving validation in BCPOptions, and centralizing BCP control option constants.

  • Introduces a new BCPClient class with detailed logging and BCP operation handling.
  • Enhances validation logic in BCPOptions with additional checks and supports new parameters (bulk_mode, hints, code_page).
  • Adds BCPControlOptions as an enum to centralize and standardize BCP control settings.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
mssql_python/constants.py Added BCPControlOptions enum for BCP control settings.
mssql_python/bcp_options.py Updated types, default values, and validation logic for BCP options.
mssql_python/bcp_main.py Introduced BCPClient class to encapsulate bulk copy operations.
Comments suppressed due to low confidence (1)

mssql_python/bcp_options.py:104

  • [nitpick] There is a duplicated check for data_file being non-empty for 'in' or 'out' directions. Consider consolidating these validations to eliminate redundancy.
if self.direction in ["in", "out"]: ... if not self.data_file:

@sumitmsft
Copy link
Contributor

This is a duplicate of https://github.com/microsoft/mssql-python/pull/57/files which was reviewed earlier. Jahnvi has already resolved the comments and made necessary changes. We are approving this PR.

@sumitmsft sumitmsft closed this May 28, 2025
@sumitmsft sumitmsft reopened this May 28, 2025
sumitmsft
sumitmsft previously approved these changes May 28, 2025
bewithgaurav
bewithgaurav previously approved these changes May 29, 2025
@gargsaumya gargsaumya self-requested a review June 2, 2025 09:30
gargsaumya
gargsaumya previously approved these changes Jun 2, 2025
@jahnvi480 jahnvi480 dismissed stale reviews from gargsaumya, bewithgaurav, and sumitmsft via 0a6c1cd June 4, 2025 05:50
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.

4 participants