Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into all-structs
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Feb 3, 2025
2 parents 4299743 + 78c7470 commit 7d2ff8d
Show file tree
Hide file tree
Showing 10 changed files with 9,501 additions and 9,464 deletions.
2 changes: 2 additions & 0 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2261,6 +2261,8 @@ func (columnFormat ColumnFormat) ToString() string {
return keywordStrings[DYNAMIC]
case DefaultFormat:
return keywordStrings[DEFAULT]
case CompressedFormat:
return keywordStrings[COMPRESSED]
default:
return "Unknown column format type"
}
Expand Down
1 change: 1 addition & 0 deletions go/vt/sqlparser/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ const (
FixedFormat
DynamicFormat
DefaultFormat
CompressedFormat
)

// Transaction access mode
Expand Down
20 changes: 19 additions & 1 deletion go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,9 @@ var (
}, {
input: "alter table a add spatial key indexes (column1)",
output: "alter table a add spatial key `indexes` (column1)",
}, {
input: "alter table locations add lat_long point as (point(geocode->>'$.geometry.location.lat', geocode->>'$.geometry.location.lng')) SRID 4326 after geocodes",
output: "alter table locations add column lat_long point as (point(json_unquote(json_extract(geocode, '$.geometry.location.lat')), json_unquote(json_extract(geocode, '$.geometry.location.lng')))) virtual srid 4326 after geocodes",
}, {
input: "create table a",
partialDDL: true,
Expand Down Expand Up @@ -5975,6 +5978,10 @@ partition by range (YEAR(purchased)) subpartition by hash (TO_DAYS(purchased))
input: "create table t (id int, vec VECTOR(4))",
output: "create table t (\n\tid int,\n\tvec VECTOR(4)\n)",
},
{
input: "CREATE TABLE `locations` (`geocode` json DEFAULT NULL, `lat_long` point GENERATED ALWAYS AS (point(json_unquote(json_extract(`geocode`,_utf8mb4'$.geometry.location.lat')),json_unquote(json_extract(`geocode`,_utf8mb4'$.geometry.location.lng')))) VIRTUAL /*!80003 SRID 4326 */) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci",
output: "create table locations (\n\tgeocode json default null,\n\tlat_long point as (point(json_unquote(json_extract(geocode, _utf8mb4 '$.geometry.location.lat')), json_unquote(json_extract(geocode, _utf8mb4 '$.geometry.location.lng')))) virtual srid 4326\n) ENGINE InnoDB,\n CHARSET utf8mb4,\n COLLATE utf8mb4_0900_ai_ci",
},
}
parser := NewTestParser()
for _, test := range createTableQueries {
Expand Down Expand Up @@ -6347,14 +6354,25 @@ func TestParseVersionedComments(t *testing.T) {
partition by range (id)
(partition x values less than (5) engine InnoDB,
partition t values less than (20) engine InnoDB)`,
}, {
input: "CREATE TABLE `TABLE_NAME` (\n `col1` longblob /*!50633 COLUMN_FORMAT COMPRESSED */,\n `id` bigint unsigned NOT NULL,\n PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED",
mysqlVersion: "8.0.1",
output: `create table TABLE_NAME (
col1 longblob column_format compressed,
id bigint unsigned not null,
primary key (id)
) ENGINE InnoDB,
CHARSET utf8mb4,
COLLATE utf8mb4_bin,
ROW_FORMAT COMPRESSED`,
},
}

for _, testcase := range testcases {
t.Run(testcase.input+":"+testcase.mysqlVersion, func(t *testing.T) {
parser, err := New(Options{MySQLServerVersion: testcase.mysqlVersion})
require.NoError(t, err)
tree, err := parser.Parse(testcase.input)
tree, err := parser.ParseStrictDDL(testcase.input)
require.NoError(t, err, testcase.input)
out := String(tree)
require.Equal(t, testcase.output, out)
Expand Down
Loading

0 comments on commit 7d2ff8d

Please sign in to comment.