1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.tikv.common.expression;
19
20 import static com.google.common.base.Preconditions.checkNotNull;
21
22 import java.io.Serializable;
23 import org.tikv.common.expression.visitor.ProtoConverter;
24
25 public class ByItem implements Serializable {
26 private final Expression expr;
27 private final boolean desc;
28
29 private ByItem(Expression expr, boolean desc) {
30 checkNotNull(expr, "Expr cannot be null for ByItem");
31
32 this.expr = expr;
33 this.desc = desc;
34 }
35
36 public static ByItem create(Expression expr, boolean desc) {
37 return new ByItem(expr, desc);
38 }
39
40 public com.pingcap.tidb.tipb.ByItem toProto(Object context) {
41 com.pingcap.tidb.tipb.ByItem.Builder builder = com.pingcap.tidb.tipb.ByItem.newBuilder();
42 return builder.setExpr(ProtoConverter.toProto(expr, context)).setDesc(desc).build();
43 }
44
45 public Expression getExpr() {
46 return expr;
47 }
48
49 public boolean isDesc() {
50 return desc;
51 }
52
53 @Override
54 public String toString() {
55 return String.format("[%s %s]", expr.toString(), desc ? "DESC" : "ASC");
56 }
57 }