1 | /* | |
2 | * | |
3 | * * Copyright OpenSearch Contributors | |
4 | * * SPDX-License-Identifier: Apache-2.0 | |
5 | * | |
6 | */ | |
7 | ||
8 | package org.opensearch.sql.analysis; | |
9 | ||
10 | import java.util.List; | |
11 | import java.util.Set; | |
12 | ||
13 | public class CatalogSchemaIdentifierNameResolver { | |
14 | ||
15 | public static final String DEFAULT_CATALOG_NAME = "@opensearch"; | |
16 | public static final String DEFAULT_SCHEMA_NAME = "default"; | |
17 | public static final String INFORMATION_SCHEMA_NAME = "information_schema"; | |
18 | ||
19 | private String catalogName = DEFAULT_CATALOG_NAME; | |
20 | private String schemaName = DEFAULT_SCHEMA_NAME; | |
21 | private String identifierName; | |
22 | ||
23 | private static final String DOT = "."; | |
24 | ||
25 | /** | |
26 | * Data model for capturing catalog, schema and identifier from | |
27 | * fully qualifiedName. In the current state, it is used to capture | |
28 | * CatalogSchemaTable name and CatalogSchemaFunction in case of table | |
29 | * functions. | |
30 | * | |
31 | * @param parts parts of qualifiedName. | |
32 | * @param allowedCatalogs allowedCatalogs. | |
33 | */ | |
34 | public CatalogSchemaIdentifierNameResolver(List<String> parts, Set<String> allowedCatalogs) { | |
35 | List<String> remainingParts = captureSchemaName(captureCatalogName(parts, allowedCatalogs)); | |
36 | identifierName = String.join(DOT, remainingParts); | |
37 | } | |
38 | ||
39 | public String getIdentifierName() { | |
40 |
1
1. getIdentifierName : replaced return value with "" for org/opensearch/sql/analysis/CatalogSchemaIdentifierNameResolver::getIdentifierName → KILLED |
return identifierName; |
41 | } | |
42 | ||
43 | public String getCatalogName() { | |
44 |
1
1. getCatalogName : replaced return value with "" for org/opensearch/sql/analysis/CatalogSchemaIdentifierNameResolver::getCatalogName → KILLED |
return catalogName; |
45 | } | |
46 | ||
47 | public String getSchemaName() { | |
48 |
1
1. getSchemaName : replaced return value with "" for org/opensearch/sql/analysis/CatalogSchemaIdentifierNameResolver::getSchemaName → KILLED |
return schemaName; |
49 | } | |
50 | ||
51 | ||
52 | // Capture catalog name and return remaining parts(schema name and table name) | |
53 | // from the fully qualified name. | |
54 | private List<String> captureCatalogName(List<String> parts, Set<String> allowedCatalogs) { | |
55 |
3
1. captureCatalogName : changed conditional boundary → SURVIVED 2. captureCatalogName : negated conditional → KILLED 3. captureCatalogName : negated conditional → KILLED |
if (parts.size() > 1 && allowedCatalogs.contains(parts.get(0)) |
56 |
1
1. captureCatalogName : negated conditional → KILLED |
|| DEFAULT_CATALOG_NAME.equals(parts.get(0))) { |
57 | catalogName = parts.get(0); | |
58 |
1
1. captureCatalogName : replaced return value with Collections.emptyList for org/opensearch/sql/analysis/CatalogSchemaIdentifierNameResolver::captureCatalogName → KILLED |
return parts.subList(1, parts.size()); |
59 | } else { | |
60 |
1
1. captureCatalogName : replaced return value with Collections.emptyList for org/opensearch/sql/analysis/CatalogSchemaIdentifierNameResolver::captureCatalogName → KILLED |
return parts; |
61 | } | |
62 | } | |
63 | ||
64 | // Capture schema name and return the remaining parts(table name ) | |
65 | // in the fully qualified name. | |
66 | private List<String> captureSchemaName(List<String> parts) { | |
67 |
2
1. captureSchemaName : changed conditional boundary → KILLED 2. captureSchemaName : negated conditional → KILLED |
if (parts.size() > 1 |
68 |
1
1. captureSchemaName : negated conditional → KILLED |
&& (DEFAULT_SCHEMA_NAME.equals(parts.get(0)) |
69 |
1
1. captureSchemaName : negated conditional → KILLED |
|| INFORMATION_SCHEMA_NAME.contains(parts.get(0)))) { |
70 | schemaName = parts.get(0); | |
71 |
1
1. captureSchemaName : replaced return value with Collections.emptyList for org/opensearch/sql/analysis/CatalogSchemaIdentifierNameResolver::captureSchemaName → KILLED |
return parts.subList(1, parts.size()); |
72 | } else { | |
73 |
1
1. captureSchemaName : replaced return value with Collections.emptyList for org/opensearch/sql/analysis/CatalogSchemaIdentifierNameResolver::captureSchemaName → KILLED |
return parts; |
74 | } | |
75 | } | |
76 | ||
77 | ||
78 | } | |
Mutations | ||
40 |
1.1 |
|
44 |
1.1 |
|
48 |
1.1 |
|
55 |
1.1 2.2 3.3 |
|
56 |
1.1 |
|
58 |
1.1 |
|
60 |
1.1 |
|
67 |
1.1 2.2 |
|
68 |
1.1 |
|
69 |
1.1 |
|
71 |
1.1 |
|
73 |
1.1 |