Skip to content

Commit

Permalink
assert() to exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
grammaright committed Dec 17, 2024
1 parent 8efdb10 commit db39ad4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/array_writer/dense_to_dense_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ void DenseToTileCopyArrayWriter::WriteArrayData(ExecutionContext &context,
// exploit the vector type
auto vector = FlatVector::GetData<double>(input.data[0]);

D_ASSERT(cur_idx + input.size() <= array_gstate.buf_size);
if (cur_idx + input.size() > array_gstate.buf_size) {
throw std::runtime_error("Buffer overflow");
}

for (idx_t i = 0; i < input.size(); i++) {
array_gstate.buf[cur_idx++] = vector[i];
Expand Down
9 changes: 6 additions & 3 deletions src/copy_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ GlobalWriteArrayData::GlobalWriteArrayData(ClientContext &context,
}

void GlobalWriteArrayData::pin(vector<uint64_t> _tile_coords) {
assert(!is_pinned);
if (is_pinned) {
throw std::runtime_error("Tile is already pinned");
}

// getbuffer
for (uint32_t i = 0; i < this->dim_len; i++) {
Expand All @@ -50,8 +52,9 @@ void GlobalWriteArrayData::pin(vector<uint64_t> _tile_coords) {

key = {arrname_char, tile_coords, dim_len, emptytileTemplate};

int res = BF_GetBuf(key, &page);
assert(res == BFE_OK);
if (BF_GetBuf(key, &page) != BFE_OK) {
throw std::runtime_error("Failed to get buffer");
}

buf_size = page->pagebuf_len / sizeof(double);
buf = (double *)bf_util_get_pagebuf(page);
Expand Down
12 changes: 9 additions & 3 deletions src/read_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ unique_ptr<FunctionData> ReadArrayBind(ClientContext &context,
<< std::endl;
if (it->first == "coords") {
auto coords = ListValue::GetChildren(it->second);
assert(coords.size() == bind_data->dim_len);
if (coords.size() != bind_data->dim_len) {
throw std::runtime_error("Invalid number of coordinates");
}

for (int d = 0; d < (int) bind_data->dim_len; d++) {
bind_data->requestedCoords.push_back(
Expand All @@ -161,11 +163,15 @@ unique_ptr<FunctionData> ReadArrayBind(ClientContext &context,
}

// TODO: CSR array is not supported yet
assert(bind_data->format != TILESTORE_SPARSE_CSR);
if (bind_data->format == TILESTORE_SPARSE_CSR) {
throw NotImplementedException("Sparse CSR array is not supported yet");
}

// TODO: multi-attributes are not supported yet for dense array
bool isMultiAttrs = bind_data->attrTypes.size() > 1;
if (bind_data->format == TILESTORE_DENSE) assert(!isMultiAttrs);
if (bind_data->format == TILESTORE_DENSE && isMultiAttrs) {
throw NotImplementedException("Multi-attributes are not supported yet");
}

// dimensions first
if (bind_data->dim_len == 1) {
Expand Down

0 comments on commit db39ad4

Please sign in to comment.