Skip to content

Commit 44723e6

Browse files
committed
Add support for boolean
1 parent 391ee91 commit 44723e6

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

lib/activerecord_adbc_adapter/result.rb

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,29 @@ def attach_model(model)
2020
chunked_array = nil
2121
model_column = model_columns_hash[field.name]
2222
if model_column
23-
case model_column.sql_type_metadata.type
24-
when :date
25-
case field.data_type
26-
when Arrow::StringDataType
27-
casted_type = Arrow::Date32DataType.new
28-
chunked_array = column.cast(casted_type)
29-
field = Arrow::Field.new(field.name, casted_type)
30-
casted = true
31-
end
32-
when :datetime
33-
case field.data_type
34-
when Arrow::StringDataType
35-
casted_type = Arrow::TimestampDataType.new(:micro)
36-
chunked_array = column.cast(casted_type)
37-
field = Arrow::Field.new(field.name, casted_type)
38-
casted = true
39-
end
40-
end
23+
casted_type = nil
24+
case model_column.sql_type_metadata.type
25+
when :boolean
26+
case field.data_type
27+
when Arrow::IntegerDataType
28+
casted_type = Arrow::BooleanDataType.new
29+
end
30+
when :date
31+
case field.data_type
32+
when Arrow::StringDataType
33+
casted_type = Arrow::Date32DataType.new
34+
end
35+
when :datetime
36+
case field.data_type
37+
when Arrow::StringDataType
38+
casted_type = Arrow::TimestampDataType.new(:micro)
39+
end
40+
end
41+
if casted_type
42+
chunked_array = column.cast(casted_type)
43+
field = Arrow::Field.new(field.name, casted_type)
44+
casted = true
45+
end
4146
end
4247
new_chunked_arrays << (chunked_array || column.data)
4348
new_fields << field
@@ -109,6 +114,8 @@ def fields
109114

110115
def resolve_type(data_type)
111116
case data_type
117+
when Arrow::BooleanDataType
118+
ActiveRecord::Type::Boolean.new
112119
when Arrow::Int32DataType
113120
ActiveRecord::Type::Integer.new(limit: 4)
114121
when Arrow::Int64DataType

test/test_type.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
class TestType < Test::Unit::TestCase
22
include Helper::Sandbox
33

4+
def test_boolean_active_record
5+
ActiveRecord::Base.connection.create_table("users") do |table|
6+
table.boolean :boolean
7+
end
8+
User.create!(boolean: true)
9+
assert_equal(User.new(id: 1, boolean: true),
10+
User.first)
11+
end
12+
13+
def test_boolean_arrow
14+
ActiveRecord::Base.connection.create_table("users") do |table|
15+
table.boolean :boolean
16+
end
17+
User.create!(boolean: true)
18+
assert_equal(Arrow::Table.new(id: Arrow::Int64Array.new([1]),
19+
boolean: Arrow::BooleanArray.new([true])),
20+
User.to_arrow)
21+
end
22+
423
def test_bigint_active_record
524
ActiveRecord::Base.connection.create_table("users") do |table|
625
table.bigint :bigint

0 commit comments

Comments
 (0)