GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [sqllib] Fix binary substring boundary calculation for non-positive start index by Tyagiquamar · Pull Request #7831 · feldera/feldera

Conversation

@Tyagiquamar

@Tyagiquamar Tyagiquamar commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix the SQL standard boundary calculation in binary_substring3___ for non-positive starting offsets, fix 1-based indexing in binary_overlay4____, and add unit tests.

Fixes #7830.

Root Cause & Problem

In crates/sqllib/src/binary.rs:

  1. binary_substring3___(source, left, count) handles left < 1 by clamping start = 0 but leaving count unchanged. Under SQL 1-based substring semantics (such as in string.rs), the extraction window starts at index left with length count. Any part of the window preceding position 1 should be omitted, yielding an effective count of (count + left - 1).max(0). Because count was unadjusted, non-positive start values extracted more bytes than expected (or extracted prefix bytes when the entire window was non-positive).
  2. binary_overlay4____ invoked binary_substring3___(source.clone(), 0, position - 1) with 0 instead of 1, which previously succeeded only because left = 0 was clamped to 0 without adjusting count.
  3. Both binary_substring2__ and binary_substring3___ were consuming source.data and allocating via .into_iter().skip(...).take(...).collect(), which is inefficient compared to direct slice construction via ByteArray::new(&slice[start..end]).

Technical Solution

  1. In binary_substring3___, calculate the extracted count for left < 1 using (count.saturating_add(left).saturating_sub(1)).max(0) to prevent integer overflow while correctly clamping non-positive starting windows.
  2. Replace iterator-based collection with direct byte slicing on source.as_slice().
  3. In binary_overlay4____, pass 1 as the 1-based start position for the prefix substring.
  4. Add comprehensive unit test coverage in crates/sqllib/src/binary.rs testing standard 1-based offsets, non-positive starts (left = 0, left < 0), zero/negative count, edge-case integer extremes (i32::MIN, i32::MAX), and binary_overlay.

Test Plan

  • Run targeted unit tests in Rust 1.99 container: cargo test -p feldera-sqllib --lib binary:: (passed, 34 tests ok)
  • Run code formatting check: rustfmt --check crates/sqllib/src/binary.rs (passed with code 0)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mihaibudiu

mihaibudiu commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

This looks fine, but can you also please update the documentation for substring in binary.md?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mihaibudiu

mihaibudiu commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Also check string.md if it needs updates.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Tyagiquamar @mihaibudiu
[sqllib] Fix binary substring boundary calculation for non-positive s…
f5e27d7
…tart index

Fixes feldera#7830

Signed-off-by: Mihai Budiu <[email protected]>
@mihaibudiu
mihaibudiu force-pushed the fix-binary-substring-bounds branch from 39071ba to f5e27d7 Compare November 6, 2026 03:25
@mihaibudiu

mihaibudiu commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

I took the liberty to amend this commit adding documentation. Now I plan to merge it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mihaibudiu
mihaibudiu approved these changes Nov 6, 2026
View reviewed changes
@mihaibudiu
mihaibudiu added this pull request to the merge queue Nov 6, 2026
Merged via the queue into feldera:main with commit 206cf9f Nov 6, 2026
1 check passed

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mihaibudiu mihaibudiu mihaibudiu approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

fix(sqllib): fix binary substring boundary calculation for non-positive start index

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Tyagiquamar @mihaibudiu
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.