Skip to content

Commit

Permalink
[Go & Cpp] Fix vector type check (#70)
Browse files Browse the repository at this point in the history
Signed-off-by: sunby <[email protected]>
  • Loading branch information
sunby committed Oct 8, 2023
1 parent 8692767 commit 62be323
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions cpp/src/storage/options.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "storage/options.h"
#include <arrow/type_fwd.h>
#include "arrow/type.h"
#include "common/status.h"

Expand Down Expand Up @@ -30,8 +31,9 @@ Status SchemaOptions::Validate(const arrow::Schema* schema) {
auto vector_field = schema->GetFieldByName(vector_column);
if (!vector_field) {
return Status::InvalidArgument("vector column is not exist");
} else if (vector_field->type()->id() != arrow::Type::FIXED_SIZE_BINARY) {
return Status::InvalidArgument("vector column is not fixed size binary");
} else if (vector_field->type()->id() != arrow::Type::FIXED_SIZE_BINARY &&
vector_field->type()->id() != arrow::Type::FIXED_SIZE_LIST) {
return Status::InvalidArgument("vector column is not fixed size binary or fixed size list");
}
} else {
return Status::InvalidArgument("vector column is empty");
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/options_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ TEST(SchemaOptionsTest, VectorColTypeTest) {
auto status = schema_options.Validate(schema.get());
ASSERT_FALSE(status.ok());
ASSERT_TRUE(status.IsInvalidArgument());
ASSERT_EQ("InvalidArgument: vector column is not fixed size binary", status.ToString());
ASSERT_EQ("InvalidArgument: vector column is not fixed size binary or fixed size list", status.ToString());

schema = CreateArrowSchema({"field1", "field2"}, {arrow::int64(), arrow::fixed_size_binary(8)});
status = schema_options.Validate(schema.get());
Expand Down
6 changes: 3 additions & 3 deletions go/storage/schema/schema_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
ErrVersionColumnNotFound = errors.New("version column not found")
ErrVersionColumnType = errors.New("version column is not int64")
ErrVectorColumnNotFound = errors.New("vector column not found")
ErrVectorColumnType = errors.New("vector column is not fixed size binary")
ErrVectorColumnType = errors.New("vector column is not fixed size binary or fixed size list")
ErrVectorColumnEmpty = errors.New("vector column is empty")
)

Expand Down Expand Up @@ -69,8 +69,8 @@ func (o *SchemaOptions) Validate(schema *arrow.Schema) error {
vectorField, b := schema.FieldsByName(o.VectorColumn)
if !b {
return ErrVectorColumnNotFound
} else if vectorField[0].Type.ID() != arrow.FIXED_SIZE_BINARY {
return ErrVectorColumnType
} else if vectorField[0].Type.ID() != arrow.FIXED_SIZE_BINARY && vectorField[0].Type.ID() != arrow.FIXED_SIZE_LIST {
return ErrVectorColumnType
}
} else {
return ErrVectorColumnEmpty
Expand Down

0 comments on commit 62be323

Please sign in to comment.