Guardians of Grail Forum Index Guardians of Grail
The best PVKII Clan
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   GalleriesGalleries   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to convert the following MySQL schema into Cou

 
Post new topic   Reply to topic    Guardians of Grail Forum Index -> Reports/Complaints
View previous topic :: View next topic  
Author Message
cheapbag214s
Post Master
Post Master



Joined: 27 Jun 2013
Posts: 19871
Read: 0 topics

Warns: 0/5
Location: England

PostPosted: Tue 2:10, 03 Sep 2013    Post subject: How to convert the following MySQL schema into Cou

How to convert the following MySQL schema into CouchDB,[link widoczny dla zalogowanych]
If each shoe is a document,[link widoczny dla zalogowanych], with a date_in and date_out,[link widoczny dla zalogowanych], then your reduce function will +1 if the date_out is null,[link widoczny dla zalogowanych], and +0 (no change) if date_out is not null. That will give you the total count of shoes in the warehouse.
To compute the average time,[link widoczny dla zalogowanych], for each shoe,[link widoczny dla zalogowanych], you know the time in the warehouse. So the reduce function simply accumulates the average. Since reduce functions must be commutative and associative,[link widoczny dla zalogowanych], you use a different average algorithm. The easiest way is to reduce to a [sum,[link widoczny dla zalogowanych], count] array,[link widoczny dla zalogowanych], where sum is an accumulator of all time for all shoes,[link widoczny dla zalogowanych], and count is a counter for the number of shoes counted. Then the client simply divides sum / count to compute the final average.
I think you could combine both of these into one big reduce if you want,[link widoczny dla zalogowanych], perhaps building up a {"shoes in warehouse": 1,[link widoczny dla zalogowanych], "average time in warehouse": [253,[link widoczny dla zalogowanych], 15]} kind of object.
However,[link widoczny dla zalogowanych], if you can accept two different views for this data,[link widoczny dla zalogowanych], then there is a shortcut for the average. In the map,[link widoczny dla zalogowanych], emit(null,[link widoczny dla zalogowanych], time) where time is the time spent in the warehouse. In the reduce,[link widoczny dla zalogowanych], set the entire reduce value to _stats (see Built-in reduce functions). The view output will be an object with the sum and count already computed.
相关的主题文章:


[link widoczny dla zalogowanych]

[link widoczny dla zalogowanych]

[link widoczny dla zalogowanych]

[link widoczny dla zalogowanych]

[link widoczny dla zalogowanych]

[link widoczny dla zalogowanych]

[link widoczny dla zalogowanych]

[link widoczny dla zalogowanych]

[link widoczny dla zalogowanych]

[link widoczny dla zalogowanych]

[link widoczny dla zalogowanych]

[link widoczny dla zalogowanych]

[link widoczny dla zalogowanych]

[link widoczny dla zalogowanych]

[link widoczny dla zalogowanych]


The post has been approved 0 times
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    Guardians of Grail Forum Index -> Reports/Complaints All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

fora.pl - załóż własne forum dyskusyjne za darmo
Powered by phpBB © 2001, 2005 phpBB Group
Regulamin