[Geoserver-users] Invalid SQL query with Oracle Spatial view

Hi,

Geoserver tries to execute an invalid SQL query against Oracle Spatial
10r2 when I try to fetch a feature from a layer that originates from a
view (not table). In this case, the query is as follows:

SELECT "OID", "MY_GEOM" FROM "VW_TEST" WHERE ()

"WHERE ()" is the problem.

My view is as follows:
SQL> desc vw_test;
Name Null? Type
----------------------------------------- -------- ----------------------------

OID NOT NULL NUMBER(10)
MY_GEOM MDSYS.SDO_GEOMETRY

OID comes from a column that is the primary key in the original table.
The view is listed in USER_SDO_GEOM_METADATA. SRID is NULL, but I've
declared it in Geoserver configuration.

WFS DescribeFeatureType for this layer returns:

<?xml version="1.0" encoding="UTF-8"?><xs:schema
targetNamespace="http://www.example.org"
xmlns:example="http://www.example.org"
xmlns:gml="http://www.opengis.net/gml&quot;
xmlns:xs="http://www.w3.org/2001/XMLSchema&quot;
elementFormDefault="qualified" attributeFormDefault="unqualified"
version="1.0"><xs:import namespace="http://www.opengis.net/gml&quot;
schemaLocation="http://localhost:8080/geoserver/schemas/gml/2.1.2.1/feature.xsd&quot;/&gt;&lt;xs:complexType
xmlns:xs="http://www.w3.org/2001/XMLSchema&quot;
xmlns="http://www.w3.org/2001/XMLSchema&quot; name="VW_TEST_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="OID" minOccurs="1" nillable="false" type="xs:decimal"/>
<xs:element name="MY_GEOM" minOccurs="0" nillable="true"
type="gml:GeometryAssociationType"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>

</xs:complexType>
<xs:element name="VW_TEST" type="example:VW_TEST_Type"
substitutionGroup="gml:_Feature"/></xs:schema>

It lists OID as an attribute. Is this correct? It is not treated as a
unique identifier of the feature, right?

The client (uDig), now invents interesting FID values, like
VW_TEST.nfm--408ac6b7_11b0caefb1c_-5b03, as in the following WFS
request it sends:

<?xml version="1.0" encoding="UTF-8"?>
<GetFeature xmlns="http://www.opengis.net/wfs&quot;
xmlns:gml="http://www.opengis.net/gml&quot;
xmlns:ogc="http://www.opengis.net/ogc&quot; version="1.0.0" service="WFS"
outputFormat="GML2"><Query handle="liteRenderer"
typeName="example:VW_TEST"><ogc:PropertyName>MY_GEOM</ogc:PropertyName>
<ogc:Filter><ogc:FeatureId fid="VW_TEST.nfm--408ac6b7_11b0caefb1c_-5b03"/>
</ogc:Filter>
</Query>
</GetFeature>

That causes Geoserver to fail:

<?xml version="1.0" ?>
<ServiceExceptionReport
   version="1.2.0"
   xmlns="http://www.opengis.net/ogc&quot;
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
   xsi:schemaLocation="http://www.opengis.net/ogc
http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd&quot;&gt;
   <ServiceException>
       error:Translator error
Translator error
Error reading Features
Could not aquire feature:org.geotools.data.DataSourceException: Error
Performing SQL query: SELECT "OID", "MY_GEOM" FROM "VW_TEST" WHERE ()
Error Performing SQL query: SELECT "OID", "MY_GEOM" FROM "VW_TEST" WHERE ()
ORA-00936: missing expression

</ServiceException></ServiceExceptionReport>

Geoserver and Oracle plugin are dated 2008-07-08 (trunk).

Have I overlooked something? Does this look like a problem with the
client, Geoserver or perhaps with GS Oracle Spatial plugin? Should I
expect Oracle Spatial views to work with Geoserver?

Janne Nivala ha scritto:

Hi,

Geoserver tries to execute an invalid SQL query against Oracle Spatial
10r2 when I try to fetch a feature from a layer that originates from a
view (not table). In this case, the query is as follows:

SELECT "OID", "MY_GEOM" FROM "VW_TEST" WHERE ()

"WHERE ()" is the problem.

My view is as follows:
SQL> desc vw_test;
Name Null? Type
----------------------------------------- -------- ----------------------------

OID NOT NULL NUMBER(10)
MY_GEOM MDSYS.SDO_GEOMETRY

OID comes from a column that is the primary key in the original table.
The view is listed in USER_SDO_GEOM_METADATA. SRID is NULL, but I've
declared it in Geoserver configuration.

WFS DescribeFeatureType for this layer returns:

<?xml version="1.0" encoding="UTF-8"?><xs:schema
targetNamespace="http://www.example.org"
xmlns:example="http://www.example.org"
xmlns:gml="http://www.opengis.net/gml&quot;
xmlns:xs="http://www.w3.org/2001/XMLSchema&quot;
elementFormDefault="qualified" attributeFormDefault="unqualified"
version="1.0"><xs:import namespace="http://www.opengis.net/gml&quot;
schemaLocation="http://localhost:8080/geoserver/schemas/gml/2.1.2.1/feature.xsd&quot;/&gt;&lt;xs:complexType
xmlns:xs="http://www.w3.org/2001/XMLSchema&quot;
xmlns="http://www.w3.org/2001/XMLSchema&quot; name="VW_TEST_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="OID" minOccurs="1" nillable="false" type="xs:decimal"/>
<xs:element name="MY_GEOM" minOccurs="0" nillable="true"
type="gml:GeometryAssociationType"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>

</xs:complexType>
<xs:element name="VW_TEST" type="example:VW_TEST_Type"
substitutionGroup="gml:_Feature"/></xs:schema>

It lists OID as an attribute. Is this correct? It is not treated as a
unique identifier of the feature, right?

Correct, we oracle spatial plugin does not have the logic
necessary to decide that OID is a primary key and can be still
used as one since you did not do a join.

The client (uDig), now invents interesting FID values, like
VW_TEST.nfm--408ac6b7_11b0caefb1c_-5b03, as in the following WFS
request it sends:

<?xml version="1.0" encoding="UTF-8"?>
<GetFeature xmlns="http://www.opengis.net/wfs&quot;
xmlns:gml="http://www.opengis.net/gml&quot;
xmlns:ogc="http://www.opengis.net/ogc&quot; version="1.0.0" service="WFS"
outputFormat="GML2"><Query handle="liteRenderer"
typeName="example:VW_TEST"><ogc:PropertyName>MY_GEOM</ogc:PropertyName>
<ogc:Filter><ogc:FeatureId fid="VW_TEST.nfm--408ac6b7_11b0caefb1c_-5b03"/>
</ogc:Filter>
</Query>
</GetFeature>

That causes Geoserver to fail:

<?xml version="1.0" ?>
<ServiceExceptionReport
   version="1.2.0"
   xmlns="http://www.opengis.net/ogc&quot;
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
   xsi:schemaLocation="http://www.opengis.net/ogc
http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd&quot;&gt;
   <ServiceException>
       error:Translator error
Translator error
Error reading Features
Could not aquire feature:org.geotools.data.DataSourceException: Error
Performing SQL query: SELECT "OID", "MY_GEOM" FROM "VW_TEST" WHERE ()
Error Performing SQL query: SELECT "OID", "MY_GEOM" FROM "VW_TEST" WHERE ()
ORA-00936: missing expression

</ServiceException></ServiceExceptionReport>

Geoserver and Oracle plugin are dated 2008-07-08 (trunk).

Have I overlooked something? Does this look like a problem with the
client, Geoserver or perhaps with GS Oracle Spatial plugin? Should I
expect Oracle Spatial views to work with Geoserver?

I believe they won't be working properly, because the GS oracle
spatial plugin cannot determine which column is the primary
key, as a result it'll start making up fake FIDs just to answer
GetFeature requests, but of course the first time a FeatureID
filter is used the ability of retrieving the row back fails
since the FID is made up (and as a result cannot be turned
back into a proper WHERE filter)

Cheers
Andrea