[ https://issues.apache.org/jira/browse/DATAFU-63?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16247893#comment-16247893 ]
OlgaK commented on DATAFU-63: ----------------------------- Hi Eyal, thank you for your reply. If UDFs don't have indices it's sad but still one don't need to go through the entire set in the best case. Instead I'd suggest to create a sorted set (`S`) of int and generate `k` numbers, then go through the input and pick elements by the order in `S`. In case the requested set is bigger than 1/2 of the original, making exclusion will definitely save time but if we'd like to save memory at the same time, we should be able to alter the input (not making any copy of it). For me it's still not clear how the input is handled. I'd expect `SRS(data, parameter)` results in SRS constructor call but the constructor is empty, data and parameter aren't mentioned in the main class but then magically appear in the sub-class. [Here|https://github.com/cur4so/incubator-datafu/tree/feature-DATAFU-63] is my preliminary attempt to demonstrate in the code what I mean. > SimpleRandomSample by a fixed number > ------------------------------------ > > Key: DATAFU-63 > URL: https://issues.apache.org/jira/browse/DATAFU-63 > Project: DataFu > Issue Type: New Feature > Reporter: jian wang > Assignee: jian wang > > SimpleRandomSample currently supports random sampling by probability, it does > not support random sample a fixed number of items. ReserviorSample may do the > work but since it relies on an in-memory priority queue, memory issue may > happen if we are going to sample a huge number of items, eg: sample 100M from > 100G data. > Suggested approach is to create a new class "SimpleRandomSampleByCount" that > uses Manuver's rejection threshold to reject items whose weight exceeds the > threshold as we go from mapper to combiner to reducer. The majority part of > the algorithm will be very similar to SimpleRandomSample, except that we do > not use Berstein's theory to accept items and replace probability p = k / n, > k is the number of items to sample, n is the total number of items local in > mapper, combiner and reducer. > Quote this requirement from others: > "Hi folks, > Question: does anybody know if there is a quicker way to randomly sample a > specified number of rows from grouped data? I’m currently doing this, since > it appears that the SAMPLE operator doesn’t work inside FOREACH statements: > photosGrouped = GROUP photos BY farm; > agg = FOREACH photosGrouped { > rnds = FOREACH photos GENERATE *, RANDOM() as rnd; > ordered_rnds = ORDER rnds BY rnd; > limitSet = LIMIT ordered_rnds 5000; > GENERATE group AS farm, > FLATTEN(limitSet.(photo_id, server, secret)) AS (photo_id, server, > secret); > }; > This approach seems clumsy, and appears to run quite slowly (I’m assuming the > ORDER/LIMIT isn’t great for performance). Is there a less awkward way to do > this? > Thanks, > " -- This message was sent by Atlassian JIRA (v6.4.14#64029)