Skip to content

Commit

Permalink
GH-44656: [GLib] Add GArrowBinaryViewDataType (#44659)
Browse files Browse the repository at this point in the history
### Rationale for this change

The `arrow::BinaryViewType` has been introduced.
GLib needs to be implemented as the `GArrowBinaryViewDataType`.

### What changes are included in this PR?

Implement `GArrowBinaryViewDataType`.

### Are these changes tested?

YES

### Are there any user-facing changes?

NO

* GitHub Issue: #44656

Lead-authored-by: Hiroyuki Sato <[email protected]>
Co-authored-by: Sutou Kouhei <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
  • Loading branch information
hiroyuki-sato and kou authored Nov 7, 2024
1 parent 9b27f42 commit ac6b8ff
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 1 deletion.
30 changes: 30 additions & 0 deletions c_glib/arrow-glib/basic-data-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ G_BEGIN_DECLS
*
* #GArrowExtensionDataTypeRegistry is a class to manage extension
* data types.
*
* #GArrowBinaryViewDataType is a class for the binary view data type.
*/

struct GArrowDataTypePrivate
Expand Down Expand Up @@ -2207,6 +2209,34 @@ garrow_extension_data_type_registry_lookup(GArrowExtensionDataTypeRegistry *regi
return GARROW_EXTENSION_DATA_TYPE(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_END_DECLS

GArrowDataType *
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 @@ -770,4 +770,20 @@ GArrowExtensionDataType *
garrow_extension_data_type_registry_lookup(GArrowExtensionDataTypeRegistry *registry,
const gchar *name);

#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);

G_END_DECLS
2 changes: 2 additions & 0 deletions c_glib/arrow-glib/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ 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::BINARY_VIEW:
return GARROW_TYPE_BINARY_VIEW;
default:
return GARROW_TYPE_NA;
}
Expand Down
6 changes: 5 additions & 1 deletion c_glib/arrow-glib/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ G_BEGIN_DECLS
* @GARROW_TYPE_LARGE_LIST: A list of some logical data type with 64-bit offsets.
* @GARROW_TYPE_MONTH_DAY_NANO_INTERVAL: MONTH_DAY_NANO interval in SQL style.
* @GARROW_TYPE_RUN_END_ENCODED: Run-end encoded data.
* @GARROW_TYPE_BINARY_VIEW: Bytes view type with 4-byte prefix and inline small string
* optimization.
* @GARROW_TYPE_DECIMAL32: Precision- and scale-based decimal
* @GARROW_TYPE_DECIMAL64: Precision- and scale-based decimal
* type with 64-bit. Storage type depends on the parameters.
Expand Down Expand Up @@ -116,7 +118,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). */
/* TODO: Remove = 40 when we add STRING_VIEW(39) */
GARROW_TYPE_BINARY_VIEW = 40,
/* 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 ac6b8ff

Please sign in to comment.