Skip to content

Commit 5a9747a

Browse files
committed
Add support for time
1 parent 38d27da commit 5a9747a

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

lib/activerecord_adbc_adapter/database_statements.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ def perform_query(raw_connection,
2424
end
2525
when DateTime
2626
array = Arrow::TimestampArray.new(:micro,
27-
[type_casted_bind.localtime])
27+
[type_casted_bind.dup.localtime])
2828
when Date
2929
array = Arrow::Date32Array.new([type_casted_bind])
30+
when ActiveRecord::Type::Time::Value
31+
local_time = type_casted_bind.dup.localtime
32+
time_value = (local_time.seconds_since_midnight * 1_000_000).to_i
33+
array = Arrow::Time64Array.new(:micro, [time_value])
3034
else
3135
array = [type_casted_bind]
3236
end

lib/activerecord_adbc_adapter/quoting.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,9 @@ def quote_column_name(column_name)
1111
def quoted_date(value)
1212
value
1313
end
14+
15+
def quoted_time(value)
16+
value
17+
end
1418
end
1519
end

lib/activerecord_adbc_adapter/result.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ def resolve_type(data_type)
132132
ActiveRecord::Type::Date.new
133133
when Arrow::TimestampDataType
134134
ActiveRecord::Type::DateTime.new
135+
when Arrow::Time64DataType
136+
ActiveRecord::Type::Time.new
135137
else
136138
raise "Unknown: #{data_type.inspect}"
137139
end

test/test_type.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,29 @@ def test_datetime_arrow
186186
datetime: array),
187187
User.to_arrow)
188188
end
189+
190+
def test_time_active_record
191+
omit("SQLite ADBC adapter doesn't support time for now") if sqlite?
192+
ActiveRecord::Base.connection.create_table("users") do |table|
193+
table.time :time
194+
end
195+
time = ActiveRecord::Type::Time::Value.new(Time.new(2025, 7, 20, 20, 40, 23))
196+
User.create!(time: time)
197+
assert_equal(User.new(id: 1, time: time),
198+
User.first)
199+
end
200+
201+
def test_time_arrow
202+
omit("SQLite ADBC adapter doesn't support time for now") if sqlite?
203+
ActiveRecord::Base.connection.create_table("users") do |table|
204+
table.time :time
205+
end
206+
time = ActiveRecord::Type::Time::Value.new(Time.new(2025, 7, 20, 20, 40, 23))
207+
User.create!(time: time)
208+
value = (time.seconds_since_midnight * 1_000_000).to_i
209+
array = Arrow::Time64Array.new(:micro, [value])
210+
assert_equal(Arrow::Table.new(id: Arrow::Int64Array.new([1]),
211+
time: array),
212+
User.to_arrow)
213+
end
189214
end

0 commit comments

Comments
 (0)