-
1. Re: Teiid and Rails
shawkins Jan 17, 2012 10:25 AM (in response to johnp)It must be going by the type names and not the type codes. Our bigdecimal is roughly equivalent to the standard decimal type. Can you provide a type mapping to Rails? We could also add our built-in standard type aliases to our driver for varchar, tinyint, smallint, bigint, real, and decimal.
Steve
-
2. Re: Teiid and Rails
johnp Jan 17, 2012 7:02 PM (in response to shawkins)Steve,
Thanks for the reply - I will need to do some more investigation before I can give you an answer. I am using the standard activerecord-jdbc-adapter at the moment and you can certainly create another adapter which is specific to Teiid (there are already flavours for MySQL, Postgresql, h2 etc). Alternatively, if you could use the base adapter and the teiid driver jar file did the work that would also be nice.
I did check the TorqueBox mailing lists but couldn't find anything there.
Thanks again,
John
-
3. Re: Teiid and Rails
johnp Jan 18, 2012 1:24 AM (in response to shawkins)Steve,
Hopefully a bit of progress ... I monkey patched the typeconverter.rb in the jdbc adapter and added a type of bigdecimal for the decimal conversion
:decimal => [ lambda {|r| Jdbc::Types::DECIMAL == r['data_type'].to_i},
lambda {|r| r['type_name'] =~ /^decimal$/i},
+ lambda {|r| r['type_name'] =~ /^bigdecimal$/i},
lambda {|r| r['type_name'] =~ /^numeric$/i},
lambda {|r| r['type_name'] =~ /^number$/i},
lambda {|r| r['type_name'] =~ /^real$/i},
lambda {|r| r['precision'] == '38'},
lambda {|r| r['data_type'].to_i == Jdbc::Types::DECIMAL}],
I also had to subsequently add an arel2_visitor method for JdbcAdapter and this appears to have made the connection to the VDB although I now get an ActiveRecord::JDBCError: Table xxx does not exist when doing a find.
I assume that this is something to do with a qualified table name in my VDB so hopefully I am a bit closer.
Cheers
-
4. Re: Teiid and Rails
johnp Jan 18, 2012 10:22 PM (in response to johnp)Ok I have managed to progress this further by changing the jdbc_columns method in the jdbc adapter so that it gets the correct column details from Teiid - the default jdbc adapter method returns null and therefore you get the "table does not exist" error
def jdbc_columns(table_name, name = nil)
sql = "select * from sys.columns where tablename = '#{table_name.to_s}'"
execute(sql, 'col_split_' + table_name.to_s).map do |field|
::ActiveRecord::ConnectionAdapters::JdbcColumn.new(field["Name"], field["DefaultValue"], field["DataType"], field["NullType"] == "Nullable")
end
end
After doing this I am about to access vdb tables from the raw connection (tbles = ActiveRecord::Base.connection.tables) or using a normal Rails model (rc = Provider.count).
Based on these early problems I think that there will probably be some other issues with using the standard jdbc adapter and an activerecord-teiid-adapter would be nice to have - maybe the Torquebox gang could write one
I am now able to deploy my Rails app to TorqueBox and everything seems to be ok except that I am using the Kaminari gem for pagination and the SQL that is generated causes errors ...
SELECT * FROM providers ORDER BY providers.id desc LIMIT 30 OFFSET 0
I believe it is because OFFSET is not supported and should be replaced with a comma...
SELECT * FROM providers ORDER BY providers.id desc LIMIT 30, 0
This returns no rows but if the values are reversed then it's all ok
SELECT * FROM providers ORDER BY providers.id desc LIMIT 0, 30
Any help or suggestions welcomed - do you know if the Torquebox people monitor this - there is no user forum on the TB site for this type of discussion.
Cheers,
JP
-
5. Re: Teiid and Rails
shawkins Jan 19, 2012 10:55 AM (in response to johnp)John,
That looks like good progress. Yes, we can certianly bring these findings to the attention of the Tourquebox people and at least get something documented on our side. The Teiid limit clause syntax is the same as MySQL, which is "LIMIT [offset,] limit" where the limit is logically applied after the offset. We also support the ansi standard FETCH FIRST syntax as an alternative. Are there options for changing the SQL generated by Kaminari?
Based upon your previous post it does look like adding the standard type name to our typeinfo would eliminate the need for the typeconverter.rb patch as there wouldn't be confusion between the biginteger and bigdecimal types. I'll log a JIRA for that.
Steve
-
6. Re: Teiid and Rails
shawkins Jan 27, 2012 10:17 AM (in response to shawkins)John,
https://issues.jboss.org/browse/TEIID-1908 added the standard type names to getTypeInfo. This fix is in 7.7 Beta1 if you have a chance to work with the Beta release. Do you have anything else fleshed out for a Teiid JDBC adapter / Kaminari dialect that could be captured in either Teiid or TorqueBox?
Steve