8
8
import lombok .Getter ;
9
9
import lombok .RequiredArgsConstructor ;
10
10
import lombok .experimental .UtilityClass ;
11
+ import org .opensearch .sql .lang .LangSpec ;
11
12
12
13
/** System Index Utils. Todo. Find the better name for this class. */
13
14
@ UtilityClass
@@ -39,7 +40,47 @@ public static Boolean isSystemIndex(String indexName) {
39
40
* @return system mapping table.
40
41
*/
41
42
public static String mappingTable (String indexName ) {
42
- return String .join ("." , indexName , SYS_MAPPINGS_SUFFIX );
43
+ return mappingTable (indexName , LangSpec .SQL_SPEC );
44
+ }
45
+
46
+ public static String mappingTable (String indexName , LangSpec langSpec ) {
47
+
48
+ return String .join ("." , indexName , encodeLangSpec (langSpec ));
49
+ }
50
+
51
+ /**
52
+ * Encodes the language specification into a system mappings suffix.
53
+ *
54
+ * <p>The returned suffix is composed of the language name (e.g., "SQL" or "PPL") concatenated
55
+ * with an underscore and the system mappings suffix constant. For example:
56
+ * "SQL_MAPPINGS_ODFE_SYS_TABLE".
57
+ *
58
+ * @param spec the language specification.
59
+ * @return the encoded system mappings suffix.
60
+ */
61
+ public static String encodeLangSpec (LangSpec spec ) {
62
+ return spec .language ().name () + "_" + SYS_MAPPINGS_SUFFIX ;
63
+ }
64
+
65
+ /**
66
+ * Extracts the language specification from a given system mappings suffix.
67
+ *
68
+ * <p>This method expects the suffix to start with the language name followed by an underscore.
69
+ * For example, given "SQL_MAPPINGS_ODFE_SYS_TABLE", it extracts "SQL" and returns the
70
+ * corresponding language specification via {@link LangSpec#fromLanguage(String)}. If the expected
71
+ * format is not met, the default SQL specification is returned.
72
+ *
73
+ * @param systemMappingsSuffix the system mappings suffix.
74
+ * @return the language specification extracted from the suffix, or {@link LangSpec#SQL_SPEC} if
75
+ * the format is invalid.
76
+ */
77
+ public static LangSpec extractLangSpec (String systemMappingsSuffix ) {
78
+ int underscoreIndex = systemMappingsSuffix .indexOf ('_' );
79
+ if (underscoreIndex <= 0 ) {
80
+ return LangSpec .SQL_SPEC ;
81
+ }
82
+ String langName = systemMappingsSuffix .substring (0 , underscoreIndex );
83
+ return LangSpec .fromLanguage (langName );
43
84
}
44
85
45
86
/**
@@ -52,10 +93,10 @@ public static SystemTable systemTable(String indexName) {
52
93
String suffix = indexName .substring (lastDot + 1 );
53
94
String tableName = indexName .substring (0 , lastDot ).replace ("%" , "*" );
54
95
55
- if (suffix .equalsIgnoreCase (SYS_META_SUFFIX )) {
96
+ if (suffix .endsWith (SYS_META_SUFFIX )) {
56
97
return new SystemInfoTable (tableName );
57
- } else if (suffix .equalsIgnoreCase (SYS_MAPPINGS_SUFFIX )) {
58
- return new MetaInfoTable (tableName );
98
+ } else if (suffix .endsWith (SYS_MAPPINGS_SUFFIX )) {
99
+ return new MetaInfoTable (tableName , extractLangSpec ( suffix ) );
59
100
} else {
60
101
throw new IllegalStateException ("Invalid system index name: " + indexName );
61
102
}
@@ -66,6 +107,10 @@ public interface SystemTable {
66
107
67
108
String getTableName ();
68
109
110
+ default LangSpec getLangSpec () {
111
+ return LangSpec .SQL_SPEC ;
112
+ }
113
+
69
114
default boolean isSystemInfoTable () {
70
115
return false ;
71
116
}
@@ -93,6 +138,7 @@ public boolean isSystemInfoTable() {
93
138
public static class MetaInfoTable implements SystemTable {
94
139
95
140
private final String tableName ;
141
+ private final LangSpec langSpec ;
96
142
97
143
public boolean isMetaInfoTable () {
98
144
return true ;
0 commit comments