FW: [mapguide-internals] Exception thrown on null values?

Orest Halustchak orest.halustchak at autodesk.com
Fri Feb 29 12:17:28 EST 2008


Hi,

See Dan's email below. He's not on the mapguide-internals email list so he's sending it through me! However, as with the other part of the thread, maybe we should move it to fdo-internals after this email.

Regarding Dan's comment then, even if it's implemented under the hood for some providers, it would not be available for accessing all providers and not directly usable by users of fdo. We need the benefit generically available. It seems worth considering adding the indexed access as overrides for these heavy access cases like the feature reader methods.

Thanks,
Orest.

-----Original Message-----
From: Dan Stoica
Sent: Friday, February 29, 2008 12:11 PM
To: Orest Halustchak
Subject: RE: [mapguide-internals] Exception thrown on null values?

Hi,


Getting the values by index is already implemented under the hood. It has been done last year for SHP, Oracle and generic RDBMS.

Indeed, string comparison was the culprit. As Carsten pointed out, the properties are fetched in the same order and there is no reason to navigate the list of properties to find the current property by name.

And with this optimization and according to benchmarks, calling IsNull() doesn't add any visible overhead.

I can provide more details if needed...

Thanks,
Dan.

-----Original Message-----
From: Orest Halustchak
Sent: Friday, February 29, 2008 11:59 AM
To: Dan Stoica
Subject: FW: [mapguide-internals] Exception thrown on null values?



-----Original Message-----
From: mapguide-internals-bounces at lists.osgeo.org [mailto:mapguide-internals-bounces at lists.osgeo.org] On Behalf Of Carsten Hess
Sent: Friday, February 29, 2008 10:36 AM
To: MapGuide Internals Mail List
Subject: RE: [mapguide-internals] Exception thrown on null values?

Hi,

Alright I can't resist joining that discussion.

Currently we have two reliable ways of testing for NULL if a provider is correctly implemented. One is the NULL exception and the other is "IsNull" function. If you compare the two then IsNull is the wrong choice for performance. The reason is that both the IsNull and the GetValue methods use a name of the column for identifying what to check for. The longer the column name, the slower this gets (string comparison is O(n) ).

If we had one method that can return the state of NULL and the value then we would safe one string comparison. An exception really is nothing but a return value you can check so that is how you can check NULL as exceptions are typed.

There are other ways of cutting that performance overhead without touching the undefined value null.

E.g.

int i = reader.GetIndex(columname);
if !(reader.IsNull(i))
        value = reader.GetValue(i)

we just saved a string comparison ... better yet, the index doesn't change between features in a reader so you have to get that index only once for a feature reader and hence can save 2 * # features string comparisons.

Better yet we could have a method with two return values, one indicating isnull and the other the value (if it is not null)

bool GetValue(ref double v, index i); // v is only set if attribute i is not null ... that could save us not only a function call but also an if ...

Of course this all assumes that this is really something where we are hurting for performance...

Cheers,
  Carsten


-----Original Message-----
From: mapguide-internals-bounces at lists.osgeo.org [mailto:mapguide-internals-bounces at lists.osgeo.org] On Behalf Of Orest Halustchak
Sent: Friday, February 29, 2008 9:39 AM
To: MapGuide Internals Mail List
Subject: RE: [mapguide-internals] Exception thrown on null values?

Trevor makes a valid point that some of the languages that we use can't represent null values for some scalars such as int and double. String is an easy one since you make a convention that an empty string is null. The IsNull() function is the only reliable way to determine if the value is null or not for all cases. If we wanted to change the FDO spec, what behavior would you prefer? Do you want the GetXXX function just to return some value with no exception even if the property value is null? If so, what value should it return? The issue is that whatever value that is returned will be incorrect (except maybe in the string case).

Note that a recent fdo enhancement added a number of new expression functions one of which is NullValue(a, b). This allows you to return a non-null value in all cases by specifying what value to use if the related property is null. E.g. NullValue(ParcelValue, 0.0) or NullValue(Status, -1). This doesn't solve the problem of handling nulls, but is something that some applications might find useful.

Thanks,
Orest.

-----Original Message-----
From: mapguide-internals-bounces at lists.osgeo.org [mailto:mapguide-internals-bounces at lists.osgeo.org] On Behalf Of Zac Spitzer
Sent: Thursday, February 28, 2008 6:59 PM
To: MapGuide Internals Mail List
Subject: Re: [mapguide-internals] Exception thrown on null values?

I really like Trevor's suggestion of oracle null style string handling
of this. MG 2.0
is already much slower than 1.2, any additional over header is going
to be painful.

On Fri, Feb 29, 2008 at 9:59 AM, Jason Birch <Jason.Birch at nanaimo.ca> wrote:
> Oh, just looked at the example a bit closer, and the calling function
>  printFeatureReader() does the IsNull check.
>
>
>  Jason
>
>  -----Original Message-----
>  From: mapguide-internals-bounces at lists.osgeo.org
>
> [mailto:mapguide-internals-bounces at lists.osgeo.org] On Behalf Of Jason
>  Birch
>
>
> Sent: Thursday, February 28, 2008 14:24
>  To: MapGuide Internals Mail List
>  Subject: RE: [mapguide-internals] Exception thrown on null values?
>
>  Ahh.  I guess I can see where that would be a problem.  With PHP, you
>  can just set the variable to NULL, regardless of the "type" :)
>
>  I guess... if this isn't fixable (without changing the FDO spec) could
>  we look at changing the documentation to reflect calling IsNull as a
>  best practice?  For example, the printPropertyValueFromFeatRead()
>  function on this page:
>
>  http://mapguide.osgeo.org/files/mapguide/docs/webapi/d6/ddc/class_mg_fea
>  ture_reader.htm
>
>  Should probably have something like this in it:
>
>  if ($featureReader->IsNull($propertyName))
>  {
>   $val = NULL;
>  }
>  else
>  {
>   switch ($propertyType) {
>  ...
>
>  Hmm.  While I'm at it, the \n's in the source for that example should
>  probably be double-escaped.
>
>  Jason
>
>
>
>  -----Original Message-----
>  From: mapguide-internals-bounces at lists.osgeo.org
>  [mailto:mapguide-internals-bounces at lists.osgeo.org] On Behalf Of Trevor
>  Wekel
>  Sent: Thursday, February 28, 2008 14:02
>  To: MapGuide Internals Mail List
>  Subject: RE: [mapguide-internals] Exception thrown on null values?
>
>  Hi Jason,
>
>  Since we have multiple web tier implementation languages, creating a
>  standard for NULL is tricky.  I'm not aware of constructs in .Net, PHP,
>  and Java for NULL scalar values.  For a string, we could return "" or
>  maybe "<null>".  Not sure what to do with NULL for doubles and integers.
>
>
>
>  -----Original Message-----
>  From: mapguide-internals-bounces at lists.osgeo.org
>  [mailto:mapguide-internals-bounces at lists.osgeo.org] On Behalf Of Jason
>  Birch
>  Sent: Thursday, February 28, 2008 2:48 PM
>  To: MapGuide Internals Mail List
>  Subject: RE: [mapguide-internals] Exception thrown on null values?
>
>  Am I allowed to say "lame"?  :)  NULL is a perfectly valid value for
>  most data types, and throwing an exception in this case adds a lot of
>  additional processing that should not be required.
>
>  I personally feel that this is a case where MapGuide could make
>  application developers lives a lot easier and improve (slightly?) the
>  performance of web-level apps by swallowing the exception and returning
>  NULL.
>
>  Jason
>
>  -----Original Message-----
>  From: mapguide-internals-bounces at lists.osgeo.org
>  [mailto:mapguide-internals-bounces at lists.osgeo.org] On Behalf Of Traian
>  Stanev
>  Sent: Thursday, February 28, 2008 13:31
>  To: 'MapGuide Internals Mail List'
>  Subject: RE: [mapguide-internals] Exception thrown on null values?
>
>  I think this complies with the FDO spec, which requires an exception to
>  be thrown when the value is null and you try to get it anyway. The two
>  solutions are to check for IsNull() before getting it, or to catch the
>  exception. The code *could* in theory return NULL in this case, but...
>
>  Traian
>
>  > -----Original Message-----
>  > From: mapguide-internals-bounces at lists.osgeo.org [mailto:mapguide-
>  > internals-bounces at lists.osgeo.org] On Behalf Of Jason Birch
>  > Sent: Thursday, February 28, 2008 4:29 PM
>  > To: MapGuide Internals Mail List
>  > Subject: [mapguide-internals] Exception thrown on null values?
>  >
>  > Hi,
>  >
>  > I'm seeing a case in MGOS 2.0 where MgFeatureReader->GetString() is
>  > throwing an exception when the value of the string is null.
>  >
>  > Is this expected behaviour?  Has it changed since 1.2?  I believe that
>  > I've seen a similar error in geometry, but don't have a test case for
>  > that yet.
>  >
>  > This is relatively easy to work around with a try/catch and
>  suppressing
>  > the error output if the message includes "null", but it's a bit
>  > annoying.  Is there a better way of dealing with this?
>  >
>  > Jason
>  > _______________________________________________
>  > mapguide-internals mailing list
>  > mapguide-internals at lists.osgeo.org
>  > http://lists.osgeo.org/mailman/listinfo/mapguide-internals
>  _______________________________________________
>  mapguide-internals mailing list
>  mapguide-internals at lists.osgeo.org
>  http://lists.osgeo.org/mailman/listinfo/mapguide-internals
>  _______________________________________________
>  mapguide-internals mailing list
>  mapguide-internals at lists.osgeo.org
>  http://lists.osgeo.org/mailman/listinfo/mapguide-internals
>  _______________________________________________
>  mapguide-internals mailing list
>  mapguide-internals at lists.osgeo.org
>  http://lists.osgeo.org/mailman/listinfo/mapguide-internals
>  _______________________________________________
>  mapguide-internals mailing list
>  mapguide-internals at lists.osgeo.org
>  http://lists.osgeo.org/mailman/listinfo/mapguide-internals
>  _______________________________________________
>  mapguide-internals mailing list
>  mapguide-internals at lists.osgeo.org
>  http://lists.osgeo.org/mailman/listinfo/mapguide-internals
>



--
Zac Spitzer -
http://zacster.blogspot.com (My Blog)
+61 405 847 168
_______________________________________________
mapguide-internals mailing list
mapguide-internals at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-internals
_______________________________________________
mapguide-internals mailing list
mapguide-internals at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-internals
_______________________________________________
mapguide-internals mailing list
mapguide-internals at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-internals


More information about the mapguide-internals mailing list