Skip to content

Commit

Permalink
apacheGH-35417: [GLib] Add GArrowRunEndEncodedDataType
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jul 4, 2023
1 parent 7ebc88c commit 2930761
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 0 deletions.
3 changes: 3 additions & 0 deletions c_glib/arrow-glib/basic-data-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,9 @@ garrow_data_type_new_raw(std::shared_ptr<arrow::DataType> *arrow_data_type)
}
type = GARROW_TYPE_EXTENSION_DATA_TYPE;
break;
case arrow::Type::type::RUN_END_ENCODED:
type = GARROW_TYPE_RUN_END_ENCODED_DATA_TYPE;
break;
default:
type = GARROW_TYPE_DATA_TYPE;
break;
Expand Down
78 changes: 78 additions & 0 deletions c_glib/arrow-glib/composite-data-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ G_BEGIN_DECLS
* #GArrowDenseUnionDataType is a class for dense union data type.
*
* #GArrowDictionaryDataType is a class for dictionary data type.
*
* #GArrowRunEndEncodedDataType is a class for run end encoded data type.
*/

G_DEFINE_TYPE(GArrowListDataType,
Expand Down Expand Up @@ -717,4 +719,80 @@ garrow_dictionary_data_type_is_ordered(GArrowDictionaryDataType *dictionary_data
return arrow_dictionary_data_type->ordered();
}


G_DEFINE_TYPE(GArrowRunEndEncodedDataType,
garrow_run_end_encoded_data_type,
GARROW_TYPE_FIXED_WIDTH_DATA_TYPE)

static void
garrow_run_end_encoded_data_type_init(GArrowRunEndEncodedDataType *object)
{
}

static void
garrow_run_end_encoded_data_type_class_init(
GArrowRunEndEncodedDataTypeClass *klass)
{
}

/**
* garrow_run_end_encoded_data_type_new:
* @run_end_data_type: The data type of run-end.
* @value_data_type: The data type of value.
*
* Returns: The newly created run-end encoded data type.
*
* Since: 13.0.0
*/
GArrowRunEndEncodedDataType *
garrow_run_end_encoded_data_type_new(GArrowDataType *run_end_data_type,
GArrowDataType *value_data_type)
{
auto arrow_run_end_data_type = garrow_data_type_get_raw(run_end_data_type);
auto arrow_value_data_type = garrow_data_type_get_raw(value_data_type);
auto arrow_data_type = arrow::run_end_encoded(arrow_run_end_data_type,
arrow_value_data_type);
return GARROW_RUN_END_ENCODED_DATA_TYPE(
garrow_data_type_new_raw(&arrow_data_type));
}

/**
* garrow_run_end_encoded_data_type_get_run_end_data_type:
* @data_type: The #GArrowRunEndEncodedDataType.
*
* Returns: (transfer full): The #GArrowDataType of run-end.
*
* Since: 13.0.0
*/
GArrowDataType *
garrow_run_end_encoded_data_type_get_run_end_data_type(
GArrowRunEndEncodedDataType *data_type)
{
auto arrow_data_type = garrow_data_type_get_raw(GARROW_DATA_TYPE(data_type));
auto arrow_run_end_encoded_data_type =
std::static_pointer_cast<arrow::RunEndEncodedType>(arrow_data_type);
auto arrow_run_end_data_type = arrow_run_end_encoded_data_type->run_end_type();
return garrow_data_type_new_raw(&arrow_run_end_data_type);
}

/**
* garrow_run_end_encoded_data_type_get_value_data_type:
* @data_type: The #GArrowRunEndEncodedDataType.
*
* Returns: (transfer full): The #GArrowDataType of value.
*
* Since: 13.0.0
*/
GArrowDataType *
garrow_run_end_encoded_data_type_get_value_data_type(
GArrowRunEndEncodedDataType *data_type)
{
auto arrow_data_type = garrow_data_type_get_raw(GARROW_DATA_TYPE(data_type));
auto arrow_run_end_encoded_data_type =
std::static_pointer_cast<arrow::RunEndEncodedType>(arrow_data_type);
auto arrow_value_data_type = arrow_run_end_encoded_data_type->value_type();
return garrow_data_type_new_raw(&arrow_value_data_type);
}


G_END_DECLS
26 changes: 26 additions & 0 deletions c_glib/arrow-glib/composite-data-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,30 @@ gboolean
garrow_dictionary_data_type_is_ordered(GArrowDictionaryDataType *dictionary_data_type);


#define GARROW_TYPE_RUN_END_ENCODED_DATA_TYPE \
(garrow_run_end_encoded_data_type_get_type())
G_DECLARE_DERIVABLE_TYPE(GArrowRunEndEncodedDataType,
garrow_run_end_encoded_data_type,
GARROW,
RUN_END_ENCODED_DATA_TYPE,
GArrowFixedWidthDataType)
struct _GArrowRunEndEncodedDataTypeClass
{
GArrowFixedWidthDataTypeClass parent_class;
};

GARROW_AVAILABLE_IN_13_0
GArrowRunEndEncodedDataType *
garrow_run_end_encoded_data_type_new(GArrowDataType *run_end_data_type,
GArrowDataType *value_data_type);
GARROW_AVAILABLE_IN_13_0
GArrowDataType *
garrow_run_end_encoded_data_type_get_run_end_data_type(
GArrowRunEndEncodedDataType *data_type);
GARROW_AVAILABLE_IN_13_0
GArrowDataType *
garrow_run_end_encoded_data_type_get_value_data_type(
GArrowRunEndEncodedDataType *data_type);


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 @@ -108,6 +108,8 @@ garrow_type_from_raw(arrow::Type::type type)
return GARROW_TYPE_LARGE_LIST;
case arrow::Type::type::INTERVAL_MONTH_DAY_NANO:
return GARROW_TYPE_MONTH_DAY_NANO_INTERVAL;
case arrow::Type::type::RUN_END_ENCODED:
return GARROW_TYPE_RUN_END_ENCODED;
default:
return GARROW_TYPE_NA;
}
Expand Down
2 changes: 2 additions & 0 deletions c_glib/arrow-glib/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ G_BEGIN_DECLS
* @GARROW_TYPE_LARGE_BINARY: 64bit offsets Variable-length bytes (no guarantee of UTF-8-ness).
* @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.
*
* They are corresponding to `arrow::Type::type` values.
*/
Expand Down Expand Up @@ -110,6 +111,7 @@ typedef enum {
GARROW_TYPE_LARGE_BINARY,
GARROW_TYPE_LARGE_LIST,
GARROW_TYPE_MONTH_DAY_NANO_INTERVAL,
GARROW_TYPE_RUN_END_ENCODED,
} GArrowType;

/**
Expand Down
52 changes: 52 additions & 0 deletions c_glib/test/test-run-end-encoded-data-type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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 TestRunEndEncodedDataType < Test::Unit::TestCase
include Helper::Buildable

def setup
@run_end_data_type = Arrow::Int32DataType.new
@value_data_type = Arrow::StringDataType.new
@data_type = Arrow::RunEndEncodedDataType.new(@run_end_data_type,
@value_data_type)
end

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

def test_name
assert_equal("run_end_encoded", @data_type.name)
end

def test_to_s
assert_equal("run_end_encoded<run_ends: int32, values: string>",
@data_type.to_s)
end

def test_bit_width
assert_equal(-1, @data_type.bit_width)
end

def test_run_end_data_type
assert_equal(@run_end_data_type, @data_type.run_end_data_type)
end

def test_value_data_type
assert_equal(@value_data_type, @data_type.value_data_type)
end
end

0 comments on commit 2930761

Please sign in to comment.