1 2 3 Previous Next 32 Replies Latest reply on Jan 26, 2015 7:42 PM by shawkins Go to original post
      • 15. Re: WFS translator & spatial
        shawkins

        > Fixing the tests - I broke a great deal of the integration tests by adding types and functions. It looks like there are a bunch of dumps of the system schema tables. I think I inadvertently caused some of the UUIDs to change. What's standard procedure here? Just update the "expected" from the results?

         

        Yes, the standard would be to just update the test results.  TestMMDatabaseMetaData has a replace expected flag that can be toggled to write new expected results.  The goal is that server generated uuids are consistent within a given instance of a vdb, but can change if the metadata changes and the vdb is restarted (this is because id assignment is positional).

         

        It sounds like you've made great progress.  I hope to look at this next week.

         

        Steve

        • 16. Re: WFS translator & spatial
          shawkins

          Thanks Tom.  I squashed and refined the commits you had for the initial commit to Teiid.  From here we'll look to keep expanding the source support and the system functions.

          • 17. Re: WFS translator & spatial
            tom9729

            Very cool! Thanks for cleaning up the SELECT/LITERAL stuff and adding JTS to the kit. Rewriting with the ST_* functions makes a lot more sense than what I had with CONVERT.

             

            -----------

             

            I'm hoping to get some time towards the end of the week to tackle Geometry SRID. This shifted priorities because (unlike MySQL) Oracle requires SRID to be set for any kind of comparison (unless both are NULL). This isn't something that can be stored in WKB, so I'm thinking of adding an int field to GeometryType to keep track of it. The tricky thing is going to be getting it out of the database with one select. MySQL GEOMETRY type seems to be the 32bit SRID concatenated with the WKB blob, so my idea is to force something similar and then split off the SRID when reading the value back.

             

            On MySQL this returns the SRID + WKB.

             

            select CONCAT(RPAD(REVERSE(CHAR(SRID(shape))), 4, CHAR(0)), AsWKB(shape)) from cola_markets;

             

            (Note that "select shape from cola_markets" does the same thing, but I can't find this in any documentation. It looks like GeoTools relies on it however.)

             

            The strategy would be to rewrite Teiid to MySQL like this:

             

            select shape from cola_markets;

             

            select ST_AsTeiidFormat(shape) from cola_markets;

             

            select  CONCAT(RPAD(REVERSE(CHAR(SRID(shape))), 4, CHAR(0)), AsWKB(shape)) from cola_markets;

             

            When retrieving values from results, would splice off the first 4 bytes and save as SRID int field on GeometryType. Going the other direction (literals) would be pretty straightforward because the source functions to convert from WKB/WKT all take an optional SRID value. Work in progress implementation: gist:2e73037eff85fe9eddff

             

            (Note that gist is slightly outdated; I will rebase and work from latest.)

             

            -----------

             

            Note that the Oracle support was added from docs + memory and has not been tested yet! (I am downloading Oracle Enterprise as I type this.)

             

            There are some known flaws in the Oracle support as-is. First off, the SDO_UTIL functions (at least dealing with WKT/WKB) do not work on Oracle XE because they are implemented in Java and there is no JVM in that edition. Secondly they only support an early version of the OGC spec which means that even though Oracle supports more than 2 dimensions, it is not possible to specify Z or M coords with them. I don't think the second part is that big of a deal for now because >2d is missing from most data sources I can think of. One workaround I'm investigating is reimplementing the conversion functions in PL/SQL, similar to the work done here: general/pg_user_geom_util_body.sql at master · TolonUK/general · GitHub

             

            Is it possible that anyone is currently selecting the Oracle geometry structs through Teiid and using the OJDBC classes to work with them? I think these changes would break that use case, so it might be good to add a system property to disable recognizing columns as GEOMETRY.

             

            Thanks!

            Tom

            • 18. Re: WFS translator & spatial
              shawkins

              > I'm hoping to get some time towards the end of the week to tackle Geometry SRID.

               

              It seems like you are trying to emulate the EWKB format:

               

              • EWKT and EWKBExtended Well-Known Text/Binary – A PostGIS-specific format that includes the spatial reference system identifier (SRID) and up to 4 ordinate values.[5][6] For example: SRID=4326;POINT(-44.3 60.1) to locate a longitude/latitude coordinate using the WGS 84 reference coordinate system.

               

              I can't find any docs on the EWKB format to know what would be a valid representation including the SRID, but the WKT is straightforward.

               

              > The tricky thing is going to be getting it out of the database with one select. MySQL GEOMETRY type seems to be the 32bit SRID concatenated with the WKB blob, so my idea is to force something similar and then split off the SRID when reading the value back.

               

              It may end up being easier to stick with the text format or to select a struct/array that can be converted to the geometry type including the SRID.

               

              > There are some known flaws in the Oracle support as-is.

               

              I don't think we'll be too concerned with the limitations for now.  Eventually we can add capabilities as needed to prevent pushdown.

               

              > Is it possible that anyone is currently selecting the Oracle geometry structs through Teiid and using the OJDBC classes to work with them? I think these changes would break that use case, so it might be good to add a system property to disable recognizing columns as GEOMETRY.

               

              Yes good call it is possible - an issue was logged on the struct retrieval - [TEIID-2502] Oracle Struct Serialization Error - JBoss Issue Tracker

              This change would affect dynamic vdbs, otherwise the type would not be seen as geometry.  A system property as a default seems good, but an import property may make sense as well - importer.useGeometryType

              • 19. Re: WFS translator & spatial
                tom9729

                Closest thing to a EWKB spec (that I can find) is here http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/io/WKBWriter.html.

                 

                Pulling back as text would definitely be simpler, but it's the same basic idea. I've been trying to stick with the binary format for supposed efficiency. I'm not sure how array/struct would work.

                 

                select 'SRID=' || SRID(shape) || ';' || AsText(shape) from cola_markets;

                 

                I will focus on adding support for sending SRID to the database first, as that should be simple.

                • Add SRID integer field on the GeometryType
                • Add optional SRID argument to Java functions that convert from WKB/WKT to GeometryType.
                • Change Literal GEOMETRY rewrite in JDBCExecutionFactory to pass geometry SRID as second value.

                 

                For reading SRID back it might be simpler to just store it as a property on the column metadata since it _should_ be the same for all values in that column. From a quick survey of the GeoTools JDBC modules it appears they all read the SRID from geometry_columns[1] table. This could initially be set manually by DDL, and we could phase in support for the importers to pick it up. [2]

                 

                [1] From OGC Simple Features (?) spec. One row for every GEOMETRY column in the database. Keeps track of geometry type, SRID, coordinate dimension, etc.

                [2] geometry_columns (and spatial_ref_sys) are not implemented across the board. Oracle names them something else, MySQL doesn't have them, etc. There will need to be some DB-specific logic to detect this stuff.

                 

                Thanks,

                Tom

                • 20. Re: WFS translator & spatial
                  shawkins

                  > Closest thing to a EWKB spec (that I can find) is here http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/io/WKBWriter.html.

                   

                  That was all I could find as well.  It does look like text would be the way to go to include the srid.

                   

                  > I'm not sure how array/struct would work

                   

                  Not very well.  For oracle It does look like the SRID is the first value in the struct data array, but the rest of the struct cannot be converted to a common format without an oracle specific geometry library.

                   

                  > Add optional SRID argument to Java functions that convert from WKB/WKT to GeometryType.

                   

                  I see that fits with mysql, but it does not line up with Oracle as their conversion functions from WKB, WKT do not consider SRID.

                   

                  > For reading SRID back it might be simpler to just store it as a property on the column metadata since it _should_ be the same for all values in that column.

                   

                  That seems good as well.

                   

                  I'm taking a pass through what is currently there just to correct some of my initial refactoring and to add more function support.  I should have those changes in later today.

                  • 21. Re: WFS translator & spatial
                    shawkins

                    There are now specific handlers in JDBCExecutionFactory.retrieveValue for Geometry.  A strategy there could be to use getObejct and to handle both Blob and Clob values for both binary and text formats.

                     

                    A start of the function documentation is at: Spatial Functions - Teiid 8.10 (draft) - Project Documentation Editor

                    Anything that you can add there would be good.

                     

                    I'm going to try and look into PostGIS as well to see what should be updated in the PostgreSQL translator.

                    • 22. Re: WFS translator & spatial
                      tom9729

                      > I see that fits with mysql, but it does not line up with Oracle as their conversion functions from WKB, WKT do not consider SRID.

                       

                      These look a little more promising.

                       

                      http://docs.oracle.com/cd/B19306_01/appdev.102/b14255/sdo_objrelschema.htm#CBBFGHAE

                       

                      SDO_GEOMETRY(wkt CLOB, srid NUMBER DEFAULT NULL);

                      SDO_GEOMETRY(wkt VARCHAR2, srid NUMBER DEFAULT NULL);

                      SDO_GEOMETRY(wkb BLOB, srid NUMBER DEFAULT NULL);

                       

                      Thanks,

                      Tom

                      • 23. Re: WFS translator & spatial
                        tom9729

                        Need to find some time this week to test these, but here they are:

                         

                        Initial cut at SRID support:

                        https://github.com/Tom9729/teiid/commit/fe2d5c428a34b86f2fa57e136a46a0e85ac5b242

                         

                        Oracle pushdown support:

                        https://github.com/Tom9729/teiid/commit/42dc924df2e08f41797260fa721ce2cba2a35b17

                         

                        I will see about filling out the spatial docs.

                         

                        Thanks,

                        Tom

                        • 24. Re: WFS translator & spatial
                          tom9729

                          Fixed some issues with spatial filter pushdown and MySQL.

                          https://github.com/Tom9729/teiid/commit/183e660e77ff6fca2d7421aa6a4d2bf93b55dabb

                          • Default value of pushdown for the function annotation is CANNOT_PUSHDOWN, and all of the geometry functions were set like this. I changed all of them (except the conversion ones) to CAN_PUSHDOWN.
                          • MySQL translator uses DB version to determine whether to enable spatial filter pushdown, but usesDatabaseVersion=false so the database version never gets set on startup. I changed this to true to fix it, but I think this is kind of confusing. IMO it would be better to have getVersion() throw an exception if the version is null.

                           

                          I can't seem to track down the cause of this issue, but this insert seems to cause a NPE if org.teiid.COMMAND_LOG is set to TRACE. I only see an error in Squirrel, and the insert appears to work.

                           

                          insert into cola_markets(name,shape) values('foo124', ST_GeomFromText('POINT (300 100)', 8307));

                           

                          Error: java.lang.NullPointerException

                          SQLState:  38000

                          ErrorCode: 0

                           

                          Other than that, seems to be working well. My next focus will be to give some attention to Oracle.

                           

                          Thanks,

                          Tom

                          • 25. Re: WFS translator & spatial
                            shawkins

                            > MySQL translator uses DB version to determine whether to enable spatial filter pushdown, but usesDatabaseVersion=false so the database version never gets set on startup. I changed this to true to fix it, but I think this is kind of confusing. IMO it would be better to have getVersion() throw an exception if the version is null.

                             

                            I think what you are looking for is getVersion to throw an assertion error if it is not set and yet called.  More than likely it was to not modify unit tests as to why that was not done originally.

                             

                            > I can't seem to track down the cause of this issue, but this insert seems to cause a NPE if org.teiid.COMMAND_LOG is set to TRACE. I only see an error in Squirrel, and the insert appears to work.

                             

                            You aren't seeing anything on the server side?  I'll have a look.

                            • 26. Re: WFS translator & spatial
                              shawkins

                              The use of SDO_GEOMETRY with a blob binding (as a stream) fails for me:

                               

                              Caused by: java.sql.SQLException: ORA-29532: Java call terminated by uncaught Java exception: java.lang.RuntimeException: -2

                              ORA-06512: at "MDSYS.SDO_UTIL", line 177

                              ORA-06512: at "MDSYS.SDO_GEOMETRY", line 76

                               

                              But the SDO_UTIL methods seem to work as does the SDO_GEOMETRY construct when used directly on oracle without a blob binding.

                               

                              I was not able to reproduce an npe.

                              • 27. Re: WFS translator & spatial
                                tom9729

                                > The use of SDO_GEOMETRY with a blob binding (as a stream) fails for me

                                 

                                Are you passing a valid SRID? If unspecified, it will send UNKNOWN_SRID (aka 0) which might make Oracle unhappy.

                                 

                                https://github.com/Tom9729/teiid/commit/98e3ade67e3561fb91b2a5ab4a28074581f1260a

                                 

                                Thanks,

                                Tom

                                • 28. Re: WFS translator & spatial
                                  shawkins

                                  Oracle seems fine with a zero SRID.  I resolved it with using the TO_CLOB/TO_BLOB functions as it seemed related to type resolution - SDO_GEOMETRY(?, int) is effectively ambiguous.

                                   

                                  Let's move the discussion moving forward over to the issue.

                                  • 29. Re: WFS translator & spatial
                                    shawkins

                                    A follow up from above.  I believe the NPE you saw was related to [TEIID-3299] Errors when calculating bytes sent. - JBoss Issue Tracker