forked from xinyual/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCrossClusterSearchIT.java
More file actions
249 lines (225 loc) · 8.52 KB
/
Copy pathCrossClusterSearchIT.java
File metadata and controls
249 lines (225 loc) · 8.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
package org.opensearch.sql.security;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DOG;
import static org.opensearch.sql.util.MatcherUtils.columnName;
import static org.opensearch.sql.util.MatcherUtils.rows;
import static org.opensearch.sql.util.MatcherUtils.verifyColumn;
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows;
import java.io.IOException;
import lombok.SneakyThrows;
import org.json.JSONObject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.opensearch.client.ResponseException;
import org.opensearch.sql.ppl.PPLIntegTestCase;
/** Cross Cluster Search tests to be executed with security plugin. */
public class CrossClusterSearchIT extends PPLIntegTestCase {
static {
// find a remote cluster
String[] clusterNames = System.getProperty("cluster.names").split(",");
var remote = "remoteCluster";
for (var cluster : clusterNames) {
if (cluster.startsWith("remote")) {
remote = cluster;
break;
}
}
REMOTE_CLUSTER = remote;
}
public static final String REMOTE_CLUSTER;
private static final String TEST_INDEX_BANK_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_BANK;
private static final String TEST_INDEX_DOG_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_DOG;
private static final String TEST_INDEX_DOG_MATCH_ALL_REMOTE =
MATCH_ALL_REMOTE_CLUSTER + ":" + TEST_INDEX_DOG;
private static final String TEST_INDEX_ACCOUNT_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_ACCOUNT;
private static boolean initialized = false;
@SneakyThrows
@BeforeEach
public void initialize() {
if (!initialized) {
setUpIndices();
initialized = true;
}
}
@Override
protected void init() throws Exception {
configureMultiClusters(REMOTE_CLUSTER);
loadIndex(Index.BANK);
loadIndex(Index.BANK, remoteClient());
loadIndex(Index.DOG);
loadIndex(Index.DOG, remoteClient());
loadIndex(Index.ACCOUNT);
}
@Test
public void testCrossClusterSearchAllFields() throws IOException {
JSONObject result = executeQuery(String.format("search source=%s", TEST_INDEX_DOG_REMOTE));
verifyColumn(result, columnName("dog_name"), columnName("holdersName"), columnName("age"));
}
@Test
public void testMatchAllCrossClusterSearchAllFields() throws IOException {
JSONObject result =
executeQuery(String.format("search source=%s", TEST_INDEX_DOG_MATCH_ALL_REMOTE));
verifyColumn(result, columnName("dog_name"), columnName("holdersName"), columnName("age"));
}
@Test
public void testCrossClusterSearchWithoutLocalFieldMappingShouldFail() throws IOException {
var exception =
assertThrows(
ResponseException.class,
() -> executeQuery(String.format("search source=%s", TEST_INDEX_ACCOUNT_REMOTE)));
assertTrue(exception.getMessage().contains("IndexNotFoundException"));
}
@Test
public void testCrossClusterSearchCommandWithLogicalExpression() throws IOException {
JSONObject result =
executeQuery(
String.format(
"search source=%s firstname='Hattie' | fields firstname", TEST_INDEX_BANK_REMOTE));
verifyDataRows(result, rows("Hattie"));
}
@Test
public void testCrossClusterSearchMultiClusters() throws IOException {
JSONObject result =
executeQuery(
String.format(
"search source=%s,%s firstname='Hattie' | fields firstname",
TEST_INDEX_BANK_REMOTE, TEST_INDEX_BANK));
verifyDataRows(result, rows("Hattie"), rows("Hattie"));
}
@Test
public void testCrossClusterDescribeAllFields() throws IOException {
JSONObject result = executeQuery(String.format("describe %s", TEST_INDEX_DOG_REMOTE));
verifyColumn(
result,
columnName("TABLE_CAT"),
columnName("TABLE_SCHEM"),
columnName("TABLE_NAME"),
columnName("COLUMN_NAME"),
columnName("DATA_TYPE"),
columnName("TYPE_NAME"),
columnName("COLUMN_SIZE"),
columnName("BUFFER_LENGTH"),
columnName("DECIMAL_DIGITS"),
columnName("NUM_PREC_RADIX"),
columnName("NULLABLE"),
columnName("REMARKS"),
columnName("COLUMN_DEF"),
columnName("SQL_DATA_TYPE"),
columnName("SQL_DATETIME_SUB"),
columnName("CHAR_OCTET_LENGTH"),
columnName("ORDINAL_POSITION"),
columnName("IS_NULLABLE"),
columnName("SCOPE_CATALOG"),
columnName("SCOPE_SCHEMA"),
columnName("SCOPE_TABLE"),
columnName("SOURCE_DATA_TYPE"),
columnName("IS_AUTOINCREMENT"),
columnName("IS_GENERATEDCOLUMN"));
}
@Test
public void testMatchAllCrossClusterDescribeAllFields() throws IOException {
JSONObject result = executeQuery(String.format("describe %s", TEST_INDEX_DOG_MATCH_ALL_REMOTE));
verifyColumn(
result,
columnName("TABLE_CAT"),
columnName("TABLE_SCHEM"),
columnName("TABLE_NAME"),
columnName("COLUMN_NAME"),
columnName("DATA_TYPE"),
columnName("TYPE_NAME"),
columnName("COLUMN_SIZE"),
columnName("BUFFER_LENGTH"),
columnName("DECIMAL_DIGITS"),
columnName("NUM_PREC_RADIX"),
columnName("NULLABLE"),
columnName("REMARKS"),
columnName("COLUMN_DEF"),
columnName("SQL_DATA_TYPE"),
columnName("SQL_DATETIME_SUB"),
columnName("CHAR_OCTET_LENGTH"),
columnName("ORDINAL_POSITION"),
columnName("IS_NULLABLE"),
columnName("SCOPE_CATALOG"),
columnName("SCOPE_SCHEMA"),
columnName("SCOPE_TABLE"),
columnName("SOURCE_DATA_TYPE"),
columnName("IS_AUTOINCREMENT"),
columnName("IS_GENERATEDCOLUMN"));
}
@Test
public void testCrossClusterSortWithCount() throws IOException {
JSONObject result =
executeQuery(
String.format(
"search source=%s | sort 1 age | fields firstname, age", TEST_INDEX_BANK_REMOTE));
verifyDataRows(result, rows("Nanette", 28));
}
@Test
public void testCrossClusterSortWithDesc() throws IOException {
JSONObject result =
executeQuery(
String.format(
"search source=%s | sort age desc | fields firstname", TEST_INDEX_BANK_REMOTE));
verifyDataRows(
result,
rows("Virginia"),
rows("Hattie"),
rows("Elinor"),
rows("Dillard"),
rows("Dale"),
rows("Amber JOHnny"),
rows("Nanette"));
}
@Test
public void testCrossClusterSortWithTypeCasting() throws IOException {
JSONObject result =
executeQuery(
String.format(
"search source=%s | sort num(account_number) | fields account_number",
TEST_INDEX_BANK_REMOTE));
verifyDataRows(result, rows(1), rows(6), rows(13), rows(18), rows(20), rows(25), rows(32));
}
@Test
public void testCrossClusterPercentileShortcuts() throws IOException {
JSONObject result =
executeQuery(
String.format(
"search source=%s | stats perc50(balance), p95(balance)", TEST_INDEX_BANK_REMOTE));
verifyColumn(result, columnName("perc50(balance)"), columnName("p95(balance)"));
}
@Test
public void testCrossClusterMultiMatchWithoutFields() throws IOException {
// Test multi_match without fields parameter on remote cluster
JSONObject result =
executeQuery(
String.format(
"search source=%s | where multi_match('Hattie') | fields firstname",
TEST_INDEX_BANK_REMOTE));
verifyDataRows(result, rows("Hattie"));
}
@Test
public void testCrossClusterSimpleQueryStringWithoutFields() throws IOException {
// Test simple_query_string without fields parameter on remote cluster
JSONObject result =
executeQuery(
String.format(
"search source=%s | where simple_query_string('Hattie') | fields firstname",
TEST_INDEX_BANK_REMOTE));
verifyDataRows(result, rows("Hattie"));
}
@Test
public void testCrossClusterQueryStringWithoutFields() throws IOException {
// Test query_string without fields parameter on remote cluster
JSONObject result =
executeQuery(
String.format(
"search source=%s | where query_string('Hattie') | fields firstname",
TEST_INDEX_BANK_REMOTE));
verifyDataRows(result, rows("Hattie"));
}
}