Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 343845

Summary: OQL UNION clause problems
Product: [Tools] MAT Reporter: Andrew Johnson <andrew_johnson>
Component: CoreAssignee: Andrew Johnson <andrew_johnson>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 1.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Andrew Johnson CLA 2011-04-26 09:49:18 EDT
The OQL union clause is useful but has some problems.

In the OQL console the text display changes from typing in this:

SELECT s FROM OBJECTS 0,1 s  UNION ( SELECT t FROM OBJECTS 1,2 t  )

to this after executing the query

SELECT s FROM OBJECTS 0,1 s  UNION ( SELECT t FROM OBJECTS 1,2 t  ) UNION (SELECT t FROM OBJECTS 1,2 t )


Union queries with a first statement returning nothing also have problems:

Executed Query:
select s from notfound s union (select t from objects 1,2 t)


java.lang.NullPointerException
	at org.eclipse.mat.parser.internal.oql.OQLQueryImpl.union(OQLQueryImpl.java:676)
	at org.eclipse.mat.parser.internal.oql.OQLQueryImpl.internalExecute(OQLQueryImpl.java:655)
	at org.eclipse.mat.parser.internal.oql.OQLQueryImpl.execute(OQLQueryImpl.java:627)
	at org.eclipse.mat.inspections.OQLQuery.execute(OQLQuery.java:50)
	at org.eclipse.mat.inspections.OQLQuery.execute(OQLQuery.java:1)


Executed Query:
select * from notfound union (select * from objects 1,2)


java.lang.NullPointerException
	at org.eclipse.mat.parser.internal.oql.OQLQueryImpl.union(OQLQueryImpl.java:676)
	at org.eclipse.mat.parser.internal.oql.OQLQueryImpl.internalExecute(OQLQueryImpl.java:655)
	at org.eclipse.mat.parser.internal.oql.OQLQueryImpl.execute(OQLQueryImpl.java:627)
	at org.eclipse.mat.inspections.OQLQuery.execute(OQLQuery.java:50)
	at org.eclipse.mat.inspections.OQLQuery.execute(OQLQuery.java:1)

	
The UNION clause returns duplicates, rather like SQL UNION ALL. Is that deliberate?
Comment 1 Andrew Johnson CLA 2011-05-04 09:17:43 EDT
There are two problems.

The duplicate UNION clauses in the text is because the partial result has the full OQL query string, instead of the result without the union which is then combined with the union subresults. The ResultSet and ObjectResultSet need to be built with the correct sub query.

The null pointer exception is because the first result has no objects so is null. The fix is to create an empty result when needed (i.e. when another sub result is not null).
Comment 2 Andrew Johnson CLA 2011-05-04 09:32:06 EDT
Fixed as described.