Skip to content

{182577691} fix: make tonumber accept comdb2 number#5760

Merged
emelialei88 merged 3 commits intobloomberg:mainfrom
emelialei88:fix/tonumber
Mar 10, 2026
Merged

{182577691} fix: make tonumber accept comdb2 number#5760
emelialei88 merged 3 commits intobloomberg:mainfrom
emelialei88:fix/tonumber

Conversation

@emelialei88
Copy link
Contributor

@emelialei88 emelialei88 commented Feb 24, 2026

1. Make luaV_tonumber handle comdb2 integer and real types

Extended luaV_tonumber to convert comdb2 int and real userdata to Lua numbers, enabling arithmetic between comdb2 types and Lua numbers without going through metamethods.

2. Remove broken userdata handling from OP_MOVE and OP_LOADK

Both opcodes had runtime checks attempting to detect typed comdb2 variables and route through the __type metamethod. These checks were buggy (check lopcodes.c for more information):

  • OP_LOADK is iABx format (B and C are combined into one 18-bit Bx field), but the code called RKB(i) which reads the upper 9 bits of Bx as a register index — pointing to an unrelated register.
  • OP_MOVE read RKC(i) where C is unused, always resolving to R(0).

Both could accidentally trigger the typed assignment path when an unrelated register held a comdb2 userdata.

These checks are also unnecessary: the compiler emits OP_CAST for typed assignment (:=) and plain OP_MOVE/OP_LOADK for regular assignment (=). Per documentation, plain = is intended to lose type. No tests rely on this runtime behavior.

3. Restore lua_to_client_type check order

Comdb2 userdata must be identified before lua_isnumber/lua_isstring, since luaV_tonumber now succeeds on comdb2 int/real and would misclassify them as SQLITE_FLOAT.

Copy link

@roborivers roborivers left a comment

Choose a reason for hiding this comment

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

Cbuild submission: Error ⚠.
Regression testing: Success ✓.

The first 10 failing tests are:
disttxn
consumer_non_atomic_default_consumer_generated

@emelialei88 emelialei88 marked this pull request as draft February 24, 2026 22:13
Copy link

@roborivers roborivers left a comment

Choose a reason for hiding this comment

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

Cbuild submission: Error ⚠.
Regression testing: Success ✓.

The first 10 failing tests are:
sc_truncate_multiddl_generated
autoanalyze
consumer_non_atomic_default_consumer_generated
remsql_locks_rte_connect_generated
remsql_locks
reco-ddlk-sql

@emelialei88 emelialei88 marked this pull request as ready for review February 26, 2026 22:59
@emelialei88 emelialei88 marked this pull request as draft March 2, 2026 21:56
@emelialei88 emelialei88 marked this pull request as ready for review March 3, 2026 16:31
Copy link

@roborivers roborivers left a comment

Choose a reason for hiding this comment

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

Cbuild submission: Error ⚠.
Regression testing: 0/0 tests failed ⚠.

Copy link

@roborivers roborivers left a comment

Choose a reason for hiding this comment

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

Cbuild submission: Error ⚠.
Regression testing: Success ✓.

The first 10 failing tests are:
nogensc
reco-ddlk-sql
consumer_non_atomic_default_consumer_generated

@akshatsikarwar
Copy link
Contributor

akshatsikarwar commented Mar 10, 2026

This was failing robomark build:
error: implicit declaration of function 'cdb2_is_valid_int' [-Werror=implicit-function-declaration]

I rebased the branch and submitted for robom.

@@ -0,0 +1,88 @@
DROP TABLE IF EXISTS t19
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test for decimal type's exclusion

if (bb->is_null) return NULL;
switch (bb->dbtype) {
case DBTYPES_INTEGER:
setnvalue(n, (lua_Number)(((lua_int_t *)bb)->val));
Copy link
Contributor

Choose a reason for hiding this comment

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

add test for number close to max longlong?

create procedure tonumber_arith_null_int version 'sptest' {
local function main()
local row = db:exec("select i from t19 where i is null"):fetch()
db:emit(row.i + 10)
Copy link
Contributor

Choose a reason for hiding this comment

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

add tests where lua_number comes before comdb2's? like 10 + row.i

Copy link

@roborivers roborivers left a comment

Choose a reason for hiding this comment

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

Cbuild submission: Success ✓.
Regression testing: Success ✓.

The first 10 failing tests are:
sc_truncate
queuedb_rollover
sp_snapshot_generated
consumer_non_atomic_default_consumer_generated
bulkimport
reco-ddlk-sql

Copy link

@roborivers roborivers left a comment

Choose a reason for hiding this comment

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

Cbuild submission: Success ✓.
Regression testing: Success ✓.

The first 10 failing tests are:
consumer_non_atomic_default_consumer_generated
sc_transactional_rowlocks_generated
reco-ddlk-sql

Signed-off-by: Emelia Lei <wlei29@bloomberg.net>
Signed-off-by: Emelia Lei <wlei29@bloomberg.net>
Signed-off-by: Emelia Lei <wlei29@bloomberg.net>
Copy link
Contributor

@mohitkhullar mohitkhullar left a comment

Choose a reason for hiding this comment

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

Thanks, lgtm

@emelialei88 emelialei88 merged commit ca9ab60 into bloomberg:main Mar 10, 2026
4 checks passed
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.

4 participants