Re: JDBC Array datatype handling

2019-08-15 Thread 'Guy Boertje' via sequel-talk
Thank you Jeremy and thanks too for your tireless work on Sequel.

Guy

On Thursday, August 15, 2019 at 4:14:13 PM UTC+1, Jeremy Evans wrote:
>
> On Thursday, August 15, 2019 at 3:53:45 AM UTC-7, Guy Boertje wrote:
>>
>> > Do other drivers use driver-specific array types?
>>
>> I'm not sure about the driver-specific bit but I imagine that the driver 
>> designers will use a Java JDBC array type if the DB technology supports 
>> array columns or similar. I'm thinking of the newer breed of DB tech that 
>> is not tables, columns and rows for which JDBC APIs are becoming common.
>>
>> > Do all of the JDBC drivers that support array columns return an object 
>> that will respond to to_ary?
>>
>> My understanding is, the driver returns an instance of java.sql.Array, 
>> via the `getArray(column)` Jruby will wrap the result in some kind of Ruby 
>> compatible proxy. That proxy will translate the `.array` call into 
>> `getArray()` and that call will return another JRuby proxy. If that proxy 
>> is an instance of `ArrayJavaProxy` then it has a `to_ary` method returning 
>> `JavaUtil.convertJavaArrayToRubyWithNesting(context, array)`.
>> Without the call to `array` (as the postgres adapter does), AFAICT, 
>> `process_result_set` adds the proxy wrapped result of the 
>> `getArray(column)`.
>>
>> FWIW the activerecord-jdbc-adapter 
>> 
>>  uses 
>> a arrayToRuby method on all jdbc for at least 7 years with the Postgres 
>> specific override removed in 28 Mar 2018 (array handling identical but 
>> different because "Method org.postgresql.jdbc4.Jdbc4Array.free() is not yet 
>> implemented"). Their approach is interesting as it recursive into the array 
>> but their code is in Java/JRuby so they avoid the proxy wrappers.
>>
>
> Thank you for that information, it was very help to provide context.  I've 
> tested moving the code from the jdbc/postgresql subadapter to the jdbc 
> adapter and it appears to work.  I'll push the changes to GitHub shortly.
>
> Thanks,
> Jeremy
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/d92a7ec5-94fa-445e-9cb0-7140a0b54885%40googlegroups.com.


Re: JDBC Array datatype handling

2019-08-15 Thread Jeremy Evans
On Thursday, August 15, 2019 at 3:53:45 AM UTC-7, Guy Boertje wrote:
>
> > Do other drivers use driver-specific array types?
>
> I'm not sure about the driver-specific bit but I imagine that the driver 
> designers will use a Java JDBC array type if the DB technology supports 
> array columns or similar. I'm thinking of the newer breed of DB tech that 
> is not tables, columns and rows for which JDBC APIs are becoming common.
>
> > Do all of the JDBC drivers that support array columns return an object 
> that will respond to to_ary?
>
> My understanding is, the driver returns an instance of java.sql.Array, 
> via the `getArray(column)` Jruby will wrap the result in some kind of Ruby 
> compatible proxy. That proxy will translate the `.array` call into 
> `getArray()` and that call will return another JRuby proxy. If that proxy 
> is an instance of `ArrayJavaProxy` then it has a `to_ary` method returning 
> `JavaUtil.convertJavaArrayToRubyWithNesting(context, array)`.
> Without the call to `array` (as the postgres adapter does), AFAICT, 
> `process_result_set` adds the proxy wrapped result of the 
> `getArray(column)`.
>
> FWIW the activerecord-jdbc-adapter 
> 
>  uses 
> a arrayToRuby method on all jdbc for at least 7 years with the Postgres 
> specific override removed in 28 Mar 2018 (array handling identical but 
> different because "Method org.postgresql.jdbc4.Jdbc4Array.free() is not yet 
> implemented"). Their approach is interesting as it recursive into the array 
> but their code is in Java/JRuby so they avoid the proxy wrappers.
>

Thank you for that information, it was very help to provide context.  I've 
tested moving the code from the jdbc/postgresql subadapter to the jdbc 
adapter and it appears to work.  I'll push the changes to GitHub shortly.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/05fddca7-b2ec-4768-a9cf-af51413ba944%40googlegroups.com.


Re: JDBC Array datatype handling

2019-08-15 Thread 'Guy Boertje' via sequel-talk
> Do other drivers use driver-specific array types?

I'm not sure about the driver-specific bit but I imagine that the driver 
designers will use a Java JDBC array type if the DB technology supports 
array columns or similar. I'm thinking of the newer breed of DB tech that 
is not tables, columns and rows for which JDBC APIs are becoming common.

> Do all of the JDBC drivers that support array columns return an object 
that will respond to to_ary?

My understanding is, the driver returns an instance of java.sql.Array, via 
the `getArray(column)` Jruby will wrap the result in some kind of Ruby 
compatible proxy. That proxy will translate the `.array` call into 
`getArray()` and that call will return another JRuby proxy. If that proxy 
is an instance of `ArrayJavaProxy` then it has a `to_ary` method returning 
`JavaUtil.convertJavaArrayToRubyWithNesting(context, array)`.
Without the call to `array` (as the postgres adapter does), AFAICT, 
`process_result_set` adds the proxy wrapped result of the 
`getArray(column)`.

FWIW the activerecord-jdbc-adapter 

 uses 
a arrayToRuby method on all jdbc for at least 7 years with the Postgres 
specific override removed in 28 Mar 2018 (array handling identical but 
different because "Method org.postgresql.jdbc4.Jdbc4Array.free() is not yet 
implemented"). Their approach is interesting as it recursive into the array 
but their code is in Java/JRuby so they avoid the proxy wrappers.

HTH,
Guy



On Wednesday, August 14, 2019 at 3:02:18 PM UTC+1, Jeremy Evans wrote:
>
> On Wednesday, August 14, 2019 at 2:23:16 AM UTC-7, Guy Boertje wrote:
>>
>> Hi,
>>
>> I have a question regarding the generic type conversion for JDBC Array 
>> types.
>>
>> The java examples I've seen do a further getArray call on the object 
>> returned by resultset.getArray(column)
>>
>>   java.sql.Array array = rs.getArray(columnIndex);
>>   if (array == null) {
>> return true;
>>   }
>>   Object o = array.getArray();
>>
>> It looks like the postgres jdbc adapter does the correct thing.
>>
>> # Return PostgreSQL array types as ruby Arrays instead of
>> # JDBC PostgreSQL driver-specific array type. Only used if the
>> # database does not have a conversion proc for the type.
>> ARRAY_METHOD = Object.new
>> def ARRAY_METHOD.call(r, i)
>>   if v = r.getArray(i)
>> v.array.to_ary
>>   end
>> end 
>>
>> However, it looks like the generic jdbc adapter only calls 
>> getArray(column)
>>
>>   %w'Object Array String Time Date Timestamp BigDecimal Blob Bytes 
>> Clob'.each do |meth|
>> x = convertors[meth.to_sym] = Object.new
>> class_eval("def x.call(r, i) r.get#{meth}(i) end", __FILE__, 
>> __LINE__)
>>   end
>>
>> Before I create an issue in github, I wanted to check if there is a 
>> reason for not making the postgres specific handling the default for all of 
>> JDBC.
>>
>
> The documentation for the PostgreSQL method mentions that it is because 
> the JDBC PostgreSQL driver uses a driver-specific array type.  Do other 
> drivers use driver-specific array types?  Do all of the JDBC drivers that 
> support array columns return an object that will respond to to_ary?
>
> Thanks,
> Jeremy
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/48b7f533-1a18-478b-a1ff-0c61d40295a5%40googlegroups.com.


Re: JDBC Array datatype handling

2019-08-14 Thread Jeremy Evans
On Wednesday, August 14, 2019 at 2:23:16 AM UTC-7, Guy Boertje wrote:
>
> Hi,
>
> I have a question regarding the generic type conversion for JDBC Array 
> types.
>
> The java examples I've seen do a further getArray call on the object 
> returned by resultset.getArray(column)
>
>   java.sql.Array array = rs.getArray(columnIndex);
>   if (array == null) {
> return true;
>   }
>   Object o = array.getArray();
>
> It looks like the postgres jdbc adapter does the correct thing.
>
> # Return PostgreSQL array types as ruby Arrays instead of
> # JDBC PostgreSQL driver-specific array type. Only used if the
> # database does not have a conversion proc for the type.
> ARRAY_METHOD = Object.new
> def ARRAY_METHOD.call(r, i)
>   if v = r.getArray(i)
> v.array.to_ary
>   end
> end 
>
> However, it looks like the generic jdbc adapter only calls getArray(column)
>
>   %w'Object Array String Time Date Timestamp BigDecimal Blob Bytes 
> Clob'.each do |meth|
> x = convertors[meth.to_sym] = Object.new
> class_eval("def x.call(r, i) r.get#{meth}(i) end", __FILE__, 
> __LINE__)
>   end
>
> Before I create an issue in github, I wanted to check if there is a reason 
> for not making the postgres specific handling the default for all of JDBC.
>

The documentation for the PostgreSQL method mentions that it is because the 
JDBC PostgreSQL driver uses a driver-specific array type.  Do other drivers 
use driver-specific array types?  Do all of the JDBC drivers that support 
array columns return an object that will respond to to_ary?

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/a92864d0-cd60-4e35-b250-4a12401be41c%40googlegroups.com.


JDBC Array datatype handling

2019-08-14 Thread 'Guy Boertje' via sequel-talk
Hi,

I have a question regarding the generic type conversion for JDBC Array 
types.

The java examples I've seen do a further getArray call on the object 
returned by resultset.getArray(column)

  java.sql.Array array = rs.getArray(columnIndex);
  if (array == null) {
return true;
  }
  Object o = array.getArray();

It looks like the postgres jdbc adapter does the correct thing.

# Return PostgreSQL array types as ruby Arrays instead of
# JDBC PostgreSQL driver-specific array type. Only used if the
# database does not have a conversion proc for the type.
ARRAY_METHOD = Object.new
def ARRAY_METHOD.call(r, i)
  if v = r.getArray(i)
v.array.to_ary
  end
end 

However, it looks like the generic jdbc adapter only calls getArray(column)

  %w'Object Array String Time Date Timestamp BigDecimal Blob Bytes Clob'
.each do |meth|
x = convertors[meth.to_sym] = Object.new
class_eval("def x.call(r, i) r.get#{meth}(i) end", __FILE__, 
__LINE__)
  end

Before I create an issue in github, I wanted to check if there is a reason 
for not making the postgres specific handling the default for all of JDBC.

Thanks,
Guy Boertje
Elastic/Logstash


-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/5fef5f58-8f7c-4cc3-bc51-292d43f1c583%40googlegroups.com.