Repository navigation
Postgis types - #255
Postgis types#255rossini-t wants to merge 6 commits into
Conversation
|
That's excellent, @rossini-t ! I'm reviewing your patch. Would you mind to rebase your work on current master branch? Today github say it can't merge your patch which means it may have some conflicts with current master branch code. Can you explain better what is the need for the preliminary cast? I have some plans to remove the cast Npgsql is adding to parameters. Did you add this preliminary cast because of Npgsql? Thanks in advance. |
|
I didn't see that there was conflicts with master (i'm new to githhub), so I will rebase the branch no problems ! Concerning the preliminary cast, you cannot cast an hexstring directly to geometry, so you have to cast it to bytea first, that's the "preliminary" cast. So this is more a pgsql problem. |
|
Hi, |
|
That's excellent, @rossini-t ! I'll review your patch and send you my comments. |
|
Hi, @rossini-t ! I think you have your editor to use tabs instead of spaces. Thanks in advance! |
|
Got it ! |
|
@franciscojunior, have you had any time to review this? I can take a look as well... |
|
Hi, @roji ! Sorry. I'll have a look at it. |
|
I think the code is very good! The only issue I'm seeing is the need to change the constructor of @rossini-t , do you think that it would be possible to change the code to maybe use a subclass of NpgsqlNativeTypeInfo to handle the custom casting and maybe add an extension method to handle the I think this would make the geometry types handling code self contained regarding this specific requirement. This could even change in the future ( I saw your note about checking another way of making the geometry work without the bytea casting). Please, have a look at this and check if it is possible and not too much complex. Thanks in advance. |
|
This looks like feasible ! |
|
Hi, @rossini-t ! I think your changes for postgis NativeTypeInfo are very good! I think you don't need to add a connection string to enable the postgis types. |
|
Hi @franciscojunior ! If we leave this responsability to the user, then we automatically load the backend geometry type, regardless of the extension being installed. Is this behavior accepted ? |
No problem! :)
I think there is no problem loading the backend geometry type. With the current PR, NpgsqlDbType will already expose the geometry types and the converters won't add any impact. When I tried your code, I used a postgresql with no postgis extension installed to see how it would run and it run ok and just skipped the tests as expected (as you added a check for the extension). That's why I think the user can check if the extension is installed or not before using. Also, if she tries to use the postgis code without installing the extension, Postgresql will throw an exception talking about this problem. What do you think? |
|
@rossini-t, thanks for this PR, it looks like a very nice addition to Npgsql. I just did a code review, please take a look at the comments above. I also have one more general question. Is it really necessary to require the WithPostGis connection string parameter? I do understand that it is currently needed, since the LoadTypeMappings needs to know in advance what types to load OIDs for. But I'd like us to see if it's not possible to have it simply load all types, and this way PostGis is always enabled without a PostGis type. The same, by the way, goes for UseExtendedTypes. This would mean a more fundamental change in the way we load types. @franciscojunior, do you know anything about this? |
I also pointed out this to @rossini-t . I think there is no need to use use a connection string to flag if the postgis types should be used or not.
In the case of UseExtendedTypes, I think it is different because they change some of the types returned from Npgsql through the use of different type converters. Unless we get to the conclusion that those extended types are going to be the default for 3.0. In this case I think we can get rid of this connection string parameter and load only the extended types version. I think @jbcooley has more information about that as he worked in those extended types. |
|
OK. @rossini-t and @franciscojunior, I'll try to look at modifying the type mapping loading process the way I said. If it can be done we can change the PostGis support to not require the connstring param. For the UseExtendedTypes let's see what @jbcooley says and treat separately. |
There was a problem hiding this comment.
The property will actually never returns null. ExecuteScalar will throw an exception because postgis_version will be missing. What behavior is prefered here ?
There was a problem hiding this comment.
It would be ideal if we could check in some way that PostGis is installed before calling postgis_version(). One idea that comes to mind, is to check whether a PostGis type was found in the type loading phase; if so it means PostGis is installed, right?
If you're OK with doing it this way, then let me look at the refactor of the type loading as I described below (i.e. load all types from Postgresql rather than loading only a preset list. Then you'll simply be able to check whether the PostGis type is mapped to a Postgresql OID. Sounds good?
There was a problem hiding this comment.
I agree it is a good approch.
Thank you for taking interest in my code !
|
@rossini-t, out of the box your TestConnectionString test fails with the message "WITH POSTGIS is not working". I get a String rather than an OgrPoint from the st_point() query. Can you please confirm that it works on your setup? (I'm using Postgresql 9.3 with PostGis 2.1.3). Also, if you could rebase you PR on master that would be a great help. |
0b35ef0 to
c43b6af
Compare
Common Postgis OGR geometries handling. Implemented a subset of OGR features as native types and their respective backend/native coding. Added backend to native validation tests. Added enumerables tests Typo in test file. Common Postgis OGR geometries handling. Implemented a subset of OGR features as native types and their respective backend/native coding. Added enumerables tests Typo in test file. Corrected errors generated by previous merge. Changed the way NpgsqlConnector loads postgis types The PostgisVersion property is not used anymore to determine if the connector should loads postgis types. The new keyword 'WITH POSTGIS' in the connection string is used to tell the connector to load it. Replaced tabulations to 4 spaces indentation. Unnecessary call to ToString() Replacing ToString Call to String casting Attempt to Postgis NativeTypeInfo specialization Corrected bad WKB output of OgrPolygon Corrected bad type id for OgrMultiPoint. Simplyfing PostgisNativeTypeInfo Changed masking CastName property to overriding. Removed unnecessary parameters on PostgisNativeTypeInfo instanciation. Refactoring Postgis Tests Removed unnecessary variable in Postgis test Added explicit casting for Framework 3.5 compat. Removed needless spaces Use of an enum for geometry type matching Use of an enum for geometry type matching rather than integer. Changed UsePostgisTypes To AutoProp Removed comments Removed env variable for pgis testing.
Maked usePostgisTypes parameter optional for compliance with base code.
df96f87 to
abead85
Compare
|
Hi, @rossini-t ! Can you check the recent changes we are doing on #390? As we are changing the CastName property to a method GetCastName(int size) which receives a size value, I'd like to know if it has a big impact in your design. Thanks in advance. |
Corrected bug mentionned by @roji : npgsql#255 (comment) The postgis types was actually never loaded.
|
Hi, @franciscojunior ! As is, it looks like it's only requring to override GetCastName in PostGisNativeTypeInfo to make it returning the right cast name (i.e. bytea::geometry) |
Great! I was worried that this modification would break significantly your code. I'll keep reviewing your code and #390 . Thanks for your feedback! |
|
Just a thought... with all the work that's happening on type read/write in #385, it may be a good idea to wait with this PR for a bit. |
e1d8c57 to
1f140e5
Compare
|
@rossini-t, we're deep in the v3.0 rewrite, where the type system has completely changed. I'm sorry that this means some of your work has been lost... But on the other hand the new type system is much more powerful, efficient and async-compatible. If you want to resume work on PostGIS support, the type system is probably safe enough to do so; take a look at some existing types and note especially the difference between chunking (variable-length) and simple (fixed-length) type handlers. It may be a bit too much to include in 3.0, let's wait and see. |
|
@rossini-t, I'm going to close this PR and open a separate issue for PostGIS implementation. A considerable amount of code can probably be taken from your work in this PR. Again, sorry about your work not being merged, it was a matter of bad timing and I hope you'll consider continuing work on this for v3.0. |
I've started to implement the most common geometric features of Postgres Spatial Extension as Npgsql Types to easily manage them in npgsql commands. I use it in some private projects, but this is always work in progress. It will be great to have some feedback.
Thanks !
[addendum] Code tested with .NET 4.5 and PostgreSQL 9.1 + Postgis 2.0