3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/activerecord_adbc_adapter/database_statements.rb', line 3
def perform_query(raw_connection,
sql,
binds,
type_casted_binds,
prepare:,
notification_payload:,
batch:)
raw_connection.open_statement do |statement|
statement.sql_query = sql
if binds.empty?
statement.execute[0]
else
statement.prepare
raw_records = {}
binds.zip(type_casted_binds) do |bind, type_casted_bind|
case type_casted_bind
when String
if type_casted_bind.encoding == Encoding::ASCII_8BIT
array = Arrow::BinaryArray.new([type_casted_bind])
else
array = Arrow::StringArray.new([type_casted_bind])
end
when DateTime
array = Arrow::TimestampArray.new(:micro,
[type_casted_bind.dup.localtime])
when Date
array = Arrow::Date32Array.new([type_casted_bind])
when ActiveRecord::Type::Time::Value
local_time = type_casted_bind.dup.localtime
time_value = (local_time.seconds_since_midnight * 1_000_000).to_i
array = Arrow::Time64Array.new(:micro, [time_value])
else
array = [type_casted_bind]
end
raw_records[bind.name] = array
end
record_batch = Arrow::RecordBatch.new(raw_records)
statement.bind(record_batch) do
statement.execute[0]
end
end
end
end
|