Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions c_glib/arrow-glib/basic-data-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ G_BEGIN_DECLS
*
* #GArrowBinaryDataType is a class for binary data type.
*
* #GArrowFixedSizeBinaryDataType is a class for fixed-size binary data type.
*
* #GArrowStringDataType is a class for UTF-8 encoded string data
* type.
*
Expand Down Expand Up @@ -239,7 +241,7 @@ garrow_fixed_width_data_type_class_init(GArrowFixedWidthDataTypeClass *klass)
}

/**
* garrow_fixed_width_data_type_get_id:
* garrow_fixed_width_data_type_get_bit_width:
* @data_type: A #GArrowFixedWidthDataType.
*
* Returns: The number of bits for one data.
Expand Down Expand Up @@ -716,6 +718,59 @@ garrow_binary_data_type_new(void)
}


G_DEFINE_TYPE(GArrowFixedSizeBinaryDataType,
garrow_fixed_size_binary_data_type,
GARROW_TYPE_FIXED_WIDTH_DATA_TYPE)

static void
garrow_fixed_size_binary_data_type_init(GArrowFixedSizeBinaryDataType *object)
{
}

static void
garrow_fixed_size_binary_data_type_class_init(GArrowFixedSizeBinaryDataTypeClass *klass)
{
}

/**
* garrow_fixed_size_binary_data_type:
* @byte_width: The byte width.
*
* Returns: The newly created fixed-size binary data type.
*
* Since: 0.12.0
*/
GArrowFixedSizeBinaryDataType *
garrow_fixed_size_binary_data_type_new(gint32 byte_width)
{
auto arrow_fixed_size_binary_data_type = arrow::fixed_size_binary(byte_width);

auto fixed_size_binary_data_type =
GARROW_FIXED_SIZE_BINARY_DATA_TYPE(g_object_new(GARROW_TYPE_FIXED_SIZE_BINARY_DATA_TYPE,
"data-type", &arrow_fixed_size_binary_data_type,
NULL));
return fixed_size_binary_data_type;
}

/**
* garrow_fixed_size_binary_data_type_get_byte_width:
* @data_type: A #GArrowFixedSizeBinaryDataType.
*
* Returns: The number of bytes for one data.
*
* Since: 0.12.0
*/
gint32
garrow_fixed_size_binary_data_type_get_byte_width(GArrowFixedSizeBinaryDataType *data_type)
{
const auto arrow_data_type =
garrow_data_type_get_raw(GARROW_DATA_TYPE(data_type));
const auto arrow_fixed_size_binary_type =
std::static_pointer_cast<arrow::FixedSizeBinaryType>(arrow_data_type);
return arrow_fixed_size_binary_type->byte_width();
}


G_DEFINE_TYPE(GArrowStringDataType,
garrow_string_data_type,
GARROW_TYPE_DATA_TYPE)
Expand Down Expand Up @@ -1044,7 +1099,7 @@ garrow_time64_data_type_new(GArrowTimeUnit unit, GError **error)

G_DEFINE_ABSTRACT_TYPE(GArrowDecimalDataType,
garrow_decimal_data_type,
GARROW_TYPE_DATA_TYPE)
GARROW_TYPE_FIXED_SIZE_BINARY_DATA_TYPE)

static void
garrow_decimal_data_type_init(GArrowDecimalDataType *object)
Expand Down Expand Up @@ -1197,6 +1252,9 @@ garrow_data_type_new_raw(std::shared_ptr<arrow::DataType> *arrow_data_type)
case arrow::Type::type::BINARY:
type = GARROW_TYPE_BINARY_DATA_TYPE;
break;
case arrow::Type::type::FIXED_SIZE_BINARY:
type = GARROW_TYPE_FIXED_SIZE_BINARY_DATA_TYPE;
break;
case arrow::Type::type::STRING:
type = GARROW_TYPE_STRING_DATA_TYPE;
break;
Expand Down
24 changes: 21 additions & 3 deletions c_glib/arrow-glib/basic-data-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,25 @@ GType garrow_binary_data_type_get_type (void) G_GNUC_CONST;
GArrowBinaryDataType *garrow_binary_data_type_new (void);


#define GARROW_TYPE_FIXED_SIZE_BINARY_DATA_TYPE (garrow_fixed_size_binary_data_type_get_type())
G_DECLARE_DERIVABLE_TYPE(GArrowFixedSizeBinaryDataType,
garrow_fixed_size_binary_data_type,
GARROW,
FIXED_SIZE_BINARY_DATA_TYPE,
GArrowDataType)
struct _GArrowFixedSizeBinaryDataTypeClass
{
GArrowFixedWidthDataTypeClass parent_class;
};

GARROW_AVAILABLE_IN_0_12
GArrowFixedSizeBinaryDataType *
garrow_fixed_size_binary_data_type_new(gint32 byte_width);
GARROW_AVAILABLE_IN_0_12
gint32
garrow_fixed_size_binary_data_type_get_byte_width(GArrowFixedSizeBinaryDataType *data_type);


#define GARROW_TYPE_STRING_DATA_TYPE \
(garrow_string_data_type_get_type())
#define GARROW_STRING_DATA_TYPE(obj) \
Expand Down Expand Up @@ -651,15 +670,14 @@ GArrowTime64DataType *garrow_time64_data_type_new (GArrowTimeUnit unit,


#define GARROW_TYPE_DECIMAL_DATA_TYPE (garrow_decimal_data_type_get_type())
/* TODO: Delivered from GArrowFixedSizeBinaryDataType. */
G_DECLARE_DERIVABLE_TYPE(GArrowDecimalDataType,
garrow_decimal_data_type,
GARROW,
DECIMAL_DATA_TYPE,
GArrowDataType)
GArrowFixedSizeBinaryDataType)
struct _GArrowDecimalDataTypeClass
{
GArrowDataTypeClass parent_class;
GArrowFixedSizeBinaryDataTypeClass parent_class;
};

#ifndef GARROW_DISABLE_DEPRECATED
Expand Down
2 changes: 2 additions & 0 deletions c_glib/arrow-glib/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ garrow_type_from_raw(arrow::Type::type type)
return GARROW_TYPE_STRING;
case arrow::Type::type::BINARY:
return GARROW_TYPE_BINARY;
case arrow::Type::type::FIXED_SIZE_BINARY:
return GARROW_TYPE_FIXED_SIZE_BINARY;
case arrow::Type::type::DATE32:
return GARROW_TYPE_DATE32;
case arrow::Type::type::DATE64:
Expand Down
3 changes: 3 additions & 0 deletions c_glib/arrow-glib/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ G_BEGIN_DECLS
* @GARROW_TYPE_DOUBLE: 8-byte floating point value.
* @GARROW_TYPE_STRING: UTF-8 variable-length string.
* @GARROW_TYPE_BINARY: Variable-length bytes (no guarantee of UTF-8-ness).
* @GARROW_TYPE_FIXED_SIZE_BINARY: Fixed-size binary. Each value occupies
* the same number of bytes.
* @GARROW_TYPE_DATE32: int32 days since the UNIX epoch.
* @GARROW_TYPE_DATE64: int64 milliseconds since the UNIX epoch.
* @GARROW_TYPE_TIMESTAMP: Exact timestamp encoded with int64 since UNIX epoch.
Expand Down Expand Up @@ -72,6 +74,7 @@ typedef enum {
GARROW_TYPE_DOUBLE,
GARROW_TYPE_STRING,
GARROW_TYPE_BINARY,
GARROW_TYPE_FIXED_SIZE_BINARY,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting a new enum value into middle of enums breaks a ABI compatibility.
But we don't need to care for now. Because we bump shared library version for each version. We can't do this when we release 1.0.0.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I'll care from now on.

GARROW_TYPE_DATE32,
GARROW_TYPE_DATE64,
GARROW_TYPE_TIMESTAMP,
Expand Down
39 changes: 39 additions & 0 deletions c_glib/test/test-fixed-size-binary-data-type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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 TestFixedSizeBinaryDataType < Test::Unit::TestCase
def setup
@byte_width = 10
@data_type = Arrow::FixedSizeBinaryDataType.new(@byte_width)
end

def test_type
assert_equal(Arrow::Type::FIXED_SIZE_BINARY, @data_type.id)
end

def test_to_s
assert_equal("fixed_size_binary[10]", @data_type.to_s)
end

def test_byte_width
assert_equal(@byte_width, @data_type.byte_width)
end

def test_bit_width
assert_equal(@byte_width * 8, @data_type.bit_width)
end
end