@@ -503,27 +503,18 @@ func TestOtherFunc2Pb(t *testing.T) {
503
503
}
504
504
}
505
505
506
- func TestExprPushDownToFlash (t * testing.T ) {
506
+ func TestJsonPushDownToFlash (t * testing.T ) {
507
507
sc := new (stmtctx.StatementContext )
508
508
client := new (mock.Client )
509
509
510
510
exprs := make ([]Expression , 0 )
511
511
512
512
jsonColumn := genColumn (mysql .TypeJSON , 1 )
513
513
intColumn := genColumn (mysql .TypeLonglong , 2 )
514
- realColumn := genColumn (mysql .TypeDouble , 3 )
515
- decimalColumn := genColumn (mysql .TypeNewDecimal , 4 )
516
- decimalColumn .RetType .SetDecimal (mysql .MaxDecimalScale )
517
- decimalColumn .RetType .SetFlen (mysql .MaxDecimalWidth )
518
514
stringColumn := genColumn (mysql .TypeString , 5 )
519
- datetimeColumn := genColumn (mysql .TypeDatetime , 6 )
520
- binaryStringColumn := genColumn (mysql .TypeString , 7 )
521
- binaryStringColumn .RetType .SetCollate (charset .CollationBin )
522
- int32Column := genColumn (mysql .TypeLong , 8 )
523
- float32Column := genColumn (mysql .TypeFloat , 9 )
524
- enumColumn := genColumn (mysql .TypeEnum , 10 )
525
- durationColumn := genColumn (mysql .TypeDuration , 11 )
526
515
516
+ // functions that can be pushdown to tiflash
517
+ // json_length
527
518
function , err := NewFunction (mock .NewContext (), ast .JSONLength , types .NewFieldType (mysql .TypeLonglong ), jsonColumn )
528
519
require .NoError (t , err )
529
520
exprs = append (exprs , function )
@@ -540,8 +531,104 @@ func TestExprPushDownToFlash(t *testing.T) {
540
531
require .NoError (t , err )
541
532
exprs = append (exprs , function )
542
533
534
+ // CastJsonAsString
535
+ function , err = NewFunction (mock .NewContext (), ast .Cast , types .NewFieldType (mysql .TypeString ), jsonColumn )
536
+ require .NoError (t , err )
537
+ exprs = append (exprs , function )
538
+
539
+ // IfNullJson
540
+ function , err = NewFunction (mock .NewContext (), ast .Ifnull , types .NewFieldType (mysql .TypeJSON ), jsonColumn , jsonColumn )
541
+ require .NoError (t , err )
542
+ exprs = append (exprs , function )
543
+
544
+ // JsonIsNull is not implement, for function json_col is null, it will be converted to cast(json as string) is null
545
+ function , err = NewFunction (mock .NewContext (), ast .IsNull , types .NewFieldType (mysql .TypeLonglong ), jsonColumn )
546
+ require .NoError (t , err )
547
+ exprs = append (exprs , function )
548
+
549
+ // CaseWhenJson
550
+ function , err = NewFunction (mock .NewContext (), ast .Case , types .NewFieldType (mysql .TypeJSON ), intColumn , jsonColumn , intColumn , jsonColumn , jsonColumn )
551
+ require .NoError (t , err )
552
+ exprs = append (exprs , function )
553
+
554
+ // CoalesceJson
555
+ function , err = NewFunction (mock .NewContext (), ast .Coalesce , types .NewFieldType (mysql .TypeJSON ), jsonColumn , jsonColumn , jsonColumn )
556
+ require .NoError (t , err )
557
+ exprs = append (exprs , function )
558
+
559
+ pushed , remained := PushDownExprs (sc , exprs , client , kv .TiFlash )
560
+ require .Len (t , pushed , len (exprs ))
561
+ require .Len (t , remained , 0 )
562
+
563
+ // functions that can not be pushed to tiflash
564
+ exprs = exprs [:0 ]
565
+ // LTJson
566
+ function , err = NewFunction (mock .NewContext (), ast .LT , types .NewFieldType (mysql .TypeLonglong ), jsonColumn , jsonColumn )
567
+ require .NoError (t , err )
568
+ exprs = append (exprs , function )
569
+
570
+ // LEJson
571
+ function , err = NewFunction (mock .NewContext (), ast .LE , types .NewFieldType (mysql .TypeLonglong ), jsonColumn , jsonColumn )
572
+ require .NoError (t , err )
573
+ exprs = append (exprs , function )
574
+
575
+ // GTJson
576
+ function , err = NewFunction (mock .NewContext (), ast .GT , types .NewFieldType (mysql .TypeLonglong ), jsonColumn , jsonColumn )
577
+ require .NoError (t , err )
578
+ exprs = append (exprs , function )
579
+
580
+ // GEJson
581
+ function , err = NewFunction (mock .NewContext (), ast .GE , types .NewFieldType (mysql .TypeLonglong ), jsonColumn , jsonColumn )
582
+ require .NoError (t , err )
583
+ exprs = append (exprs , function )
584
+
585
+ // EQJson
586
+ function , err = NewFunction (mock .NewContext (), ast .EQ , types .NewFieldType (mysql .TypeLonglong ), jsonColumn , jsonColumn )
587
+ require .NoError (t , err )
588
+ exprs = append (exprs , function )
589
+
590
+ // NEJson
591
+ function , err = NewFunction (mock .NewContext (), ast .NE , types .NewFieldType (mysql .TypeLonglong ), jsonColumn , jsonColumn )
592
+ require .NoError (t , err )
593
+ exprs = append (exprs , function )
594
+
595
+ // InJson
596
+ function , err = NewFunction (mock .NewContext (), ast .In , types .NewFieldType (mysql .TypeLonglong ), jsonColumn , jsonColumn , jsonColumn )
597
+ require .NoError (t , err )
598
+ exprs = append (exprs , function )
599
+
600
+ // json_depth
601
+ function , err = NewFunction (mock .NewContext (), ast .JSONDepth , types .NewFieldType (mysql .TypeLonglong ), jsonColumn )
602
+ require .NoError (t , err )
603
+ exprs = append (exprs , function )
604
+
605
+ pushed , remained = PushDownExprs (sc , exprs , client , kv .TiFlash )
606
+ require .Len (t , pushed , 0 )
607
+ require .Len (t , remained , len (exprs ))
608
+ }
609
+
610
+ func TestExprPushDownToFlash (t * testing.T ) {
611
+ sc := new (stmtctx.StatementContext )
612
+ client := new (mock.Client )
613
+
614
+ exprs := make ([]Expression , 0 )
615
+
616
+ intColumn := genColumn (mysql .TypeLonglong , 2 )
617
+ realColumn := genColumn (mysql .TypeDouble , 3 )
618
+ decimalColumn := genColumn (mysql .TypeNewDecimal , 4 )
619
+ decimalColumn .RetType .SetDecimal (mysql .MaxDecimalScale )
620
+ decimalColumn .RetType .SetFlen (mysql .MaxDecimalWidth )
621
+ stringColumn := genColumn (mysql .TypeString , 5 )
622
+ datetimeColumn := genColumn (mysql .TypeDatetime , 6 )
623
+ binaryStringColumn := genColumn (mysql .TypeString , 7 )
624
+ binaryStringColumn .RetType .SetCollate (charset .CollationBin )
625
+ int32Column := genColumn (mysql .TypeLong , 8 )
626
+ float32Column := genColumn (mysql .TypeFloat , 9 )
627
+ enumColumn := genColumn (mysql .TypeEnum , 10 )
628
+ durationColumn := genColumn (mysql .TypeDuration , 11 )
629
+
543
630
// lpad
544
- function , err = NewFunction (mock .NewContext (), ast .Lpad , types .NewFieldType (mysql .TypeString ), stringColumn , int32Column , stringColumn )
631
+ function , err : = NewFunction (mock .NewContext (), ast .Lpad , types .NewFieldType (mysql .TypeString ), stringColumn , int32Column , stringColumn )
545
632
require .NoError (t , err )
546
633
exprs = append (exprs , function )
547
634
@@ -651,11 +738,6 @@ func TestExprPushDownToFlash(t *testing.T) {
651
738
require .NoError (t , err )
652
739
exprs = append (exprs , function )
653
740
654
- // CastJsonAsString
655
- function , err = NewFunction (mock .NewContext (), ast .Cast , types .NewFieldType (mysql .TypeString ), jsonColumn )
656
- require .NoError (t , err )
657
- exprs = append (exprs , function )
658
-
659
741
// CastIntAsTime
660
742
function , err = NewFunction (mock .NewContext (), ast .Cast , types .NewFieldType (mysql .TypeDatetime ), intColumn )
661
743
require .NoError (t , err )
@@ -990,10 +1072,6 @@ func TestExprPushDownToFlash(t *testing.T) {
990
1072
require .NoError (t , err )
991
1073
exprs = append (exprs , function )
992
1074
993
- function , err = NewFunction (mock .NewContext (), ast .JSONDepth , types .NewFieldType (mysql .TypeLonglong ), jsonColumn )
994
- require .NoError (t , err )
995
- exprs = append (exprs , function )
996
-
997
1075
// ExtractDatetimeFromString: can not be pushed
998
1076
extractDatetimeFromStringUnitCol := new (Constant )
999
1077
extractDatetimeFromStringUnitCol .Value = types .NewStringDatum ("day_microsecond" )
0 commit comments