Skip to content

[3.0-dev] Backport function/window compatibility (Fixes #24185)#24194

Open
jiangxinmeng1 wants to merge 6 commits intomatrixorigin:3.0-devfrom
jiangxinmeng1:fix-issue-24185
Open

[3.0-dev] Backport function/window compatibility (Fixes #24185)#24194
jiangxinmeng1 wants to merge 6 commits intomatrixorigin:3.0-devfrom
jiangxinmeng1:fix-issue-24185

Conversation

@jiangxinmeng1
Copy link
Copy Markdown
Contributor

@jiangxinmeng1 jiangxinmeng1 commented Apr 24, 2026

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

fixes #24185

What this PR does / why we need it:

Notes on adaptation

  • CUME_DIST and PERCENT_RANK did not cherry-pick cleanly because main's
    pkg/sql/colexec/aggexec layer has been refactored substantially relative
    to 3.0-dev (different signatures for initAggResultWithFixedTypeResult,
    marshalToBytes, unmarshalFromBytes, plus new SaveIntermediateResult* /
    UnmarshalFromReader interface methods and an i64Slice type).
    These two executors were rewritten to follow 3.0-dev's existing
    singleWindowExec pattern ([][]int64 groups, 3-return marshalToBytes,
    2-arg unmarshalFromBytes, no streaming serialization). Algorithms match
    the originals exactly.

  • The ELT cherry-pick brought in a copy of func_binary_test.go from main
    containing tests for TimeFormat / TimestampDiffDateString / etc. that
    don't exist on 3.0-dev. Those test blocks were removed; the ELT-specific
    tests at the end of the file are preserved. Also added the ELT function
    id and overload registration that the cherry-pick didn't include.

Verification

go build ./...
go test -tags matrixone_test ./pkg/sql/colexec/aggexec/ \
                            ./pkg/sql/colexec/window/ \
                            ./pkg/sql/parsers/... \
                            ./pkg/sql/plan/function/

all pass.

Fixes #24185

gouhongshen and others added 4 commits April 24, 2026 14:02
Fix the `ELT()` function to be fully compatible with MySQL.

**Root Cause:**
`eltCheck` skipped casting for integer types other than `int64` (e.g. `int32`, `int16`, `bool`), but the `Elt` executor hardcodes `GenerateFunctionFixedTypeParameter[int64]`, causing a type mismatch panic when using `INT`/`SMALLINT`/`TINYINT` columns or `BOOL` values as the index argument.

**Fix:**
In `eltCheck`, explicitly handle all numeric types (`bool`, `integer`, `float`, `decimal`, `bit`) by always casting the first argument to `int64`. For other types (e.g. `varchar`), fall back to `tryToMatch`.

**Test Coverage:**
Updated BVT tests (52 SQL statements) covering:
- INT/SMALLINT/TINYINT/UNSIGNED column as index (was panic)
- BOOL index: `ELT(TRUE, ...)` / `ELT(FALSE, ...)`
- Float index with rounding: `ELT(1.9, ...)` → 2
- String index: `ELT('2', ...)`
- Negative/zero float index
- Table with NULL index rows
- Table with out-of-range index rows
- BINARY return type
- Expression as index
- ELT + FIELD complement
- Removed all `@bvt:issue#22992` skip tags

Approved by: @heni02, @ouyuanning, @aunjgr
This PR implements a minimal MySQL-compatible AES_ENCRYPT/AES_DECRYPT enhancement aligned with block_encryption_mode.
What changed:
Added 3-argument overloads (AES_ENCRYPT(str, key, iv) / AES_DECRYPT(crypt, key, iv)) for varchar/char/text/blob inputs, returning blob/varchar as appropriate.
Implemented MySQL-style XOR key folding and switched key derivation away from SHA1.
Added AES-CBC support alongside the existing ECB path, gated by block_encryption_mode (aes-128-ecb default, aes-256-cbc supported).
Enforced IV requirements for CBC (missing/short IV returns NULL, matching MySQL’s error-to-NULL behavior).
Added focused tests for ECB/CBC roundtrip and CBC missing-IV behavior.
Files touched:
[func_binary.go](https://file+.vscode-resource.vscode-cdn.net/Users/moukeyu/.vscode/extensions/openai.chatgpt-0.4.67-darwin-x64/webview/#)
[list_builtIn.go](https://file+.vscode-resource.vscode-cdn.net/Users/moukeyu/.vscode/extensions/openai.chatgpt-0.4.67-darwin-x64/webview/#)
[func_binary_aes_test.go](https://file+.vscode-resource.vscode-cdn.net/Users/moukeyu/.vscode/extensions/openai.chatgpt-0.4.67-darwin-x64/webview/#)
Test:
go test ./pkg/sql/plan/function -count=1

Approved by: @ouyuanning, @heni02, @aunjgr
Backport of matrixorigin#23762 and matrixorigin#23764 to 3.0-dev, adapted to the older
aggexec API on this branch (no SaveIntermediateResult / streaming
serialization helpers, [][]int64 instead of []i64Slice, 3-return
marshalToBytes / 2-arg unmarshalFromBytes / 4-arg
initAggResultWithFixedTypeResult).

CUME_DIST() returns the cumulative distribution of a value within a
partition: (rows with values <= current row) / (total rows in
partition).

PERCENT_RANK() returns the relative rank of a row within a partition
as a percentage: (rank - 1) / (total rows - 1).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The earlier ELT cherry-pick (b130341) brought in a copy of
func_binary_test.go from main that contains tests for TimeFormat,
TimestampDiffDateString, TimestampDiffStringDate, etc.—functions that
exist on main but not on 3.0-dev. It also forgot to register the ELT
function id and overload, so 'elt(...)' resolution would fail.

This commit:
* Adds the ELT function id (348) and 'elt' name mapping.
* Registers the ELT overload in list_builtIn.go bound to the existing
  Elt / eltCheck implementations from func_binary.go.
* Updates function_id_test.go's predefined map.
* Removes the main-only TimeFormat / TIMESTAMPDIFF / DATE_*_ADD test
  blocks that don't compile on 3.0-dev, while preserving the
  ELT-specific tests at the end of the file. Adds the 'vector' import
  needed by those preserved tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ jiangxinmeng1
✅ gouhongshen
❌ robll-v1
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Labels

kind/bug Something isn't working size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants