SystemIndexUtils.java

1
/*
2
 * Copyright OpenSearch Contributors
3
 * SPDX-License-Identifier: Apache-2.0
4
 */
5
6
7
package org.opensearch.sql.utils;
8
9
import lombok.Getter;
10
import lombok.RequiredArgsConstructor;
11
import lombok.experimental.UtilityClass;
12
13
/**
14
 * System Index Utils.
15
 * Todo. Find the better name for this class.
16
 */
17
@UtilityClass
18
public class SystemIndexUtils {
19
20
  public static final String TABLE_NAME_FOR_TABLES_INFO = "tables";
21
  /**
22
   * The suffix of all the system tables.
23
   */
24
  private static final String SYS_TABLES_SUFFIX = "ODFE_SYS_TABLE";
25
26
  /**
27
   * The suffix of all the meta tables.
28
   */
29
  private static final String SYS_META_SUFFIX = "META_" + SYS_TABLES_SUFFIX;
30
31
  /**
32
   * The suffix of all the table mappings.
33
   */
34
  private static final String SYS_MAPPINGS_SUFFIX =  "MAPPINGS_" + SYS_TABLES_SUFFIX;
35
36
  /**
37
   * The ALL.META_ODFE_SYS_TABLE contain all the table info.
38
   */
39
  public static final String TABLE_INFO = "ALL." + SYS_META_SUFFIX;
40
41
  public static final String CATALOGS_TABLE_NAME = ".CATALOGS";
42
43
44
  public static Boolean isSystemIndex(String indexName) {
45 2 1. isSystemIndex : replaced Boolean return with False for org/opensearch/sql/utils/SystemIndexUtils::isSystemIndex → KILLED
2. isSystemIndex : replaced Boolean return with True for org/opensearch/sql/utils/SystemIndexUtils::isSystemIndex → KILLED
    return indexName.endsWith(SYS_TABLES_SUFFIX);
46
  }
47
48
  /**
49
   * Compose system mapping table.
50
   *
51
   * @return system mapping table.
52
   */
53
  public static String mappingTable(String indexName) {
54 1 1. mappingTable : replaced return value with "" for org/opensearch/sql/utils/SystemIndexUtils::mappingTable → KILLED
    return String.join(".", indexName, SYS_MAPPINGS_SUFFIX);
55
  }
56
57
  /**
58
   * Build the {@link SystemTable}.
59
   *
60
   * @return {@link SystemTable}
61
   */
62
  public static SystemTable systemTable(String indexName) {
63
    final int lastDot = indexName.lastIndexOf(".");
64 1 1. systemTable : Replaced integer addition with subtraction → KILLED
    String suffix = indexName.substring(lastDot + 1);
65
    String tableName = indexName.substring(0, lastDot)
66
        .replace("%", "*");
67
68 1 1. systemTable : negated conditional → KILLED
    if (suffix.equalsIgnoreCase(SYS_META_SUFFIX)) {
69 1 1. systemTable : replaced return value with null for org/opensearch/sql/utils/SystemIndexUtils::systemTable → KILLED
      return new SystemInfoTable(tableName);
70 1 1. systemTable : negated conditional → KILLED
    } else if (suffix.equalsIgnoreCase(SYS_MAPPINGS_SUFFIX)) {
71 1 1. systemTable : replaced return value with null for org/opensearch/sql/utils/SystemIndexUtils::systemTable → KILLED
      return new MetaInfoTable(tableName);
72
    } else {
73
      throw new IllegalStateException("Invalid system index name: " + indexName);
74
    }
75
  }
76
77
  /**
78
   * System Table.
79
   */
80
  public interface SystemTable {
81
82
    String getTableName();
83
84
    default boolean isSystemInfoTable() {
85 1 1. isSystemInfoTable : replaced boolean return with true for org/opensearch/sql/utils/SystemIndexUtils$SystemTable::isSystemInfoTable → KILLED
      return false;
86
    }
87
88
    default boolean isMetaInfoTable() {
89 1 1. isMetaInfoTable : replaced boolean return with true for org/opensearch/sql/utils/SystemIndexUtils$SystemTable::isMetaInfoTable → KILLED
      return false;
90
    }
91
  }
92
93
  /**
94
   * System Info Table.
95
   */
96
  @Getter
97
  @RequiredArgsConstructor
98
  public static class SystemInfoTable implements SystemTable {
99
100
    private final String tableName;
101
102
    public boolean isSystemInfoTable() {
103 1 1. isSystemInfoTable : replaced boolean return with false for org/opensearch/sql/utils/SystemIndexUtils$SystemInfoTable::isSystemInfoTable → KILLED
      return true;
104
    }
105
  }
106
107
  /**
108
   * System Table.
109
   */
110
  @Getter
111
  @RequiredArgsConstructor
112
  public static class MetaInfoTable implements SystemTable {
113
114
    private final String tableName;
115
116
    public boolean isMetaInfoTable() {
117 1 1. isMetaInfoTable : replaced boolean return with false for org/opensearch/sql/utils/SystemIndexUtils$MetaInfoTable::isMetaInfoTable → KILLED
      return true;
118
    }
119
  }
120
}

Mutations

45

1.1
Location : isSystemIndex
Killed by : org.opensearch.sql.utils.SystemIndexUtilsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.utils.SystemIndexUtilsTest]/[method:test_system_index()]
replaced Boolean return with False for org/opensearch/sql/utils/SystemIndexUtils::isSystemIndex → KILLED

2.2
Location : isSystemIndex
Killed by : org.opensearch.sql.utils.SystemIndexUtilsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.utils.SystemIndexUtilsTest]/[method:test_system_index()]
replaced Boolean return with True for org/opensearch/sql/utils/SystemIndexUtils::isSystemIndex → KILLED

54

1.1
Location : mappingTable
Killed by : org.opensearch.sql.utils.SystemIndexUtilsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.utils.SystemIndexUtilsTest]/[method:test_compose_mapping_table()]
replaced return value with "" for org/opensearch/sql/utils/SystemIndexUtils::mappingTable → KILLED

64

1.1
Location : systemTable
Killed by : org.opensearch.sql.utils.SystemIndexUtilsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.utils.SystemIndexUtilsTest]/[method:test_mapping_info_table_with_special_index_name()]
Replaced integer addition with subtraction → KILLED

68

1.1
Location : systemTable
Killed by : org.opensearch.sql.utils.SystemIndexUtilsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.utils.SystemIndexUtilsTest]/[method:throw_exception_for_invalid_index()]
negated conditional → KILLED

69

1.1
Location : systemTable
Killed by : org.opensearch.sql.utils.SystemIndexUtilsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.utils.SystemIndexUtilsTest]/[method:test_system_info_table()]
replaced return value with null for org/opensearch/sql/utils/SystemIndexUtils::systemTable → KILLED

70

1.1
Location : systemTable
Killed by : org.opensearch.sql.utils.SystemIndexUtilsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.utils.SystemIndexUtilsTest]/[method:throw_exception_for_invalid_index()]
negated conditional → KILLED

71

1.1
Location : systemTable
Killed by : org.opensearch.sql.utils.SystemIndexUtilsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.utils.SystemIndexUtilsTest]/[method:test_mapping_info_table_with_special_index_name()]
replaced return value with null for org/opensearch/sql/utils/SystemIndexUtils::systemTable → KILLED

85

1.1
Location : isSystemInfoTable
Killed by : org.opensearch.sql.utils.SystemIndexUtilsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.utils.SystemIndexUtilsTest]/[method:test_mapping_info_table_with_special_index_name()]
replaced boolean return with true for org/opensearch/sql/utils/SystemIndexUtils$SystemTable::isSystemInfoTable → KILLED

89

1.1
Location : isMetaInfoTable
Killed by : org.opensearch.sql.utils.SystemIndexUtilsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.utils.SystemIndexUtilsTest]/[method:test_system_info_table()]
replaced boolean return with true for org/opensearch/sql/utils/SystemIndexUtils$SystemTable::isMetaInfoTable → KILLED

103

1.1
Location : isSystemInfoTable
Killed by : org.opensearch.sql.utils.SystemIndexUtilsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.utils.SystemIndexUtilsTest]/[method:test_system_info_table()]
replaced boolean return with false for org/opensearch/sql/utils/SystemIndexUtils$SystemInfoTable::isSystemInfoTable → KILLED

117

1.1
Location : isMetaInfoTable
Killed by : org.opensearch.sql.utils.SystemIndexUtilsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.utils.SystemIndexUtilsTest]/[method:test_mapping_info_table_with_special_index_name()]
replaced boolean return with false for org/opensearch/sql/utils/SystemIndexUtils$MetaInfoTable::isMetaInfoTable → KILLED

Active mutators

Tests examined


Report generated by PIT 1.9.0