Allow extra parameters to be passed to dbWriteTable (first steps for st_write())#64
Allow extra parameters to be passed to dbWriteTable (first steps for st_write())#64
Conversation
|
This is just adding an ellipse to the doltr dbWriteTable() method right? That definitely seems like a good step and closes in on the location of the WKB / EWKB issue. |
|
Yup! |
|
Tooling around today I identified where sf is storing the CRS in the binary string crs is encoded as two pairs of hex digits in the coord string. First thing to note is that the order of the pairs in the string appear to be reversed. For example, I set the CRS above as 4326 which in hex is 10e6. In the string above that is represented as the four characters after 0101000020 which are e6 and 10. Varying the epsg crs code only changed those 4 digits. |
|
Maybe I've already referenced this but this is the specification for the MySQL modified WKB: https://dev.mysql.com/doc/refman/8.0/en/gis-data-formats.html#gis-internal-format |
|
Thanks! What I'm looking for now is differences between the PostGIS and MySQL specification. Mostly just to orient myself. |
|
Another thing to note is that the points returned by do not match those specified during Which adds more evidence to a difference in EWKB specification. |
|
drilling down this occurs within readWKB |
|
Some more clues. sf expects the WKB hex provided by the dolt db to be big endian, that the point coordinates come last, and are 8L long each. Maybe this is just a precision difference? I think starting with nailing st_read() on both points and crs first will be pretty informative about what's going wrong with st_write(). |
|
It's that and an endian problem. There's a difference in precision in the leading ints or dolt / mySQL is storing more stuff. The following recovers the original points. |
|
Okay how about this? I think I'm up to speed with what you have been saying this whole time now. |
|
Also I think we can declare srid in an insert query via |
…thout crs stuck into the hex somehwere incompatible with MySQL specs
|
I think the next steps will be to modify We need the final sql query generated within dbxInsert to look like this: If we add an isWKB or isSF check in |
|
Okay I have a patch proposed to dbx that should allow dbWriteTable to handle sf objects. In testing I was able to create an sf object in R, create a table using dbCreateTable, add rows using dbxInsert and then pull down and unpack the wkb column with my version of sf_read. It still needs a bit of polish but I think the framework is there. Check out the patch here |
…d` and `dbxInsert.R`. This allows for building package from branch.
…stop dispatch from applying sf's PostgreSQLConnection method which changes geometry column class to 'character'.
|
I had some method dispatch problems with dbWriteTable which are (hopefully) now resolved. You can try the patch by installing doltr from this branch. So far |
|
Okay now we have |
|
Okay I have |
|
@noamross can you give it a try? I think both are working now. One thing to note is that st_write seems to overwrite the table by default. To prevent that you have to set delete_layer = F. |
This change is a baby step to working with spatial data (#38, #60) . When
sfpasses a table todbWriteTable(), it includes afactorsAsCharacterargument (https://github.com/r-spatial/sf/blob/97bc8ddf733bbeddb283265f5714a6f9817b3aa8/R/read.R#L442-L444), which causes an error because ourdbWriteTable()method does not have this argument. (It remains to be seen if factors in the data frame causes an issue).Note I found this in some helpful initial testing. It turns out that
st_read()works just fine:The error
Is what you get at
st_write(). With this patch, the error changes to the lower level error sent from Dolt (or mysql or mariadb, I guess):Diving in, this is the statement that causes the error
So
sfconverts the data to WKB and then SQL text, but the WKB isn't the EWKB binary that dolt expects. This conversion happens here, into_postgis(): https://github.com/r-spatial/sf/blob/97bc8ddf733bbeddb283265f5714a6f9817b3aa8/R/db.R#L478 . This, along with thedb_binary()andsync_crs()bits, are what need Dolt/MySQL-specific methods. I think method could have Dolt/MySQL/MariaDB signatures and work for all of them. The geometry columns would work the same, not sure about the CRS component.