@@ -19,8 +19,10 @@ import (
19
19
"time"
20
20
21
21
"github.com/pingcap/tidb/pkg/errctx"
22
+ "github.com/pingcap/tidb/pkg/expression/context"
22
23
"github.com/pingcap/tidb/pkg/parser/ast"
23
24
"github.com/pingcap/tidb/pkg/parser/charset"
25
+ "github.com/pingcap/tidb/pkg/parser/model"
24
26
"github.com/pingcap/tidb/pkg/parser/mysql"
25
27
"github.com/pingcap/tidb/pkg/types"
26
28
"github.com/pingcap/tidb/pkg/util/chunk"
@@ -606,3 +608,53 @@ func TestMod(t *testing.T) {
606
608
require .NoError (t , err )
607
609
require .Equal (t , types .NewDatum (1.5 ), r )
608
610
}
611
+
612
+ func TestOptionalProp (t * testing.T ) {
613
+ ctx := createContext (t )
614
+
615
+ fc := funcs [ast .Plus ]
616
+ arg1fc := funcs [ast .CurrentUser ]
617
+ arg1f , err := arg1fc .getFunction (ctx , nil )
618
+ require .NoError (t , err )
619
+ arg1 := & ScalarFunction {
620
+ FuncName : model .NewCIStr (ast .CurrentUser ),
621
+ Function : arg1f ,
622
+ RetType : arg1f .getRetTp (),
623
+ }
624
+ arg2fc := funcs [ast .TiDBIsDDLOwner ]
625
+ arg2f , err := arg2fc .getFunction (ctx , nil )
626
+ require .NoError (t , err )
627
+ arg2 := & ScalarFunction {
628
+ FuncName : model .NewCIStr (ast .TiDBIsDDLOwner ),
629
+ Function : arg2f ,
630
+ RetType : arg2f .getRetTp (),
631
+ }
632
+
633
+ f , err := fc .getFunction (ctx , []Expression {arg1 , arg2 })
634
+ require .NoError (t , err )
635
+ fe := & ScalarFunction {
636
+ FuncName : model .NewCIStr (ast .Plus ),
637
+ Function : f ,
638
+ RetType : f .getRetTp (),
639
+ }
640
+
641
+ fc2 := funcs [ast .GetLock ]
642
+ f2 , err := fc2 .getFunction (ctx , datumsToConstants (types .MakeDatums ("tidb_distsql_scan_concurrency" , 10 )))
643
+ require .NoError (t , err )
644
+ fe2 := & ScalarFunction {
645
+ FuncName : model .NewCIStr (ast .GetLock ),
646
+ Function : f2 ,
647
+ RetType : f2 .getRetTp (),
648
+ }
649
+
650
+ require .Equal (t , context .OptionalEvalPropKeySet (0 ), f .RequiredOptionalEvalProps ())
651
+ require .Equal (t , context .OptPropCurrentUser .AsPropKeySet ()| context .OptPropDDLOwnerInfo .AsPropKeySet (),
652
+ getOptionalEvalPropsForExpr (fe ))
653
+ require .Equal (t , context .OptPropCurrentUser .AsPropKeySet ()| context .OptPropDDLOwnerInfo .AsPropKeySet ()|
654
+ context .OptPropAdvisoryLock .AsPropKeySet (),
655
+ getOptionalEvalPropsForExpr (fe )| getOptionalEvalPropsForExpr (fe2 ))
656
+
657
+ evalSuit := NewEvaluatorSuite ([]Expression {fe , fe2 }, false )
658
+ require .Equal (t , context .OptPropCurrentUser .AsPropKeySet ()| context .OptPropDDLOwnerInfo .AsPropKeySet ()|
659
+ context .OptPropAdvisoryLock .AsPropKeySet (), evalSuit .RequiredOptionalEvalProps ())
660
+ }
0 commit comments