diff --git a/c_glib/arrow-glib/basic-data-type.cpp b/c_glib/arrow-glib/basic-data-type.cpp index dff972515022f..b2bd99e0f228d 100644 --- a/c_glib/arrow-glib/basic-data-type.cpp +++ b/c_glib/arrow-glib/basic-data-type.cpp @@ -114,6 +114,8 @@ G_BEGIN_DECLS * * #GArrowDecimalDataType is a base class for the decimal data types. * + * #GArrowDecimal64DataType is a class for the 64-bit decimal data type. + * * #GArrowDecimal128DataType is a class for the 128-bit decimal data type. * * #GArrowDecimal256DataType is a class for the 256-bit decimal data type. @@ -1500,7 +1502,10 @@ garrow_decimal_data_type_class_init(GArrowDecimalDataTypeClass *klass) GArrowDecimalDataType * garrow_decimal_data_type_new(gint32 precision, gint32 scale, GError **error) { - if (precision <= garrow_decimal128_data_type_max_precision()) { + if (precision <= garrow_decimal64_data_type_max_precision()) { + return GARROW_DECIMAL_DATA_TYPE( + garrow_decimal64_data_type_new(precision, scale, error)); + } else if (precision <= garrow_decimal128_data_type_max_precision()) { return GARROW_DECIMAL_DATA_TYPE( garrow_decimal128_data_type_new(precision, scale, error)); } else { @@ -1545,6 +1550,57 @@ garrow_decimal_data_type_get_scale(GArrowDecimalDataType *decimal_data_type) return arrow_decimal_type->scale(); } +G_DEFINE_TYPE(GArrowDecimal64DataType, + garrow_decimal64_data_type, + GARROW_TYPE_DECIMAL_DATA_TYPE) + +static void +garrow_decimal64_data_type_init(GArrowDecimal64DataType *object) +{ +} + +static void +garrow_decimal64_data_type_class_init(GArrowDecimal64DataTypeClass *klass) +{ +} + +/** + * garrow_decimal64_data_type_max_precision: + * + * Returns: The max precision of 64-bit decimal data type. + * + * Since: 19.0.0 + */ +gint32 +garrow_decimal64_data_type_max_precision() +{ + return arrow::Decimal64Type::kMaxPrecision; +} + +/** + * garrow_decimal64_data_type_new: + * @precision: The precision of decimal data. + * @scale: The scale of decimal data. + * @error: (nullable): Return location for a #GError or %NULL. + * + * Returns: (nullable): + * The newly created 64-bit decimal data type on success, %NULL on error. + * + * Since: 19.0.0 + */ +GArrowDecimal64DataType * +garrow_decimal64_data_type_new(gint32 precision, gint32 scale, GError **error) +{ + auto arrow_data_type_result = arrow::Decimal64Type::Make(precision, scale); + if (garrow::check(error, arrow_data_type_result, "[decimal64-data-type][new]")) { + auto arrow_data_type = *arrow_data_type_result; + return GARROW_DECIMAL64_DATA_TYPE( + g_object_new(GARROW_TYPE_DECIMAL64_DATA_TYPE, "data-type", &arrow_data_type, NULL)); + } else { + return NULL; + } +} + G_DEFINE_TYPE(GArrowDecimal128DataType, garrow_decimal128_data_type, GARROW_TYPE_DECIMAL_DATA_TYPE) @@ -2193,6 +2249,9 @@ garrow_data_type_new_raw(std::shared_ptr *arrow_data_type) case arrow::Type::type::MAP: type = GARROW_TYPE_MAP_DATA_TYPE; break; + case arrow::Type::type::DECIMAL64: + type = GARROW_TYPE_DECIMAL64_DATA_TYPE; + break; case arrow::Type::type::DECIMAL128: type = GARROW_TYPE_DECIMAL128_DATA_TYPE; break; diff --git a/c_glib/arrow-glib/basic-data-type.h b/c_glib/arrow-glib/basic-data-type.h index 77180018c9be8..52764e1e1473e 100644 --- a/c_glib/arrow-glib/basic-data-type.h +++ b/c_glib/arrow-glib/basic-data-type.h @@ -608,6 +608,26 @@ GARROW_AVAILABLE_IN_ALL gint32 garrow_decimal_data_type_get_scale(GArrowDecimalDataType *decimal_data_type); +#define GARROW_TYPE_DECIMAL64_DATA_TYPE (garrow_decimal64_data_type_get_type()) +GARROW_AVAILABLE_IN_19_0 +G_DECLARE_DERIVABLE_TYPE(GArrowDecimal64DataType, + garrow_decimal64_data_type, + GARROW, + DECIMAL64_DATA_TYPE, + GArrowDecimalDataType) +struct _GArrowDecimal64DataTypeClass +{ + GArrowDecimalDataTypeClass parent_class; +}; + +GARROW_AVAILABLE_IN_19_0 +gint32 +garrow_decimal64_data_type_max_precision(); + +GARROW_AVAILABLE_IN_0_12 +GArrowDecimal64DataType * +garrow_decimal64_data_type_new(gint32 precision, gint32 scale, GError **error); + #define GARROW_TYPE_DECIMAL128_DATA_TYPE (garrow_decimal128_data_type_get_type()) GARROW_AVAILABLE_IN_ALL G_DECLARE_DERIVABLE_TYPE(GArrowDecimal128DataType, diff --git a/c_glib/arrow-glib/type.cpp b/c_glib/arrow-glib/type.cpp index d9fc36b8861c4..c4c0748357673 100644 --- a/c_glib/arrow-glib/type.cpp +++ b/c_glib/arrow-glib/type.cpp @@ -78,6 +78,8 @@ garrow_type_from_raw(arrow::Type::type type) return GARROW_TYPE_MONTH_INTERVAL; case arrow::Type::type::INTERVAL_DAY_TIME: return GARROW_TYPE_DAY_TIME_INTERVAL; + case arrow::Type::type::DECIMAL64: + return GARROW_TYPE_DECIMAL64; case arrow::Type::type::DECIMAL128: return GARROW_TYPE_DECIMAL128; case arrow::Type::type::DECIMAL256: diff --git a/c_glib/arrow-glib/type.h b/c_glib/arrow-glib/type.h index 6f33ad64ef55c..04562a8ccad11 100644 --- a/c_glib/arrow-glib/type.h +++ b/c_glib/arrow-glib/type.h @@ -50,6 +50,8 @@ G_BEGIN_DECLS * @GARROW_TYPE_TIME64: Exact time encoded with int64, supporting micro- or nanoseconds * @GARROW_TYPE_MONTH_INTERVAL: YEAR_MONTH interval in SQL style. * @GARROW_TYPE_DAY_TIME_INTERVAL: DAY_TIME interval in SQL style. + * @GARROW_TYPE_DECIMAL64: Precision- and scale-based decimal + * type with 64-bit. Storage type depends on the parameters. * @GARROW_TYPE_DECIMAL128: Precision- and scale-based decimal * type with 128-bit. Storage type depends on the parameters. * @GARROW_TYPE_DECIMAL256: Precision- and scale-based decimal @@ -97,6 +99,7 @@ typedef enum { GARROW_TYPE_TIME64, GARROW_TYPE_MONTH_INTERVAL, GARROW_TYPE_DAY_TIME_INTERVAL, + GARROW_TYPE_DECIMAL64, GARROW_TYPE_DECIMAL128, GARROW_TYPE_DECIMAL256, GARROW_TYPE_LIST, diff --git a/c_glib/test/test-decimal128-data-type.rb b/c_glib/test/test-decimal128-data-type.rb index 8cf97e38d47b5..74f39f6ef3eb2 100644 --- a/c_glib/test/test-decimal128-data-type.rb +++ b/c_glib/test/test-decimal128-data-type.rb @@ -42,8 +42,8 @@ def test_scale end def test_decimal_data_type_new - assert_equal(Arrow::Decimal128DataType.new(8, 2), - Arrow::DecimalDataType.new(8, 2)) + assert_equal(Arrow::Decimal128DataType.new(19, 2), + Arrow::DecimalDataType.new(19, 2)) end def test_invalid_precision diff --git a/c_glib/test/test-decimal64-data-type.rb b/c_glib/test/test-decimal64-data-type.rb new file mode 100644 index 0000000000000..5a0c5d08401e2 --- /dev/null +++ b/c_glib/test/test-decimal64-data-type.rb @@ -0,0 +1,54 @@ +# 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 TestDecimal64DataType < Test::Unit::TestCase + def test_type + data_type = Arrow::Decimal64DataType.new(2, 0) + assert_equal(Arrow::Type::DECIMAL64, data_type.id) + end + + def test_name + data_type = Arrow::Decimal64DataType.new(2, 0) + assert_equal("decimal64", data_type.name) + end + + def test_to_s + data_type = Arrow::Decimal64DataType.new(2, 0) + assert_equal("decimal64(2, 0)", data_type.to_s) + end + + def test_precision + data_type = Arrow::Decimal64DataType.new(8, 2) + assert_equal(8, data_type.precision) + end + + def test_scale + data_type = Arrow::Decimal64DataType.new(8, 2) + assert_equal(2, data_type.scale) + end + + def test_decimal_data_type_new + assert_equal(Arrow::Decimal64DataType.new(18, 2), + Arrow::DecimalDataType.new(18, 2)) + end + + def test_invalid_precision + assert_raise(Arrow::Error::Invalid) do + Arrow::Decimal64DataType.new(19, 1) + end + end +end