Skip to content

Convert non-string arguments of LEFT and RIGHT to text - #4296

Open
sarankumar1325 wants to merge 1 commit into
dolthub:mainfrom
sarankumar1325:fix-left-right-non-string
Open

sarankumar1325 wants to merge 1 commit into
dolthub:mainfrom
sarankumar1325:fix-left-right-non-string

Conversation

@sarankumar1325

Copy link
Copy Markdown

Fixes dolthub/dolt#12611
Fixes dolthub/dolt#12646

LEFT() and RIGHT() only accepted string and binary first arguments. Anything else failed with invalid type: int8, invalid type: *types.LazyJSONDocument and so on, where MySQL converts the argument to text first (LEFT(105, 2) is 10, RIGHT(j, 2) on {"a": 1} is 1}).

The default case now converts the value with types.ConvertToString (the same conversion JSON_SEARCH and other functions here use) instead of returning ErrInvalidType. String, binary and NULL handling is unchanged. A value that can't be converted still returns an error.

Tests:

  • TestLeft and TestRight had a bad string type case that expected an error for the integer 1. I replaced it with an integer case (105, 2 gives 10 and 05) and an unconvertible-type case (struct{}{}) that still errors.
  • New left and right convert non-string arguments to text script in json_scripts.go: integer and decimal literals, TINYINT and INT columns, a JSON column, and JSON_OBJECT(). It fails without the change (invalid type: int8).
  • enginetest and ./sql/... pass, except TestRegex and TestRegexpReplaceWithFlags, which fail in the pure-Go regex build I ran with (-tags gms_pure_go, no ICU here). The change doesn't touch regex code.

AI assistance: written with the help of an AI coding assistant (Grok Bot). I reviewed the diff and ran the tests above.

LEFT and RIGHT only accepted string and binary arguments, so an integer
or JSON first argument failed with 'invalid type: int8' or 'invalid type:
*types.LazyJSONDocument'. MySQL converts the argument to text first.
Convert any other value with ConvertToString.

Refs dolthub/dolt#12611
Refs dolthub/dolt#12646

Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-12-05T17:06:51.077927Z
We couldn’t complete this review. Comment @codex review to try again.
f90d694 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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

Labels

None yet

Projects

None yet

1 participant