Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic in GeometryType.SQL when trying to cast GeometryType to string #3645

Closed
fulghum opened this issue Jun 18, 2022 · 5 comments
Closed

Panic in GeometryType.SQL when trying to cast GeometryType to string #3645

fulghum opened this issue Jun 18, 2022 · 5 comments
Assignees
Labels
bug Something isn't working spatial types

Comments

@fulghum
Copy link
Contributor

fulghum commented Jun 18, 2022

When running in sql-server mode selecting geometry types can cause a panic and crash the server:

2022-06-17T17:10:04-07:00 TRACE [conn 10] committing transaction DoltTransaction {connectTime=2022-06-17T17:09:52-07:00, connectionDb=db2, query=select * from t1}
panic: interface conversion: interface {} is sql.Point, not string

goroutine 2277 [running]:
github.com/dolthub/go-mysql-server/sql.GeometryType.SQL({0x912c58?, 0x40?}, {0x0, 0x0, 0x0}, {0x104012220?, 0x14000dc8018?})
        /Users/jason/Projects/go-mysql-server/sql/geometry.go:293 +0x170
github.com/dolthub/go-mysql-server/server.rowToSQL({0x14000c51bb0, 0x2, 0x14000b1c508?}, {0x14000c3c0c0, 0x2, 0x10253d201?})
        /Users/jason/Projects/go-mysql-server/server/handler.go:720 +0x12c
github.com/dolthub/go-mysql-server/server.(*Handler).doQuery.func4()
        /Users/jason/Projects/go-mysql-server/server/handler.go:500 +0x4fc
golang.org/x/sync/errgroup.(*Group).Go.func1()
        /Users/jason/go/pkg/mod/golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/errgroup/errgroup.go:57 +0x64
created by golang.org/x/sync/errgroup.(*Group).Go
        /Users/jason/go/pkg/mod/golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/errgroup/errgroup.go:54 +0x90

When running in a local sql shell, we just see garbled output:

select * from t1;
+---+-----+
| i | g                         |
+---+-----+
| 0 | �?@ |
+---+-----+

The problem is that GeometryType::SQL attempts to cast a geometry type to a string:
https://github.com/dolthub/go-mysql-server/blob/main/sql/geometry.go#L293

We should follow MySQL and convert geometry binary values to hex for display:

mysql> select * from t1;
+------------------------------------------------------+
| g                                                    |
+------------------------------------------------------+
| 0x000000000101000000000000000000F03F0000000000000040 |
+------------------------------------------------------+
1 row in set (0.00 sec)
@jycor
Copy link
Contributor

jycor commented Jun 20, 2022

On my windows machine, MySQL does not convert geometry binary values to hex for display.

@fulghum
Copy link
Contributor Author

fulghum commented Jun 21, 2022

Thanks for testing on Windows. What's the result you see in the mysql shell on Windows for a select of a geometry column with a simple geo type like point(1,2)? Just a couple of garbled characters?

@jycor
Copy link
Contributor

jycor commented Jun 21, 2022

Yep, selecting a simple point like that is mostly null characters

mysql> select point(1,2);
+---------------------------+
| point(1,2)                |
+---------------------------+
|     ��         ?       @ |
+---------------------------+

@fulghum
Copy link
Contributor Author

fulghum commented Jun 21, 2022

Weird that the Windows MySQL shell behavior is different. It seems like a bug to ever print out unreadable chars. Could you search/open a bug report with MySQL and we'll see what they say? I couldn't find any documentation for that behavior anywhere yet. Here's the Mac MySQL shell behavior, for completeness, too:

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.29    |
+-----------+
1 row in set (0.00 sec)

mysql> select point(1, 2);
+------------------------------------------------------+
| point(1, 2)                                          |
+------------------------------------------------------+
| 0x000000000101000000000000000000F03F0000000000000040 |
+------------------------------------------------------+
1 row in set (0.00 sec)

Thanks for jumping on the fix, too!

@zachmu
Copy link
Member

zachmu commented Jun 21, 2022

This appears to be a printing issue from certain shells.

% mysql --version
mysql  Ver 8.0.27-cluster for Linux on x86_64 (MySQL Cluster Community Server - GPL)
mysql> select point(1,2)
    -> ;
+------------------------------------------------------+
| point(1,2)                                           |
+------------------------------------------------------+
| 0x000000000101000000000000000000F03F0000000000000040 |
+------------------------------------------------------+

We need 2 things here:

  1. Geometry types on the wire must match what MySQL does
  2. Dolt shell should print something reasonable for these values

@jycor jycor closed this as completed Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working spatial types
Projects
None yet
Development

No branches or pull requests

3 participants