Skip to content

Commit

Permalink
Prevent panics for more invalid geometry queries
Browse files Browse the repository at this point in the history
  • Loading branch information
nicktobey committed Dec 2, 2023
1 parent 94f5476 commit 09287d7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 39 deletions.
77 changes: 38 additions & 39 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -2881,25 +2881,32 @@ func (ct *ColumnType) SQLType() querypb.Type {
return sqltypes.Int64
case keywordStrings[BOOL], keywordStrings[BOOLEAN]:
return sqltypes.Uint8
case keywordStrings[TEXT]:
case keywordStrings[TEXT],
keywordStrings[TINYTEXT],
keywordStrings[MEDIUMTEXT],
keywordStrings[LONGTEXT],
keywordStrings[LONG],
"long varchar":
return sqltypes.Text
case keywordStrings[TINYTEXT]:
return sqltypes.Text
case keywordStrings[MEDIUMTEXT]:
return sqltypes.Text
case keywordStrings[LONGTEXT]:
return sqltypes.Text
case keywordStrings[BLOB]:
return sqltypes.Blob
case keywordStrings[TINYBLOB]:
case keywordStrings[BLOB],
keywordStrings[TINYBLOB],
keywordStrings[MEDIUMBLOB],
keywordStrings[LONGBLOB]:
return sqltypes.Blob
case keywordStrings[MEDIUMBLOB]:
return sqltypes.Blob
case keywordStrings[LONGBLOB]:
return sqltypes.Blob
case keywordStrings[CHAR]:
case keywordStrings[CHAR],
keywordStrings[NCHAR],
"national char",
"national character":
return sqltypes.Char
case keywordStrings[VARCHAR]:
case keywordStrings[VARCHAR],
keywordStrings[NVARCHAR],
"char varying",
"character varying",
"nchar varchar",
"nchar varying",
"national varchar",
"national char varying",
"national character varying":
return sqltypes.VarChar
case keywordStrings[BINARY]:
return sqltypes.Binary
Expand All @@ -2917,15 +2924,14 @@ func (ct *ColumnType) SQLType() querypb.Type {
return sqltypes.Year
case keywordStrings[FLOAT_TYPE]:
return sqltypes.Float32
case keywordStrings[DOUBLE]:
case keywordStrings[DOUBLE],
keywordStrings[REAL],
"double precision":
return sqltypes.Float64
case keywordStrings[REAL]:
return sqltypes.Float64
case keywordStrings[DECIMAL]:
return sqltypes.Decimal
case keywordStrings[DEC]:
return sqltypes.Decimal
case keywordStrings[FIXED]:
case keywordStrings[DECIMAL],
keywordStrings[DEC],
keywordStrings[FIXED],
keywordStrings[NUMERIC]:
return sqltypes.Decimal
case keywordStrings[BIT]:
return sqltypes.Bit
Expand All @@ -2935,21 +2941,14 @@ func (ct *ColumnType) SQLType() querypb.Type {
return sqltypes.Set
case keywordStrings[JSON]:
return sqltypes.TypeJSON
case keywordStrings[GEOMETRY]:
return sqltypes.Geometry
case keywordStrings[POINT]:
return sqltypes.Geometry
case keywordStrings[LINESTRING]:
return sqltypes.Geometry
case keywordStrings[POLYGON]:
return sqltypes.Geometry
case keywordStrings[GEOMETRYCOLLECTION]:
return sqltypes.Geometry
case keywordStrings[MULTIPOINT]:
return sqltypes.Geometry
case keywordStrings[MULTILINESTRING]:
return sqltypes.Geometry
case keywordStrings[MULTIPOLYGON]:
case keywordStrings[GEOMETRY],
keywordStrings[POINT],
keywordStrings[LINESTRING],
keywordStrings[POLYGON],
keywordStrings[GEOMETRYCOLLECTION],
keywordStrings[MULTIPOINT],
keywordStrings[MULTILINESTRING],
keywordStrings[MULTIPOLYGON]:
return sqltypes.Geometry
}
panic("unimplemented type " + ct.Type)
Expand Down
3 changes: 3 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6785,6 +6785,9 @@ var (
}, {
input: "create table t (id int primary key, col1 FIXED(4, 4) SRID 0)",
output: "cannot define SRID for non spatial types at position 61 near '0'",
}, {
input: "create table t (id int primary key, col1 NCHAR VARCHAR SRID 0)",
output: "cannot define SRID for non spatial types at position 63 near '0'",
}, {
input: "create table t (id int primary key, col1 geometry SRID -1)",
output: "syntax error at position 57 near 'SRID'",
Expand Down

0 comments on commit 09287d7

Please sign in to comment.