@@ -67,6 +67,20 @@ size_t computeTotalStringsLength(std::shared_ptr<arrow::ChunkedArray> arr,
67
67
return total_bytes;
68
68
}
69
69
70
+ /* *
71
+ * Get column ID by its 0-based index (position) in the table.
72
+ */
73
+ int columnId (size_t col_idx) {
74
+ return static_cast <int >(col_idx + 1000 );
75
+ }
76
+
77
+ /* *
78
+ * Translate column ID to 0-based index (position) in the table.
79
+ */
80
+ size_t columnIndex (int col_id) {
81
+ return static_cast <size_t >(col_id - 1000 );
82
+ }
83
+
70
84
} // anonymous namespace
71
85
72
86
void ArrowStorage::fetchBuffer (const ChunkKey& key,
@@ -79,7 +93,7 @@ void ArrowStorage::fetchBuffer(const ChunkKey& key,
79
93
mapd_shared_lock<mapd_shared_mutex> table_lock (table.mutex );
80
94
data_lock.unlock ();
81
95
82
- size_t col_idx = static_cast < size_t > (key[CHUNK_KEY_COLUMN_IDX] - 1 );
96
+ size_t col_idx = columnIndex (key[CHUNK_KEY_COLUMN_IDX]);
83
97
size_t frag_idx = static_cast <size_t >(key[CHUNK_KEY_FRAGMENT_IDX] - 1 );
84
98
CHECK_LT (frag_idx, table.fragments .size ());
85
99
CHECK_LT (col_idx, table.col_data .size ());
@@ -134,7 +148,7 @@ std::unique_ptr<AbstractDataToken> ArrowStorage::getZeroCopyBufferMemory(
134
148
->type ;
135
149
136
150
if (!col_type->isVarLen ()) {
137
- size_t col_idx = static_cast < size_t > (key[CHUNK_KEY_COLUMN_IDX] - 1 );
151
+ size_t col_idx = columnIndex (key[CHUNK_KEY_COLUMN_IDX]);
138
152
size_t frag_idx = static_cast <size_t >(key[CHUNK_KEY_FRAGMENT_IDX] - 1 );
139
153
CHECK_EQ (key.size (), (size_t )4 );
140
154
size_t elem_size = col_type->size ();
@@ -293,7 +307,7 @@ TableFragmentsInfo ArrowStorage::getTableMetadata(int db_id, int table_id) const
293
307
frag_info.deviceIds .push_back (0 ); // Data_Namespace::CPU_LEVEL
294
308
frag_info.deviceIds .push_back (0 ); // Data_Namespace::GPU_LEVEL
295
309
for (size_t col_idx = 0 ; col_idx < frag.metadata .size (); ++col_idx) {
296
- frag_info.setChunkMetadata (static_cast < int > (col_idx + 1 ), frag.metadata [col_idx]);
310
+ frag_info.setChunkMetadata (columnId (col_idx), frag.metadata [col_idx]);
297
311
}
298
312
}
299
313
return res;
@@ -331,14 +345,14 @@ TableInfoPtr ArrowStorage::createTable(const std::string& table_name,
331
345
TableInfoPtr res;
332
346
int table_id;
333
347
mapd_unique_lock<mapd_shared_mutex> data_lock (data_mutex_);
348
+ size_t next_col_idx = 0 ;
334
349
{
335
350
mapd_unique_lock<mapd_shared_mutex> dict_lock (dict_mutex_);
336
351
mapd_unique_lock<mapd_shared_mutex> schema_lock (schema_mutex_);
337
352
table_id = next_table_id_++;
338
353
checkNewTableParams (table_name, columns, options);
339
354
res = addTableInfo (
340
355
db_id_, table_id, table_name, false , Data_Namespace::MemoryLevel::CPU_LEVEL, 0 );
341
- int next_col_id = 1 ;
342
356
std::unordered_map<int , int > dict_ids;
343
357
for (auto & col : columns) {
344
358
auto type = col.type ;
@@ -382,10 +396,10 @@ TableInfoPtr ArrowStorage::createTable(const std::string& table_name,
382
396
type = elem_type;
383
397
}
384
398
}
385
- auto col_info =
386
- addColumnInfo ( db_id_, table_id, next_col_id++ , col.name , type, false );
399
+ auto col_info = addColumnInfo (
400
+ db_id_, table_id, columnId (next_col_idx++) , col.name , type, false );
387
401
}
388
- addRowidColumn (db_id_, table_id);
402
+ addRowidColumn (db_id_, table_id, columnId (next_col_idx++) );
389
403
}
390
404
391
405
std::vector<std::shared_ptr<arrow::Field>> fields;
@@ -479,7 +493,7 @@ void ArrowStorage::appendArrowTable(std::shared_ptr<arrow::Table> at, int table_
479
493
threading::parallel_for (
480
494
threading::blocked_range (0 , (int )at->columns ().size ()), [&](auto range) {
481
495
for (auto col_idx = range.begin (); col_idx != range.end (); col_idx++) {
482
- auto col_info = getColumnInfo (db_id_, table_id, col_idx + 1 );
496
+ auto col_info = getColumnInfo (db_id_, table_id, columnId ( col_idx) );
483
497
auto col_type = col_info->type ;
484
498
auto col_arr = at->column (col_idx);
485
499
@@ -605,7 +619,7 @@ void ArrowStorage::appendArrowTable(std::shared_ptr<arrow::Table> at, int table_
605
619
auto & first_frag = fragments.front ();
606
620
last_frag.row_count += first_frag.row_count ;
607
621
for (size_t col_idx = 0 ; col_idx < last_frag.metadata .size (); ++col_idx) {
608
- auto col_type = getColumnInfo (db_id_, table_id, col_idx + 1 )->type ;
622
+ auto col_type = getColumnInfo (db_id_, table_id, columnId ( col_idx) )->type ;
609
623
size_t num_elems = last_frag.metadata [col_idx]->numElements () +
610
624
first_frag.metadata [col_idx]->numElements ();
611
625
size_t num_bytes = last_frag.metadata [col_idx]->numBytes () +
0 commit comments