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 static java.util.Objects.requireNonNull; | |
10 | import static java.util.stream.Collectors.toList; | |
11 | ||
12 | import com.google.common.collect.ImmutableList; | |
13 | import java.util.ArrayList; | |
14 | import java.util.Arrays; | |
15 | import java.util.Collections; | |
16 | import java.util.List; | |
17 | import java.util.Optional; | |
18 | import java.util.stream.StreamSupport; | |
19 | import lombok.EqualsAndHashCode; | |
20 | import lombok.Getter; | |
21 | import org.opensearch.sql.ast.AbstractNodeVisitor; | |
22 | ||
23 | @Getter | |
24 | @EqualsAndHashCode(callSuper = false) | |
25 | public class QualifiedName extends UnresolvedExpression { | |
26 | private final List<String> parts; | |
27 | ||
28 | public QualifiedName(String name) { | |
29 | this.parts = Collections.singletonList(name); | |
30 | } | |
31 | ||
32 | /** | |
33 | * QualifiedName Constructor. | |
34 | */ | |
35 | public QualifiedName(Iterable<String> parts) { | |
36 | List<String> partsList = StreamSupport.stream(parts.spliterator(), false).collect(toList()); | |
37 |
1
1. <init> : negated conditional → KILLED |
if (partsList.isEmpty()) { |
38 | throw new IllegalArgumentException("parts is empty"); | |
39 | } | |
40 | this.parts = partsList; | |
41 | } | |
42 | ||
43 | /** | |
44 | * Construct {@link QualifiedName} from list of string. | |
45 | */ | |
46 | public static QualifiedName of(String first, String... rest) { | |
47 | requireNonNull(first); | |
48 | ArrayList<String> parts = new ArrayList<>(); | |
49 | parts.add(first); | |
50 | parts.addAll(Arrays.asList(rest)); | |
51 |
1
1. of : replaced return value with null for org/opensearch/sql/ast/expression/QualifiedName::of → KILLED |
return new QualifiedName(parts); |
52 | } | |
53 | ||
54 | public static QualifiedName of(Iterable<String> parts) { | |
55 |
1
1. of : replaced return value with null for org/opensearch/sql/ast/expression/QualifiedName::of → KILLED |
return new QualifiedName(parts); |
56 | } | |
57 | ||
58 | /** | |
59 | * Get Prefix of {@link QualifiedName}. | |
60 | */ | |
61 | public Optional<QualifiedName> getPrefix() { | |
62 |
1
1. getPrefix : negated conditional → KILLED |
if (parts.size() == 1) { |
63 | return Optional.empty(); | |
64 | } | |
65 |
2
1. getPrefix : Replaced integer subtraction with addition → KILLED 2. getPrefix : replaced return value with Optional.empty for org/opensearch/sql/ast/expression/QualifiedName::getPrefix → KILLED |
return Optional.of(QualifiedName.of(parts.subList(0, parts.size() - 1))); |
66 | } | |
67 | ||
68 | public String getSuffix() { | |
69 |
2
1. getSuffix : Replaced integer subtraction with addition → KILLED 2. getSuffix : replaced return value with "" for org/opensearch/sql/ast/expression/QualifiedName::getSuffix → KILLED |
return parts.get(parts.size() - 1); |
70 | } | |
71 | ||
72 | /** | |
73 | * Get first part of the qualified name. | |
74 | * @return first part | |
75 | */ | |
76 | public Optional<String> first() { | |
77 |
1
1. first : negated conditional → KILLED |
if (parts.size() == 1) { |
78 | return Optional.empty(); | |
79 | } | |
80 |
1
1. first : replaced return value with Optional.empty for org/opensearch/sql/ast/expression/QualifiedName::first → KILLED |
return Optional.of(parts.get(0)); |
81 | } | |
82 | ||
83 | /** | |
84 | * Get rest parts of the qualified name. Assume that there must be remaining parts | |
85 | * so caller is responsible for the check (first() or size() must be called first). | |
86 | * For example: | |
87 | * {@code | |
88 | * QualifiedName name = ... | |
89 | * Optional<String> first = name.first(); | |
90 | * if (first.isPresent()) { | |
91 | * name.rest() ... | |
92 | * } | |
93 | * } | |
94 | * @return rest part(s) | |
95 | */ | |
96 | public QualifiedName rest() { | |
97 |
1
1. rest : replaced return value with null for org/opensearch/sql/ast/expression/QualifiedName::rest → KILLED |
return QualifiedName.of(parts.subList(1, parts.size())); |
98 | } | |
99 | ||
100 | public String toString() { | |
101 |
1
1. toString : replaced return value with "" for org/opensearch/sql/ast/expression/QualifiedName::toString → KILLED |
return String.join(".", this.parts); |
102 | } | |
103 | ||
104 | @Override | |
105 | public List<UnresolvedExpression> getChild() { | |
106 |
1
1. getChild : replaced return value with Collections.emptyList for org/opensearch/sql/ast/expression/QualifiedName::getChild → SURVIVED |
return ImmutableList.of(); |
107 | } | |
108 | ||
109 | @Override | |
110 | public <R, C> R accept(AbstractNodeVisitor<R, C> nodeVisitor, C context) { | |
111 |
1
1. accept : replaced return value with null for org/opensearch/sql/ast/expression/QualifiedName::accept → KILLED |
return nodeVisitor.visitQualifiedName(this, context); |
112 | } | |
113 | } | |
Mutations | ||
37 |
1.1 |
|
51 |
1.1 |
|
55 |
1.1 |
|
62 |
1.1 |
|
65 |
1.1 2.2 |
|
69 |
1.1 2.2 |
|
77 |
1.1 |
|
80 |
1.1 |
|
97 |
1.1 |
|
101 |
1.1 |
|
106 |
1.1 |
|
111 |
1.1 |