Hi,
I like the use case for orElse(), that looks indeed useful. I added a
test case for that.
I switched to the latest m4-SNAPSHOT, that solves most of the problems.
Two problems remain:
a) Currently, "!(optionalPC.id == 88)" does not return objects with an
'empty' optionalPC field.
I can't really tell whether this is correct or not. The spec says (14.6.2):
"Navigation through a null-valued field, which would throw
NullPointerException, is treated as if the subexpression returned false."
If 'subexpression' means '!(optionalPC.id == 88)', the above behaviour
is as intended.
However, so far (in ZooDB) I interpreted 'subexpression' as the
'minimal' subexpression, i.e. 'optionalPC.id == 88' is the
sub-expression. In this interpretation, the above query should also
match all objects with an 'empty' optional field.
I'm not sure which is correct.
@Craig, @Michael, maybe you could clarify?
b) the first test in orElse() now accepts orElse(), but fails with a NPE:
testOrElse(org.apache.jdo.tck.query.jdoql.methods.SupportedOptionalMethods)java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at
org.datanucleus.store.rdbms.sql.method.OptionalOrElseMethod.getExpression(OptionalOrElseMethod.java:61)
at
org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory.invokeMethod(SQLExpressionFactory.java:306)
at
org.datanucleus.store.rdbms.sql.expression.OptionalExpression.invoke(OptionalExpression.java:42)
at
org.datanucleus.store.rdbms.query.QueryToSQLMapper.processInvokeExpression(QueryToSQLMapper.java:3711)
at
org.datanucleus.store.rdbms.query.QueryToSQLMapper.processInvokeExpression(QueryToSQLMapper.java:3585)
at
org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compilePrimaryExpression(AbstractExpressionEvaluator.java:213)
at
org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileUnaryExpression(AbstractExpressionEvaluator.java:182)
at
org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileAdditiveMultiplicativeExpression(AbstractExpressionEvaluator.java:161)
at
org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileRelationalExpression(AbstractExpressionEvaluator.java:136)
at
org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileOrAndExpression(AbstractExpressionEvaluator.java:78)
at
org.datanucleus.query.evaluator.AbstractExpressionEvaluator.evaluate(AbstractExpressionEvaluator.java:46)
at
org.datanucleus.query.expression.Expression.evaluate(Expression.java:338)
at
org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:69)
at
org.datanucleus.store.rdbms.query.QueryToSQLMapper.compileFilter(QueryToSQLMapper.java:553)
at
org.datanucleus.store.rdbms.query.QueryToSQLMapper.compile(QueryToSQLMapper.java:429)
at
org.datanucleus.store.rdbms.query.JDOQLQuery.compileQueryFull(JDOQLQuery.java:887)
at
org.datanucleus.store.rdbms.query.JDOQLQuery.compileInternal(JDOQLQuery.java:347)
at org.datanucleus.store.query.Query.executeQuery(Query.java:1883)
at org.datanucleus.store.query.Query.executeWithArray(Query.java:1811)
at org.datanucleus.api.jdo.JDOQuery.executeInternal(JDOQuery.java:369)
at org.datanucleus.api.jdo.JDOQuery.executeWithArray(JDOQuery.java:268)
at org.apache.jdo.tck.query.QueryTest.execute(QueryTest.java:1257)
at org.apache.jdo.tck.query.QueryTest.execute(QueryTest.java:1133)
at
org.apache.jdo.tck.query.QueryTest.executeAPIQuery(QueryTest.java:1069)
at
org.apache.jdo.tck.query.jdoql.methods.SupportedOptionalMethods.checkQuery(SupportedOptionalMethods.java:297)
at
org.apache.jdo.tck.query.jdoql.methods.SupportedOptionalMethods.testOrElse(SupportedOptionalMethods.java:312)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.apache.jdo.tck.JDO_Test.runBare(JDO_Test.java:284)
at
org.apache.jdo.tck.util.BatchTestRunner.doRun(BatchTestRunner.java:108)
at
org.apache.jdo.tck.util.BatchTestRunner.start(BatchTestRunner.java:148)
at
org.apache.jdo.tck.util.BatchTestRunner.main(BatchTestRunner.java:123)
I'll upload the latest version to the JIRA.
Cheers,
Tilmann
On 04-Jun-16 15:30, Andy Jefferson wrote:
Hi,
a) SQLSyntaxErrorException : Encountered "NOT" at line 1, column 185
Just seen your SQL generated. "WHERE NOT NOT (A0.OPTIONAL_PC IS NULL)"
That is valid on some RDBMS but maybe Derby is throwing its toys out of the
pram due to it? Current DN code will put brackets in there. i.e NOT (NOT (...))
b) optionalPC.get().id
Released DN code only supports "optionalPC.get()" and not the access of fields
of the dereferenced object (i.e it didn't do a join to the related table holding the
object). Current DN code does however support that.
As I mentioned previously, if having problems use nightly builds.
c) Optional.orElse is currently not supported
Yes it is, and has been since DataNucleus v5.0.0-m4. You must be using an old
version.
Regarding a use-case for orElse, the test I use is putting the orElse in the
SELECT clause
Query q = pm.newQuery("SELECT id, stringField.orElse('NotPresent') FROM
mydomain.MyClass");
so I get back the value that is stored when it is set, or some other value if
not set (much like could be achieved with a CASE statement with other
datatypes).
Regards