Skip to content

Commit

Permalink
Copy jsonb value within populate_slot() into the allocator buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
za-arthur committed Aug 9, 2024
1 parent 88dec77 commit ee79d34
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,10 +1003,21 @@ class DefaultParquetReader : public ParquetReader
}
case arrow::Type::MAP:
{
arrow::MapArray* maparray = (arrow::MapArray*) array;
arrow::MapArray *maparray = (arrow::MapArray*) array;
Datum jsonb = this->map_to_datum(maparray, chunkInfo.pos, typinfo);

slot->tts_values[attr] =
this->map_to_datum(maparray, chunkInfo.pos, typinfo);
/*
* Copy jsonb into memory block allocated by
* FastAllocator to prevent its destruction though
* to be able to recycle it once it fulfilled its
* purpose.
*/
void *jsonb_val = allocator->fast_alloc(VARSIZE_ANY(jsonb));

memcpy(jsonb_val, DatumGetPointer(jsonb), VARSIZE_ANY(jsonb));
pfree(DatumGetPointer(jsonb));

slot->tts_values[attr] = PointerGetDatum(jsonb_val);
break;
}
default:
Expand Down Expand Up @@ -1255,20 +1266,21 @@ class CachingParquetReader : public ParquetReader
case arrow::Type::MAP:
{
arrow::MapArray* maparray = (arrow::MapArray*) array;

Datum jsonb =
this->map_to_datum(maparray, j, typinfo);
Datum jsonb = this->map_to_datum(maparray, j, typinfo);

/*
* Copy jsonb into memory block allocated by
* FastAllocator to prevent its destruction though
* to be able to recycle it once it fulfilled its
* purpose.
*/
void *res = allocator->fast_alloc(VARSIZE_ANY(jsonb));
memcpy(res, (Jsonb *) jsonb, VARSIZE_ANY(jsonb));
((Datum *) data)[row] = (Datum) res;
pfree((Jsonb *) jsonb);
void *jsonb_val = allocator->fast_alloc(VARSIZE_ANY(jsonb));

memcpy(jsonb_val, DatumGetPointer(jsonb), VARSIZE_ANY(jsonb));
pfree(DatumGetPointer(jsonb));

((Datum *) data)[row] = PointerGetDatum(jsonb_val);

break;
}
default:
Expand Down

0 comments on commit ee79d34

Please sign in to comment.