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

expression: Support VALUES function for VectorFloat32 #55151

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
353a2aa
Add Vector data type
EricZequan Jul 15, 2024
fed4b76
Add Vector data type
EricZequan Jul 15, 2024
fc20922
Add Vector data type
EricZequan Jul 15, 2024
6a8847e
Add Vector data type
EricZequan Jul 15, 2024
16f63cb
Add Vector data type
EricZequan Jul 16, 2024
59867fd
Add Vector data type(2)
EricZequan Jul 16, 2024
91b8cdd
Add Vector data type(3)
EricZequan Jul 17, 2024
8ed8337
Add Vector data type(4)
EricZequan Jul 17, 2024
e2e9cf7
Add Vector data type(4)
EricZequan Jul 17, 2024
1d9a8d1
Add Vector data type(5)
EricZequan Jul 17, 2024
0356240
Add Vector data type(7)
EricZequan Jul 17, 2024
aa023be
Add Vector data type(8)
EricZequan Jul 18, 2024
ab46c25
Add Vector data type(9)
EricZequan Jul 18, 2024
116bba7
Add Vector data type(10)
EricZequan Jul 18, 2024
a2310ed
vector data type(11)
EricZequan Jul 22, 2024
8d143f8
Add Vector Data Type(12)
EricZequan Jul 22, 2024
e232147
Add Vector Data Type(13)
EricZequan Jul 25, 2024
c0a6481
fixed dimension vector
EricZequan Jul 29, 2024
b937bb1
fixed dimension vector
EricZequan Jul 29, 2024
0ec012f
remove some unneed line
EricZequan Jul 29, 2024
20ecd5f
modify pkg/parser/parser.y
EricZequan Jul 31, 2024
c6cf7e1
modify pkg/ddl/index.go
EricZequan Jul 31, 2024
eced042
Add vector function
EricZequan Aug 1, 2024
e69498f
Deprecate VECTOR<FLOAT>
EricZequan Aug 1, 2024
6bfc528
RowFormatV1 surpport vector
EricZequan Aug 2, 2024
356b43d
Support VALUES function for VectorFloat32
EricZequan Aug 2, 2024
46245eb
removed the variable EnableVectorType
EricZequan Aug 2, 2024
43d0d6e
fix TestVectorColumnInfo fail
EricZequan Aug 5, 2024
bb4775d
fix the build fail
EricZequan Aug 6, 2024
bc4be25
fix a test fail
EricZequan Aug 6, 2024
68ee0e4
rebase to feature branch
EricZequan Aug 12, 2024
1649cfd
fix conflict
EricZequan Aug 12, 2024
ef68c1d
fix conflict
EricZequan Aug 12, 2024
0e3c290
fix conflict
EricZequan Aug 12, 2024
a29e84d
fix conflict
EricZequan Aug 12, 2024
540bd35
Merge remote-tracking branch 'upstream/feature/vector-search/vector-d…
EricZequan Aug 12, 2024
a44b66b
modify the return
EricZequan Aug 13, 2024
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
39 changes: 39 additions & 0 deletions pkg/expression/builtin_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,8 @@ func (c *valuesFunctionClass) getFunction(ctx BuildContext, args []Expression) (
sig = &builtinValuesDurationSig{baseBuiltinFunc: bf, offset: c.offset}
case types.ETJson:
sig = &builtinValuesJSONSig{baseBuiltinFunc: bf, offset: c.offset}
case types.ETVectorFloat32:
sig = &builtinValuesVectorFloat32Sig{baseBuiltinFunc: bf, offset: c.offset}
default:
return nil, errors.Errorf("%s is not supported for VALUES()", c.tp.EvalType())
}
Expand Down Expand Up @@ -1595,6 +1597,43 @@ func (b *builtinValuesJSONSig) evalJSON(ctx EvalContext, _ chunk.Row) (types.Bin
return types.BinaryJSON{}, true, errors.Errorf("Session current insert values len %d and column's offset %v don't match", row.Len(), b.offset)
}

type builtinValuesVectorFloat32Sig struct {
baseBuiltinFunc
contextopt.SessionVarsPropReader

offset int
}

func (b *builtinValuesVectorFloat32Sig) Clone() builtinFunc {
newSig := &builtinValuesVectorFloat32Sig{offset: b.offset}
newSig.cloneFrom(&b.baseBuiltinFunc)
return newSig
}

func (b *builtinValuesVectorFloat32Sig) RequiredOptionalEvalProps() OptionalEvalPropKeySet {
return b.SessionVarsPropReader.RequiredOptionalEvalProps()
}

// evalVectorFloat32 evals a builtinValuesVectorFloat32Sig.
// See https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_values
func (b *builtinValuesVectorFloat32Sig) evalVectorFloat32(ctx EvalContext, _ chunk.Row) (types.VectorFloat32, bool, error) {
sessionvar, err := b.GetSessionVars(ctx)
if err != nil {
return types.ZeroVectorFloat32, true, err
}
row := sessionvar.CurrInsertValues
if row.IsEmpty() {
return types.ZeroVectorFloat32, true, nil
}
if b.offset < row.Len() {
if row.IsNull(b.offset) {
return types.ZeroVectorFloat32, true, nil
}
return row.GetVectorFloat32(b.offset), false, nil
}
return types.ZeroVectorFloat32, true, errors.Errorf("Session current insert values len %d and column's offset %v don't match", row.Len(), b.offset)
}

type bitCountFunctionClass struct {
baseFunctionClass
}
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 = 40,
shard_count = 41,
deps = [
"//pkg/config",
"//pkg/domain",
Expand Down
15 changes: 15 additions & 0 deletions pkg/expression/integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,21 @@ func TestVectorFunctions(t *testing.T) {
tk.MustQuery(`SELECT VEC_L2_NORM('[0,1]');`).Check(testkit.Rows("1"))
}

func TestVectorMiscFunctions(t *testing.T) {
store := testkit.CreateMockStore(t)

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

tk.MustExec("CREATE TABLE a(pk INT PRIMARY KEY, c VECTOR(3), time INT);")
tk.MustExec("INSERT INTO a VALUES (1, '[1,2,3]', 5);")
tk.MustQuery(`SELECT * FROM a;`).Check(testkit.Rows("1 [1,2,3] 5"))
tk.MustExec("INSERT INTO a VALUES (1, '[1,1,1]', 10) ON DUPLICATE KEY UPDATE time=VALUES(time), c=VALUES(c);")
tk.MustQuery(`SELECT * FROM a;`).Check(testkit.Rows("1 [1,1,1] 10"))
tk.MustExec("INSERT INTO a VALUES (1, '[1,5,7]', 15) ON DUPLICATE KEY UPDATE time=VEC_DIMS(c), c=VALUES(c)+VALUES(c);")
tk.MustQuery(`SELECT * FROM a;`).Check(testkit.Rows("1 [2,10,14] 3"))
}

func TestGetLock(t *testing.T) {
ctx := context.Background()
store := testkit.CreateMockStore(t, mockstore.WithStoreType(mockstore.EmbedUnistore))
Expand Down