|
11 | 11 | import static org.junit.Assert.assertTrue; |
12 | 12 | import static org.opensearch.sql.common.setting.Settings.Key.*; |
13 | 13 |
|
| 14 | +import java.util.HashMap; |
| 15 | +import java.util.List; |
| 16 | +import java.util.Map; |
14 | 17 | import org.junit.Test; |
15 | 18 | import org.opensearch.sql.calcite.SysLimit; |
| 19 | +import org.opensearch.sql.common.setting.Settings; |
16 | 20 | import org.opensearch.sql.executor.QueryType; |
17 | 21 |
|
18 | 22 | public class UnifiedQueryContextTest extends UnifiedQueryTestBase { |
@@ -83,6 +87,99 @@ public void testInvalidDefaultNamespace() { |
83 | 87 | .build(); |
84 | 88 | } |
85 | 89 |
|
| 90 | + @Test |
| 91 | + public void testLiveSettingsBridgeRespectsClusterRexMaxMatchLimit() { |
| 92 | + // When the operator has set plugins.ppl.rex.max_match.limit on the cluster, |
| 93 | + // UnifiedQueryContext should return that value, not the hardcoded 10. |
| 94 | + Settings live = stubSettings(Map.of(PPL_REX_MAX_MATCH_LIMIT, 5)); |
| 95 | + |
| 96 | + UnifiedQueryContext context = |
| 97 | + UnifiedQueryContext.builder() |
| 98 | + .language(QueryType.PPL) |
| 99 | + .catalog("opensearch", testSchema) |
| 100 | + .settings(live) |
| 101 | + .build(); |
| 102 | + |
| 103 | + assertEquals( |
| 104 | + "Cluster override should win over the static default", |
| 105 | + Integer.valueOf(5), |
| 106 | + context.getSettings().getSettingValue(PPL_REX_MAX_MATCH_LIMIT)); |
| 107 | + } |
| 108 | + |
| 109 | + @Test |
| 110 | + public void testLiveSettingsAbsentFallsBackToStaticDefault() { |
| 111 | + // No liveSettings injected — the static default (10) wins. Confirms the |
| 112 | + // pre-bridge behavior is preserved when the REST handler doesn't supply a |
| 113 | + // live Settings instance (e.g. in test paths that build the context directly). |
| 114 | + UnifiedQueryContext context = |
| 115 | + UnifiedQueryContext.builder() |
| 116 | + .language(QueryType.PPL) |
| 117 | + .catalog("opensearch", testSchema) |
| 118 | + .build(); |
| 119 | + |
| 120 | + assertEquals( |
| 121 | + "Static default of 10 should win when no liveSettings are injected", |
| 122 | + Integer.valueOf(10), |
| 123 | + context.getSettings().getSettingValue(PPL_REX_MAX_MATCH_LIMIT)); |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + public void testLiveSettingsNullValueFallsBackToStaticDefault() { |
| 128 | + // liveSettings injected, but getSettingValue returns null for the rex key |
| 129 | + // (i.e. the operator has not set a cluster-side override). Static default (10) |
| 130 | + // should still win — pins the {@code != null} guard in build(). |
| 131 | + Settings live = stubSettings(new HashMap<>()); |
| 132 | + |
| 133 | + UnifiedQueryContext context = |
| 134 | + UnifiedQueryContext.builder() |
| 135 | + .language(QueryType.PPL) |
| 136 | + .catalog("opensearch", testSchema) |
| 137 | + .settings(live) |
| 138 | + .build(); |
| 139 | + |
| 140 | + assertEquals( |
| 141 | + "Static default of 10 should win when liveSettings has no override", |
| 142 | + Integer.valueOf(10), |
| 143 | + context.getSettings().getSettingValue(PPL_REX_MAX_MATCH_LIMIT)); |
| 144 | + } |
| 145 | + |
| 146 | + @Test |
| 147 | + public void testLiveSettingsDoNotBridgeOtherKeys() { |
| 148 | + // Pins the rex-only scoping decision: a cluster override for QUERY_SIZE_LIMIT |
| 149 | + // (or any other key in the static map) is intentionally NOT picked up by |
| 150 | + // liveSettings. Widening the snapshot is a future scope decision; this test |
| 151 | + // surfaces accidental scope creep as a hard failure. |
| 152 | + Settings live = stubSettings(Map.of(QUERY_SIZE_LIMIT, 999)); |
| 153 | + |
| 154 | + UnifiedQueryContext context = |
| 155 | + UnifiedQueryContext.builder() |
| 156 | + .language(QueryType.PPL) |
| 157 | + .catalog("opensearch", testSchema) |
| 158 | + .settings(live) |
| 159 | + .build(); |
| 160 | + |
| 161 | + assertEquals( |
| 162 | + "Static default for QUERY_SIZE_LIMIT should win — bridge is rex-only", |
| 163 | + Integer.valueOf(SysLimit.DEFAULT.querySizeLimit()), |
| 164 | + context.getSettings().getSettingValue(QUERY_SIZE_LIMIT)); |
| 165 | + } |
| 166 | + |
| 167 | + /** Minimal Settings stub: returns values from the supplied map; null for any other key. */ |
| 168 | + private static Settings stubSettings(Map<Settings.Key, Object> values) { |
| 169 | + return new Settings() { |
| 170 | + @Override |
| 171 | + @SuppressWarnings("unchecked") |
| 172 | + public <T> T getSettingValue(Key key) { |
| 173 | + return (T) values.get(key); |
| 174 | + } |
| 175 | + |
| 176 | + @Override |
| 177 | + public List<?> getSettings() { |
| 178 | + return List.copyOf(values.entrySet()); |
| 179 | + } |
| 180 | + }; |
| 181 | + } |
| 182 | + |
86 | 183 | @Test |
87 | 184 | public void testContextClose() throws Exception { |
88 | 185 | // Create a separate context for this test to avoid affecting other tests |
|
0 commit comments