Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 343845 - OQL UNION clause problems
Summary: OQL UNION clause problems
Status: RESOLVED FIXED
Alias: None
Product: MAT
Classification: Tools
Component: Core (show other bugs)
Version: 1.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Andrew Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-26 09:49 EDT by Andrew Johnson CLA
Modified: 2011-05-04 09:32 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.