On Thursday, April 26, 2018 at 7:41:42 AM UTC-7, [email protected] 
wrote:
>
> Sorry for my super response here. I actually began work on a sequel-drill 
> driver, but this project has sort of been on-again-off-again. Definitely 
> committed to seeing this through now and getting this over the finish line:
>
> https://github.com/joeauty/sequel-drill
>
> A question I have for the community:
>
> The above driver is a little crude on account of it being my first go at 
> writing this, but also because it sort of generates table names in SQL 
> statements in a rather hacky way (regex). Do you have any tips for an 
> abstraction layer I can override/plug into that would help? Basically, 
> normally a SQL statement would be in the format:
>
> select * from <table name>
>
> where Drill needs this to be:
>
> select * from dfs.<workspace>.`<table name>`
>
> The workspace I'm deriving from the connection string (it is sort of a 
> conceptual database), but the big challenge is basically adding this entire 
> preface and wrapping it in backticks. My regex does work, but obviously it 
> will be messy to keep tacking on new regex for new sort of query support 
> (e.g. join statements). It would be lovely to be able to do this in one 
> place overriding some sort of abstraction where table names are generated.
>
> Do you have any suggestions for how I might go about this, whether this is 
> in the form of a Sequel PR, or something that can be done in my driver 
> without modifications to the parent project?
>

I would override Dataset#from and Dataset#join_table.:

DB.extend_datasets do
  def from(*sources)
    sources.map!{|table| wrap_table(table)}
    super
  end

  def join_table(type, table, *args)
    table = wrap_table(table)
    super
  end

  private

  def wrap_table(table)
    case table
    when Symbol, Sequel::SQL::Identifier
      Sequel.qualify(Sequel.qualify(Sequel.lit('dfs'), 
Sequel.lit(db.opts[:workspace])), table)
    else
      table
    end
  end
end

That should handle the most common places where table names are used.  If 
there are other cases, you can call wrap_table in those cases as well.  I 
don't want to include direct support for this type of mangling in Sequel.

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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to