1 | /* | |
2 | * Copyright OpenSearch Contributors | |
3 | * SPDX-License-Identifier: Apache-2.0 | |
4 | */ | |
5 | ||
6 | ||
7 | package org.opensearch.sql.ast.expression; | |
8 | ||
9 | import com.google.common.collect.ImmutableList; | |
10 | import java.util.List; | |
11 | import lombok.AllArgsConstructor; | |
12 | import lombok.EqualsAndHashCode; | |
13 | import lombok.Getter; | |
14 | import lombok.ToString; | |
15 | import org.opensearch.sql.ast.AbstractNodeVisitor; | |
16 | import org.opensearch.sql.ast.Node; | |
17 | ||
18 | /** | |
19 | * AST node that represents CASE clause similar as Switch statement in programming language. | |
20 | */ | |
21 | @AllArgsConstructor | |
22 | @EqualsAndHashCode(callSuper = false) | |
23 | @Getter | |
24 | @ToString | |
25 | public class Case extends UnresolvedExpression { | |
26 | ||
27 | /** | |
28 | * Value to be compared by WHEN statements. Null in the case of CASE WHEN conditions. | |
29 | */ | |
30 | private final UnresolvedExpression caseValue; | |
31 | ||
32 | /** | |
33 | * Expression list that represents WHEN statements. Each is a mapping from condition | |
34 | * to its result. | |
35 | */ | |
36 | private final List<When> whenClauses; | |
37 | ||
38 | /** | |
39 | * Expression that represents ELSE statement result. | |
40 | */ | |
41 | private final UnresolvedExpression elseClause; | |
42 | ||
43 | @Override | |
44 | public List<? extends Node> getChild() { | |
45 | ImmutableList.Builder<Node> children = ImmutableList.builder(); | |
46 |
1
1. getChild : negated conditional → NO_COVERAGE |
if (caseValue != null) { |
47 | children.add(caseValue); | |
48 | } | |
49 | children.addAll(whenClauses); | |
50 | ||
51 |
1
1. getChild : negated conditional → NO_COVERAGE |
if (elseClause != null) { |
52 | children.add(elseClause); | |
53 | } | |
54 |
1
1. getChild : replaced return value with Collections.emptyList for org/opensearch/sql/ast/expression/Case::getChild → NO_COVERAGE |
return children.build(); |
55 | } | |
56 | ||
57 | @Override | |
58 | public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) { | |
59 |
1
1. accept : replaced return value with null for org/opensearch/sql/ast/expression/Case::accept → KILLED |
return nodeVisitor.visitCase(this, context); |
60 | } | |
61 | ||
62 | } | |
Mutations | ||
46 |
1.1 |
|
51 |
1.1 |
|
54 |
1.1 |
|
59 |
1.1 |