Changing behaviour of regex filters for adapter

2016-09-01 Thread Eric Schwartz
I'm working on updating a Sequel adapter (sequel-vertica) for my own 
nefarious purposes (actually, I'm adding support for COPY FROM STDIN), and 
I am running across a problem trying to get all the existing tests to pass.

It seems that when Sequel sees a dataset filter like: @ds.filter(name: /bc/) 
that it wants to turn this into WHERE "name" ~ /bc/ but Vertica doesn't 
support ~; instead it wants to use WHERE "name" REGEXP_LIKE('bc'). When I 
traced this, it seemed to be a result of looking up a set of filter types 
in Sequel::SQL::StringExpression::LIKE_MAP. I'm not clear on how I could 
coerce the Vertica adapter to use REGEXP_LIKE instead of ~ in this context. 
What should I try?

-=Eric

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


Re: proprietary timeseries clause for subquery

2015-12-10 Thread Eric Schwartz
Thanks, Jeremy! That was a lot easier than I expected.

If you'd care to take a look, my changes are up 
here: 
https://github.com/nexiahome/sequel-vertica/commit/832442163a45b797a328a208529ce7d8563eb746

I think it looks pretty good, but there's probably a better way to do the 
quoting around the AS clause.

-=Eric

On Wednesday, December 9, 2015 at 9:01:28 PM UTC-7, Jeremy Evans wrote:
>
> On Wednesday, December 9, 2015 at 7:48:53 PM UTC-8, Eric Schwartz wrote:
>>
>> HPE's Vertica database has a proprietary extension used for generating 
>> timeseries data. I am trying to figure out how to invoke it from Sequel 
>> with minimal hullabaloo.
>>
>> Here's an example of the kind of query I'm trying to build:
>>
>> SELECT slice_time,
>>round(ts_last_value(a_column IGNORE NULLS, 'linear')) AS a_col
>> FROM(
>>   select occurred_at,
>>  a_column
>>   FROM a_table
>>   WHERE something = 'something else'
>> ) subq -- this is not used, but the parser requires a name here
>> TIMESERIES slice_time AS '1 second' OVER(ORDER BY occurred_at)
>>
>> I can build the subquery with:
>>
>> subquery = DB.from(:a_table).select(:occurred_at, 
>> :a_column).where(something: 'something_else')
>>
>> I can then compose it into the outer query with 
>>
>> DB.from(subquery).select { |o| [o.slice_time, 
>> o.round(o.ts_last_value(Sequel.lit("a_column IGNORE NULLS"), 
>> 'linear')).as(:a_col)] }
>>
>> but I can't figure out how to add the TIMESERIES clause to the query. I 
>> don't mind dropping into Sequel.lit if required (as you can see), but I 
>> need to get a dataset back, since this query will itself be included into 
>> another query as a subquery. Any suggestions are greatly appreciated.
>>
>
> This is really something that should be added to the vertica adapter. You 
> want to add the ability to call a method to append an additional clause. 
>  Look at the Dataset.def_sql_method calls in the shared adapters that ship 
> with Sequel for an example of how to do this.  It should be possible to 
> hack it in:
>
>   DB.extend_datasets do
> Dataset.def_sql_method(self, :select, %w'with select distinct columns 
> from join timeseries where group having compounds order limit lock'
>
> def timeseries(s)
>   clone(:timeseries => s)
> end
>
> private
>
> def select_timeseries_sql(sql)
>   if opts[:timeseries]
> sql << 'TIMESERIES ' << opts[:timeseries]
>   end
> end
>   end
>  
> That's not necessarily a good way to do it, as you have to specify the 
> timeseries as a string, and I didn't even try it, but it should give you 
> the basic idea for how to implement it.
>
> BTW, if there's a better way to do the round(ts_last_value(...)) bit, I'm 
>> not super-thrilled with how that looks (it works fine, though).
>>
>
> That doesn't seem like a bad way to do it.  The only faster way would be 
> not having the virtual row block accept an argument.
>
> 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 post to this group, send email to sequel-talk@googlegroups.com.
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.


proprietary timeseries clause for subquery

2015-12-09 Thread Eric Schwartz
HPE's Vertica database has a proprietary extension used for generating 
timeseries data. I am trying to figure out how to invoke it from Sequel 
with minimal hullabaloo.

Here's an example of the kind of query I'm trying to build:

SELECT slice_time,
   round(ts_last_value(a_column IGNORE NULLS, 'linear')) AS a_col
FROM(
  select occurred_at,
 a_column
  FROM a_table
  WHERE something = 'something else'
) subq -- this is not used, but the parser requires a name here
TIMESERIES slice_time AS '1 second' OVER(ORDER BY occurred_at)

I can build the subquery with:

subquery = DB.from(:a_table).select(:occurred_at, 
:a_column).where(something: 'something_else')

I can then compose it into the outer query with 

DB.from(subquery).select { |o| [o.slice_time, 
o.round(o.ts_last_value(Sequel.lit("a_column IGNORE NULLS"), 
'linear')).as(:a_col)] }

but I can't figure out how to add the TIMESERIES clause to the query. I 
don't mind dropping into Sequel.lit if required (as you can see), but I 
need to get a dataset back, since this query will itself be included into 
another query as a subquery. Any suggestions are greatly appreciated.

BTW, if there's a better way to do the round(ts_last_value(...)) bit, I'm 
not super-thrilled with how that looks (it works fine, though).

-=Eric

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