Skip to content

fix: cap SQL Server random row batch size to avoid parameter limit (#1835) - #1863

Merged
nj1973 merged 4 commits into
GoogleCloudPlatform:developfrom
reginaldalfret:fix/data-validator-correctness
Nov 3, 2026
Merged

nj1973 merged 4 commits into
GoogleCloudPlatform:developfrom
reginaldalfret:fix/data-validator-correctness

Conversation

@reginaldalfret

Copy link
Copy Markdown
Contributor

Description of changes

When validating tables with random-row filter against SQL Server (either as source or target), random_row_batch_size default or configured values (e.g. 10000) cause SQL Server queries to fail with pyodbc.Error (SQLSTATE 07002 / parameter limit) or similar driver errors because SQL Server has a maximum parameter limit of 2,100 bound parameters per query.

This change:

  1. Detects when either source_client.name == "mssql" or target_client.name == "mssql".
  2. Calculates the maximum allowable batch size as max(1, 2000 // len(source_pk_columns)) to account for composite primary keys while staying strictly below the 2,100 parameter limit.
  3. Caches and caps random_row_batch_size to that safe limit if the configured batch size exceeds it, and issues an informative warning log.
  4. Adds unit regression test coverage in tests/unit/test_data_validation.py for both single and composite primary keys with MSSQL source/target.

Issues to be closed

Closes #1835

Checklist

  • I have followed the CONTRIBUTING Guide.
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated any relevant documentation to reflect my changes, if applicable
  • I have added unit and/or integration tests relevant to my change as needed
  • I have already checked locally that all unit tests and linting are passing (use the tests/local_check.sh script)
  • I have manually executed end-to-end testing (E2E) with the affected databases/engines

@nj1973
nj1973 self-requested a review October 26, 2026 12:49

@nj1973 nj1973 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the contribution, I think we just need a tweak.

Also, remember to run black on your code using the version specified in nox.py.

Comment thread data_validation/data_validation.py Resolved
@reginaldalfret

Copy link
Copy Markdown
Contributor Author

@nj1973 Thanks for the feedback! I have updated the implementation:

  1. Moved the capping logic into a dedicated helper check_mssql_random_row_batch_size() in data_validation/config_manager.py.
  2. In ConfigManager.random_row_batch_size(), when use_random_rows() is true and SQL Server is the source or target, the batch size is capped and self._config[CONFIG_RANDOM_ROW_BATCH_SIZE] is mutated in place so result handlers (get_random_row_batch_size()) and config generation output reflect the updated batch size.
  3. Added unit tests in ests/unit/test_config_manager.py verifying both the helper logic and the mutation of self._config.
  4. Formatted code with �lack==26.5.1 per
    oxfile.py and verified lake8 clean.

@nj1973

nj1973 commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

/gcbrun

… size capping

Update SQL Server section in limitations.md to state that random row batch size is automatically capped to avoid exceeding the 2,100 query parameter limit, and that the effective batch size is reflected in validation results. Also add boundary and disabled-state unit tests for ConfigManager random row batch size.

Signed-off-by: reginaldalfret <[email protected]>
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Oct 29, 2026
@reginaldalfret

Copy link
Copy Markdown
Contributor Author

@nj1973 I have updated \docs/limitations.md\ as requested to document the automatic behavior:

  • States that SQL Server has a 2,100 query parameter limit affecting --use-random-row\ validation.
  • Notes that DVT automatically caps --random-row-batch-size\ to \2000 // number_of_primary_keys\ (minimum 1) when SQL Server is either the source or target.
  • Notes that the effective batch size is logged, used during query execution, and reflected in the validation results.

Additionally, added boundary and disabled-state unit tests in \ ests/unit/test_config_manager.py\ and formatted with \�lack==26.5.1\ per
oxfile.py. All unit tests pass.

@nj1973

nj1973 commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

/gcbrun

@nj1973 nj1973 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@nj1973
nj1973 merged commit 0b676f7 into GoogleCloudPlatform:develop Nov 3, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQL Server random-row validation fails with batch_size over 2000

2 participants