Skip to content

Commit

Permalink
apacheGH-44656: Add GArrowBinaryViewDataType
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroyuki-sato committed Nov 6, 2024
1 parent 4274db8 commit e3f18f9
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
29 changes: 29 additions & 0 deletions c_glib/arrow-glib/basic-data-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ G_BEGIN_DECLS
*
* #GArrowBinaryDataType is a class for the binary data type.
*
* #GArrowBinaryViewDataType is a class for the binary data type.
*
* #GArrowLargeBinaryDataType is a class for the 64-bit offsets binary
* data type.
*
Expand Down Expand Up @@ -813,6 +815,33 @@ garrow_binary_data_type_new(void)
return data_type;
}

G_DEFINE_TYPE(GArrowBinaryViewDataType, garrow_binary_view_data_type, GARROW_TYPE_DATA_TYPE)

static void
garrow_binary_view_data_type_init(GArrowBinaryViewDataType *object)
{
}

static void
garrow_binary_view_data_type_class_init(GArrowBinaryViewDataTypeClass *klass)
{
}

/**
* garrow_binary_view_data_type_new:
*
* Returns: The newly created binary view data type.
*/
GArrowBinaryViewDataType *
garrow_binary_view_data_type_new(void)
{
auto arrow_data_type = arrow::binary_view();

GArrowBinaryViewDataType *data_type = GARROW_BINARY_VIEW_DATA_TYPE(
g_object_new(GARROW_TYPE_BINARY_VIEW_DATA_TYPE, "data-type", &arrow_data_type, NULL));
return data_type;
}

G_DEFINE_TYPE(GArrowFixedSizeBinaryDataType,
garrow_fixed_size_binary_data_type,
GARROW_TYPE_FIXED_WIDTH_DATA_TYPE)
Expand Down
16 changes: 16 additions & 0 deletions c_glib/arrow-glib/basic-data-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,22 @@ struct _GArrowTemporalDataTypeClass
GArrowFixedWidthDataTypeClass parent_class;
};

#define GARROW_TYPE_BINARY_VIEW_DATA_TYPE (garrow_binary_view_data_type_get_type())
GARROW_AVAILABLE_IN_19_0
G_DECLARE_DERIVABLE_TYPE(GArrowBinaryViewDataType,
garrow_binary_view_data_type,
GARROW,
BINARY_VIEW_DATA_TYPE,
GArrowDataType)
struct _GArrowBinaryViewDataTypeClass
{
GArrowDataTypeClass parent_class;
};

GARROW_AVAILABLE_IN_19_0
GArrowBinaryViewDataType *
garrow_binary_view_data_type_new(void);

#define GARROW_TYPE_DATE32_DATA_TYPE (garrow_date32_data_type_get_type())
GARROW_AVAILABLE_IN_ALL
G_DECLARE_DERIVABLE_TYPE(GArrowDate32DataType,
Expand Down
4 changes: 4 additions & 0 deletions c_glib/arrow-glib/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ garrow_type_from_raw(arrow::Type::type type)
return GARROW_TYPE_MONTH_DAY_NANO_INTERVAL;
case arrow::Type::type::RUN_END_ENCODED:
return GARROW_TYPE_RUN_END_ENCODED;
case arrow::Type::type::STRING_VIEW:
return GARROW_TYPE_STRING_VIEW;
case arrow::Type::type::BINARY_VIEW:
return GARROW_TYPE_BINARY_VIEW;
default:
return GARROW_TYPE_NA;
}
Expand Down
4 changes: 3 additions & 1 deletion c_glib/arrow-glib/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ typedef enum {
GARROW_TYPE_LARGE_LIST,
GARROW_TYPE_MONTH_DAY_NANO_INTERVAL,
GARROW_TYPE_RUN_END_ENCODED,
/* TODO: Remove = 43 when we add STRING_VIEW(39)..LARGE_LIST_VIEW(42). */
GARROW_TYPE_STRING_VIEW,
GARROW_TYPE_BINARY_VIEW,
/* TODO: Remove = 43 when we add LIST_VIEW(41)..LARGE_LIST_VIEW(42). */
GARROW_TYPE_DECIMAL32 = 43,
GARROW_TYPE_DECIMAL64,
} GArrowType;
Expand Down
33 changes: 33 additions & 0 deletions c_glib/test/test-binary-view-data-type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

class TestBinaryViewDataType < Test::Unit::TestCase
def test_type
data_type = Arrow::BinaryViewDataType.new
assert_equal(Arrow::Type::BINARY_VIEW, data_type.id)
end

def test_name
data_type = Arrow::BinaryViewDataType.new
assert_equal("binary_view", data_type.name)
end

def test_to_s
data_type = Arrow::BinaryViewDataType.new
assert_equal("binary_view", data_type.to_s)
end
end

0 comments on commit e3f18f9

Please sign in to comment.