Skip to content

Commit

Permalink
parser: Support VECTOR type (#54246)
Browse files Browse the repository at this point in the history
ref #54245
  • Loading branch information
breezewish authored Jun 27, 2024
1 parent 64a166b commit 14ed0c0
Show file tree
Hide file tree
Showing 12 changed files with 10,804 additions and 10,620 deletions.
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
2 changes: 1 addition & 1 deletion pkg/expression/integration_test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go_test(
"main_test.go",
],
flaky = True,
shard_count = 26,
shard_count = 27,
deps = [
"//pkg/config",
"//pkg/domain",
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

0 comments on commit 14ed0c0

Please sign in to comment.