Problem with GeographyUnionAggregate

May 3, 2010 at 8:18 AM

We are running into a very weird issue with the GeographyUnionAggregate and im not really sure what is causing the problem

I am trying to merge a group of line strings into a single line string using the GeographyUnionAggregate grouping function.

When run the query on a group of records from my raw table the system throws and exception and fails, the exception is

 

Msg 6522, Level 16, State 1, Line 1
A .NET Framework error occurred during execution of user-defined routine or aggregate "GeographyUnionAggregate": 
System.NullReferenceException: Object reference not set to an instance of an object.
System.NullReferenceException: 
   at SQLSpatialTools.GeographyCollectionAggregate.Merge(GeographyCollectionAggregate group)
   at SQLSpatialTools.GeographyUnionAggregate.Merge(GeographyUnionAggregate group)

 

When i copy that exact list of records into a temp table and then run a group by on them, it works without an issue

I am tearing my hair out over what is going on

The query that fails is

 

select positiveTMC , dbo.GeographyUnionAggregate(Geo)
  from NavStreets.dbo.RawStreetsVIC
  where DIR_TRAVEL in ('F','B') and geo is not null and negativeTMC is null and positiveTMC is not null 
  group by positiveTMC


When i do it via a temporary table, the whole thing works

 

create table #Points
(
positiveTMC int,
geo geography
)

insert into #Points (positiveTMC, geo)
select positiveTMC, Geo.STAsText()
from NavStreets.dbo.RawStreetsVIC
where DIR_TRAVEL in ('F','B') and geo is not null and negativeTMC is null and positiveTMC is not null order by positiveTMC

select COUNT(*) from #Points

select positiveTMC , dbo.GeographyUnionAggregate(Geo)
from #Points
group by positiveTMC

drop table #Points

In the second example, everything works without a problem. I would prefer to do the work on the table directly rather than having to create a temp table just to get around a quirk. Does any one have any ideas on why the first query is failing?

 

 

 

Developer
May 3, 2010 at 7:00 PM
Merge is called when multiple threads merge their answers into one and may be the source of this issue. To fix, try disabling parallelism: OPTION(MAXDOP=1).
May 4, 2010 at 6:06 AM

Looks like that has fixed it.  If i had more time i would have a go at debugging it. If anyone wants to have a go, i can put together some examples.

Developer
May 5, 2010 at 3:22 PM

Does it repro in the last changelist (#23749)?

http://sqlspatialtools.codeplex.com/SourceControl/list/changesets