Skip to content
Merged
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
28 changes: 25 additions & 3 deletions c_glib/arrow-glib/basic-data-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1165,13 +1165,13 @@ GArrowTimestampDataType *
garrow_timestamp_data_type_new(GArrowTimeUnit unit, GTimeZone *time_zone)
{
auto arrow_unit = garrow_time_unit_to_raw(unit);
std::string arrow_timezone;
std::string arrow_time_zone;
#if GLIB_CHECK_VERSION(2, 58, 0)
if (time_zone) {
arrow_timezone = g_time_zone_get_identifier(time_zone);
arrow_time_zone = g_time_zone_get_identifier(time_zone);
}
#endif
auto arrow_data_type = arrow::timestamp(arrow_unit, arrow_timezone);
auto arrow_data_type = arrow::timestamp(arrow_unit, arrow_time_zone);
auto data_type =
GARROW_TIMESTAMP_DATA_TYPE(g_object_new(GARROW_TYPE_TIMESTAMP_DATA_TYPE,
"data-type",
Expand Down Expand Up @@ -2645,6 +2645,28 @@ garrow_data_type_new_raw(std::shared_ptr<arrow::DataType> *arrow_data_type)
break;
case arrow::Type::type::TIMESTAMP:
type = GARROW_TYPE_TIMESTAMP_DATA_TYPE;
{
auto arrow_timestamp_data_type =
std::static_pointer_cast<arrow::TimestampType>(*arrow_data_type);
const auto &arrow_time_zone = arrow_timestamp_data_type->timezone();
if (!arrow_time_zone.empty()) {
#if GLIB_CHECK_VERSION(2, 68, 0)
auto time_zone = g_time_zone_new_identifier(arrow_time_zone.c_str());
#else
auto time_zone = g_time_zone_new(arrow_time_zone.c_str());
#endif
data_type = GARROW_DATA_TYPE(g_object_new(type,
"data-type",
arrow_data_type,
"time-zone",
time_zone,
nullptr));
if (time_zone) {
g_time_zone_unref(time_zone);
}
return data_type;
}
}
break;
case arrow::Type::type::TIME32:
type = GARROW_TYPE_TIME32_DATA_TYPE;
Expand Down
13 changes: 10 additions & 3 deletions ruby/red-arrow-format/lib/arrow-format/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,11 @@ def build_array(size, validity_buffer, values_buffer)

class TimestampType < TemporalType
attr_reader :unit
attr_reader :timezone
def initialize(unit, timezone)
attr_reader :time_zone
def initialize(unit, time_zone)
super()
@unit = unit
@timezone = timezone
@time_zone = time_zone
end

def name
Expand All @@ -448,6 +448,13 @@ def name
def build_array(size, validity_buffer, values_buffer)
TimestampArray.new(self, size, validity_buffer, values_buffer)
end

def to_flatbuffers
fb_type = FB::Timestamp::Data.new
fb_type.unit = FB::TimeUnit.try_convert(@unit.to_s.upcase)
fb_type.timezone = @time_zone
fb_type
end
end

class IntervalType < TemporalType
Expand Down
38 changes: 19 additions & 19 deletions ruby/red-arrow-format/test/test-reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,15 @@ def test_type

sub_test_case("Timestamp(:second)") do
def setup(&block)
@timestamp_2019_11_18_00_09_11 = 1574003351
@timestamp_2019_11_17_15_09_11 = 1574003351
@timestamp_2025_12_16_05_33_58 = 1765863238
super(&block)
end

def build_array
Arrow::TimestampArray.new(:second,
[
@timestamp_2019_11_18_00_09_11,
@timestamp_2019_11_17_15_09_11,
nil,
@timestamp_2025_12_16_05_33_58,
])
Expand All @@ -369,7 +369,7 @@ def test_read
assert_equal([
{
"value" => [
@timestamp_2019_11_18_00_09_11,
@timestamp_2019_11_17_15_09_11,
nil,
@timestamp_2025_12_16_05_33_58,
],
Expand All @@ -381,15 +381,15 @@ def test_read

sub_test_case("Timestamp(:millisecond)") do
def setup(&block)
@timestamp_2019_11_18_00_09_11 = 1574003351 * 1_000
@timestamp_2019_11_17_15_09_11 = 1574003351 * 1_000
@timestamp_2025_12_16_05_33_58 = 1765863238 * 1_000
super(&block)
end

def build_array
Arrow::TimestampArray.new(:milli,
[
@timestamp_2019_11_18_00_09_11,
@timestamp_2019_11_17_15_09_11,
nil,
@timestamp_2025_12_16_05_33_58,
])
Expand All @@ -399,7 +399,7 @@ def test_read
assert_equal([
{
"value" => [
@timestamp_2019_11_18_00_09_11,
@timestamp_2019_11_17_15_09_11,
nil,
@timestamp_2025_12_16_05_33_58,
],
Expand All @@ -411,15 +411,15 @@ def test_read

sub_test_case("Timestamp(:microsecond)") do
def setup(&block)
@timestamp_2019_11_18_00_09_11 = 1574003351 * 1_000_000
@timestamp_2019_11_17_15_09_11 = 1574003351 * 1_000_000
@timestamp_2025_12_16_05_33_58 = 1765863238 * 1_000_000
super(&block)
end

def build_array
Arrow::TimestampArray.new(:micro,
[
@timestamp_2019_11_18_00_09_11,
@timestamp_2019_11_17_15_09_11,
nil,
@timestamp_2025_12_16_05_33_58,
])
Expand All @@ -429,7 +429,7 @@ def test_read
assert_equal([
{
"value" => [
@timestamp_2019_11_18_00_09_11,
@timestamp_2019_11_17_15_09_11,
nil,
@timestamp_2025_12_16_05_33_58,
],
Expand All @@ -441,15 +441,15 @@ def test_read

sub_test_case("Timestamp(:nanosecond)") do
def setup(&block)
@timestamp_2019_11_18_00_09_11 = 1574003351 * 1_000_000_000
@timestamp_2019_11_17_15_09_11 = 1574003351 * 1_000_000_000
@timestamp_2025_12_16_05_33_58 = 1765863238 * 1_000_000_000
super(&block)
end

def build_array
Arrow::TimestampArray.new(:nano,
[
@timestamp_2019_11_18_00_09_11,
@timestamp_2019_11_17_15_09_11,
nil,
@timestamp_2025_12_16_05_33_58,
])
Expand All @@ -459,7 +459,7 @@ def test_read
assert_equal([
{
"value" => [
@timestamp_2019_11_18_00_09_11,
@timestamp_2019_11_17_15_09_11,
nil,
@timestamp_2025_12_16_05_33_58,
],
Expand All @@ -469,27 +469,27 @@ def test_read
end
end

sub_test_case("Timestamp(timezone)") do
sub_test_case("Timestamp(time_zone)") do
def setup(&block)
@timezone = "UTC"
@timestamp_2019_11_18_00_09_11 = 1574003351
@time_zone = "UTC"
@timestamp_2019_11_17_15_09_11 = 1574003351
@timestamp_2025_12_16_05_33_58 = 1765863238
super(&block)
end

def build_array
data_type = Arrow::TimestampDataType.new(:second, @timezone)
data_type = Arrow::TimestampDataType.new(:second, @time_zone)
Arrow::TimestampArray.new(data_type,
[
@timestamp_2019_11_18_00_09_11,
@timestamp_2019_11_17_15_09_11,
nil,
@timestamp_2025_12_16_05_33_58,
])
end

def test_type
assert_equal([:second, @timezone],
[type.unit, type.timezone])
assert_equal([:second, @time_zone],
[type.unit, type.time_zone])
end
end

Expand Down
Loading
Loading