[storm] SELECT with expressions, how to use new column

Daniel Åkerud daniel.akerud at gmail.com
Sat Dec 15 23:43:42 UTC 2012


So subtracting two timestamps was not really what I wanted to do ;-)

This works better:

age = SQL("TIMESTAMPDIFF(SECOND, timestamp, CURRENT_TIMESTAMP)")

result = self.store.find((Report, age), age < max_age_in_seconds)

Is there a smarter way to do this? It looks like mysql would have to call TIMESTAMPDIFF more than once for each row (but I have no clue how smart the database is though).

--  
BR/D


On Saturday, December 15, 2012 at 9:49 PM, Daniel Åkerud wrote:

>  
> Hello! I'm using Storm with a mysql backend, and I'm doing a select with an expression, like this:
>  
> result = self.store.find((Report, SQL("CURRENT_TIMESTAMP") - Report.timestamp as age), SQL("CURRENT_TIMESTAMP") - Report.timestamp < $max_age)
>  
> i.e:
> SELECT *, (CURRENT_TIMESTAMP - timestamp) AS age FROM report WHERE report.(CURRENT_TIMESTAMP - timestamp) < $max_age;
>  
>  
> (notice the "AS age")
>  
> So I want to use the new column in Storm, but do not know how to achieve that.
>  
> Thanks!
>  
> PS: If you know how to optimise away writing "SQL("CURRENT_TIMESTAMP") - Report.timestamp" twice, that would be SUPER :-)
> --  
>  
> BR/D
>  
>  
>  

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/storm/attachments/20121216/f43ecf6d/attachment.html>


More information about the storm mailing list