11package sqlancer .duckdb .gen ;
22
33import java .util .ArrayList ;
4+ import java .util .Arrays ;
45import java .util .List ;
56
67import sqlancer .IgnoreMeException ;
@@ -34,7 +35,7 @@ public DuckDBExpressionGenerator(DuckDBGlobalState globalState) {
3435 }
3536
3637 private enum Expression {
37- UNARY_POSTFIX , UNARY_PREFIX , BINARY_COMPARISON , BINARY_LOGICAL , BINARY_ARITHMETIC , CAST , FUNC , BETWEEN , CASE , IN
38+ UNARY_POSTFIX , UNARY_PREFIX , BINARY_COMPARISON , BINARY_LOGICAL , BINARY_ARITHMETIC , CAST , FUNC , BETWEEN , CASE , IN , COLLATE
3839 }
3940
4041 protected Node <DuckDBExpression > generateExpression (int depth ) {
@@ -48,8 +49,14 @@ protected Node<DuckDBExpression> generateExpression(int depth) {
4849 generateExpressions (depth + 1 , aggregate .getNrArgs ()), aggregate );
4950 return aggr ;
5051 }
51- Expression expr = Randomly .fromOptions (Expression .values ());
52+ List <Expression > possibleOptions = new ArrayList <>(Arrays .asList (Expression .values ()));
53+ if (!globalState .getDmbsSpecificOptions ().testCollate ) {
54+ possibleOptions .remove (Expression .COLLATE );
55+ }
56+ Expression expr = Randomly .fromList (possibleOptions );
5257 switch (expr ) {
58+ case COLLATE :
59+ return new NewUnaryPostfixOperatorNode <DuckDBExpression >(generateExpression (depth + 1 ), DuckDBCollate .getRandom ());
5360 case UNARY_PREFIX :
5461 return new NewUnaryPrefixOperatorNode <DuckDBExpression >(generateExpression (depth + 1 ),
5562 DuckDBUnaryPrefixOperator .getRandom ());
@@ -225,6 +232,25 @@ public static DuckDBUnaryPostfixOperator getRandom() {
225232 }
226233
227234 }
235+
236+ public static class DuckDBCollate implements Operator {
237+
238+ private String textRepr ;
239+
240+ private DuckDBCollate (String textRepr ) {
241+ this .textRepr = textRepr ;
242+ }
243+
244+ @ Override
245+ public String getTextRepresentation () {
246+ return "COLLATE " + textRepr ;
247+ }
248+
249+ public static DuckDBCollate getRandom () {
250+ return new DuckDBCollate (DuckDBTableGenerator .getRandomCollate ());
251+ }
252+
253+ }
228254
229255 public enum DuckDBUnaryPrefixOperator implements Operator {
230256
0 commit comments