forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostgresOrderByTerm.java
More file actions
62 lines (49 loc) · 1.6 KB
/
Copy pathPostgresOrderByTerm.java
File metadata and controls
62 lines (49 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package sqlancer.postgres.ast;
import sqlancer.Randomly;
import sqlancer.postgres.PostgresSchema.PostgresDataType;
public class PostgresOrderByTerm implements PostgresExpression {
private final PostgresExpression expr;
private final PostgresOrder order;
public enum PostgresOrder {
ASC, DESC;
public static PostgresOrder getRandomOrder() {
return Randomly.fromOptions(PostgresOrder.values());
}
}
public PostgresOrderByTerm(PostgresExpression expr, PostgresOrder order) {
if (expr == null) {
throw new IllegalArgumentException("Expression cannot be null");
}
this.expr = expr;
this.order = order;
}
// Constructor for window functions, might be removed in the future to have only one constructor
public PostgresOrderByTerm(PostgresExpression expr, boolean ascending) {
if (expr == null) {
throw new IllegalArgumentException("Expression cannot be null");
}
this.expr = expr;
this.order = ascending ? PostgresOrder.ASC : PostgresOrder.DESC;
}
public PostgresExpression getExpr() {
return expr;
}
public PostgresOrder getOrder() {
return order;
}
public boolean isAscending() {
return order == PostgresOrder.ASC;
}
@Override
public PostgresConstant getExpectedValue() {
throw new AssertionError(this);
}
@Override
public PostgresDataType getExpressionType() {
return null;
}
@Override
public String toString() {
return String.format("%s %s", expr, order);
}
}