You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by J Chris Anderson <jc...@gmail.com> on 2010/07/26 20:58:27 UTC

Re: question on CouchDB views: how to use a query sting (formula) in the view

On Jul 26, 2010, at 11:23 AM, Fink Mark wrote:

> Hi there,
> 
> I am using CouchDB for some time now and now I am stuck with the following
> question.
> 
> Lets say I store some values from some Physics experiments in couchdb:
> 
> ID   x1   x2
> 1     1     1.1
> 2     2     1.2
> 3     3     1.3
> 4     4     1.4
> ...
> 
> Now I want to do some calculations within couchdb (NOT on the client side).
> Lets say I want to apply some formulas:
> y1 = 1*x1 + 0.5*x2*x2
> y2 = 1/3*x1 + 0.7*x2*x2*x2
> ...
> 
> I am thinking about passing the formula as a parameter to the view. Is this
> possible without using eval and does the caching still work like if I apply
> the same formula again it is faster? Maybe there is a sample available?
> 
> For a RDBMS I would probably do something like that:
> select (1*x1 + 0.5*x2*x2) as y1 from experiments;
> 
> Please do not tell me that I have to use a different view for each formula
> because this is not possible besides it is possible to create new views
> dynamically when needed.
> 

if you have a list of needed formulas ahead of time you could run them each in the view and emit them under keys, so for each doc you can look up by key, the forumula you'd like.

so keys would be like emit([doc._id, formul_name], formula_value)

I'm thinking you don't want to do this.

Instead you want to apply the formula at runtime (on the server)

In this case you should use a _show function. Here's some info about them:

http://books.couchdb.org/relax/example-app/show-documents

Cheers,
Chris






> 
> Regards
> Mark


Re: question on CouchDB views: how to use a query sting (formula) in the view

Posted by Fink Mark <ma...@mark-fink.de>.
> if you have a list of needed formulas ahead of time you could run them each
> in the view and emit them under keys, so for each doc you can look up by
> key, the forumula you'd like.
>
> so keys would be like emit([doc._id, formul_name], formula_value)
>
> I'm thinking you don't want to do this.
>

I think that is a solution for what I was talking about. What I can not
understand so far is why I need the formulas ahead of time. Don't you think
I can run them when a new formula is introduced to the system? That would
make the whole thing a little bit more interactive.

I think the show and list functionality is more for markup related use
cases. Of cause I also want the Reduce functionality to calculate min, max,
avg, etc. for new formulas y1, y2, .... Therefore the view would be the
right place to implement the formulas.

A little bit of topic but is there a JSON, RESTful data store available
which supports queries? I am into data analysis and naturally the queries
are defined by the end user and not by the system administrator. I am a
little disappointed of CouchDB because I often read that it is particularly
well suited for data analysis.

Best Regards
Mark