13
13
*/
14
14
15
15
import {
16
+ MochowClient ,
16
17
Row ,
17
18
IndexSchema ,
18
19
FieldSchema ,
19
20
ClientConfiguration ,
20
21
AutoBuildTiming ,
21
- PartitionParams ,
22
22
TableSchema ,
23
23
FieldType ,
24
24
IndexType ,
25
25
MetricType ,
26
26
PartitionType ,
27
- PrimaryKey ,
28
- PartitionKey ,
29
27
ReadConsistency ,
30
- UpdateFields ,
31
28
IndexState ,
32
- SearchParams ,
33
- ANNSearchParams ,
34
- BatchANNSearchParams ,
35
29
TableState ,
36
30
ServerErrCode ,
37
31
InvertedIndexFieldAttribute ,
@@ -48,8 +42,14 @@ import {
48
42
BM25SearchArgs ,
49
43
HybridSearchArgs ,
50
44
HybridSearchRequest ,
51
- } from "../mochow/types/index"
52
- import { MochowClient } from "../mochow/MochowClient"
45
+ CreateTableArgs ,
46
+ InsertArgs ,
47
+ QueryArgs ,
48
+ SelectArgs ,
49
+ ElementType ,
50
+ IndexStructureType ,
51
+ BatchQueryArgs ,
52
+ } from "../mochow" ;
53
53
54
54
export class MochowTest {
55
55
private client : MochowClient
@@ -71,8 +71,7 @@ export class MochowTest {
71
71
}
72
72
73
73
public async createTable ( ) {
74
- let fields : FieldSchema [ ]
75
- fields = [
74
+ let fields : FieldSchema [ ] = [
76
75
{
77
76
fieldName : "id" ,
78
77
fieldType : FieldType . String ,
@@ -106,6 +105,12 @@ export class MochowTest {
106
105
fieldName : "segment" ,
107
106
fieldType : FieldType . Text ,
108
107
notNull : true
108
+ } ,
109
+ {
110
+ fieldName : "arrayField" ,
111
+ fieldType : FieldType . Array ,
112
+ elementType : ElementType . String ,
113
+ notNull : true
109
114
}
110
115
]
111
116
@@ -117,6 +122,16 @@ export class MochowTest {
117
122
field : "bookName" ,
118
123
indexType : IndexType . SecondaryIndex ,
119
124
} ,
125
+ {
126
+ indexName : "filtering_idx" ,
127
+ indexType : IndexType . FilteringIndex ,
128
+ fields : [
129
+ {
130
+ field : "author" ,
131
+ indexStructureType : IndexStructureType . Bitmap
132
+ }
133
+ ]
134
+ } ,
120
135
{
121
136
indexName : "vector_idx" ,
122
137
field : "vector" ,
@@ -142,10 +157,20 @@ export class MochowTest {
142
157
]
143
158
144
159
// create table
145
- let partitionParams : PartitionParams = { partitionType : PartitionType . HASH , partitionNum : 1 }
146
160
let schema : TableSchema = { fields : fields , indexes : indexes }
147
-
148
- let resp = await this . client . createTable ( this . database_name , this . table_name , "test" , 1 , partitionParams , true , schema )
161
+ let createTableReq : CreateTableArgs = {
162
+ database : this . database_name ,
163
+ table : this . table_name ,
164
+ description : "test" ,
165
+ replication : 1 ,
166
+ partitionParams : {
167
+ partitionType : PartitionType . HASH ,
168
+ partitionNum : 1 ,
169
+ } ,
170
+ enableDynamicField : false ,
171
+ schema : schema
172
+ }
173
+ let resp = await this . client . createTable ( createTableReq )
149
174
if ( resp . code != 0 ) {
150
175
console . log ( "fail to create table due to: " + resp . msg )
151
176
return resp
@@ -186,6 +211,7 @@ export class MochowTest {
186
211
"page" : 21 ,
187
212
"vector" : [ 0.2123 , 0.21 , 0.213 ] ,
188
213
"segment" : "富贵功名,前缘分定,为人切莫欺心。" ,
214
+ "arrayField" : [ ] ,
189
215
} ,
190
216
{
191
217
"id" : "0002" ,
@@ -194,6 +220,7 @@ export class MochowTest {
194
220
"page" : 22 ,
195
221
"vector" : [ 0.2123 , 0.22 , 0.213 ] ,
196
222
"segment" : "正大光明,忠良善果弥深。些些狂妄天加谴,眼前不遇待时临。" ,
223
+ "arrayField" : [ "细作" ] ,
197
224
} ,
198
225
{
199
226
"id" : "0003" ,
@@ -202,6 +229,7 @@ export class MochowTest {
202
229
"page" : 23 ,
203
230
"vector" : [ 0.2123 , 0.23 , 0.213 ] ,
204
231
"segment" : "细作探知这个消息,飞报吕布。" ,
232
+ "arrayField" : [ "细作" , "吕布" ] ,
205
233
} ,
206
234
{
207
235
"id" : "0004" ,
@@ -210,6 +238,7 @@ export class MochowTest {
210
238
"page" : 24 ,
211
239
"vector" : [ 0.2123 , 0.24 , 0.213 ] ,
212
240
"segment" : "布大惊,与陈宫商议。宫曰:“闻刘玄德新领徐州,可往投之。” 布从其言,竟投徐州来。有人报知玄德。" ,
241
+ "arrayField" : [ "吕布" , "陈宫" , "刘玄德" ] ,
213
242
} ,
214
243
{
215
244
"id" : "0005" ,
@@ -218,9 +247,15 @@ export class MochowTest {
218
247
"page" : 25 ,
219
248
"vector" : [ 0.2123 , 0.24 , 0.213 ] ,
220
249
"segment" : "玄德曰:“布乃当今英勇之士,可出迎之。”糜竺曰:“吕布乃虎狼之徒,不可收留;收则伤人矣。" ,
250
+ "arrayField" : [ "玄德" , "吕布" , "糜竺" ] ,
221
251
}
222
252
]
223
- let resp = await this . client . insertRows ( this . database_name , this . table_name , data )
253
+ let insertArgs : InsertArgs = {
254
+ database : this . database_name ,
255
+ table : this . table_name ,
256
+ rows : data ,
257
+ }
258
+ let resp = await this . client . upsert ( insertArgs )
224
259
if ( resp . code != 0 ) {
225
260
console . log ( "fail to upsert row due to: " + resp . msg )
226
261
return resp
@@ -229,16 +264,17 @@ export class MochowTest {
229
264
}
230
265
231
266
public async queryData ( ) {
232
- let pk : PrimaryKey = { "id" : "0001" }
233
- let projections : string [ ] = [ "id" , "bookName" ]
234
- let resp = await this . client . queryRow (
235
- this . database_name ,
236
- this . table_name ,
237
- pk ,
238
- undefined ,
239
- projections ,
240
- false ,
241
- ReadConsistency . EVENTUAL )
267
+ let queryArgs : QueryArgs = {
268
+ database : this . database_name ,
269
+ table : this . table_name ,
270
+ primaryKey : {
271
+ "id" : "0001"
272
+ } ,
273
+ projections : [ "id" , "bookName" ] ,
274
+ retrieveVector : false ,
275
+ readConsistency : ReadConsistency . EVENTUAL
276
+ }
277
+ let resp = await this . client . query ( queryArgs ) ;
242
278
if ( resp . code != 0 ) {
243
279
console . log ( "fail to query data due to: " + resp . msg )
244
280
return resp
@@ -247,15 +283,43 @@ export class MochowTest {
247
283
return resp
248
284
}
249
285
286
+ public async batchQuery ( ) {
287
+ let queryArgs : BatchQueryArgs = {
288
+ database : this . database_name ,
289
+ table : this . table_name ,
290
+ keys : [
291
+ {
292
+ primaryKey : {
293
+ "id" : "0001"
294
+ }
295
+ } ,
296
+ {
297
+ primaryKey : {
298
+ "id" : "0002"
299
+ }
300
+ }
301
+ ] ,
302
+ projections : [ "id" , "bookName" ] ,
303
+ retrieveVector : false ,
304
+ readConsistency : ReadConsistency . EVENTUAL
305
+ }
306
+ let resp = await this . client . batchQuery ( queryArgs ) ;
307
+ if ( resp . code != 0 ) {
308
+ console . log ( "fail to query data due to: " + resp . msg )
309
+ return resp
310
+ }
311
+ console . log ( "batch query result: " , JSON . stringify ( resp , null , " " ) )
312
+ return resp
313
+ }
314
+
250
315
public async selectData ( ) {
251
- let projections : string [ ] = [ "id" , "bookName" ]
252
- let resp = await this . client . selectRows (
253
- this . database_name ,
254
- this . table_name ,
255
- undefined ,
256
- undefined ,
257
- projections ,
258
- 1 )
316
+ let selectArgs : SelectArgs = {
317
+ database : this . database_name ,
318
+ table : this . table_name ,
319
+ projections : [ "id" , "bookName" ] ,
320
+ limit : 1
321
+ }
322
+ let resp = await this . client . select ( selectArgs ) ;
259
323
if ( resp . code != 0 ) {
260
324
console . log ( "fail to select data due to: " + resp . msg )
261
325
return resp
@@ -265,19 +329,19 @@ export class MochowTest {
265
329
}
266
330
267
331
public async updateData ( ) {
268
- let pk : PrimaryKey = { "id" : "0001" }
269
- let update : UpdateFields = {
270
- "bookName" : "红楼梦" ,
271
- "author" : "曹雪芹" ,
272
- "page" : 100 ,
273
- "segment" : "满纸荒唐言,一把辛酸泪" ,
274
- }
275
- let resp = await this . client . updateRow (
276
- this . database_name ,
277
- this . table_name ,
278
- pk ,
279
- undefined ,
280
- update )
332
+ let resp = await this . client . update ( {
333
+ database : this . database_name ,
334
+ table : this . table_name ,
335
+ primaryKey : {
336
+ id : "0001" ,
337
+ } ,
338
+ update : {
339
+ bookName : "红楼梦" ,
340
+ author : "曹雪芹" ,
341
+ page : 100 ,
342
+ segment : "满纸荒唐言,一把辛酸泪" ,
343
+ } ,
344
+ } ) ;
281
345
if ( resp . code != 0 ) {
282
346
console . log ( "fail to update row due to: " + resp . msg )
283
347
return resp
@@ -433,7 +497,13 @@ export class MochowTest {
433
497
}
434
498
435
499
public async deleteDataWithPK ( ) {
436
- let resp = await this . client . deleteRow ( this . database_name , this . table_name , { "id" : "0001" } )
500
+ let resp = await this . client . delete ( {
501
+ database : this . database_name ,
502
+ table : this . table_name ,
503
+ primaryKey : {
504
+ "id" : "0001"
505
+ }
506
+ } )
437
507
if ( resp . code != 0 ) {
438
508
console . log ( "delete data with pk failed" )
439
509
return resp
@@ -442,7 +512,11 @@ export class MochowTest {
442
512
}
443
513
444
514
public async deleteDataWithFilter ( ) {
445
- let resp = await this . client . deleteRow ( this . database_name , this . table_name , undefined , undefined , "id = '0002'" )
515
+ let resp = await this . client . delete ( {
516
+ database : this . database_name ,
517
+ table : this . table_name ,
518
+ filter : "id = '0002'" ,
519
+ } )
446
520
if ( resp . code != 0 ) {
447
521
console . log ( "delete data with pk failed" )
448
522
return resp
@@ -560,6 +634,7 @@ export class MochowTest {
560
634
await new Promise ( f => setTimeout ( f , 10000 ) ) ;
561
635
await mochowTest . insertRow ( )
562
636
await mochowTest . queryData ( )
637
+ await mochowTest . batchQuery ( )
563
638
await mochowTest . selectData ( )
564
639
await mochowTest . updateData ( )
565
640
await mochowTest . descIndex ( )
0 commit comments