Skip to content

Commit

Permalink
Add validation for writing offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
lixueclaire committed Apr 17, 2023
1 parent c7e7038 commit e994590
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions cpp/src/arrow_chunk_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ Status VertexPropertyWriter::Validate(
" not found");
auto field = schema->field(indice);
if (DataType::ArrowDataTypeToDataType(field->type()) != property.type)
return Status::InvalidOperation("invalid data type for property: " +
property.name);
return Status::TypeError("invalid data type for property: " +
property.name);
}
}
return Status::OK();
Expand Down Expand Up @@ -199,7 +199,14 @@ Status EdgeChunkWriter::Validate(
// weak validate
if (!edge_info_.ContainAdjList(adj_list_type_))
return Status::InvalidOperation("invalid adj list type");
if (input_table->num_rows() > edge_info_.GetChunkSize())
if (adj_list_type_ != AdjListType::ordered_by_source &&
adj_list_type_ != AdjListType::ordered_by_dest)
return Status::InvalidOperation("invalid adj list type");
if (adj_list_type_ == AdjListType::ordered_by_source &&
input_table->num_rows() > edge_info_.GetSrcChunkSize() + 1)
return Status::OutOfRange();
if (adj_list_type_ == AdjListType::ordered_by_dest &&
input_table->num_rows() > edge_info_.GetDstChunkSize() + 1)
return Status::OutOfRange();
if (vertex_chunk_index < 0)
return Status::InvalidOperation("invalid vertex chunk index");
Expand All @@ -211,7 +218,7 @@ Status EdgeChunkWriter::Validate(
return Status::InvalidOperation("offsets not provided");
auto field = schema->field(index);
if (field->type()->id() != arrow::Type::INT64)
return Status::InvalidOperation("invalid data type for offsets");
return Status::TypeError("invalid data type for offsets");
}
return Status::OK();
}
Expand Down Expand Up @@ -242,13 +249,13 @@ Status EdgeChunkWriter::Validate(
return Status::InvalidOperation("sources not provided");
auto field = schema->field(index);
if (field->type()->id() != arrow::Type::INT64)
return Status::InvalidOperation("invalid data type for sources");
return Status::TypeError("invalid data type for sources");
index = schema->GetFieldIndex(GeneralParams::kDstIndexCol);
if (index == -1)
return Status::InvalidOperation("destinations not provided");
field = schema->field(index);
if (field->type()->id() != arrow::Type::INT64)
return Status::InvalidOperation("invalid data type for destinations");
return Status::TypeError("invalid data type for destinations");
}
return Status::OK();
}
Expand Down Expand Up @@ -284,8 +291,8 @@ Status EdgeChunkWriter::Validate(
" not found");
auto field = schema->field(indice);
if (DataType::ArrowDataTypeToDataType(field->type()) != property.type)
return Status::InvalidOperation("invalid data type for property: " +
property.name);
return Status::TypeError("invalid data type for property: " +
property.name);
}
}
return Status::OK();
Expand Down Expand Up @@ -480,7 +487,6 @@ Status EdgeChunkWriter::SortAndWriteAdjListTable(
GAR_ASSIGN_OR_RAISE(
auto response_table,
sortTable(input_table, getSortColumnName(adj_list_type_)));

if (adj_list_type_ == AdjListType::ordered_by_source ||
adj_list_type_ == AdjListType::ordered_by_dest) {
GAR_ASSIGN_OR_RAISE(
Expand All @@ -489,7 +495,6 @@ Status EdgeChunkWriter::SortAndWriteAdjListTable(
vertex_chunk_index));
GAR_RETURN_NOT_OK(WriteOffsetChunk(offset_table, vertex_chunk_index));
}

return WriteAdjListTable(response_table, vertex_chunk_index,
start_chunk_index);
}
Expand Down

0 comments on commit e994590

Please sign in to comment.