@@ -187,6 +187,51 @@ std::unique_ptr<AbstractDataToken> ArrowStorage::getZeroCopyBufferMemory(
187
187
return nullptr ;
188
188
}
189
189
190
+ std::unique_ptr<AbstractDataToken> ArrowStorage::getZeroCopyColumnData (
191
+ const ColumnRef& col_ref) {
192
+ mapd_shared_lock<mapd_shared_mutex> data_lock (data_mutex_);
193
+ CHECK_EQ (col_ref.db_id , db_id_);
194
+ CHECK_EQ (tables_.count (col_ref.table_id ), (size_t )1 );
195
+ auto & table = *tables_.at (col_ref.table_id );
196
+ mapd_shared_lock<mapd_shared_mutex> table_lock (table.mutex );
197
+ data_lock.unlock ();
198
+
199
+ auto col_type = getColumnInfo (col_ref.db_id , col_ref.table_id , col_ref.column_id )->type ;
200
+
201
+ if (col_type->isExtDictionary ()) {
202
+ auto dict_id = col_type->as <hdk::ir::ExtDictionaryType>()->dictId ();
203
+ auto dict_descriptor = getDictMetadata (
204
+ dict_id); // this will force materialize the dictionary. it is thread safe
205
+ CHECK (dict_descriptor);
206
+ }
207
+
208
+ if (!col_type->isVarLen ()) {
209
+ size_t col_idx = columnIndex (col_ref.column_id );
210
+ size_t elem_size = col_type->size ();
211
+ const auto * fixed_type =
212
+ dynamic_cast <const arrow::FixedWidthType*>(table.col_data [col_idx]->type ().get ());
213
+ CHECK (fixed_type) << table.col_data [col_idx]->type ()->ToString () << " (table "
214
+ << col_ref.table_id << " , column " << col_idx << " )" ;
215
+ size_t arrow_elem_size = fixed_type->bit_width () / 8 ;
216
+ // For fixed size arrays we simply use elem type in arrow and therefore have to scale
217
+ // to get a proper slice.
218
+ size_t elems = elem_size / arrow_elem_size;
219
+ CHECK_GT (elems, (size_t )0 );
220
+ auto data_to_fetch = table.col_data [col_idx];
221
+ LOG (ERROR) << " getZeroCopyColumnData num_chunks: " << data_to_fetch->num_chunks ();
222
+ if (data_to_fetch->num_chunks () == 1 ) {
223
+ auto chunk = data_to_fetch->chunk (0 );
224
+ const int8_t * ptr =
225
+ chunk->data ()->GetValues <int8_t >(1 , chunk->data ()->offset * arrow_elem_size);
226
+ size_t chunk_size = chunk->length () * arrow_elem_size;
227
+ return std::make_unique<ArrowChunkDataToken>(
228
+ std::move (chunk), col_type, ptr, chunk_size);
229
+ }
230
+ }
231
+
232
+ return nullptr ;
233
+ }
234
+
190
235
void ArrowStorage::fetchFixedLenData (const TableData& table,
191
236
size_t frag_idx,
192
237
size_t col_idx,
0 commit comments