<div dir="ltr">Hi�Vsevolod!<div><br></div><div>I think it is possible to implement this feature in Pony ORM with the following API:<br><br>q1 = select(s for s in Student if ...)<br>q2 = select(s for s in Student if ...)<br>
q3 = q1.union(q2)<br>q4 = q1.intersect(q2)<br>q5 = q1.except(q2)<br><br>The implementation will take 3-5 work days (or may be longer, because MySQL has no direct support of INTERSECT and EXCEPT and requires to write a workaround via joins), and currently we have more urgent tasks (such as migration support), so I don't think this feature can be implemented during this year. Please add this feature to our issue list on GitHub, and we'll implement it when time permits.</div>
<div><br></div><div>By the way, I fear that some programmers may overuse such 'algebra' and as a result construct inefficient queries. Let's consider the next query:</div><div><br></div><div>SELECT * FROM T1 WHERE X > 100</div>
<div>INTERSECT</div><div>SELECT * FROM T1 WHERE Y < 200</div><div><br></div><div>In many situations, the next equivalent query will be faster:<br><br>SELECT * FROM T1 WHERE X > 100 and Y < 200</div><div><br></div>
<div>So in case of implementing user-restricted document search, it may be more efficient to implement it in the following way, via incremental filtering of the same query:</div><div><br></div><div><div>def document_search(current_user, specified_keyword=None,</div>
<div>� � � � part_of_title=None, document_type=None,</div><div>� � � � min_size=None, max_size=None):<br></div><div><br></div>� � query = select(d for d in Documents</div><div>� � � � if d.owner == current_user or current_user in d.editors)</div>
<div><div><br></div><div>� � if specified_keyword is not None:</div>� � � � query.filter(lambda d: specified_keyword in d.keywords)</div><div><br></div><div>� � if part_of_title is not None:</div><div>� � � � query.filter(lambda d: part_of_title in d.title)</div>
<div><br></div><div>� � if document_type is not None:<br></div><div>� � � � query.filter(lambda d: d.type = document_type)</div><div><br></div><div>� � if min_size is not None:</div><div>� � � � query.filter(lambda d: d.size >= min_size)</div>
<div><div><br></div><div>� � if max_size is not None:</div><div>� � � � query.filter(lambda d: d.size <= max_size)</div></div><div><br></div><div>� � return query<br><br>This way of filtering should works in the development version of Pony (it was accidentally broken in the last release 0.4.8, but will be restored in the upcoming release 0.4.9)</div>
<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Oct 21, 2013 at 2:27 PM, Vsevolod Novikov <span dir="ltr"><<a href="mailto:nnseva@gmail.com" target="_blank">nnseva@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi All,<div><br></div><div><div>It would be useful to implement some kind of 'algebra of sets': intersection, union, and subtraction of sets defined by two abstract queries.</div>
<div><br></div>
<div>Let I am writing a subsystem which should accept some queries A and B and do something with it's intersection. Is it possible someway?</div><div><br></div><div>The particular (simplified) usecase: Let we have Users, Groups, and Documents belonging to User (individual), or Group (shared).</div>
<div><br></div><div>We have wrote a 'user access' subsystem which restricts access to Documents and returns some DocumentSet (query?) object (document_set_a) which refers to all Documents belonging to this User directly or through the Group.</div>
<div><br></div><div>Also we have wrote some other subsystem, let it be 'document index', which returns other DocumentSet (query?) object (document_set_b) which refers to all Documents containing passed keywords.</div>
<div><br></div><div>Now we want to write user-restricted document index: the user passes us keywords and wants to see all Documents belonging to him and containing these keywords. So we should return a DocumentSet which is an intersection of document_set_a and document_set_b.</div>
<div><br></div><div>Regards,</div><div>Vsevolod</div><div><br></div></div></div>
<br>_______________________________________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">/ponyorm-list</a><br>
<br></blockquote></div><br></div>