Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL: Add ability to perform CCS through SQL querying #78903

Merged
merged 18 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add metadata test and fix expected output of other
Add getClusters() metadata test.
Adjust expected output of other 'SHOW TABLES' tests.
  • Loading branch information
bpintea committed Oct 11, 2021
commit b6cf6782a4f858fd00ac4b1563c3ca78733cf740
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ dependencies {

def remoteClusterReg = testClusters.register('remote-cluster') {
testDistribution = 'DEFAULT'
// numberOfNodes = 2
setting 'node.roles', '[data,ingest,master]'
setting 'xpack.ml.enabled', 'false'
setting 'xpack.watcher.enabled', 'false'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.sql.qa.multi_cluster_with_security;

import org.elasticsearch.xpack.sql.qa.jdbc.JdbcIntegrationTestCase;

import java.sql.Connection;
import java.sql.ResultSet;

public class JdbcMetadataIT extends JdbcIntegrationTestCase {

// gradle defines
public static final String LOCAL_CLUSTER_NAME = "integTest";
public static final String REMOTE_CLUSTER_NAME = "my_remote_cluster";

@AwaitsFix(bugUrl = "foo")
bpintea marked this conversation as resolved.
Show resolved Hide resolved
public void testJdbcGetClusters() throws Exception {
try (Connection es = esJdbc()) {
ResultSet rs = es.getMetaData().getCatalogs();
assertEquals(1, rs.getMetaData().getColumnCount());
assertTrue(rs.next());
assertEquals(LOCAL_CLUSTER_NAME, rs.getString(1));
assertTrue(rs.next());
assertEquals(REMOTE_CLUSTER_NAME, rs.getString(1));
assertFalse(rs.next());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,19 @@ public void expectDescribe(Map<String, List<String>> columns, String user) throw
public void expectShowTables(List<String> tables, String user) throws Exception {
try (EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), true, userSecurity(user))) {
String tablesOutput = cli.command("SHOW TABLES");
assertThat(tablesOutput, containsString("catalog"));
assertThat(tablesOutput, containsString("name"));
assertThat(tablesOutput, containsString("type"));
assertThat(tablesOutput, containsString("kind"));
assertEquals("---------------+---------------+---------------", cli.readLine());
assertEquals("---------------+---------------+---------------+---------------", cli.readLine());
for (String table : tables) {
String line = null;
/*
* Security automatically creates either a `.security` or a
* `.security6` index but it might not have created the index
* by the time the test runs.
*/
while (line == null || line.startsWith(".security")) {
while (line == null || line.contains("|.security")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change if the comment says ".security" or ".security6"? Either leave it as is, or do also change the comment, because there is a slight contradiction now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHOW TABLES will now have as first column the catalog and the table will be second. So for both .security and .security6 indices, the listing will no longer startWith() that value, but the line will contain a |.security (and/or |.security6).

line = cli.readLine();
}
assertThat(line, containsString(table));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public void expectDescribe(Map<String, List<String>> columns, String user) throw
public void expectShowTables(List<String> tables, String user) throws Exception {
String mode = randomMode();
List<Object> columns = new ArrayList<>();
columns.add(columnInfo(mode, "catalog", "keyword", JDBCType.VARCHAR, 32766));
columns.add(columnInfo(mode, "name", "keyword", JDBCType.VARCHAR, 32766));
columns.add(columnInfo(mode, "type", "keyword", JDBCType.VARCHAR, 32766));
columns.add(columnInfo(mode, "kind", "keyword", JDBCType.VARCHAR, 32766));
Expand All @@ -151,6 +152,7 @@ public void expectShowTables(List<String> tables, String user) throws Exception
List<List<String>> rows = new ArrayList<>();
for (String table : tables) {
List<String> fields = new ArrayList<>();
fields.add("integTest"); // gradle defined
fields.add(table);
fields.add("TABLE");
fields.add("INDEX");
Expand All @@ -167,7 +169,7 @@ public void expectShowTables(List<String> tables, String user) throws Exception
*/
@SuppressWarnings("unchecked")
List<List<String>> rowsNoSecurity = ((List<List<String>>) actual.get("rows")).stream()
.filter(ls -> ls.get(0).startsWith(".security") == false)
.filter(ls -> ls.get(1).startsWith(".security") == false)
.collect(Collectors.toList());
actual.put("rows", rowsNoSecurity);
assertResponse(expected, actual);
Expand Down