Skip to content

Commit

Permalink
feat: allow "*:index" to match all remote clusters
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Kao <[email protected]>
  • Loading branch information
seankao-az committed Apr 24, 2023
1 parent 78f895e commit 38f4a15
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public abstract class OpenSearchMultiClustersRestTestCase extends OpenSearchRestTestCase {

public static final String REMOTE_CLUSTER = "remoteCluster";
public static final String MATCH_ALL_REMOTE_CLUSTER = "*";

private static RestClient remoteClient;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class CrossClusterSearchIT extends PPLIntegTestCase {

private final static String TEST_INDEX_BANK_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_BANK;
private final static String TEST_INDEX_DOG_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_DOG;
private final static String TEST_INDEX_DOG_MATCH_ALL_REMOTE = MATCH_ALL_REMOTE_CLUSTER + ":" + TEST_INDEX_DOG;

@Override
public void init() throws IOException {
Expand All @@ -37,6 +38,12 @@ public void testCrossClusterSearchAllFields() throws IOException {
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 testCrossClusterSearchCommandWithLogicalExpression() throws IOException {
JSONObject result = executeQuery(String.format(
Expand All @@ -52,4 +59,68 @@ public void testCrossClusterSearchMultiClusters() throws IOException {
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")
);
}
}
7 changes: 6 additions & 1 deletion ppl/src/main/antlr/OpenSearchPPLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ qualifiedName
;

clusterQualifiedName
: ident COLON ident (DOT ident)*
: clusterIdent COLON ident (DOT ident)*
;

wcQualifiedName
Expand All @@ -739,6 +739,11 @@ ident
| keywordsCanBeId
;

clusterIdent
: ident
| STAR
;

wildcard
: ident (MODULE ident)* (MODULE)?
| SINGLE_QUOTE wildcard SINGLE_QUOTE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public void testSearchCommandCrossClusterShouldPass() {
assertNotEquals(null, tree);
}

@Test
public void testSearchCommandMatchAllCrossClusterShouldPass() {
ParseTree tree = new PPLSyntaxParser().parse("search source=*:t a=1 b=2");
assertNotEquals(null, tree);
}

@Test
public void testSearchCommandCrossClusterWithMultipleIndicesShouldPass() {
ParseTree tree = new PPLSyntaxParser().parse("search source=c:t,d:u,v a=1 b=2");
Expand Down Expand Up @@ -225,6 +231,12 @@ public void testDescribeCommandCrossClusterShouldPass() {
assertNotEquals(null, tree);
}

@Test
public void testDescribeCommandMatchAllCrossClusterShouldPass() {
ParseTree tree = new PPLSyntaxParser().parse("describe *:t");
assertNotEquals(null, tree);
}

@Test
public void testDescribeFieldsCommandShouldPass() {
ParseTree tree = new PPLSyntaxParser().parse("describe t | fields a,b");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ public void testSearchCrossClusterCommand() {
);
}

@Test
public void testSearchMatchAllCrossClusterCommand() {
assertEqual("search source=*:t",
relation(qualifiedName("*:t"))
);
}

@Test
public void testPrometheusSearchCommand() {
assertEqual("search source = prometheus.http_requests_total",
Expand Down Expand Up @@ -743,6 +750,12 @@ public void testDescribeCommand() {
relation(mappingTable("t")));
}

@Test
public void testDescribeMatchAllCrossClusterSearchCommand() {
assertEqual("describe *:t",
relation(mappingTable("*:t")));
}

@Test
public void testDescribeCommandWithMultipleIndices() {
assertEqual("describe t,u",
Expand Down

0 comments on commit 38f4a15

Please sign in to comment.