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 com.google.common.collect.ImmutableList; | |
10 | import java.util.Arrays; | |
11 | import java.util.List; | |
12 | import java.util.stream.Collectors; | |
13 | import lombok.AllArgsConstructor; | |
14 | import lombok.EqualsAndHashCode; | |
15 | import lombok.RequiredArgsConstructor; | |
16 | import lombok.ToString; | |
17 | import org.opensearch.sql.ast.AbstractNodeVisitor; | |
18 | import org.opensearch.sql.ast.expression.QualifiedName; | |
19 | import org.opensearch.sql.ast.expression.UnresolvedExpression; | |
20 | ||
21 | /** | |
22 | * Logical plan node of Relation, the interface for building the searching sources. | |
23 | */ | |
24 | @AllArgsConstructor | |
25 | @ToString | |
26 | @EqualsAndHashCode(callSuper = false) | |
27 | @RequiredArgsConstructor | |
28 | public class Relation extends UnresolvedPlan { | |
29 | private static final String COMMA = ","; | |
30 | ||
31 | private final List<UnresolvedExpression> tableName; | |
32 | ||
33 | public Relation(UnresolvedExpression tableName) { | |
34 | this(tableName, null); | |
35 | } | |
36 | ||
37 | public Relation(UnresolvedExpression tableName, String alias) { | |
38 | this.tableName = Arrays.asList(tableName); | |
39 | this.alias = alias; | |
40 | } | |
41 | ||
42 | /** | |
43 | * Optional alias name for the relation. | |
44 | */ | |
45 | private String alias; | |
46 | ||
47 | /** | |
48 | * Return table name. | |
49 | * | |
50 | * @return table name | |
51 | */ | |
52 | public String getTableName() { | |
53 |
1
1. getTableName : replaced return value with "" for org/opensearch/sql/ast/tree/Relation::getTableName → KILLED |
return getTableQualifiedName().toString(); |
54 | } | |
55 | ||
56 | /** | |
57 | * Get original table name or its alias if present in Alias. | |
58 | * | |
59 | * @return table name or its alias | |
60 | */ | |
61 | public String getTableNameOrAlias() { | |
62 |
2
1. getTableNameOrAlias : negated conditional → KILLED 2. getTableNameOrAlias : replaced return value with "" for org/opensearch/sql/ast/tree/Relation::getTableNameOrAlias → KILLED |
return (alias == null) ? getTableName() : alias; |
63 | } | |
64 | ||
65 | /** | |
66 | * Return alias. | |
67 | * | |
68 | * @return alias. | |
69 | */ | |
70 | public String getAlias() { | |
71 |
1
1. getAlias : replaced return value with "" for org/opensearch/sql/ast/tree/Relation::getAlias → SURVIVED |
return alias; |
72 | } | |
73 | ||
74 | /** | |
75 | * Get Qualified name preservs parts of the user given identifiers. | |
76 | * This can later be utilized to determine Catalog,Schema and Table Name during | |
77 | * Analyzer stage. So Passing QualifiedName directly to Analyzer Stage. | |
78 | * | |
79 | * @return TableQualifiedName. | |
80 | */ | |
81 | public QualifiedName getTableQualifiedName() { | |
82 |
1
1. getTableQualifiedName : negated conditional → KILLED |
if (tableName.size() == 1) { |
83 |
1
1. getTableQualifiedName : replaced return value with null for org/opensearch/sql/ast/tree/Relation::getTableQualifiedName → KILLED |
return (QualifiedName) tableName.get(0); |
84 | } else { | |
85 |
1
1. getTableQualifiedName : replaced return value with null for org/opensearch/sql/ast/tree/Relation::getTableQualifiedName → KILLED |
return new QualifiedName(tableName.stream() |
86 | .map(UnresolvedExpression::toString) | |
87 | .collect(Collectors.joining(COMMA))); | |
88 | } | |
89 | } | |
90 | ||
91 | @Override | |
92 | public List<UnresolvedPlan> getChild() { | |
93 |
1
1. getChild : replaced return value with Collections.emptyList for org/opensearch/sql/ast/tree/Relation::getChild → NO_COVERAGE |
return ImmutableList.of(); |
94 | } | |
95 | ||
96 | @Override | |
97 | public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) { | |
98 |
1
1. accept : replaced return value with null for org/opensearch/sql/ast/tree/Relation::accept → KILLED |
return nodeVisitor.visitRelation(this, context); |
99 | } | |
100 | ||
101 | @Override | |
102 | public UnresolvedPlan attach(UnresolvedPlan child) { | |
103 |
1
1. attach : replaced return value with null for org/opensearch/sql/ast/tree/Relation::attach → NO_COVERAGE |
return this; |
104 | } | |
105 | } | |
Mutations | ||
53 |
1.1 |
|
62 |
1.1 2.2 |
|
71 |
1.1 |
|
82 |
1.1 |
|
83 |
1.1 |
|
85 |
1.1 |
|
93 |
1.1 |
|
98 |
1.1 |
|
103 |
1.1 |