11package sqlancer .tidb ;
22
33import java .util .ArrayList ;
4+ import java .util .Arrays ;
45import java .util .List ;
56
67import sqlancer .IgnoreMeException ;
1718import sqlancer .tidb .ast .TiDBBinaryComparisonOperation .TiDBComparisonOperator ;
1819import sqlancer .tidb .ast .TiDBBinaryLogicalOperation ;
1920import sqlancer .tidb .ast .TiDBBinaryLogicalOperation .TiDBBinaryLogicalOperator ;
21+ import sqlancer .tidb .ast .TiDBCase ;
2022import sqlancer .tidb .ast .TiDBCastOperation ;
2123import sqlancer .tidb .ast .TiDBCollate ;
2224import sqlancer .tidb .ast .TiDBColumnReference ;
@@ -51,7 +53,9 @@ private static enum Gen {
5153 FUNCTION ,
5254 BINARY_LOGICAL ,
5355 BINARY_BIT ,
54- CAST
56+ CAST ,
57+ DEFAULT ,
58+ CASE
5559// BINARY_ARITHMETIC
5660 }
5761
@@ -66,6 +70,15 @@ protected TiDBExpression generateExpression(int depth) {
6670 return new TiDBAggregate (args , func );
6771 }
6872 switch (Randomly .fromOptions (Gen .values ())) {
73+ case DEFAULT :
74+ if (true ) {
75+ // https://github.com/tidb-challenge-program/bug-hunting-issue/issues/15
76+ throw new IgnoreMeException ();
77+ }
78+ if (globalState .getSchema ().getDatabaseTables ().isEmpty ()) {
79+ throw new IgnoreMeException ();
80+ }
81+ return new TiDBFunctionCall (TiDBFunction .DEFAULT , Arrays .asList (generateColumn ()));
6982 case UNARY_POSTFIX :
7083 return new TiDBUnaryPostfixOperation (generateExpression (depth + 1 ), TiDBUnaryPostfixOperator .getRandom ());
7184 case UNARY_PREFIX :
@@ -98,6 +111,11 @@ protected TiDBExpression generateExpression(int depth) {
98111// return new TiDBBinaryArithmeticOperation(generateExpression(depth + 1), generateExpression(depth + 1), TiDBBinaryArithmeticOperator.getRandom());
99112 case CAST :
100113 return new TiDBCastOperation (generateExpression (depth + 1 ), Randomly .fromOptions ("BINARY" , "CHAR" , /*"DATE", "DATETIME", "TIME", https://github.com/tidb-challenge-program/bug-hunting-issue/issues/13 */ "DECIMAL" , "SIGNED" , "UNSIGNED" ));
114+ case CASE :
115+ int nr = Randomly .fromOptions (1 , 2 );
116+ return new TiDBCase (generateExpression (depth + 1 ),
117+ generateExpressions (depth + 1 , nr ), generateExpressions (depth + 1 , nr ),
118+ generateExpression (depth + 1 ));
101119 default :
102120 throw new AssertionError ();
103121 }
0 commit comments