Skip to content

Commit ab71174

Browse files
committed
fix(update): set_ids by symbol columns
1 parent 8b4cf06 commit ab71174

4 files changed

Lines changed: 58 additions & 6 deletions

File tree

core/io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ obj_p io_read_csv(i8_t *types, i64_t num_types, str_p buf, i64_t size, i64_t tot
531531
return NULL_OBJ; // Success
532532
}
533533

534-
static i64_t symbol_from_str_trimmed(str_p src, i64_t len) {
534+
i64_t io_symbol_from_str_trimmed(str_p src, i64_t len) {
535535
c8_t buf[256]; // Stack buffer for common case
536536
c8_t *trimmed;
537537
i64_t i, j = 0;
@@ -681,7 +681,7 @@ obj_p ray_read_csv(obj_p *x, i64_t n) {
681681
pos--;
682682
}
683683

684-
AS_SYMBOL(names)[i] = symbol_from_str_trimmed(prev, pos - prev);
684+
AS_SYMBOL(names)[i] = io_symbol_from_str_trimmed(prev, pos - prev);
685685
pos++;
686686
len -= (pos - prev);
687687
}

core/io.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ obj_p io_set_table(obj_p path, obj_p table);
4141
obj_p io_set_table_splayed(obj_p path, obj_p table, obj_p symfile);
4242
obj_p io_get_table_splayed(obj_p path, obj_p symfile);
4343
obj_p io_read_csv(i8_t *types, i64_t num_types, str_p buf, i64_t size, i64_t total_lines, obj_p cols, c8_t sep);
44+
i64_t io_symbol_from_str_trimmed(str_p src, i64_t len);
4445

4546
#endif // IO_H

core/rayforce.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,8 +1464,8 @@ obj_p set_ids(obj_p* obj, i64_t ids[], i64_t len, obj_p vals) {
14641464
drop_obj(vals);
14651465
return *obj;
14661466
case MTYPE2(TYPE_I64, -TYPE_I64):
1467-
case MTYPE2(TYPE_SYMBOL, -TYPE_I64):
1468-
case MTYPE2(TYPE_TIMESTAMP, -TYPE_I64):
1467+
case MTYPE2(TYPE_SYMBOL, -TYPE_SYMBOL):
1468+
case MTYPE2(TYPE_TIMESTAMP, -TYPE_TIMESTAMP):
14691469
for (i = 0; i < len; i++)
14701470
AS_I64(*obj)[ids[i]] = vals->i64;
14711471
drop_obj(vals);
@@ -1513,8 +1513,8 @@ obj_p set_ids(obj_p* obj, i64_t ids[], i64_t len, obj_p vals) {
15131513
drop_obj(vals);
15141514
return *obj;
15151515
case MTYPE2(TYPE_I64, TYPE_I64):
1516-
case MTYPE2(TYPE_SYMBOL, TYPE_I64):
1517-
case MTYPE2(TYPE_TIMESTAMP, TYPE_I64):
1516+
case MTYPE2(TYPE_SYMBOL, TYPE_SYMBOL):
1517+
case MTYPE2(TYPE_TIMESTAMP, TYPE_TIMESTAMP):
15181518
for (i = 0; i < len; i++)
15191519
AS_I64(*obj)[ids[i]] = AS_I64(vals)[i];
15201520
drop_obj(vals);

tests/lang.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3188,6 +3188,57 @@ test_result_t test_lang_update() {
31883188
"t",
31893189
"(table [id val] (list [1i 2i 3i] [100i 300i 450i]))");
31903190

3191+
// ========== SYMBOL/TIMESTAMP UPDATE TESTS (regression for set_ids type handling) ==========
3192+
3193+
// Test 42: Update symbol column with symbol atom value and where clause
3194+
TEST_ASSERT_EQ(
3195+
"(set t (table [id name age] (list [1 2 3] ['alice 'bob 'charlie] [10 20 30])))"
3196+
"(update {name: 'baba from: 't where: (== age 10)})"
3197+
"t",
3198+
"(table [id name age] (list [1 2 3] [baba bob charlie] [10 20 30]))");
3199+
3200+
// Test 43: Update symbol column with symbol atom value (multiple rows match)
3201+
TEST_ASSERT_EQ(
3202+
"(set t (table [id name age] (list [1 2 3] ['alice 'bob 'charlie] [10 20 10])))"
3203+
"(update {name: 'updated from: 't where: (== age 10)})"
3204+
"t",
3205+
"(table [id name age] (list [1 2 3] [updated bob updated] [10 20 10]))");
3206+
3207+
// Test 44: Update symbol column without where clause (all rows)
3208+
TEST_ASSERT_EQ(
3209+
"(set t (table [id name] (list [1 2 3] ['x 'y 'z])))"
3210+
"(update {name: 'same from: 't})"
3211+
"t",
3212+
"(table [id name] (list [1 2 3] [same same same]))");
3213+
3214+
// Test 45: Update timestamp column with timestamp atom value and where clause
3215+
TEST_ASSERT_EQ(
3216+
"(set t (table [id ts val] (list [1 2 3] [2024.01.01D00:00:00.0 2024.01.02D00:00:00.0 2024.01.03D00:00:00.0] [10 20 30])))"
3217+
"(update {ts: 2025.06.15D12:30:00.0 from: 't where: (== val 20)})"
3218+
"t",
3219+
"(table [id ts val] (list [1 2 3] [2024.01.01D00:00:00.000000000 2025.06.15D12:30:00.000000000 2024.01.03D00:00:00.000000000] [10 20 30]))");
3220+
3221+
// Test 46: Update timestamp column with timestamp atom value (multiple rows match)
3222+
TEST_ASSERT_EQ(
3223+
"(set t (table [id ts val] (list [1 2 3] [2024.01.01D00:00:00.0 2024.01.02D00:00:00.0 2024.01.03D00:00:00.0] [10 20 10])))"
3224+
"(update {ts: 2099.12.31D23:59:59.0 from: 't where: (== val 10)})"
3225+
"t",
3226+
"(table [id ts val] (list [1 2 3] [2099.12.31D23:59:59.000000000 2024.01.02D00:00:00.000000000 2099.12.31D23:59:59.000000000] [10 20 10]))");
3227+
3228+
// Test 47: Update timestamp column without where clause (all rows)
3229+
TEST_ASSERT_EQ(
3230+
"(set t (table [id ts] (list [1 2 3] [2024.01.01D00:00:00.0 2024.01.02D00:00:00.0 2024.01.03D00:00:00.0])))"
3231+
"(update {ts: 2000.01.01D00:00:00.0 from: 't})"
3232+
"t",
3233+
"(table [id ts] (list [1 2 3] [2000.01.01D00:00:00.000000000 2000.01.01D00:00:00.000000000 2000.01.01D00:00:00.000000000]))");
3234+
3235+
// Test 48: Update both symbol and timestamp columns in same update
3236+
TEST_ASSERT_EQ(
3237+
"(set t (table [id name ts] (list [1 2] ['alice 'bob] [2024.01.01D00:00:00.0 2024.01.02D00:00:00.0])))"
3238+
"(update {name: 'updated ts: 2025.01.01D00:00:00.0 from: 't where: (== id 1)})"
3239+
"t",
3240+
"(table [id name ts] (list [1 2] [updated bob] [2025.01.01D00:00:00.000000000 2024.01.02D00:00:00.000000000]))");
3241+
31913242
PASS();
31923243
}
31933244

0 commit comments

Comments
 (0)