@@ -354,6 +354,67 @@ func TestCost(t *testing.T) {
354
354
hints : map [string ]int64 {"str1" : 10 , "str2" : 10 },
355
355
wanted : CostEstimate {Min : 2 , Max : 6 },
356
356
},
357
+ {
358
+ name : "list size comparison" ,
359
+ expr : `list1.size() == list2.size()` ,
360
+ decls : []* exprpb.Decl {
361
+ decls .NewVar ("list1" , decls .NewListType (decls .Int )),
362
+ decls .NewVar ("list2" , decls .NewListType (decls .Int )),
363
+ },
364
+ wanted : CostEstimate {Min : 5 , Max : 5 },
365
+ },
366
+ {
367
+ name : "list size from ternary" ,
368
+ expr : `x > y ? list1.size() : list2.size()` ,
369
+ decls : []* exprpb.Decl {
370
+ decls .NewVar ("x" , decls .Int ),
371
+ decls .NewVar ("y" , decls .Int ),
372
+ decls .NewVar ("list1" , decls .NewListType (decls .Int )),
373
+ decls .NewVar ("list2" , decls .NewListType (decls .Int )),
374
+ },
375
+ wanted : CostEstimate {Min : 5 , Max : 5 },
376
+ },
377
+ {
378
+ name : "str endsWith equality" ,
379
+ expr : `str1.endsWith("abcdefghijklmnopqrstuvwxyz") == str2.endsWith("abcdefghijklmnopqrstuvwxyz")` ,
380
+ decls : []* exprpb.Decl {
381
+ decls .NewVar ("str1" , decls .String ),
382
+ decls .NewVar ("str2" , decls .String ),
383
+ },
384
+ wanted : CostEstimate {Min : 9 , Max : 9 },
385
+ },
386
+ {
387
+ name : "nested subexpression operators" ,
388
+ expr : `((5 != 6) == (1 == 2)) == ((3 <= 4) == (9 != 9))` ,
389
+ wanted : CostEstimate {Min : 7 , Max : 7 },
390
+ },
391
+ {
392
+ name : "str size estimate" ,
393
+ expr : `string(timestamp1) == string(timestamp2)` ,
394
+ decls : []* exprpb.Decl {
395
+ decls .NewVar ("timestamp1" , decls .Timestamp ),
396
+ decls .NewVar ("timestamp2" , decls .Timestamp ),
397
+ },
398
+ wanted : CostEstimate {Min : 5 , Max : 1844674407370955268 },
399
+ },
400
+ {
401
+ name : "timestamp equality check" ,
402
+ expr : `timestamp1 == timestamp2` ,
403
+ decls : []* exprpb.Decl {
404
+ decls .NewVar ("timestamp1" , decls .Timestamp ),
405
+ decls .NewVar ("timestamp2" , decls .Timestamp ),
406
+ },
407
+ wanted : CostEstimate {Min : 3 , Max : 3 },
408
+ },
409
+ {
410
+ name : "duration inequality check" ,
411
+ expr : `duration1 != duration2` ,
412
+ decls : []* exprpb.Decl {
413
+ decls .NewVar ("duration1" , decls .Duration ),
414
+ decls .NewVar ("duration2" , decls .Duration ),
415
+ },
416
+ wanted : CostEstimate {Min : 3 , Max : 3 },
417
+ },
357
418
}
358
419
359
420
for _ , tc := range cases {
0 commit comments