From 62be323b3f5c53fde7dfa508b6a6066e56ab8010 Mon Sep 17 00:00:00 2001 From: Bingyi Sun Date: Sun, 8 Oct 2023 14:37:26 +0800 Subject: [PATCH] [Go & Cpp] Fix vector type check (#70) Signed-off-by: sunby --- cpp/src/storage/options.cpp | 6 ++++-- cpp/test/options_test.cpp | 2 +- go/storage/schema/schema_option.go | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cpp/src/storage/options.cpp b/cpp/src/storage/options.cpp index 507eb44f..773b23e1 100644 --- a/cpp/src/storage/options.cpp +++ b/cpp/src/storage/options.cpp @@ -1,4 +1,5 @@ #include "storage/options.h" +#include #include "arrow/type.h" #include "common/status.h" @@ -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"); diff --git a/cpp/test/options_test.cpp b/cpp/test/options_test.cpp index 5bffa170..2f94a71f 100644 --- a/cpp/test/options_test.cpp +++ b/cpp/test/options_test.cpp @@ -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()); diff --git a/go/storage/schema/schema_option.go b/go/storage/schema/schema_option.go index b3fe2f16..86a75839 100644 --- a/go/storage/schema/schema_option.go +++ b/go/storage/schema/schema_option.go @@ -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") ) @@ -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