CapableObjects forum



PSQuery bug example

Posted By PeterMorris 2014-01-04 19:28:53
Add to Favorites0
Author Message
PeterMorris
 Posted 2014-01-04 19:28:53
Supreme Being

Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)

Group: Forum Members
Last Active: 2014-08-27 20:30:28
Posts: 324, Visits: 2 449
I have attached a small sample reproducing the PSQuery bug for PersistenceMapperMemory. It throw a NullReferenceException when it shouldn't.
 EcoProject6.zip (6 views, 79,93 KB)
william
 Posted 2014-01-06 03:21:11
Supreme Being

Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)

Group: Forum Members
Last Active: 2014-03-18 11:41:59
Posts: 92, Visits: 851
So have you ever used PSQuery on a memory pmapper? According to my own experience, PSQuery never work on memory pmapper (was always returning empty result for me in the past). So for unit testing (using memory pmapper), I have to write a bit strange looking codes like:

var r = (from c in ecoSpace.PSQuery<R>() select c).ToList();
if (r.Count()==0)
{
//// This is intended to be used by unit testing.
r = (from c in ecoSpace.MemQuery<R>() select c).ToList();
}

It would be like if CapableObjects could "fix" the PSQuery for the memory pmapper, or am I using it incorrectly?
HansKarlsen
 Posted 2014-01-08 14:45:52
Supreme Being

Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)

Group: Administrators
Last Active: 2016-05-11 20:56:01
Posts: 608, Visits: 3 230
Found and fixed the problem:

When you use linq qith EcoQuery in PS the parse tree is built from the linq expression - then the parse tree is sent over any wire you may have (WCF) to the persistence server...
On the server the Sql is constructcted from the parse tree nodes.

XmlPersistenceMapper and derivates does not construct SQL from the parse tree - instead they keep a temporary ecospace from the xml file in memory and execute the ocl expression on that...

Now comes the pitfall:

Since EcoQuery does not have an OclExpression - just a parse tree - the result comes back empty (empty ocl expression)

Solution:
Reconstruct the ocl query from the parse tree...

------
Several Changes, Clean ups etc was made on this checkin for EcoQuery. Also wrote an overview on eco's relation to linq: http://www.new.capableobjects.com/2014/01/08/a-few-words-on-linq/
PeterMorris
 Posted 2014-01-08 15:11:38
Supreme Being

Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)

Group: Forum Members
Last Active: 2014-08-27 20:30:28
Posts: 324, Visits: 2 449
Well done Hans! Smile
william
 Posted 2014-01-09 08:29:13
Supreme Being

Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)

Group: Forum Members
Last Active: 2014-03-18 11:41:59
Posts: 92, Visits: 851
Does it mean that I could use Linq with PSQuery and remove all those extra MemQuery statements for unit testing?
HansKarlsen
 Posted 2014-01-09 09:55:21
Supreme Being

Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)

Group: Administrators
Last Active: 2016-05-11 20:56:01
Posts: 608, Visits: 3 230
Yes - PSQuery will now work with XMLPeristenceMapper and its derivates like MemoryPersistenceMapper
william
 Posted 2014-01-09 10:28:57
Supreme Being

Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)

Group: Forum Members
Last Active: 2014-03-18 11:41:59
Posts: 92, Visits: 851
Yes, I found it by trying the latest build but some of my unit tests failed this time:


Result Message:
Test method xxx threw exception:
Eco.FrameworkImpl.Ocl.EBoldOCLAbort: 62:System.String does not conform to System.Boolean
Result StackTrace:
at Eco.Ocl.Impl.TBoldOclSemanticsVisitor.VisitTBoldOclIteration(TBoldOclIteration N)
at Eco.Ocl.Impl.TBoldOclIteration.AcceptVisitor(OclVisitor V)
at Eco.Ocl.Impl.TBoldOclSemanticsVisitor.Traverse(OclNode InNode)
at Eco.Ocl.Impl.OclParsedExpressionHandler.SemanticCheck(OclEntry entry, OclEnvironment oclEnvironment, Boolean isPsEvaluation)
at Eco.Ocl.Impl.OclParsedExpressionHandler.SemanticCheck(String fixedExpression, String originalExpression, IClassifier context, OclEnvironment oclEnvironment, Boolean isPsEvaluation)
at Eco.Ocl.Impl.OclParsedExpressionHandler.GetEntry(String expression, IClassifier context, Boolean storeInDictionary, OclEnvironment oclEnvironment, Boolean isPsEvaluation)
at Eco.Ocl.Impl.OclImplBase.InternalEvaluate(String oclExpression, IElement rootElement, IClassifier context, SubscriberPair subscriberPair, IExternalVariableList variableList)
at Eco.Ocl.Impl.OclServiceImpl.BaseEvaluate(IElement root, IClassifier Context, IExternalVariableList vars, String expression)
at Eco.Ocl.Impl.OclServiceImpl.Evaluate(IElement root, String expression, IExternalVariableList vars)
at Eco.Persistence.AbstractDataBlockPersistenceMapper.GetOclValue(OclCondition cond, TempEcoSpace es)
at Eco.Persistence.AbstractDataBlockPersistenceMapper.GetOclCondition(OclCondition cond, Int32 maxResults, Int32 offset)
at Eco.Persistence.AbstractDataBlockPersistenceMapper.Eco.Persistence.IPersistenceMapper.FetchIDListWithCondition(AbstractCondition condition, ObjectIdList& result, Int32 maxResults, Int32 offset)
at Eco.Framework.DefaultImpl.PersistenceHandlerImpl.GetAllWithCondition(AbstractCondition Condition, Int32 MaxAnswers, Int32 Offset)
at Eco.Services.Impl.PersistenceServiceImpl.GetAllWithCondition(AbstractCondition condition, Int32 maxAnswers, Int32 offset)
at Eco.Services.Impl.PersistenceServiceImpl.Eco.Services.IPersistenceService.GetAllWithCondition(AbstractCondition condition)
...


This is a Linq query with 2 string parameters, however using a single string parameter works. i.e. (with dynamic query),

PSQuery<X>().Where("Firstname==\"abc\"") <- ok
PSQuery<X>().Where("(Firstname==\"abc\") && (Lastname==\"xyz\")") <- exception

I am looking forward to working with the latest build in order to remove all the extra MemQuery I had added during the past few years. Smile
2014-01-09 10:29:29 by william
william
 Posted 2014-01-10 06:07:18
Supreme Being

Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)

Group: Forum Members
Last Active: 2014-03-18 11:41:59
Posts: 92, Visits: 851
Found a workaround: Remove System.Linq.Dynamic ....

and now:
PSQuery<X>().Where((x => x.Firstname==\"abc\") && (x.Lastname==\"xyz\")) <- works

I think the dynamic query may got the parentheses removed as part of optimization, and I think they are not needed in fact. However there is another bug in the PSQuery:

PSQuery<X>().Where((x => x.Firstname==\"abc\") || (x.Firstname==\"xyz\")) <- exception

for unit testing, I tried to load the objects and query in memory now as a workaround:

PSQuery<X>().Select(x => x).ToList().Where(x => x.Firstname==\"abc\" || x.Firstname==\"xyz\")
2014-01-10 06:08:07 by william
HansKarlsen
 Posted 2014-01-10 10:57:21
Supreme Being

Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)

Group: Administrators
Last Active: 2016-05-11 20:56:01
Posts: 608, Visits: 3 230
Aaa - I now set the ForceParenthesis flag on all binary operations when building the parse tree from the linq query.

That solves this issue... Sorry!

Triggered new VS2012 build - done in 5 minutes...
william
 Posted 2014-01-10 11:43:45
Supreme Being

Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)Supreme Being - (15 033 reputation)

Group: Forum Members
Last Active: 2014-03-18 11:41:59
Posts: 92, Visits: 851
Excellent! BigGrin

Similar Topics

Expand / Collapse

Reading This Topic

Expand / Collapse

Back To Top