
dm-aggregates with oracle invalid calculations
Reported by Rafał Michalski | July 29th, 2010 @ 11:15 AM
All aggregate functions (count, min, max, avg) returns inappropriate values while connecting with oracle adapter.
Oracle OCI adapter returns values of all aggregate functions as BigDecimal.
conn = OCI8.new('user','***','Oracle1')
conn.exec('SELECT COUNT(*) FROM "SOME_TABLE"') {|r| puts r.first.inspect}
#<BigDecimal:8e68fc0,'0.1224E4',4(8)>
Then the return values are internally converted by DataMapper to
strings and then again to numbers.
So e.g. for count:
SomeTable.aggregate(:all.count)
#=> 0
#<BigDecimal:8e68fc0,'0.1224E4',4(8)> (to_s) => "0.1224E4" => (to_i) => 0
At first BigDecimal gets converted to String ("0.1224E4") and then to Integer (0).
I don't know if the problem is with dm-aggregates itself or rather at oracle-adapter.
As a workaround for 'count' to get working i've made change in
dm-aggregates/adapters/dm-do-adapter.rb
changing:
def count(property, value)
value.to_i
end
to
def count(property, value)
value.to_f.to_i
end
now i'm getting what i've expected:
SomeTable.aggregate(:all.count)
#=> 1224
Comments and changes to this ticket
-
Aaron Qian June 19th, 2012 @ 05:23 PM
- Tag changed from count, dm-aggregates, oracle to count, dm-aggregates, oracle
I'm seeing this as well. I'm monkey patching in my project as suggested by Rafał Michalski, and it is working so far.
Is there any plan to fixed this? This ticket has been 2 years old. Let me know if there is anything I can help to make this ticket go away! :)
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »