forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCrossClusterCoalesceIT.java
More file actions
68 lines (59 loc) · 2.26 KB
/
Copy pathCrossClusterCoalesceIT.java
File metadata and controls
68 lines (59 loc) · 2.26 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
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
package org.opensearch.sql.security;
import static org.opensearch.sql.util.MatcherUtils.columnName;
import static org.opensearch.sql.util.MatcherUtils.verifyColumn;
import java.io.IOException;
import org.json.JSONObject;
import org.junit.Test;
public class CrossClusterCoalesceIT extends CrossClusterTestBase {
@Override
protected void init() throws Exception {
super.init();
loadIndex(Index.DOG);
loadIndex(Index.DOG, remoteClient());
enableCalcite();
}
@Test
public void testCrossClusterCoalesceBasic() throws IOException {
JSONObject result =
executeQuery(
String.format(
"search source=%s | eval result = coalesce(holdersName, dog_name, 'unknown') |"
+ " fields dog_name, holdersName, result | head 1",
TEST_INDEX_DOG_REMOTE));
verifyColumn(result, columnName("dog_name"), columnName("holdersName"), columnName("result"));
}
@Test
public void testCrossClusterCoalesceMixedTypes() throws IOException {
JSONObject result =
executeQuery(
String.format(
"search source=%s | eval result = coalesce(age, holdersName, 'fallback') | fields"
+ " age, holdersName, result | head 1",
TEST_INDEX_DOG_REMOTE));
verifyColumn(result, columnName("age"), columnName("holdersName"), columnName("result"));
}
@Test
public void testCrossClusterCoalesceNonExistentFields() throws IOException {
JSONObject result =
executeQuery(
String.format(
"search source=%s | eval result = coalesce(missing_field, dog_name) | fields"
+ " dog_name, result | head 1",
TEST_INDEX_DOG_REMOTE));
verifyColumn(result, columnName("dog_name"), columnName("result"));
}
@Test
public void testCrossClusterCoalesceEmptyString() throws IOException {
JSONObject result =
executeQuery(
String.format(
"search source=%s | eval result = coalesce('', dog_name) | fields dog_name, result"
+ " | head 1",
TEST_INDEX_DOG_REMOTE));
verifyColumn(result, columnName("dog_name"), columnName("result"));
}
}