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

parser: Support VECTOR type #54246

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3420,7 +3420,7 @@ func checkPartitionByList(ctx sessionctx.Context, tbInfo *model.TableInfo) error

func isValidKeyPartitionColType(fieldType types.FieldType) bool {
switch fieldType.GetType() {
case mysql.TypeBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob, mysql.TypeJSON, mysql.TypeGeometry:
case mysql.TypeBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob, mysql.TypeJSON, mysql.TypeGeometry, mysql.TypeTiDBVectorFloat32:
return false
default:
return true
Expand Down
25 changes: 25 additions & 0 deletions pkg/expression/integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,31 @@ import (
"github.com/tikv/client-go/v2/oracle"
)

func TestVector(t *testing.T) {
// Currently we only allow parsing Vector type, but not using it.

store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")

err := tk.ExecToErr("CREATE TABLE c(a VECTOR)")
require.ErrorContains(t, err, "vector type is not supported")
err = tk.ExecToErr("CREATE TABLE c(a VECTOR(3))")
require.ErrorContains(t, err, "vector type is not supported")
err = tk.ExecToErr("SELECT CAST('123' AS VECTOR)")
require.ErrorContains(t, err, "vector type is not supported")

tk.MustExec("CREATE TABLE c(pk INT)")

err = tk.ExecToErr("ALTER TABLE c ADD COLUMN a VECTOR")
require.ErrorContains(t, err, "vector type is not supported")
err = tk.ExecToErr("ALTER TABLE c MODIFY pk VECTOR")
require.ErrorContains(t, err, "vector type is not supported")

tk.MustExec("DROP TABLE c")
}

func TestGetLock(t *testing.T) {
ctx := context.Background()
store := testkit.CreateMockStore(t, mockstore.WithStoreType(mockstore.EmbedUnistore))
Expand Down
5 changes: 5 additions & 0 deletions pkg/parser/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ type OptBinary struct {
Charset string
}

// OptVectorType represents the element type of the vector.
type VectorElementType struct {
Tp byte // Only FLOAT and DOUBLE is accepted.
}

// FuncNode represents function call expression node.
type FuncNode interface {
ExprNode
Expand Down
1 change: 1 addition & 0 deletions pkg/parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ var tokenMap = map[string]int{
"VARIABLES": variables,
"VARIANCE": varPop,
"VARYING": varying,
"VECTOR": vectorType,
"VERBOSE": verboseType,
"VOTER": voter,
"VOTER_CONSTRAINTS": voterConstraints,
Expand Down
2 changes: 2 additions & 0 deletions pkg/parser/mysql/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const (
TypeVarString byte = 0xfd
TypeString byte = 0xfe /* TypeString is char type */
TypeGeometry byte = 0xff

TypeTiDBVectorFloat32 byte = 0xe1
)

// Flag information.
Expand Down
Loading