Skip to content

Commit 266cc4a

Browse files
committed
Fix fixed length binary values
1 parent b32ac13 commit 266cc4a

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

accel.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,19 @@ int ucs4_to_utf8(const uint32_t *ucs4_str, size_t ucs4_len, char **utf8_str) {
436436
return -1;
437437
}
438438

439+
size_t length_without_trailing_nulls(const char *str, size_t len) {
440+
if (!str || len == 0) {
441+
return 0; // Handle null or empty input
442+
}
443+
444+
// Start from the end of the string and move backward
445+
while (len > 0 && str[len - 1] == '\0') {
446+
len--;
447+
}
448+
449+
return len;
450+
}
451+
439452
//
440453
// Cached int values for date/time components
441454
//
@@ -4022,6 +4035,9 @@ static PyObject *dump_rowdat_1_numpy(PyObject *self, PyObject *args, PyObject *k
40224035
} else {
40234036
Py_ssize_t str_l = col_types[i].length;
40244037
CHECKMEM(8+str_l);
4038+
4039+
str_l = length_without_trailing_nulls(bytes, str_l);
4040+
40254041
i64 = str_l;
40264042
memcpy(out+out_idx, &i64, 8);
40274043
out_idx += 8;

singlestoredb/functions/ext/asgi.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,6 @@ async def __call__(
723723
func_info['colspec'], b''.join(data),
724724
),
725725
)
726-
print(func_info['returns'], out)
727726
body = output_handler['dump'](
728727
[x[1] for x in func_info['returns']], *out, # type: ignore
729728
)

singlestoredb/tests/test_ext_func.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,9 +1213,9 @@ def test_numpy_fixed_binary(self):
12131213
self.cur.execute('select * from numpy_fixed_binary()')
12141214

12151215
assert [tuple(x) for x in self.cur] == [
1216-
('hello'.encode('utf8') + b'\x00' * 8,),
1216+
('hello'.encode('utf8'),),
12171217
('hi there 😜'.encode('utf8'),),
1218-
('😜 bye'.encode('utf8') + b'\x00' * 5,),
1218+
('😜 bye'.encode('utf8'),),
12191219
]
12201220

12211221
desc = self.cur.description

0 commit comments

Comments
 (0)