[Modeling-users] Raw Qualifiers
Status: Abandoned
Brought to you by:
sbigaret
From: Yannick G. <yan...@sa...> - 2003-07-15 19:30:41
|
=2D----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi everyone,=20 I'd like to share with you the joy of building qualifiers by hand. The use we have for the framework here is really dependent on performance. So we looked at those profiler logs and asked Seb why spark was sucking so much juice. Promptly we found out that spark was slow because it was flexible but it is possible to make Qualifier by hand without passing by the ugly string to parse. Unfortunately all this nice magic is undocumented right now : ( So it goes like this : There is a bunch of operator out there, somewhere in Qualifier.py or if you prefer Modeling.Qualifier. The operators are exactly the ones you would expect to use the in the query string : QualifierOperatorEqual for "=3D=3D", QualifierOperatorLessThan for "<", QualifierOperatorLike for "like" and so on. The main idea is to build some qualifiers that put those operators in relation with your model. I used Qualifier.KeyValueQualifier but you may want to try KeyComparisonQualifier too. that part is easy, you create some qualifiers instances with a key, an operator and a value: # match all the authors who's name start with "H" qual1 =3D KeyValueQualifier( "name",=20 QualifierOperatorLike, "H*" ) # match only young authors qual2 =3D KeyValueQualifier( "age", QualifierOperatorLessThan, 35 ) # match the authors who's name ends with "s" qual3 =3D KeyValueQualifier( "age", QualifierOperatorLike, "*s" ) And now that I'm done with the qualifier, I simply need to put them togethe= r : # I don't like authors who's name ends with "s" qual4 =3D NotQualifier(qual4) # pack all of those in a single qualifier allQuals =3D (qual1, qual2, qual4) # any sequence (list of tuple) will do qual5 =3D AndQualifier(allQuals) And finally do the fetch: objs =3D ec.fetch("author", qual5) Or the super fast: dicts =3D ec.fetch("author", qual5, rawRow=3D1) Nice isn't it ? So how fast is it ? Twice as fast on my data, you millage may vary. : ) So I hope this will help you all to get the best out of the framework. The best source of doc is not the doc, the doc may get a bit out of synch. Dive into those sources up to the unit tests. S=E9bastien works hard to get all of those working all the time so you're sure to find a lot of working example there. Enjoy ! =2D --=20 Yannick Gingras Byte Gardener, Savoir-faire Linux inc. (514) 276-5468 =2D----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE/FFZerhy5Fqn/MRARArdcAJ0T83mw1ZHCqjEOo000kE9XUXdIxwCfRppm wYlFWKyPGPMNy0uYEz8kpqk=3D =3DkiXC =2D----END PGP SIGNATURE----- |