Thanks, Jeremy
The back ticks worked. I also tried
sum([['192.168.50.', :ip_totlen]].case(0,
left(BIN_TO_IPV4(:ip_saddr),11))).as(:outgoing_bytes),
and got the error that #case wasn't a method of the Array class, so your
comment about core classes no longer being extended answers that.
Glancing through the documentation, I see "Sequel.case..." is now the way,
so I think I need to give the top-level documentation a fresh read. I know
enough Sequel to google specifically and I landed up on the StringLiteral
page: http://sequel.rubyforge.org/rdoc/classes/Sequel/LiteralString.html
This page and many others like it probably should be prefaced with a note
to load core extensions.
Michael
On Wed, Sep 18, 2013 at 11:22 PM, Jeremy Evans <[email protected]>wrote:
> On Wednesday, September 18, 2013 2:59:02 PM UTC-7, Michael Lang wrote:
>
>> DB[:ulog2].filter("timestamp > ?", now - 5.minutes).select{[
>> BIN_TO_IPV4(:ip_saddr).as(:**src_ip),
>> BIN_TO_IPV4(:ip_daddr).as(:**dst_ip),
>> "sum(if(left(BIN_TO_IPV4(ip_**saddr),11) = '192.168.50.',
>> ip_totlen, 0))".lit.as(:outgoing_bytes),
>> "sum(if(left(BIN_TO_IPV4(ip_**saddr),11) = '192.168.50.', 0,
>> ip_totlen))".lit.as(:incoming_**bytes),
>> sum(:ip_totlen).as(:volume),
>> count(:_id).as(:packets),
>> min(:timestamp).as(:flow_**start),
>> max(:timestamp).as(:flow_end)
>> ]}.
>> group(:ip_saddr, :ip_daddr)
>>
>> Gives....
>>
>> NoMethodError: undefined method ‘lit’ for #<String:0x007f91f4378da8>
>>
>
> String#lit not being available is unrelated to virtual row blocks.
> Starting in Sequel 4, Sequel no longer modifies the core classes. If you
> want to keep using String#lit, use:
>
> Sequel.extension :core_extensions
>
> Note that virtual row blocks offer a shortcut in creating literal strings
> using the ` method:
>
> DB[:ulog2].filter("timestamp > ?", now - 5.minutes).select{[
> BIN_TO_IPV4(:ip_saddr).as(:src_ip),
> BIN_TO_IPV4(:ip_daddr).as(:dst_ip),
> `sum(if(left(BIN_TO_IPV4(ip_saddr),11) = '192.168.50.', ip_totlen,
> 0))`.as(:outgoing_bytes),
> `sum(if(left(BIN_TO_IPV4(ip_saddr),11) = '192.168.50.', 0,
> ip_totlen))`.as(:incoming_bytes),
> sum(:ip_totlen).as(:volume),
> count(:_id).as(:packets),
> min(:timestamp).as(:flow_start),
> max(:timestamp).as(:flow_end)
> ]}.
> group(:ip_saddr, :ip_daddr)
>
> 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 http://groups.google.com/group/sequel-talk.
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
http://codeconnoisseur.org
--
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 http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.