Sequel Model not working with a dataset but works standalone [JDBC, Rocksetdb]

7 views
Skip to first unread message

Vysakh Sreenivasan

unread,
Aug 24, 2021, 5:22:37 AMAug 24
to sequel-talk
Hi

sample = DB[Sequel[:public][:sample]]
sample.first

This works fine. But

class SampleModel < Sequel::Model(sample); end

throws an exception. I'm using rockset database through their JDBC adapter. Based on Base.rb in sequel code, I see the schema is being fetched and all the related columns are being fetched, I suspect if that's where the code fails.

For eg:

DB.tables

This fails but 

DB.tables(:schema => :public)

This works. Initially I had a different schema (called: "common"), I thought making it into public would help Sequel infer the columns and the model would work, but it doesn't seem to work.

I was wondering if somehow set the schema name like DB.set_schema_name or load the entire database schema, then this would work.

I'm trying to get the Sequel Model get working but couldn't make a progress, I can get it working through the non-model approach, through dataset. But I don't want to lose out on the features that Model brings in. Appreciate any help.

Thanks in advance,
Vysakh




Screenshot 2021-08-24 at 2.40.18 PM.png

Jeremy Evans

unread,
Aug 24, 2021, 10:48:39 AMAug 24
to seque...@googlegroups.com
On Tue, Aug 24, 2021 at 2:22 AM Vysakh Sreenivasan <vys...@pipesort.com> wrote:
Hi

sample = DB[Sequel[:public][:sample]]
sample.first

This works fine. But

class SampleModel < Sequel::Model(sample); end

throws an exception. I'm using rockset database through their JDBC adapter. Based on Base.rb in sequel code, I see the schema is being fetched and all the related columns are being fetched, I suspect if that's where the code fails.

You could try using the same dataset:

  class SampleModel < Sequel::Model(DB[Sequel[:public][:sample]]); end

Note that Sequel does not have a jdbc subadapter for Rocksetdb, so it is using the generic support in the jdbc adapter.  The JDBC driver for Rocksetdb apparently does not return tables in the public schema if the public schema is not explicitly provided.
 
For eg:

DB.tables

This fails but 

DB.tables(:schema => :public)


You can do this manually (this is for tables, similar overrides can be made for other methods such as DB.schema.

def DB.tables(opts={})
  opts[:schema] ? super : super(opts.merge(:schema=>:public))
end

This works. Initially I had a different schema (called: "common"), I thought making it into public would help Sequel infer the columns and the model would work, but it doesn't seem to work.

I was wondering if somehow set the schema name like DB.set_schema_name or load the entire database schema, then this would work.

Sequel doesn't support a feature like that.  On PostgreSQL, you can use the :search_path option to specify the schema order to use for unqualified references.  But that relies on PostgreSQL support, it's not something where Sequel is actively checking the search path.
 
I'm trying to get the Sequel Model get working but couldn't make a progress, I can get it working through the non-model approach, through dataset. But I don't want to lose out on the features that Model brings in. Appreciate any help.

As shown above, you can pass a dataset to Sequel::Model.  That should be the simplest way to solve your issue.

Thanks,
Jeremy

Vysakh Sreenivasan

unread,
Aug 24, 2021, 12:10:03 PMAug 24
to seque...@googlegroups.com
Thanks a lot for the detailed reply, Jeremy! Appreciate it much!

I had tried the dataset solution, it hadn’t worked. Attached screenshot of the error. I suspect there are lot of things happening in Sequel::Model to sync the table to the Model. I think I have to check the function approach which overrides the schema just like you had suggested for def DB.tables.

I will give it few more tries with other approaches. The Rockset client expects the schema name explicitly, I suspect that would be the reason. 

Thank you for the great library! Have a great day!

Regards,
Vysakh

Jeremy Evans

unread,
Aug 24, 2021, 12:22:17 PMAug 24
to seque...@googlegroups.com
On Tue, Aug 24, 2021 at 9:10 AM Vysakh Sreenivasan <vys...@pipesort.com> wrote:
Thanks a lot for the detailed reply, Jeremy! Appreciate it much!

I had tried the dataset solution, it hadn’t worked. Attached screenshot of the error. I suspect there are lot of things happening in Sequel::Model to sync the table to the Model. I think I have to check the function approach which overrides the schema just like you had suggested for def DB.tables.

I will give it few more tries with other approaches. The Rockset client expects the schema name explicitly, I suspect that would be the reason. 

Thank you for the great library! Have a great day!

Regards,
Vysakh




This looks like Rocksetdb doesn't support BEGIN/ROLLBACK (used for transactions).  You'll have to write a custom jdbc subadapter to support Rocksetdb, at least for the transaction handling.  Alternatively, if you don't care about transactions:

def DB.transaction(*)
  yield
end
 
Thanks,
Jeremy

Vysakh Sreenivasan

unread,
Aug 24, 2021, 12:26:38 PMAug 24
to seque...@googlegroups.com
It worked! I don’t need transaction for now! This is great! Thanks a lot!! :) :D 



On 24-Aug-2021, at 9:52 PM, Jeremy Evans <jeremy...@gmail.com> wrote:

On Tue, Aug 24, 2021 at 9:10 AM Vysakh Sreenivasan <vys...@pipesort.com> wrote:
Thanks a lot for the detailed reply, Jeremy! Appreciate it much!

I had tried the dataset solution, it hadn’t worked. Attached screenshot of the error. I suspect there are lot of things happening in Sequel::Model to sync the table to the Model. I think I have to check the function approach which overrides the schema just like you had suggested for def DB.tables.

I will give it few more tries with other approaches. The Rockset client expects the schema name explicitly, I suspect that would be the reason. 

Thank you for the great library! Have a great day!

Regards,
Vysakh

<Screenshot 2021-08-24 at 9.36.02 PM.png>


This looks like Rocksetdb doesn't support BEGIN/ROLLBACK (used for transactions).  You'll have to write a custom jdbc subadapter to support Rocksetdb, at least for the transaction handling.  Alternatively, if you don't care about transactions:

def DB.transaction(*)
  yield
end
 
Thanks,
Jeremy

-- 
You received this message because you are subscribed to a topic in the Google Groups "sequel-talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sequel-talk/QjzbU5ZgTiY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sequel-talk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/CADGZSSd55x8gecRpv6ZVw2eAbWBXr1-JjJNHfFNYdivfsOV_uA%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages