Skip to content

fix(teradata): fix off-by-one in split_dataframe that sent empty exec… - #694

Merged
awalker4 merged 2 commits into
mainfrom
maddock-teradata-off-by-one-clean
Apr 17, 2026
Merged

awalker4 merged 2 commits into
mainfrom
maddock-teradata-off-by-one-clean

Conversation

@cmscmadd

@cmscmadd cmscmadd commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor

When a document had exactly N * batch_size elements the last chunk was empty - this causes teradatasql to send a zero-row parameterized batch to the Teradata server which returned Error 3939 (parameter count mismatch).

Replace with range(0, len(df), chunk_size) which never produces an empty slice.


Note

Low Risk
Small, well-scoped change to a shared batching utility plus targeted unit tests; primary risk is subtle behavior change for callers that (incorrectly) relied on receiving empty chunks.

Overview
Fixes an off-by-one bug in split_dataframe so it no longer yields an empty trailing DataFrame slice when len(df) is an exact multiple of chunk_size, preventing zero-row executemany batches that triggered Teradata Error 3939 (and benefiting all connectors that share this helper).

Adds Teradata-focused regression tests covering exact-multiple chunking cases, and bumps the package version/changelog entry to 1.4.26b1.

Reviewed by Cursor Bugbot for commit a4e839f. Bugbot is set up for automated code reviews on this repo. Configure here.

…utemany batches

The old formula (num_chunks = len(df) // chunk_size + 1) always appended one
extra iteration. When a document had exactly N * batch_size elements the last
chunk was empty, causing teradatasql to send a zero-row parameterized batch to
the Teradata server which returned Error 3939 (parameter count mismatch).

Replace with range(0, len(df), chunk_size) which never produces an empty slice.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

@potter-potter potter-potter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LG

assert uploader.upload_config.table_name == "my-table"


# --- Regression tests for Error 3939 (parameter count mismatch) ---

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this a hallucinated bug ID? Might be better to just explain the failure mode being tested

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, it's already doing that below haha. Maybe just drop this comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

3939 is the exception number from tera

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

parameter count mismatch is the error

@awalker4
awalker4 merged commit e58426f into main Apr 17, 2026
46 of 47 checks passed
@awalker4
awalker4 deleted the maddock-teradata-off-by-one-clean branch April 17, 2026 21:07
awalker4 added a commit that referenced this pull request Nov 19, 2026
…n empty batch (#832)

## What

`generator_batching_wbytes` (used by the Elasticsearch, OpenSearch and
Pinecone uploaders) had two batching bugs:

```python
generator_batching_wbytes(items)                                  # before: no batches   after: [items]
generator_batching_wbytes([big, small], batch_size_limit_bytes=20) # before: [[], [big], [small]]   after: [[big], [small]]
```

## Why

The `return iterable` shortcut for "no limits" is inside a generator, so
it ends iteration without yielding anything. An Elasticsearch or
OpenSearch upload with `batch_size_bytes=0` therefore sent no documents
and reported no error. Separately, when the first item alone exceeded
the byte limit, the still-empty batch was yielded before it — the same
empty-batch problem #694 fixed in `split_dataframe`.

The shortcut is removed, so with no limits everything goes in one batch,
and a batch is only closed once it has items. Behaviour with limits is
otherwise unchanged; an oversized item still gets a batch of its own.

## Validation

Two new tests in `test/unit/utils/test_data_prep.py`; both fail on main.
`pytest test/unit --ignore test/unit/unstructured`: 1941 → 1943 passed,
same 69 skipped. `ruff check .` and `ruff format --check` pass. Adds a
CHANGELOG entry and bumps the version to 1.11.27.

Co-authored-by: Austin Walker <[email protected]>

This branch was previously deployed

1 inactive deployment
ci — a4e839f6 Deployed Apr 17, 2026 by cmscmadd via test_install_cli (3.12) #3658
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.

3 participants