1 | /* | |
2 | * Copyright OpenSearch Contributors | |
3 | * SPDX-License-Identifier: Apache-2.0 | |
4 | */ | |
5 | ||
6 | ||
7 | package org.opensearch.sql.ast.tree; | |
8 | ||
9 | import static org.opensearch.sql.ast.tree.Sort.NullOrder.NULL_FIRST; | |
10 | import static org.opensearch.sql.ast.tree.Sort.NullOrder.NULL_LAST; | |
11 | import static org.opensearch.sql.ast.tree.Sort.SortOrder.ASC; | |
12 | import static org.opensearch.sql.ast.tree.Sort.SortOrder.DESC; | |
13 | ||
14 | import com.google.common.collect.ImmutableList; | |
15 | import java.util.List; | |
16 | import lombok.AllArgsConstructor; | |
17 | import lombok.Data; | |
18 | import lombok.EqualsAndHashCode; | |
19 | import lombok.Getter; | |
20 | import lombok.RequiredArgsConstructor; | |
21 | import lombok.ToString; | |
22 | import org.opensearch.sql.ast.AbstractNodeVisitor; | |
23 | import org.opensearch.sql.ast.expression.Field; | |
24 | ||
25 | /** | |
26 | * AST node for Sort {@link Sort#sortList} represent a list of sort expression and sort options. | |
27 | */ | |
28 | @ToString | |
29 | @EqualsAndHashCode(callSuper = false) | |
30 | @Getter | |
31 | @RequiredArgsConstructor | |
32 | @AllArgsConstructor | |
33 | public class Sort extends UnresolvedPlan { | |
34 | private UnresolvedPlan child; | |
35 | private final List<Field> sortList; | |
36 | ||
37 | @Override | |
38 | public Sort attach(UnresolvedPlan child) { | |
39 | this.child = child; | |
40 |
1
1. attach : replaced return value with null for org/opensearch/sql/ast/tree/Sort::attach → NO_COVERAGE |
return this; |
41 | } | |
42 | ||
43 | @Override | |
44 | public List<UnresolvedPlan> getChild() { | |
45 |
1
1. getChild : replaced return value with Collections.emptyList for org/opensearch/sql/ast/tree/Sort::getChild → KILLED |
return ImmutableList.of(child); |
46 | } | |
47 | ||
48 | @Override | |
49 | public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) { | |
50 |
1
1. accept : replaced return value with null for org/opensearch/sql/ast/tree/Sort::accept → KILLED |
return nodeVisitor.visitSort(this, context); |
51 | } | |
52 | ||
53 | /** | |
54 | * Sort Options. | |
55 | */ | |
56 | @Data | |
57 | public static class SortOption { | |
58 | ||
59 | /** | |
60 | * Default ascending sort option, null first. | |
61 | */ | |
62 | public static SortOption DEFAULT_ASC = new SortOption(ASC, NULL_FIRST); | |
63 | /** | |
64 | * Default descending sort option, null last. | |
65 | */ | |
66 | public static SortOption DEFAULT_DESC = new SortOption(DESC, NULL_LAST); | |
67 | ||
68 | private final SortOrder sortOrder; | |
69 | private final NullOrder nullOrder; | |
70 | } | |
71 | ||
72 | public enum SortOrder { | |
73 | ASC, | |
74 | DESC | |
75 | } | |
76 | ||
77 | public enum NullOrder { | |
78 | NULL_FIRST, | |
79 | NULL_LAST | |
80 | } | |
81 | } | |
Mutations | ||
40 |
1.1 |
|
45 |
1.1 |
|
50 |
1.1 |