-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ticdc: Support Vector data type | tidb=master pd=master tikv=master (#…
- Loading branch information
Showing
45 changed files
with
769 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2024 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package mysql | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/pingcap/log" | ||
"github.com/pingcap/tidb/pkg/parser" | ||
"github.com/pingcap/tidb/pkg/parser/ast" | ||
"github.com/pingcap/tidb/pkg/parser/format" | ||
"github.com/pingcap/tidb/pkg/parser/mysql" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type visiter struct{} | ||
|
||
func (f *visiter) Enter(n ast.Node) (node ast.Node, skipChildren bool) { | ||
switch v := n.(type) { | ||
case *ast.ColumnDef: | ||
if v.Tp != nil { | ||
switch v.Tp.GetType() { | ||
case mysql.TypeTiDBVectorFloat32: | ||
v.Tp.SetType(mysql.TypeLongBlob) | ||
v.Tp.SetCharset("") | ||
v.Tp.SetCollate("") | ||
v.Tp.SetFlen(-1) | ||
v.Options = []*ast.ColumnOption{} // clear COMMENT | ||
} | ||
} | ||
} | ||
return n, false | ||
} | ||
|
||
func (f *visiter) Leave(n ast.Node) (node ast.Node, ok bool) { | ||
return n, true | ||
} | ||
|
||
func formatQuery(sql string) string { | ||
p := parser.New() | ||
stmt, err := p.ParseOneStmt(sql, "", "") | ||
if err != nil { | ||
log.Error("format query parse one stmt failed", zap.Error(err)) | ||
} | ||
stmt.Accept(&visiter{}) | ||
|
||
buf := new(bytes.Buffer) | ||
restoreCtx := format.NewRestoreCtx(format.DefaultRestoreFlags, buf) | ||
if err = stmt.Restore(restoreCtx); err != nil { | ||
log.Error("format query restore failed", zap.Error(err)) | ||
} | ||
return buf.String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2024 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package mysql | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/pingcap/tidb/pkg/parser" | ||
"github.com/pingcap/tidb/pkg/parser/format" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFormatQuery(t *testing.T) { | ||
sql := "CREATE TABLE `test` (`id` INT PRIMARY KEY,`data` VECTOR(5))" | ||
expectSQL := "CREATE TABLE `test` (`id` INT PRIMARY KEY,`data` LONGTEXT)" | ||
p := parser.New() | ||
stmt, err := p.ParseOneStmt(sql, "", "") | ||
require.NoError(t, err) | ||
stmt.Accept(&visiter{}) | ||
|
||
buf := new(bytes.Buffer) | ||
restoreCtx := format.NewRestoreCtx(format.DefaultRestoreFlags, buf) | ||
err = stmt.Restore(restoreCtx) | ||
require.NoError(t, err) | ||
require.Equal(t, buf.String(), expectSQL) | ||
} | ||
|
||
func BenchmarkFormatQuery(b *testing.B) { | ||
sql := "CREATE TABLE `test` (`id` INT PRIMARY KEY,`data` LONGTEXT)" | ||
b.ReportAllocs() | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
formatQuery(sql) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.