Repository navigation
fix(function): parse numeric prefixes in CONV and BIN - #28430
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
435d38d to
1f210d7
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of exact head ac8bdf0 against base 84def69: no confirmed blocking regression found. COMMENT only, as requested for this self-authored PR.
Reviewed all 15 changed files, including the binder literal distinction, overload matcher, prefix parser/string executors, focused unit tests, embedded SQL test and changed BVT expectations.
The byte parser correctly separates empty input from nonempty/no-prefix input, accepts only ASCII leading whitespace and base-valid digits, stops at suffix/NUL/non-ASCII bytes, and performs checked fixed-width accumulation. I checked signed-source limits, negative unsigned wrap versus overflow-to-zero, positive saturation, output-base signed formatting, and invalid/NULL base handling. The selected overflow and literal-domain rules were cross-checked against MySQL 8.4 Item_func_conv::val_str. Existing numeric CONV dispatch and constant-base restrictions are unchanged; this review does not certify broader pre-existing numeric-CONV equivalence to MySQL.
BIN reserves the new overload for MySQL string families/unresolved parameters, while retaining the original numeric overload IDs and excluding the string candidate from numeric fallback matching. The binder explicitly distinguishes direct HEX/BIT numeric literals from ordinary binary-introduced strings before overload selection. Prepared values/NULLs still come through the existing parameter vector path; the added matcher test checks unresolved-parameter typing, but there is no new prepared-client execution test and I did not independently run that protocol matrix.
Both changed string loops short-circuit masked rows before decoding values, propagate NULLs and result-append allocation errors, and retain no borrowed input bytes. The parser has constant auxiliary storage, stops at provable overflow, and no longer allocates a big.Int for negative strings; leading whitespace/zero runs remain linear in supplied input size. Output is bounded by the 64-bit representation. No new goroutine, lock, retry, external I/O or long-lived cache is introduced. The issue test reuses the existing cluster fixture and closes rows/connection/database handles with an independent bounded database-cleanup context.
Independent validation: extracted the exact new parser/helpers into a temporary standard-library-only Go harness and checked 3,780 combinations across bases 2–36, both signs, signed/unsigned source bases and boundaries around 2^31/32/62/63/64/65/128 against an independent big.Int arithmetic oracle. Seven additional empty/sign/ASCII-whitespace/NUL/Unicode/100,000-zero cases passed. This proves the tested parser arithmetic and termination properties, not a full package or live MySQL differential run.
Exact-head MatrixOne ALL CI run 34295759779 completed successfully. The author also reports package tests, repeated/focused race tests and embedded SQL controls; those are distinguished from the independently run parser probe. No repository source changes and no CI polling.
…8430) ## Summary Closes matrixorigin#28392. Make `CONV()` and `BIN()` accept MySQL-compatible numeric prefixes for character inputs. A valid prefix is consumed until the first byte that is not a digit in the selected source base; an input with no usable prefix evaluates to zero, while `NULL` and the empty string retain their `NULL` behavior. ## Root cause - `CONV()` used an all-or-nothing string parser and rejected otherwise valid prefixes such as `123xyz`. - `BIN()` exposed only numeric overloads, so character inputs went through strict string-to-integer casting instead of the same prefix conversion semantics as `CONV(..., 10, 2)`. ## Implementation - Replaced strict character parsing for `CONV()` with a byte-oriented, single-pass prefix parser. - Added a character overload for `BIN()` while keeping the existing numeric overloads and their dispatch unchanged. - Preserved signs, source/destination base validation, signed output-base behavior, and MySQL-compatible overflow behavior. - Skips only ASCII SQL whitespace before the prefix. Non-ASCII bytes, NUL, and binary payload bytes are not silently reclassified as whitespace. - Uses a fixed-width `uint64` accumulator with checked multiplication/addition. It stops at the first invalid digit and saturates/clamps at the first provable overflow, without allocating a `big.Int` or copying each varlen input into a new string. - Keeps the `BIN()` type matcher allocation-free at planning time when reserving the string overload; numeric inputs continue to use the original typed fast paths. ## Correctness and unhappy paths covered - valid prefixes with trailing text; - no usable prefix, whitespace-only input, sign-only input, `NULL`, and empty strings; - positive and negative values, including unsigned overflow beyond `uint64`; - signed source bases and signed output bases; - bases 2 through 36, invalid digits, and invalid bases; - `CHAR`/`VARCHAR`/`TEXT` plus `BINARY`/`VARBINARY`/`BLOB` inputs; - binary values containing non-ASCII bytes or NUL before a digit; - masked rows in vector execution are short-circuited before input decoding; - numeric `BIN()`/`CONV()` overloads remain covered; - issue-level scalar and batch execution through an embedded MatrixOne cluster. ## Validation Passed locally on macOS with the repository CGo/native-library setup: ```text go test -mod=readonly -count=1 -timeout=240s ./pkg/sql/plan/function go test -mod=readonly -count=20 -timeout=240s ./pkg/sql/plan/function -run 'Test(Conv|Bin|ParseBase)' go test -race -mod=readonly -count=1 -timeout=240s ./pkg/sql/plan/function -run 'Test(Conv|Bin|ParseBase)' go test -mod=readonly -count=1 -timeout=6m ./pkg/tests/issues -run '^TestIssue28392ConvBinNumericPrefixes$' golangci-lint run -c .golangci.yml ./pkg/sql/plan/function ./pkg/tests/issues go vet -mod=readonly -vettool=/Users/xupeng/code/bin/molint ./pkg/sql/plan/function ./pkg/tests/issues license-eye -c .licenserc.yml header check git diff --check ``` All listed local checks passed. MySQL 8.4 controls also matched the documented prefix, sign, overflow, binary-whitespace, NUL, and base-36 cases. The failures on the previous PR head were unrelated to this function change: one Compose BVT had an existing `dtype/text_blob.sql` failure, the multi-CN BVT could not establish a CN connection during startup, and Coverage was a chained failure because the required BVT producer did not publish a profile. The updated head will run the repository CI again.
…8430) ## Summary Closes matrixorigin#28392. Make `CONV()` and `BIN()` accept MySQL-compatible numeric prefixes for character inputs. A valid prefix is consumed until the first byte that is not a digit in the selected source base; an input with no usable prefix evaluates to zero, while `NULL` and the empty string retain their `NULL` behavior. ## Root cause - `CONV()` used an all-or-nothing string parser and rejected otherwise valid prefixes such as `123xyz`. - `BIN()` exposed only numeric overloads, so character inputs went through strict string-to-integer casting instead of the same prefix conversion semantics as `CONV(..., 10, 2)`. ## Implementation - Replaced strict character parsing for `CONV()` with a byte-oriented, single-pass prefix parser. - Added a character overload for `BIN()` while keeping the existing numeric overloads and their dispatch unchanged. - Preserved signs, source/destination base validation, signed output-base behavior, and MySQL-compatible overflow behavior. - Skips only ASCII SQL whitespace before the prefix. Non-ASCII bytes, NUL, and binary payload bytes are not silently reclassified as whitespace. - Uses a fixed-width `uint64` accumulator with checked multiplication/addition. It stops at the first invalid digit and saturates/clamps at the first provable overflow, without allocating a `big.Int` or copying each varlen input into a new string. - Keeps the `BIN()` type matcher allocation-free at planning time when reserving the string overload; numeric inputs continue to use the original typed fast paths. ## Correctness and unhappy paths covered - valid prefixes with trailing text; - no usable prefix, whitespace-only input, sign-only input, `NULL`, and empty strings; - positive and negative values, including unsigned overflow beyond `uint64`; - signed source bases and signed output bases; - bases 2 through 36, invalid digits, and invalid bases; - `CHAR`/`VARCHAR`/`TEXT` plus `BINARY`/`VARBINARY`/`BLOB` inputs; - binary values containing non-ASCII bytes or NUL before a digit; - masked rows in vector execution are short-circuited before input decoding; - numeric `BIN()`/`CONV()` overloads remain covered; - issue-level scalar and batch execution through an embedded MatrixOne cluster. ## Validation Passed locally on macOS with the repository CGo/native-library setup: ```text go test -mod=readonly -count=1 -timeout=240s ./pkg/sql/plan/function go test -mod=readonly -count=20 -timeout=240s ./pkg/sql/plan/function -run 'Test(Conv|Bin|ParseBase)' go test -race -mod=readonly -count=1 -timeout=240s ./pkg/sql/plan/function -run 'Test(Conv|Bin|ParseBase)' go test -mod=readonly -count=1 -timeout=6m ./pkg/tests/issues -run '^TestIssue28392ConvBinNumericPrefixes$' golangci-lint run -c .golangci.yml ./pkg/sql/plan/function ./pkg/tests/issues go vet -mod=readonly -vettool=/Users/xupeng/code/bin/molint ./pkg/sql/plan/function ./pkg/tests/issues license-eye -c .licenserc.yml header check git diff --check ``` All listed local checks passed. MySQL 8.4 controls also matched the documented prefix, sign, overflow, binary-whitespace, NUL, and base-36 cases. The failures on the previous PR head were unrelated to this function change: one Compose BVT had an existing `dtype/text_blob.sql` failure, the multi-CN BVT could not establish a CN connection during startup, and Coverage was a chained failure because the required BVT producer did not publish a profile. The updated head will run the repository CI again.
…8430) ## Summary Closes matrixorigin#28392. Make `CONV()` and `BIN()` accept MySQL-compatible numeric prefixes for character inputs. A valid prefix is consumed until the first byte that is not a digit in the selected source base; an input with no usable prefix evaluates to zero, while `NULL` and the empty string retain their `NULL` behavior. ## Root cause - `CONV()` used an all-or-nothing string parser and rejected otherwise valid prefixes such as `123xyz`. - `BIN()` exposed only numeric overloads, so character inputs went through strict string-to-integer casting instead of the same prefix conversion semantics as `CONV(..., 10, 2)`. ## Implementation - Replaced strict character parsing for `CONV()` with a byte-oriented, single-pass prefix parser. - Added a character overload for `BIN()` while keeping the existing numeric overloads and their dispatch unchanged. - Preserved signs, source/destination base validation, signed output-base behavior, and MySQL-compatible overflow behavior. - Skips only ASCII SQL whitespace before the prefix. Non-ASCII bytes, NUL, and binary payload bytes are not silently reclassified as whitespace. - Uses a fixed-width `uint64` accumulator with checked multiplication/addition. It stops at the first invalid digit and saturates/clamps at the first provable overflow, without allocating a `big.Int` or copying each varlen input into a new string. - Keeps the `BIN()` type matcher allocation-free at planning time when reserving the string overload; numeric inputs continue to use the original typed fast paths. ## Correctness and unhappy paths covered - valid prefixes with trailing text; - no usable prefix, whitespace-only input, sign-only input, `NULL`, and empty strings; - positive and negative values, including unsigned overflow beyond `uint64`; - signed source bases and signed output bases; - bases 2 through 36, invalid digits, and invalid bases; - `CHAR`/`VARCHAR`/`TEXT` plus `BINARY`/`VARBINARY`/`BLOB` inputs; - binary values containing non-ASCII bytes or NUL before a digit; - masked rows in vector execution are short-circuited before input decoding; - numeric `BIN()`/`CONV()` overloads remain covered; - issue-level scalar and batch execution through an embedded MatrixOne cluster. ## Validation Passed locally on macOS with the repository CGo/native-library setup: ```text go test -mod=readonly -count=1 -timeout=240s ./pkg/sql/plan/function go test -mod=readonly -count=20 -timeout=240s ./pkg/sql/plan/function -run 'Test(Conv|Bin|ParseBase)' go test -race -mod=readonly -count=1 -timeout=240s ./pkg/sql/plan/function -run 'Test(Conv|Bin|ParseBase)' go test -mod=readonly -count=1 -timeout=6m ./pkg/tests/issues -run '^TestIssue28392ConvBinNumericPrefixes$' golangci-lint run -c .golangci.yml ./pkg/sql/plan/function ./pkg/tests/issues go vet -mod=readonly -vettool=/Users/xupeng/code/bin/molint ./pkg/sql/plan/function ./pkg/tests/issues license-eye -c .licenserc.yml header check git diff --check ``` All listed local checks passed. MySQL 8.4 controls also matched the documented prefix, sign, overflow, binary-whitespace, NUL, and base-36 cases. The failures on the previous PR head were unrelated to this function change: one Compose BVT had an existing `dtype/text_blob.sql` failure, the multi-CN BVT could not establish a CN connection during startup, and Coverage was a chained failure because the required BVT producer did not publish a profile. The updated head will run the repository CI again.
Summary
Closes #28392.
Make
CONV()andBIN()accept MySQL-compatible numeric prefixes for character inputs. A valid prefix is consumed until the first byte that is not a digit in the selected source base; an input with no usable prefix evaluates to zero, whileNULLand the empty string retain theirNULLbehavior.Root cause
CONV()used an all-or-nothing string parser and rejected otherwise valid prefixes such as123xyz.BIN()exposed only numeric overloads, so character inputs went through strict string-to-integer casting instead of the same prefix conversion semantics asCONV(..., 10, 2).Implementation
CONV()with a byte-oriented, single-pass prefix parser.BIN()while keeping the existing numeric overloads and their dispatch unchanged.uint64accumulator with checked multiplication/addition. It stops at the first invalid digit and saturates/clamps at the first provable overflow, without allocating abig.Intor copying each varlen input into a new string.BIN()type matcher allocation-free at planning time when reserving the string overload; numeric inputs continue to use the original typed fast paths.Correctness and unhappy paths covered
NULL, and empty strings;uint64;CHAR/VARCHAR/TEXTplusBINARY/VARBINARY/BLOBinputs;BIN()/CONV()overloads remain covered;Validation
Passed locally on macOS with the repository CGo/native-library setup:
All listed local checks passed. MySQL 8.4 controls also matched the documented prefix, sign, overflow, binary-whitespace, NUL, and base-36 cases.
The failures on the previous PR head were unrelated to this function change: one Compose BVT had an existing
dtype/text_blob.sqlfailure, the multi-CN BVT could not establish a CN connection during startup, and Coverage was a chained failure because the required BVT producer did not publish a profile. The updated head will run the repository CI again.